]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - js/userdesign.go.js
Merge branch '0.8.x' of git@gitorious.org:laconica/mainline into 0.8.x
[quix0rs-gnu-social.git] / js / userdesign.go.js
1 /** Init for Farbtastic library and page setup
2  *
3  * @package   Laconica
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/
8  */
9 $(document).ready(function() {
10     function InitColors(i, E) {
11         switch (parseInt(E.id.slice(-1))) {
12             case 1: default:
13                 $(E).val(rgb2hex($('body').css('background-color')));
14                 break;
15             case 2:
16                 $(E).val(rgb2hex($('#content').css('background-color')));
17                 break;
18             case 3:
19                 $(E).val(rgb2hex($('#aside_primary').css('background-color')));
20                 break;
21             case 4:
22                 $(E).val(rgb2hex($('html body').css('color')));
23                 break;
24             case 5:
25                 $(E).val(rgb2hex($('a').css('color')));
26                 break;
27         }
28     }
29
30     /* rgb2hex written by R0bb13 <robertorebollo@gmail.com> */
31     function rgb2hex(rgb) {
32         rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
33         function hex(x) {
34             hexDigits = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
35             return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
36         }
37         return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
38     }
39
40     function UpdateColors(S) {
41         C = $(S).val();
42         switch (parseInt(S.id.slice(-1))) {
43             case 1: default:
44                 $('body').css({'background-color':C});
45                 break;
46             case 2:
47                 $('#content, #site_nav_local_views .current a').css({'background-color':C});
48                 break;
49             case 3:
50                 $('#aside_primary').css({'background-color':C});
51                 break;
52             case 4:
53                 $('html body').css({'color':C});
54                 break;
55             case 5:
56                 $('a').css({'color':C});
57                 break;
58         }
59     }
60
61     function UpdateFarbtastic(e) {
62         f.linked = e;
63         f.setColor(e.value);
64     }
65
66     function UpdateSwatch(e) {
67         $(e).css({"background-color": e.value,
68                   "color": f.hsl[2] > 0.5 ? "#000": "#fff"});
69     }
70
71     function SynchColors(e) {
72         var S = f.linked;
73         var C = f.color;
74
75         if (S && S.value && S.value != C) {
76             S.value = C;
77             UpdateSwatch(S);
78             UpdateColors(S);
79         }
80     }
81
82     function InitFarbtastic() {
83         $('#settings_design_color').append('<div id="color-picker"></div>');
84         $('#color-picker').hide();
85
86         f = $.farbtastic('#color-picker', SynchColors);
87         swatches = $('#settings_design_color .swatch');
88         swatches.each(InitColors);
89         swatches
90             .each(SynchColors)
91             .blur(function() {
92                 tv = $(this).val();
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]) : '') : '';
95              })
96             .focus(function() {
97                 $('#color-picker').show();
98                 UpdateFarbtastic(this);
99             })
100             .change(function() {
101                 UpdateFarbtastic(this);
102                 UpdateSwatch(this);
103                 UpdateColors(this);
104             }).change();
105     }
106
107     var f, swatches;
108     InitFarbtastic();
109     $('#form_settings_design').bind('reset', function(){
110         setTimeout(function(){
111             swatches.each(function(){UpdateColors(this);});
112             $('#color-picker').remove();
113             swatches.unbind();
114             InitFarbtastic();
115         },10);
116     });
117
118     $('#design_background-image_off').focus(function() {
119         $('body').css({'background-image':'none'});
120     });
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'});
124     });
125
126     $('#design_background-image_repeat').click(function() {
127         ($(this)[0].checked) ? $('body').css({'background-repeat':'repeat'}) : $('body').css({'background-repeat':'no-repeat'});
128     });
129 });