Dotclear

source: admin/js/color-picker.js @ 3706:170617361020

Revision 3706:170617361020, 2.0 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

use strict and no more linter warnings/errors as far as possible

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

Sites map