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.
- data/lib/jquery-simplecolorpicker-rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery.simplecolorpicker.js +75 -56
- data/vendor/assets/stylesheets/jquery.simplecolorpicker-fontawesome.css +9 -0
- data/vendor/assets/stylesheets/jquery.simplecolorpicker-glyphicons.css +13 -0
- data/vendor/assets/stylesheets/jquery.simplecolorpicker-regularfont.css +6 -0
- data/vendor/assets/stylesheets/jquery.simplecolorpicker.css +55 -66
- metadata +5 -2
@@ -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
|
-
|
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: ' +
|
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
|
-
|
67
|
-
|
68
|
-
var
|
69
|
-
|
70
|
-
var
|
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 (
|
73
|
-
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
|
-
|
85
|
-
|
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
|
-
|
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.
|
134
|
+
this.$picker.show(this.options.pickerDelay);
|
116
135
|
},
|
117
136
|
|
118
137
|
hidePicker: function() {
|
119
|
-
this.$picker.hide(this.options.
|
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().
|
134
|
-
colorSpan.
|
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
|
166
|
+
* The user clicked on a color inside $colorList.
|
148
167
|
*/
|
149
|
-
|
150
|
-
|
151
|
-
if (target.
|
152
|
-
|
153
|
-
|
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
|
-
//
|
210
|
-
|
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,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
|
+
}
|
@@ -9,90 +9,79 @@
|
|
9
9
|
|
10
10
|
/**
|
11
11
|
* Inspired by Bootstrap Twitter.
|
12
|
-
* See https://github.com/
|
13
|
-
* See
|
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 (
|
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:
|
25
|
+
max-width: 283px; /* @popover-max-width = 276px + 7 */
|
49
26
|
|
50
|
-
padding:
|
51
|
-
margin:
|
27
|
+
padding: 5px 0 0 5px;
|
28
|
+
margin: 2px 0 0;
|
52
29
|
list-style: none;
|
53
|
-
background-color: #
|
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
|
-
|
59
|
-
|
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:
|
62
|
-
-moz-border-radius:
|
63
|
-
border-radius:
|
35
|
+
-webkit-border-radius: 4px; /* @border-radius-base */
|
36
|
+
-moz-border-radius: 4px;
|
37
|
+
border-radius: 4px;
|
64
38
|
|
65
|
-
-webkit-box-shadow: 0
|
66
|
-
-moz-box-shadow: 0
|
67
|
-
box-shadow: 0
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
+
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-
|
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: []
|