]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - js/farbtastic/farbtastic.go.js
Merge branch '0.8.x' of git@gitorious.org:laconica/dev into 0.8.x
[quix0rs-gnu-social.git] / js / farbtastic / farbtastic.go.js
1 $(document).ready(function() {
2     function UpdateColors(S) {
3         C = $(S).val();
4         switch (parseInt(S.id.slice(-1))) {
5             case 0: default:
6                 $('body').css({'background-color':C});
7                 break;
8             case 1:
9                 $('#content').css({'background-color':C});
10                 break;
11             case 2:
12                 $('#aside_primary').css({'background-color':C});
13                 break;
14             case 3:
15                 $('body').css({'color':C});
16                 break;
17             case 4:
18                 $('a').css({'color':C});
19                 break;
20         }
21     }
22
23     function UpdateFarbtastic(e) {
24         f.linked = e;
25         f.setColor(e.value);
26     }
27
28     function UpdateSwatch(e) {
29         $(e).css({"background-color": e.value,
30                   "color": f.hsl[2] > 0.5 ? "#000": "#fff"});
31     }
32
33     function SynchColors(e) {
34         var S = f.linked;
35         var C = f.color;
36
37         if (S && S.value && S.value != C) {
38             S.value = C;
39             UpdateSwatch(S);
40             UpdateColors(S);
41         }
42     }
43
44     function Init() {
45         $('#settings_design_color').append('<div id="color-picker"></div>');
46         $('#color-picker').hide();
47
48         f = $.farbtastic('#color-picker', SynchColors);
49         swatches = $('#settings_design_color .swatch');
50
51         swatches
52             .each(SynchColors)
53             .blur(function() {
54                 $(this).val($(this).val().toUpperCase());
55              })
56             .focus(function() {
57                 $('#color-picker').show();
58                 UpdateFarbtastic(this);
59             })
60             .change(function() {
61                 UpdateFarbtastic(this);
62                 UpdateSwatch(this);
63                 UpdateColors(this);
64             }).change();
65     }
66
67     var f, swatches;
68     Init();
69     $('#form_settings_design').bind('reset', function(){
70         setTimeout(function(){
71             swatches.each(function(){UpdateColors(this);});
72             $('#color-picker').remove();
73             swatches.unbind();
74             Init();
75         },10);
76     });
77 });