jquery-simplecolorpicker-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,6 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
19
+ .DS_Store
20
+ .idea/
@@ -1,7 +1,7 @@
1
1
  module Jquery
2
2
  module Simplecolorpicker
3
3
  module Rails
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -6,7 +6,8 @@
6
6
  * Licensed under the MIT license.
7
7
  */
8
8
 
9
- !function($) {
9
+ (function($) {
10
+ "use strict";
10
11
 
11
12
  /**
12
13
  * Constructor.
@@ -33,16 +34,16 @@
33
34
  selected = 'class="selected"';
34
35
  }
35
36
  colorList += '<div ' + selected + ' title="' + title + '" style="background-color: ' + color + ';" role="button" tabindex="0">'
36
- + fakeText +
37
- '</div>';
37
+ + fakeText
38
+ + '</div>';
38
39
  });
39
40
 
40
41
  if (this.options.picker) {
41
42
  var selectText = this.select.find('option:selected').text();
42
43
  var selectValue = this.select.val();
43
44
  this.icon = $('<span class="simplecolorpicker icon" title="' + selectText + '" style="background-color: ' + selectValue + ';" role="button" tabindex="0">'
44
- + fakeText +
45
- '</span>').insertAfter(this.select);
45
+ + fakeText
46
+ + '</span>').insertAfter(this.select);
46
47
  this.icon.on('click', $.proxy(this.show, this));
47
48
 
48
49
  this.picker = $('<span class="simplecolorpicker picker"></span>').appendTo(document.body);
@@ -57,7 +58,7 @@
57
58
  this.inline.html(colorList);
58
59
  this.inline.on('click', $.proxy(this.click, this));
59
60
  }
60
- }
61
+ };
61
62
 
62
63
  /**
63
64
  * SimpleColorPicker class.
@@ -82,31 +83,27 @@
82
83
 
83
84
  click: function(e) {
84
85
  var target = $(e.target);
85
- if (target.length == 1) {
86
- switch (target[0].nodeName.toLowerCase()) {
87
-
86
+ if (target.length === 1) {
87
+ if (target[0].nodeName.toLowerCase() === 'div') {
88
88
  // When you click on a color
89
- case 'div':
90
- var color = target.css('background-color');
91
- var title = target.attr('title');
92
89
 
93
- // Mark this div as the selected one
94
- target.siblings().removeClass('selected');
95
- target.addClass('selected');
90
+ var color = target.css('background-color');
91
+ var title = target.attr('title');
96
92
 
97
- if (this.options.picker) {
98
- this.icon.css('background-color', color);
99
- this.icon.attr('title', title);
93
+ // Mark this div as the selected one
94
+ target.siblings().removeClass('selected');
95
+ target.addClass('selected');
100
96
 
101
- // Hide the picker
102
- this.hide();
103
- }
97
+ if (this.options.picker) {
98
+ this.icon.css('background-color', color);
99
+ this.icon.attr('title', title);
104
100
 
105
- // Change select value
106
- this.select.val(this.rgb2hex(color)).change();
107
-
108
- break;
101
+ // Hide the picker
102
+ this.hide();
103
+ }
109
104
 
105
+ // Change select value
106
+ this.select.val(this.rgb2hex(color)).change();
110
107
  }
111
108
  }
112
109
  },
@@ -125,29 +122,38 @@
125
122
  * See http://stackoverflow.com/questions/1740700/get-hex-value-rather-than-rgb-value-using-jquery
126
123
  */
127
124
  rgb2hex: function(rgb) {
128
- rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
129
125
  function hex(x) {
130
- return ("0" + parseInt(x).toString(16)).slice(-2);
126
+ return ("0" + parseInt(x, 10).toString(16)).slice(-2);
127
+ }
128
+
129
+ var matches = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
130
+ if (matches === null) {
131
+ // Fix for Internet Explorer < 9
132
+ // Variable rgb is already a hexadecimal value
133
+ return rgb;
134
+ } else {
135
+ return "#" + hex(matches[1]) + hex(matches[2]) + hex(matches[3]);
131
136
  }
132
- return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
133
137
  }
134
- }
138
+ };
135
139
 
136
140
  /**
137
141
  * Plugin definition.
138
142
  */
139
143
  $.fn.simplecolorpicker = function(option) {
140
144
  // For HTML element passed to the plugin
141
- return this.each(function () {
145
+ return this.each(function() {
142
146
  var $this = $(this),
143
- data = $this.data('simplecolorpicker'),
144
- options = typeof option == 'object' && option;
147
+ data = $this.data('simplecolorpicker'),
148
+ options = typeof option === 'object' && option;
145
149
  if (!data) {
146
150
  $this.data('simplecolorpicker', (data = new SimpleColorPicker(this, options)));
147
151
  }
148
- if (typeof option == 'string') data[option]();
152
+ if (typeof option === 'string') {
153
+ data[option]();
154
+ }
149
155
  });
150
- }
156
+ };
151
157
 
152
158
  $.fn.simplecolorpicker.Constructor = SimpleColorPicker;
153
159
 
@@ -162,4 +168,4 @@
162
168
  picker: false
163
169
  };
164
170
 
165
- }(window.jQuery);
171
+ })(jQuery);
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.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-22 00:00:00.000000000 Z
12
+ date: 2012-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70305360074020 !ruby/object:Gem::Requirement
16
+ requirement: &18918120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70305360074020
24
+ version_requirements: *18918120
25
25
  description: simplecolorpicker jQuery plugin
26
26
  email:
27
27
  - tkrotoff@gmail.com
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  version: '0'
60
60
  requirements: []
61
61
  rubyforge_project:
62
- rubygems_version: 1.8.15
62
+ rubygems_version: 1.8.16
63
63
  signing_key:
64
64
  specification_version: 3
65
65
  summary: simplecolorpicker packaged for the Rails 3.1+ asset pipeline