1 /** Init for Farbtastic library and page setup
4 * @author Sarven Capadisli <csarven@controlyourself.ca>
5 * @copyright 2009 Control Yourself, Inc.
6 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
7 * @link http://laconi.ca/
9 $(document).ready(function() {
10 function InitColors(i, E) {
11 switch (parseInt(E.id.slice(-1))) {
13 $(E).val(rgb2hex($('body').css('background-color')));
16 $(E).val(rgb2hex($('#content').css('background-color')));
19 $(E).val(rgb2hex($('#aside_primary').css('background-color')));
22 $(E).val(rgb2hex($('html body').css('color')));
25 $(E).val(rgb2hex($('a').css('color')));
30 function rgb2hex(rgb) {
31 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
33 hexDigits = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
34 return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
36 return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
39 function UpdateColors(S) {
41 switch (parseInt(S.id.slice(-1))) {
43 $('body').css({'background-color':C});
46 $('#content, #site_nav_local_views .current a').css({'background-color':C});
49 $('#aside_primary').css({'background-color':C});
52 $('html body').css({'color':C});
55 $('a').css({'color':C});
60 function UpdateFarbtastic(e) {
65 function UpdateSwatch(e) {
66 $(e).css({"background-color": e.value,
67 "color": f.hsl[2] > 0.5 ? "#000": "#fff"});
70 function SynchColors(e) {
74 if (S && S.value && S.value != C) {
81 function InitFarbtastic() {
82 $('#settings_design_color').append('<div id="color-picker"></div>');
83 $('#color-picker').hide();
85 f = $.farbtastic('#color-picker', SynchColors);
86 swatches = $('#settings_design_color .swatch');
87 swatches.each(InitColors);
92 $(this).val(tv.toUpperCase());
93 (tv.length == 4) ? ((tv[0] == '#') ? $(this).val('#'+tv[1]+tv[1]+tv[2]+tv[2]+tv[3]+tv[3]) : '') : '';
96 $('#color-picker').show();
97 UpdateFarbtastic(this);
100 UpdateFarbtastic(this);
108 $('#form_settings_design').bind('reset', function(){
109 setTimeout(function(){
110 swatches.each(function(){UpdateColors(this);});
111 $('#color-picker').remove();
117 $('#design_background-image_off').focus(function() {
118 $('body').css({'background-image':'none'});
120 $('#design_background-image_on').focus(function() {
121 $('body').css({'background-image':'url('+$('#design_background-image_onoff img')[0].src+')'});
122 $('body').css({'background-attachment': 'fixed'});
125 $('#design_background-image_repeat').click(function() {
126 ($(this)[0].checked) ? $('body').css({'background-repeat':'repeat'}) : $('body').css({'background-repeat':'no-repeat'});