Dotclear

source: admin/js/color-picker.js @ 391:77ce8f145513

Revision 391:77ce8f145513, 1.9 KB checked in by kozlika, 14 years ago (diff)

Ductile, bugfix for colorpicker. Workaround on colorpicker.js with an old bug. Needs javascript sorcerer.

(La ligne 38 ne fonctionne pas comme elle le devrait.)

Line 
1$(function() {
2     $('.colorpicker').colorPicker();
3});
4
5jQuery.fn.colorPicker = function() {
6     $(this).each(function() {
7          var colbox, f;
8          var colbox = $('#jquery-colorpicker')[0];
9         
10          if (colbox == undefined) {
11               colbox = document.createElement('div');
12               colbox.id = 'jquery-colorpicker';
13               colbox.linkedto = null;
14               
15               $(colbox).css({border: '1px solid #000', width: '195px', background: '#fff', position: 'absolute'});
16               $(colbox).css({display: 'none'});
17               $('body').append(colbox);
18          }
19          f = $.farbtastic(colbox);
20          f.linkTo(this);
21         
22          var handler = $(document.createElement('img'));
23          handler.attr('src','images/picker.png');
24          handler.attr('alt','');
25         
26          var span = $(document.createElement('span'));
27         
28          if ($(this).css('position') == 'absolute') {
29               span.css('position','absolute');
30               span.css('top',$(this).css('top'));
31               span.css('left',$(this).css('left'));
32               $(this).css('position','static');
33          } else {
34               span.css('position','relative');
35          }
36          span.css('display','block');
37         
38          //span.css('width',($(this).width()+12)+'px');
39          span.css('width',($(this).width()+7.5)+'em');
40          span.css('padding','0 5px 0 0');
41          $(this).wrap(span);
42          $(this).after(handler);
43         
44          var offset = $(this).offset();
45          handler.css({
46               position: 'absolute',
47               top: 3,
48               //right: 0
49          });
50         
51          handler.css({cursor: 'default'});
52         
53          var This = this;
54          handler.click(function() {
55               if ($(colbox).css('display') == 'none' || this != colbox.linkedto) {
56                    f.linkTo(This);
57                    This.focus();
58                    var offset = $(This).offset();
59                    $(colbox).css({
60                         zIndex: 1000,
61                         top: offset.top + $(this).height() + 5,
62                         left: offset.left
63                    });
64                    if (document.all) { $('select').hide(); }
65                    $(colbox).show();
66                    colbox.linkedto = this;
67                   
68               } else {
69                    $(colbox).hide();
70                    if (document.all) { $('select').show(); }
71                    colbox.linkedto = null;
72               }
73          });
74          $(this).blur(function() {
75               $(colbox).hide();
76               if (document.all) { $('select').show(); }
77          });
78     });
79     return this;
80};
Note: See TracBrowser for help on using the repository browser.

Sites map