]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - js/userdesign.go.js
Merge branch '0.8.x' into small-fixes
[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 UpdateColors(S) {
11         C = $(S).val();
12         switch (parseInt(S.id.slice(-1))) {
13             case 1: default:
14                 $('html, body').css({'background-color':C});
15                 break;
16             case 2:
17                 $('#content, #site_nav_local_views .current a').css({'background-color':C});
18                 break;
19             case 3:
20                 $('#aside_primary').css({'background-color':C});
21                 break;
22             case 4:
23                 $('html body').css({'color':C});
24                 break;
25             case 5:
26                 $('a').css({'color':C});
27                 break;
28         }
29     }
30
31     function UpdateFarbtastic(e) {
32         f.linked = e;
33         f.setColor(e.value);
34     }
35
36     function UpdateSwatch(e) {
37         $(e).css({"background-color": e.value,
38                   "color": f.hsl[2] > 0.5 ? "#000": "#fff"});
39     }
40
41     function SynchColors(e) {
42         var S = f.linked;
43         var C = f.color;
44
45         if (S && S.value && S.value != C) {
46             S.value = C;
47             UpdateSwatch(S);
48             UpdateColors(S);
49         }
50     }
51
52     function InitFarbtastic() {
53         $('#settings_design_color').append('<div id="color-picker"></div>');
54         $('#color-picker').hide();
55
56         f = $.farbtastic('#color-picker', SynchColors);
57         swatches = $('#settings_design_color .swatch');
58
59         swatches
60             .each(SynchColors)
61             .blur(function() {
62                 tv = $(this).val();
63                 $(this).val(tv.toUpperCase());
64                 (tv.length == 4) ? ((tv[0] == '#') ? $(this).val('#'+tv[1]+tv[1]+tv[2]+tv[2]+tv[3]+tv[3]) : '') : '';
65              })
66             .focus(function() {
67                 $('#color-picker').show();
68                 UpdateFarbtastic(this);
69             })
70             .change(function() {
71                 UpdateFarbtastic(this);
72                 UpdateSwatch(this);
73                 UpdateColors(this);
74             }).change();
75     }
76
77     var f, swatches;
78     InitFarbtastic();
79     $('#form_settings_design').bind('reset', function(){
80         setTimeout(function(){
81             swatches.each(function(){UpdateColors(this);});
82             $('#color-picker').remove();
83             swatches.unbind();
84             InitFarbtastic();
85         },10);
86     });
87
88     $('#design_background-image_off').focus(function() {
89         $('body').css({'background-image':'none'});
90     });
91     $('#design_background-image_on').focus(function() {
92         var bis = $('#design_background-image_onoff img')[0].src;
93         $('body').css({'background-image':'url('+bis+')'});
94     });
95
96     $('#design_background-image_repeat').click(function() {
97         ($(this)[0].checked) ? $('body').css({'background-repeat':'repeat'}) : $('body').css({'background-repeat':'no-repeat'});
98     });
99 });