1 /** Init for Farbtastic library and page setup
4 * @author Sarven Capadisli <csarven@status.net>
5 * @copyright 2009 StatusNet, Inc.
6 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
7 * @link http://status.net/
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 if (rgb.slice(0,1) == '#') { return rgb; }
32 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
33 return '#' + dec2hex(rgb[1]) + dec2hex(rgb[2]) + dec2hex(rgb[3]);
35 /* dec2hex written by R0bb13 <robertorebollo@gmail.com> */
37 hexDigits = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
38 return isNaN(x) ? '00' : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
41 function UpdateColors(S) {
43 switch (parseInt(S.id.slice(-1))) {
45 $('body').css({'background-color':C});
48 $('#content, #site_nav_local_views .current a').css({'background-color':C});
51 $('#aside_primary').css({'background-color':C});
54 $('html body').css({'color':C});
57 $('a').css({'color':C});
62 function UpdateFarbtastic(e) {
67 function UpdateSwatch(e) {
68 $(e).css({"background-color": e.value,
69 "color": f.hsl[2] > 0.5 ? "#000": "#fff"});
72 function SynchColors(e) {
76 if (S && S.value && S.value != C) {
83 function InitFarbtastic() {
84 $('#settings_design_color').append('<div id="color-picker"></div>');
85 $('#color-picker').hide();
87 f = $.farbtastic('#color-picker', SynchColors);
88 swatches = $('#settings_design_color .swatch');
89 swatches.each(InitColors);
94 $(this).val(tv.toUpperCase());
95 (tv.length == 4) ? ((tv[0] == '#') ? $(this).val('#'+tv[1]+tv[1]+tv[2]+tv[2]+tv[3]+tv[3]) : '') : '';
98 $('#color-picker').show();
99 UpdateFarbtastic(this);
102 UpdateFarbtastic(this);
110 $('#form_settings_design').bind('reset', function(){
111 setTimeout(function(){
112 swatches.each(function(){UpdateColors(this);});
113 $('#color-picker').remove();
119 $('#design_background-image_off').focus(function() {
120 $('body').css({'background-image':'none'});
122 $('#design_background-image_on').focus(function() {
123 $('body').css({'background-image':'url('+$('#design_background-image_onoff img')[0].src+')'});
124 $('body').css({'background-attachment': 'fixed'});
127 $('#design_background-image_repeat').click(function() {
128 ($(this)[0].checked) ? $('body').css({'background-repeat':'repeat'}) : $('body').css({'background-repeat':'no-repeat'});