jquery-simplecolorpicker-rails 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Jquery
2
2
  module Simplecolorpicker
3
3
  module Rails
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
6
6
  end
7
7
  end
@@ -29,60 +29,79 @@
29
29
  self.type = type;
30
30
 
31
31
  self.$select = $(select);
32
- var selectValue = self.$select.val();
33
- self.options = $.extend({}, $.fn.simplecolorpicker.defaults, options);
34
-
35
32
  self.$select.hide();
36
33
 
37
- // Trick: fix span alignment
38
- // When a span does not contain any text, its alignment is not correct
39
- var fakeText = '    ';
34
+ self.options = $.extend({}, $.fn.simplecolorpicker.defaults, options);
40
35
 
41
36
  self.$colorList = null;
42
37
 
43
- if (self.options.picker) {
44
- var selectText = self.$select.find('option:selected').text();
38
+ if (self.options.picker === true) {
39
+ var selectText = self.$select.find('> option:selected').text();
45
40
  self.$icon = $('<span class="simplecolorpicker icon"'
46
41
  + ' title="' + selectText + '"'
47
- + ' style="background-color: ' + selectValue + ';"'
42
+ + ' style="background-color: ' + self.$select.val() + ';"'
48
43
  + ' role="button" tabindex="0">'
49
- + fakeText
50
44
  + '</span>').insertAfter(self.$select);
51
45
  self.$icon.on('click.' + self.type, $.proxy(self.showPicker, self));
52
46
 
53
- self.$picker = $('<span class="simplecolorpicker picker"></span>').appendTo(document.body);
47
+ self.$picker = $('<span class="simplecolorpicker picker ' + self.options.theme + '"></span>').appendTo(document.body);
54
48
  self.$colorList = self.$picker;
55
49
 
56
50
  // Hide picker when clicking outside
57
51
  $(document).on('mousedown.' + self.type, $.proxy(self.hidePicker, self));
58
52
  self.$picker.on('mousedown.' + self.type, $.proxy(self.mousedown, self));
59
53
  } else {
60
- self.$inline = $('<span class="simplecolorpicker inline"></span>').insertAfter(self.$select);
54
+ self.$inline = $('<span class="simplecolorpicker inline ' + self.options.theme + '"></span>').insertAfter(self.$select);
61
55
  self.$colorList = self.$inline;
62
56
  }
63
57
 
64
58
  // Build the list of colors
65
- // <span class="selected" title="Green" style="background-color: #7bd148;" role="button"></span>
66
- var colors = '';
67
- $('option', self.$select).each(function() {
68
- var option = $(this);
69
- var color = option.val();
70
- var title = option.text();
59
+ // <span class="color selected" title="Green" style="background-color: #7bd148;" role="button"></span>
60
+ self.$select.find('> option').each(function() {
61
+ var $option = $(this);
62
+ var color = $option.val();
63
+
64
+ var isSelected = $option.is(':selected');
65
+ var isDisabled = $option.is(':disabled');
66
+
71
67
  var selected = '';
72
- if (option.prop('selected') === true || selectValue === color) {
73
- selected = 'class="selected"';
68
+ if (isSelected === true) {
69
+ selected = ' data-selected';
70
+ }
71
+
72
+ var disabled = '';
73
+ if (isDisabled === true) {
74
+ disabled = ' data-disabled';
74
75
  }
75
- colors += '<span ' + selected
76
- + ' title="' + title + '"'
77
- + ' style="background-color: ' + color + ';"'
78
- + ' data-color="' + color + '"'
79
- + ' role="button" tabindex="0">'
80
- + fakeText
81
- + '</span>';
82
- });
83
76
 
84
- self.$colorList.html(colors);
85
- self.$colorList.on('click.' + self.type, $.proxy(self.click, self));
77
+ var title = '';
78
+ if (isDisabled === false) {
79
+ title = ' title="' + $option.text() + '"';
80
+ }
81
+
82
+ var role = '';
83
+ if (isDisabled === false) {
84
+ role = ' role="button" tabindex="0"';
85
+ }
86
+
87
+ var $colorSpan = $('<span class="color"'
88
+ + title
89
+ + ' style="background-color: ' + color + ';"'
90
+ + ' data-color="' + color + '"'
91
+ + selected
92
+ + disabled
93
+ + role + '>'
94
+ + '</span>');
95
+
96
+ self.$colorList.append($colorSpan);
97
+ $colorSpan.on('click.' + self.type, $.proxy(self.colorSpanClicked, self));
98
+
99
+ var $next = $option.next();
100
+ if ($next.is('optgroup') === true) {
101
+ // Vertical break, like hr
102
+ self.$colorList.append('<span class="vr"></span>');
103
+ }
104
+ });
86
105
  },
87
106
 
88
107
  /**
@@ -93,30 +112,30 @@
93
112
  selectColor: function(color) {
94
113
  var self = this;
95
114
 
96
- var colorSpan = self.$colorList.find('span').filter(function() {
115
+ var $colorSpan = self.$colorList.find('> span.color').filter(function() {
97
116
  return $(this).data('color').toLowerCase() === color.toLowerCase();
98
117
  });
99
118
 
100
- if (colorSpan.length > 0) {
101
- self.selectColorSpan(colorSpan);
119
+ if ($colorSpan.length > 0) {
120
+ self.selectColorSpan($colorSpan);
102
121
  } else {
103
122
  console.error("The given color '" + color + "' could not be found");
104
123
  }
105
124
  },
106
125
 
107
126
  showPicker: function() {
108
- var bootstrapArrowWidth = 16; // Empirical value
109
127
  var pos = this.$icon.offset();
110
128
  this.$picker.css({
111
- left: pos.left + this.$icon.width() / 2 - bootstrapArrowWidth, // Middle of the icon
129
+ // Remove some pixels to align the picker icon with the icons inside the dropdown
130
+ left: pos.left - 6,
112
131
  top: pos.top + this.$icon.outerHeight()
113
132
  });
114
133
 
115
- this.$picker.show(this.options.delay);
134
+ this.$picker.show(this.options.pickerDelay);
116
135
  },
117
136
 
118
137
  hidePicker: function() {
119
- this.$picker.hide(this.options.delay);
138
+ this.$picker.hide(this.options.pickerDelay);
120
139
  },
121
140
 
122
141
  /**
@@ -125,15 +144,15 @@
125
144
  * The given span becomes the selected one.
126
145
  * It also changes the HTML select value, this will emit the 'change' event.
127
146
  */
128
- selectColorSpan: function(colorSpan) {
129
- var color = colorSpan.data('color');
130
- var title = colorSpan.prop('title');
147
+ selectColorSpan: function($colorSpan) {
148
+ var color = $colorSpan.data('color');
149
+ var title = $colorSpan.prop('title');
131
150
 
132
151
  // Mark this span as the selected one
133
- colorSpan.siblings().removeClass('selected');
134
- colorSpan.addClass('selected');
152
+ $colorSpan.siblings().removeAttr('data-selected');
153
+ $colorSpan.attr('data-selected', '');
135
154
 
136
- if (this.options.picker) {
155
+ if (this.options.picker === true) {
137
156
  this.$icon.css('background-color', color);
138
157
  this.$icon.prop('title', title);
139
158
  this.hidePicker();
@@ -144,16 +163,13 @@
144
163
  },
145
164
 
146
165
  /**
147
- * The user clicked on a span inside $colorList.
166
+ * The user clicked on a color inside $colorList.
148
167
  */
149
- click: function(e) {
150
- var target = $(e.target);
151
- if (target.length === 1) {
152
- if (target[0].nodeName.toLowerCase() === 'span') {
153
- // When you click on a color, make it the new selected one
154
- this.selectColorSpan(target);
155
- this.$select.trigger('change');
156
- }
168
+ colorSpanClicked: function(e) {
169
+ // When a color is clicked, make it the new selected one (unless disabled)
170
+ if ($(e.target).is('[data-disabled]') === false) {
171
+ this.selectColorSpan($(e.target));
172
+ this.$select.trigger('change');
157
173
  }
158
174
  },
159
175
 
@@ -166,7 +182,7 @@
166
182
  },
167
183
 
168
184
  destroy: function() {
169
- if (this.options.picker) {
185
+ if (this.options.picker === true) {
170
186
  this.$icon.off('.' + this.type);
171
187
  this.$icon.remove();
172
188
  $(document).off('.' + this.type);
@@ -206,11 +222,14 @@
206
222
  * Default options.
207
223
  */
208
224
  $.fn.simplecolorpicker.defaults = {
209
- // Animation delay
210
- delay: 0,
225
+ // No theme by default
226
+ theme: '',
211
227
 
212
228
  // Show the picker or make it inline
213
- picker: false
229
+ picker: false,
230
+
231
+ // Animation delay in milliseconds
232
+ pickerDelay: 0
214
233
  };
215
234
 
216
235
  })(jQuery);
@@ -0,0 +1,9 @@
1
+ .simplecolorpicker.fontawesome span.color[data-selected]:after {
2
+ font-family: 'FontAwesome';
3
+ -webkit-font-smoothing: antialiased;
4
+
5
+ content: '\f00c'; /* Ok/check mark */
6
+
7
+ margin-right: 1px;
8
+ margin-left: 1px;
9
+ }
@@ -0,0 +1,13 @@
1
+ .simplecolorpicker.glyphicons span.color[data-selected]:after {
2
+ /* Taken from glyphicon class. */
3
+ position: relative;
4
+ top: 1px;
5
+ font-family: 'Glyphicons Halflings';
6
+ line-height: .9;
7
+ -webkit-font-smoothing: antialiased;
8
+
9
+ content: '\e013'; /* Ok/check mark */
10
+
11
+ margin-right: 1px;
12
+ margin-left: 1px;
13
+ }
@@ -0,0 +1,6 @@
1
+ .simplecolorpicker.regularfont span.color[data-selected]:after {
2
+ content: '\2714'; /* Ok/check mark */
3
+
4
+ margin-right: 2.2px;
5
+ margin-left: 2.2px;
6
+ }
@@ -9,90 +9,79 @@
9
9
 
10
10
  /**
11
11
  * Inspired by Bootstrap Twitter.
12
- * See https://github.com/twitter/bootstrap/blob/master/less/dropdowns.less
13
- * See http://twitter.github.com/bootstrap/assets/css/bootstrap.css
12
+ * See https://github.com/twbs/bootstrap/blob/master/less/navbar.less
13
+ * See https://github.com/twbs/bootstrap/blob/master/less/dropdowns.less
14
14
  */
15
15
 
16
- .simplecolorpicker.picker:before {
17
- position: absolute;
18
- top: -7px;
19
- left: 9px;
20
- display: inline-block;
21
- border-right: 7px solid transparent;
22
- border-bottom: 7px solid #ccc;
23
- border-left: 7px solid transparent;
24
- border-bottom-color: rgba(0, 0, 0, 0.2);
25
- content: '';
26
- }
27
-
28
- .simplecolorpicker.picker:after {
29
- position: absolute;
30
- top: -6px;
31
- left: 10px;
32
- display: inline-block;
33
- border-right: 6px solid transparent;
34
- border-bottom: 6px solid #ffffff;
35
- border-left: 6px solid transparent;
36
- content: '';
37
- }
38
-
39
16
  .simplecolorpicker.picker {
40
17
  position: absolute;
41
18
  top: 100%;
42
19
  left: 0;
43
- z-index: 1051; /* Above Bootstrap modal (z-index of 1050) */
20
+ z-index: 1051; /* Above Bootstrap modal (@zindex-modal = 1050) */
44
21
  display: none;
45
22
  float: left;
46
23
 
47
24
  min-width: 160px;
48
- max-width: 264px;
25
+ max-width: 283px; /* @popover-max-width = 276px + 7 */
49
26
 
50
- padding: 4px 0 0 4px;
51
- margin: 1px 0 0;
27
+ padding: 5px 0 0 5px;
28
+ margin: 2px 0 0;
52
29
  list-style: none;
53
- background-color: #ffffff;
54
-
55
- border: 1px solid #ccc;
56
- border: 1px solid rgba(0, 0, 0, 0.2);
30
+ background-color: #fff; /* @dropdown-bg */
57
31
 
58
- *border-right-width: 2px;
59
- *border-bottom-width: 2px;
32
+ border: 1px solid #ccc; /* @dropdown-fallback-border */
33
+ border: 1px solid rgba(0, 0, 0, .15); /* @dropdown-border */
60
34
 
61
- -webkit-border-radius: 5px;
62
- -moz-border-radius: 5px;
63
- border-radius: 5px;
35
+ -webkit-border-radius: 4px; /* @border-radius-base */
36
+ -moz-border-radius: 4px;
37
+ border-radius: 4px;
64
38
 
65
- -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
66
- -moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
67
- box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
39
+ -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
40
+ -moz-box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
41
+ box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
68
42
 
69
43
  -webkit-background-clip: padding-box;
70
44
  -moz-background-clip: padding;
71
45
  background-clip: padding-box;
72
46
  }
73
47
 
74
- .simplecolorpicker.inline {
75
- display: inline-block;
76
- height: 18px;
77
- padding: 4px 0;
78
- }
79
-
80
- .simplecolorpicker.icon,
81
- .simplecolorpicker span {
82
- cursor: pointer;
83
- display: inline-block;
84
-
85
- -webkit-border-radius: 3px;
86
- -moz-border-radius: 3px;
87
- border-radius: 3px;
88
-
89
- border: 1px solid transparent;
90
- }
91
- .simplecolorpicker span {
92
- margin: 0 4px 4px 0;
93
- }
94
-
95
- .simplecolorpicker span:hover,
96
- .simplecolorpicker span.selected {
97
- border: 1px solid black;
98
- }
48
+ .simplecolorpicker.inline {
49
+ display: inline-block;
50
+ padding: 6px 0;
51
+ }
52
+
53
+ .simplecolorpicker span {
54
+ margin: 0 5px 5px 0;
55
+ }
56
+
57
+ .simplecolorpicker.icon,
58
+ .simplecolorpicker span.color {
59
+ display: inline-block;
60
+
61
+ cursor: pointer;
62
+ border: 1px solid transparent;
63
+ }
64
+
65
+ .simplecolorpicker.icon:after,
66
+ .simplecolorpicker span.color:after {
67
+ content: '\00a0\00a0\00a0\00a0'; /* Spaces */
68
+ }
69
+
70
+ .simplecolorpicker span.color[data-disabled]:hover {
71
+ cursor: not-allowed;
72
+ border: 1px solid transparent;
73
+ }
74
+
75
+ .simplecolorpicker span.color:hover,
76
+ .simplecolorpicker span.color[data-selected],
77
+ .simplecolorpicker span.color[data-selected]:hover {
78
+ border: 1px solid #222; /* @gray-dark */
79
+ }
80
+ .simplecolorpicker span.color[data-selected]:after {
81
+ color: #fff;
82
+ }
83
+
84
+ /* Vertical separator, replaces optgroup. */
85
+ .simplecolorpicker span.vr {
86
+ border-left: 1px solid #222; /* @gray-dark */
87
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-simplecolorpicker-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-01 00:00:00.000000000 Z
12
+ date: 2013-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -43,6 +43,9 @@ files:
43
43
  - lib/jquery-simplecolorpicker-rails.rb
44
44
  - lib/jquery-simplecolorpicker-rails/version.rb
45
45
  - vendor/assets/javascripts/jquery.simplecolorpicker.js
46
+ - vendor/assets/stylesheets/jquery.simplecolorpicker-fontawesome.css
47
+ - vendor/assets/stylesheets/jquery.simplecolorpicker-glyphicons.css
48
+ - vendor/assets/stylesheets/jquery.simplecolorpicker-regularfont.css
46
49
  - vendor/assets/stylesheets/jquery.simplecolorpicker.css
47
50
  homepage: http://github.com/tkrotoff/jquery-simplecolorpicker-rails
48
51
  licenses: []