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 /* rgb2hex written by R0bb13 <robertorebollo@gmail.com> */
31 function rgb2hex(rgb) {
32 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
33 return '#' + dec2hex(rgb[1]) + dec2hex(rgb[2]) + dec2hex(rgb[3]);
36 hexDigits = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
37 return isNaN(x) ? '00' : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
40 function UpdateColors(S) {
42 switch (parseInt(S.id.slice(-1))) {
44 $('body').css({'background-color':C});
47 $('#content, #site_nav_local_views .current a').css({'background-color':C});
50 $('#aside_primary').css({'background-color':C});
53 $('html body').css({'color':C});
56 $('a').css({'color':C});
61 function UpdateFarbtastic(e) {
66 function UpdateSwatch(e) {
67 $(e).css({"background-color": e.value,
68 "color": f.hsl[2] > 0.5 ? "#000": "#fff"});
71 function SynchColors(e) {
75 if (S && S.value && S.value != C) {
82 function InitFarbtastic() {
83 $('#settings_design_color').append('<div id="color-picker"></div>');
84 $('#color-picker').hide();
86 f = $.farbtastic('#color-picker', SynchColors);
87 swatches = $('#settings_design_color .swatch');
88 swatches.each(InitColors);
93 $(this).val(tv.toUpperCase());
94 (tv.length == 4) ? ((tv[0] == '#') ? $(this).val('#'+tv[1]+tv[1]+tv[2]+tv[2]+tv[3]+tv[3]) : '') : '';
97 $('#color-picker').show();
98 UpdateFarbtastic(this);
101 UpdateFarbtastic(this);
109 $('#form_settings_design').bind('reset', function(){
110 setTimeout(function(){
111 swatches.each(function(){UpdateColors(this);});
112 $('#color-picker').remove();
118 $('#design_background-image_off').focus(function() {
119 $('body').css({'background-image':'none'});
121 $('#design_background-image_on').focus(function() {
122 $('body').css({'background-image':'url('+$('#design_background-image_onoff img')[0].src+')'});
123 $('body').css({'background-attachment': 'fixed'});
126 $('#design_background-image_repeat').click(function() {
127 ($(this)[0].checked) ? $('body').css({'background-repeat':'repeat'}) : $('body').css({'background-repeat':'no-repeat'});