hobo_simple_color 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ This is a plugin for [Hobo](http://hobocentral.net) that provides [jQuery Simple Color](https://github.com/recurser/jquery-simple-color)
2
+
3
+ ### Installation
4
+
5
+ It can be installed into a Hobo app by typing:
6
+
7
+ hobo generate install_plugin hobo_simple_color git://github.com/Hobo/hobo_simple_color.git
8
+
9
+ The source for this plugin lives at git://github.com/Hobo/hobo_simple_color. Pull requests are welcome.
10
+
11
+ ### Usage
12
+
13
+ Add to your model's field definition:
14
+
15
+ fields do
16
+ color Color, :default => "#000000"
17
+ end
18
+
19
+ ### License
20
+
21
+ See MIT-LICENSE
@@ -0,0 +1,4 @@
1
+ class Color < String
2
+ COLUMN_TYPE = :string
3
+ HoboFields.register_type(:color, self)
4
+ end
Binary file
@@ -0,0 +1,14 @@
1
+ module HoboSimpleColor
2
+
3
+ @@root = Pathname.new File.expand_path('../..', __FILE__)
4
+ def self.root; @@root; end
5
+
6
+ EDIT_LINK_BASE = 'https://github.com/my_github_username/hobo_simple_color/edit/master'
7
+
8
+ if defined?(Rails)
9
+ require 'hobo_simple_color/railtie'
10
+
11
+ class Engine < ::Rails::Engine
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ require 'hobo_simple_color'
2
+ require 'rails'
3
+
4
+ module HoboSimpleColor
5
+ class Railtie < Rails::Railtie
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module HoboSimpleColor
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,42 @@
1
+ <%#
2
+ This input uses [jQuery Simple Color](https://github.com/recurser/jquery-simple-color) to provide a color picker.
3
+
4
+ ### Usage
5
+
6
+ If you are using the Color rich type for your fields, this input will be used automatically. If not, use the `<simple-color>` tag.
7
+
8
+ ### Attributes
9
+
10
+ All attributes supported by [jQuery Simple Color](https://github.com/recurser/jquery-simple-color) are supported.
11
+
12
+ ### Examples:
13
+
14
+ <input insert="before" displayColorCode="&true" class="my_class"/>
15
+ %>
16
+ <def tag="input" for="Color">
17
+ <simple-color merge/>
18
+ </def>
19
+
20
+
21
+ <%#
22
+ This input uses [jQuery Simple Color](https://github.com/recurser/jquery-simple-color) to provide a color picker.
23
+
24
+ ### Attributes
25
+
26
+ All attributes supported by [jQuery Simple Color](https://github.com/recurser/jquery-simple-color) are supported.
27
+
28
+ ### Examples:
29
+
30
+ <simple-color insert="before" displayColorCode="&true" class="my_class"/>
31
+ %>
32
+ <def tag="simple-color" attrs="name"><%=
33
+ options, attrs = attributes.partition_hash(['defaultColor', 'border', 'cellWidth', 'cellHeight', 'cellMargin', 'boxWidth', 'boxHeight', 'columns', 'insert', 'buttonClass', 'colors', 'displayColorCode', 'colorCodeAlign', 'colorCodeColor'])
34
+ add_data_rapid!(attrs, 'simple-color', options)
35
+ text_field_tag(name, this, deunderscore_attributes(attrs))
36
+ %></def>
37
+
38
+
39
+ <%# a simple view for the Color rich type %>
40
+ <def tag="view" for="Color">
41
+ <span style="background-color: #{html_escape(this)};"><%= this %></span>
42
+ </def>
@@ -0,0 +1,3 @@
1
+ jQuery.fn.hjq_simple_color = function(annotations) {
2
+ this.simpleColor(annotations);
3
+ };
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,278 @@
1
+ /*
2
+ * jQuery simple-color plugin
3
+ * @requires jQuery v1.4.2 or later
4
+ *
5
+ * See http://recursive-design.com/projects/jquery-simple-color/
6
+ *
7
+ * Licensed under the MIT license:
8
+ * http://www.opensource.org/licenses/mit-license.php
9
+ *
10
+ * Version: 1.0.1 (201108151520)
11
+ */
12
+ (function($) {
13
+ /**
14
+ * simpleColor() provides a mechanism for displaying simple color-pickers.
15
+ *
16
+ * If an options Object is provided, the following attributes are supported:
17
+ *
18
+ * defaultColor: Default (initially selected) color.
19
+ * default value: '#FFF'
20
+ *
21
+ * border: CSS border properties.
22
+ * default value: '1px solid #000'
23
+ *
24
+ * cellWidth: Width of each individual color cell.
25
+ * default value: 10
26
+ *
27
+ * cellHeight: Height of each individual color cell.
28
+ * default value: 10
29
+ *
30
+ * cellMargin: Margin of each individual color cell.
31
+ * default value: 1
32
+ *
33
+ * boxWidth: Width of the color display box.
34
+ * default value: 115px
35
+ *
36
+ * boxHeight: Height of the color display box.
37
+ * default value: 20px
38
+ *
39
+ * columns: Number of columns to display. Color order may look strange if this is altered.
40
+ * default value: 16
41
+ *
42
+ * insert: The position to insert the color picker. 'before' or 'after'.
43
+ * default value: 'after'
44
+ *
45
+ * buttonClass: A custom CSS class to add to the button, if you want to add some custom styling.
46
+ * default value: ''
47
+ *
48
+ * colors: An array of colors to display, if you want to customize the default color set.
49
+ * default value: default color set - see 'default_colors' below.
50
+ *
51
+ * displayColorCode: Display the color code (eg #333333) as text inside the button. true or false.
52
+ * default value: false
53
+ *
54
+ * colorCodeAlign: Text alignment used to display the color code inside the button. Only used if 'displayColorCode' is true. 'left', 'center' or 'right'
55
+ * default value: 'center'
56
+ *
57
+ * colorCodeColor: Text color of the color code inside the button. Only used if 'displayColorCode' is true.
58
+ * default value: '#FFF'
59
+ */
60
+ $.fn.simpleColor = function(options) {
61
+
62
+ var default_colors =
63
+ ['990033', 'ff3366', 'cc0033', 'ff0033', 'ff9999', 'cc3366', 'ffccff', 'cc6699',
64
+ '993366', '660033', 'cc3399', 'ff99cc', 'ff66cc', 'ff99ff', 'ff6699', 'cc0066',
65
+ 'ff0066', 'ff3399', 'ff0099', 'ff33cc', 'ff00cc', 'ff66ff', 'ff33ff', 'ff00ff',
66
+ 'cc0099', '990066', 'cc66cc', 'cc33cc', 'cc99ff', 'cc66ff', 'cc33ff', '993399',
67
+ 'cc00cc', 'cc00ff', '9900cc', '990099', 'cc99cc', '996699', '663366', '660099',
68
+ '9933cc', '660066', '9900ff', '9933ff', '9966cc', '330033', '663399', '6633cc',
69
+ '6600cc', '9966ff', '330066', '6600ff', '6633ff', 'ccccff', '9999ff', '9999cc',
70
+ '6666cc', '6666ff', '666699', '333366', '333399', '330099', '3300cc', '3300ff',
71
+ '3333ff', '3333cc', '0066ff', '0033ff', '3366ff', '3366cc', '000066', '000033',
72
+ '0000ff', '000099', '0033cc', '0000cc', '336699', '0066cc', '99ccff', '6699ff',
73
+ '003366', '6699cc', '006699', '3399cc', '0099cc', '66ccff', '3399ff', '003399',
74
+ '0099ff', '33ccff', '00ccff', '99ffff', '66ffff', '33ffff', '00ffff', '00cccc',
75
+ '009999', '669999', '99cccc', 'ccffff', '33cccc', '66cccc', '339999', '336666',
76
+ '006666', '003333', '00ffcc', '33ffcc', '33cc99', '00cc99', '66ffcc', '99ffcc',
77
+ '00ff99', '339966', '006633', '336633', '669966', '66cc66', '99ff99', '66ff66',
78
+ '339933', '99cc99', '66ff99', '33ff99', '33cc66', '00cc66', '66cc99', '009966',
79
+ '009933', '33ff66', '00ff66', 'ccffcc', 'ccff99', '99ff66', '99ff33', '00ff33',
80
+ '33ff33', '00cc33', '33cc33', '66ff33', '00ff00', '66cc33', '006600', '003300',
81
+ '009900', '33ff00', '66ff00', '99ff00', '66cc00', '00cc00', '33cc00', '339900',
82
+ '99cc66', '669933', '99cc33', '336600', '669900', '99cc00', 'ccff66', 'ccff33',
83
+ 'ccff00', '999900', 'cccc00', 'cccc33', '333300', '666600', '999933', 'cccc66',
84
+ '666633', '999966', 'cccc99', 'ffffcc', 'ffff99', 'ffff66', 'ffff33', 'ffff00',
85
+ 'ffcc00', 'ffcc66', 'ffcc33', 'cc9933', '996600', 'cc9900', 'ff9900', 'cc6600',
86
+ '993300', 'cc6633', '663300', 'ff9966', 'ff6633', 'ff9933', 'ff6600', 'cc3300',
87
+ '996633', '330000', '663333', '996666', 'cc9999', '993333', 'cc6666', 'ffcccc',
88
+ 'ff3333', 'cc3333', 'ff6666', '660000', '990000', 'cc0000', 'ff0000', 'ff3300',
89
+ 'cc9966', 'ffcc99', 'ffffff', 'cccccc', '999999', '666666', '333333', '000000',
90
+ '000000', '000000', '000000', '000000', '000000', '000000', '000000', '000000'];
91
+
92
+ // Option defaults
93
+ options = $.extend({
94
+ defaultColor: this.attr('defaultColor') || '#FFF',
95
+ border: this.attr('border') || '1px solid #000',
96
+ cellWidth: this.attr('cellWidth') || 10,
97
+ cellHeight: this.attr('cellHeight') || 10,
98
+ cellMargin: this.attr('cellMargin') || 1,
99
+ boxWidth: this.attr('boxWidth') || '115px',
100
+ boxHeight: this.attr('boxHeight') || '20px',
101
+ columns: this.attr('columns') || 16,
102
+ insert: this.attr('insert') || 'after',
103
+ buttonClass: this.attr('buttonClass') || '',
104
+ colors: this.attr('colors') || default_colors,
105
+ displayColorCode: this.attr('displayColorCode') || false,
106
+ colorCodeAlign: this.attr('colorCodeAlign') || 'center',
107
+ colorCodeColor: this.attr('colorCodeColor') || '#FFF'
108
+
109
+ }, options || {});
110
+
111
+ // Hide the input
112
+ this.hide();
113
+
114
+ // Figure out the cell dimensions
115
+ options.totalWidth = options.columns * (options.cellWidth + (2 * options.cellMargin));
116
+ if ($.browser.msie) {
117
+ options.totalWidth += 2;
118
+ }
119
+
120
+ options.totalHeight = Math.ceil(options.colors.length / options.columns) * (options.cellHeight + (2 * options.cellMargin));
121
+
122
+ // Store these options so they'll be available to the other functions
123
+ // TODO - must be a better way to do this, not sure what the 'official'
124
+ // jQuery method is. Ideally i want to pass these as a parameter to the
125
+ // each() function but i'm not sure how
126
+ $.simpleColorOptions = options;
127
+
128
+
129
+
130
+ function buildSelector(index) {
131
+
132
+ var options = $.simpleColorOptions;
133
+
134
+ // Create a container to hold everything
135
+ var container = $("<div class='simpleColorContainer' />");
136
+
137
+ // Create the color display box
138
+ var default_color = (this.value && this.value != '') ? this.value : options.defaultColor;
139
+
140
+ var display_box = $("<div class='simpleColorDisplay' />");
141
+ display_box.css('backgroundColor', default_color);
142
+ display_box.css('border', options.border);
143
+ display_box.css('width', options.boxWidth);
144
+ display_box.css('height', options.boxHeight);
145
+ display_box.css('cursor', 'pointer');
146
+ container.append(display_box);
147
+
148
+ // If 'displayColorCode' is turned on, display the currently selected color code as text inside the button.
149
+ if (options.displayColorCode) {
150
+ display_box.text(this.value);
151
+ display_box.css('color', options.colorCodeColor);
152
+ display_box.css('textAlign', options.colorCodeAlign);
153
+ }
154
+
155
+ // Create the select button
156
+ var select_button = $("<input type='button' value='Select'" +
157
+ " class='simpleColorSelectButton "+options.buttonClass+"'>");
158
+ container.append(select_button);
159
+
160
+ // Create the cancel button
161
+ var cancel_button = $("<input type='button' value='Cancel'" +
162
+ " class='simpleColorCancelButton "+options.buttonClass+"'>");
163
+
164
+ container.append(cancel_button);
165
+ cancel_button.hide();
166
+
167
+ var select_callback = function (event) {
168
+ event.data.select_button.hide();
169
+ event.data.cancel_button.show();
170
+
171
+ // Use an existing chooser if there is one
172
+ if (event.data.container.chooser) {
173
+ event.data.container.chooser.show();
174
+
175
+ // Build the chooser
176
+ } else {
177
+
178
+ // Make a chooser div to hold the cells
179
+ var chooser = $("<div class='simpleColorChooser'/>");
180
+ chooser.css('border', options.border);
181
+ chooser.css('margin', '0px');
182
+ chooser.css('margin-top', '3px');
183
+ chooser.css('width', options.totalWidth + 'px');
184
+ chooser.css('height', options.totalHeight + 'px');
185
+
186
+ event.data.container.chooser = chooser;
187
+ event.data.container.append(chooser);
188
+
189
+ // Create the cells
190
+ for (var i=0; i<options.colors.length; i++) {
191
+ var cell = $("<div class='simpleColorCell' id='" + options.colors[i] + "'/>");
192
+ cell.css('width', options.cellWidth + 'px');
193
+ cell.css('height', options.cellHeight + 'px');
194
+ cell.css('margin', options.cellMargin + 'px');
195
+ cell.css('cursor', 'pointer');
196
+ cell.css('lineHeight', options.cellHeight + 'px');
197
+ cell.css('fontSize', '1px');
198
+ cell.css('float', 'left');
199
+ cell.css('backgroundColor', '#'+options.colors[i]);
200
+ chooser.append(cell);
201
+
202
+ cell.bind('click', {
203
+ input: event.data.input,
204
+ chooser: chooser,
205
+ select_button: select_button,
206
+ cancel_button: cancel_button,
207
+ display_box: display_box},
208
+ function(event) {
209
+ event.data.input.value = '#' + this.id;
210
+ $(event.data.input).change();
211
+ event.data.display_box.css('backgroundColor', '#' + this.id);
212
+ event.data.chooser.hide();
213
+ event.data.cancel_button.hide();
214
+ event.data.display_box.show();
215
+ event.data.select_button.show();
216
+
217
+ // If 'displayColorCode' is turned on, display the currently selected color code as text inside the button.
218
+ if (options.displayColorCode) {
219
+ event.data.display_box.text('#' + this.id);
220
+ }
221
+ }
222
+ );
223
+ }
224
+ }
225
+ };
226
+
227
+ var callback_params = {
228
+ container: container,
229
+ input: this,
230
+ cancel_button: cancel_button,
231
+ display_box: display_box,
232
+ select_button: select_button
233
+ };
234
+
235
+ // Bind the select button to display the chooser.
236
+ select_button.bind('click', callback_params, select_callback);
237
+
238
+ // Also bind the display box button to display the chooser.
239
+ display_box.bind('click', callback_params, select_callback);
240
+
241
+ // Bind the cancel button to hide the chooser
242
+ cancel_button.bind('click', {
243
+ container: container,
244
+ select_button: select_button,
245
+ display_box: display_box},
246
+ function (event) {
247
+ $(this).hide();
248
+ event.data.container.find('.simpleColorChooser').hide();
249
+ event.data.display_box.show();
250
+ event.data.select_button.show();
251
+ }
252
+ );
253
+
254
+ $(this).after(container);
255
+
256
+ };
257
+
258
+ this.each(buildSelector);
259
+
260
+ return this;
261
+ };
262
+
263
+ /*
264
+ * Close the given color selectors
265
+ */
266
+ $.fn.closeSelector = function() {
267
+ this.each( function(index) {
268
+ var container = $(this).parent().find('div.simpleColorContainer');
269
+ container.find('.simpleColorCancelButton').hide();
270
+ container.find('.simpleColorChooser').hide();
271
+ container.find('.simpleColorDisplay').show();
272
+ container.find('.simpleColorSelectButton').show();
273
+ });
274
+
275
+ return this;
276
+ };
277
+
278
+ })(jQuery);
@@ -0,0 +1,3 @@
1
+ /*
2
+ * require_tree .
3
+ */
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hobo_simple_color
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Bryan Larsen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-03-29 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hobo
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.0.pre4
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description: Hobofication of [jQuery Simple Color](https://github.com/recurser/jquery-simple-color)
27
+ email:
28
+ - bryan@larsen.st
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - .gitignore
37
+ - MIT-LICENSE
38
+ - README.markdown
39
+ - app/rich_types/color.rb
40
+ - hobo_simple_color.gemspec
41
+ - lib/hobo_simple_color.rb
42
+ - lib/hobo_simple_color/railtie.rb
43
+ - lib/hobo_simple_color/version.rb
44
+ - taglibs/hobo_simple_color.dryml
45
+ - vendor/assets/javascripts/hjq_simple_color.js
46
+ - vendor/assets/javascripts/hobo_simple_color.js
47
+ - vendor/assets/javascripts/jquery.simple-color.js
48
+ - vendor/assets/stylesheets/hobo_simple_color.css
49
+ homepage: http://hobocentral.net
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.17
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Hobofication of jQuery Simple Color
76
+ test_files: []
77
+
78
+ has_rdoc: