ios-checkboxes 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/.gitignore +12 -6
  2. data/Gemfile +21 -0
  3. data/HISTORY.md +10 -0
  4. data/README.md +136 -0
  5. data/Rakefile +36 -21
  6. data/build/.gitignore +2 -0
  7. data/build/build.sh +7 -0
  8. data/build/output/assets/ios-checkboxes/ios-checkboxes-5d38e09413b47993266b4343b181d2f9.css +1 -0
  9. data/build/output/assets/ios-checkboxes/ios-checkboxes-767fc292f6a04316d3a54b18f4637b57.js +1 -0
  10. data/{vendor/assets/images/ios-style-checkboxes/off.png → build/output/assets/ios-checkboxes/off-32586c60c5c48b7002326fdff55cd42e.png} +0 -0
  11. data/{vendor/assets/images/ios-style-checkboxes/on.png → build/output/assets/ios-checkboxes/on-c1710e0553b5cb2ba6b41a59ace60662.png} +0 -0
  12. data/{vendor/assets/images/ios-style-checkboxes/slider.png → build/output/assets/ios-checkboxes/slider-a8cd833485793750ee72350ac5adb4d4.png} +0 -0
  13. data/{vendor/assets/images/ios-style-checkboxes/slider_center.png → build/output/assets/ios-checkboxes/slider_center-137b6fa2802dc0a9be192b66c5a76815.png} +0 -0
  14. data/{vendor/assets/images/ios-style-checkboxes/slider_left.png → build/output/assets/ios-checkboxes/slider_left-e6930b387dd9c0a424e7c1aedd0b0aea.png} +0 -0
  15. data/{vendor/assets/images/ios-style-checkboxes/slider_right.png → build/output/assets/ios-checkboxes/slider_right-e8654b2a69377361211e57422446c703.png} +0 -0
  16. data/ios-checkboxes.gemspec +18 -12
  17. data/{vendor/assets/images/iphone-style-checkboxes → lib/assets/images/ios-checkboxes}/off.png +0 -0
  18. data/{vendor/assets/images/iphone-style-checkboxes → lib/assets/images/ios-checkboxes}/on.png +0 -0
  19. data/{vendor/assets/images/iphone-style-checkboxes → lib/assets/images/ios-checkboxes}/slider.png +0 -0
  20. data/{vendor/assets/images/iphone-style-checkboxes → lib/assets/images/ios-checkboxes}/slider_center.png +0 -0
  21. data/{vendor/assets/images/iphone-style-checkboxes → lib/assets/images/ios-checkboxes}/slider_left.png +0 -0
  22. data/{vendor/assets/images/iphone-style-checkboxes → lib/assets/images/ios-checkboxes}/slider_right.png +0 -0
  23. data/lib/assets/javascripts/ios-checkboxes.js.coffee +2 -0
  24. data/lib/assets/javascripts/ios-checkboxes/ios-checkboxes.js.coffee +269 -0
  25. data/lib/assets/stylesheets/ios-checkboxes.css.sass +3 -0
  26. data/lib/assets/stylesheets/ios-checkboxes/_mixins.sass +104 -0
  27. data/lib/assets/stylesheets/ios-checkboxes/ios-checkboxes.css.sass +3 -0
  28. data/lib/ios-checkboxes.rb +5 -5
  29. data/lib/ios-checkboxes/engine.rb +4 -0
  30. data/lib/ios-checkboxes/railtie.rb +10 -0
  31. data/lib/ios-checkboxes/version.rb +2 -2
  32. data/lib/ios-style-checkboxes/off.png +0 -0
  33. data/lib/ios-style-checkboxes/on.png +0 -0
  34. data/lib/ios-style-checkboxes/slider.png +0 -0
  35. data/lib/ios-style-checkboxes/slider_center.png +0 -0
  36. data/lib/ios-style-checkboxes/slider_left.png +0 -0
  37. data/lib/ios-style-checkboxes/slider_right.png +0 -0
  38. data/lib/tasks/ios-checkboxes_tasks.rake +4 -0
  39. data/spec/dummy/Rakefile +7 -0
  40. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  41. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  43. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  44. data/spec/dummy/app/mailers/.gitkeep +0 -0
  45. data/spec/dummy/app/models/.gitkeep +0 -0
  46. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  47. data/spec/dummy/config.ru +4 -0
  48. data/spec/dummy/config/application.rb +57 -0
  49. data/spec/dummy/config/boot.rb +10 -0
  50. data/spec/dummy/config/database.yml +25 -0
  51. data/spec/dummy/config/environment.rb +5 -0
  52. data/spec/dummy/config/environments/development.rb +30 -0
  53. data/spec/dummy/config/environments/production.rb +60 -0
  54. data/spec/dummy/config/environments/test.rb +39 -0
  55. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  56. data/spec/dummy/config/initializers/inflections.rb +10 -0
  57. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  58. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  59. data/spec/dummy/config/initializers/session_store.rb +8 -0
  60. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  61. data/spec/dummy/config/locales/en.yml +5 -0
  62. data/spec/dummy/config/routes.rb +58 -0
  63. data/spec/dummy/lib/assets/.gitkeep +0 -0
  64. data/spec/dummy/log/.gitkeep +0 -0
  65. data/spec/dummy/public/404.html +26 -0
  66. data/spec/dummy/public/422.html +26 -0
  67. data/spec/dummy/public/500.html +26 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/dummy/script/rails +6 -0
  70. data/spec/ios-checkboxes_spec.rb +13 -0
  71. data/spec/javascripts/ios-checkboxes_spec.js.coffee +36 -0
  72. data/spec/javascripts/spec.css +4 -0
  73. data/spec/javascripts/spec.js.coffee +2 -0
  74. data/spec/javascripts/support/custom-theme.css.sass +7 -0
  75. data/spec/spec_helper.rb +10 -0
  76. data/spec/support/asset_matchers.rb +37 -0
  77. metadata +171 -28
  78. data/vendor/assets/javascripts/ios-checkboxes.js +0 -283
  79. data/vendor/assets/stylesheets/ios-checkboxes.css.erb +0 -147
@@ -1,283 +0,0 @@
1
- //= require jquery
2
-
3
- (function() {
4
- var iOSCheckbox;
5
- var __slice = Array.prototype.slice;
6
- iOSCheckbox = (function() {
7
- function iOSCheckbox(elem, options) {
8
- var key, opts, value;
9
- this.elem = $(elem);
10
- opts = $.extend({}, iOSCheckbox.defaults, options);
11
- for (key in opts) {
12
- value = opts[key];
13
- this[key] = value;
14
- }
15
- this.elem.data(this.dataName, this);
16
- this.wrapCheckboxWithDivs();
17
- this.attachEvents();
18
- this.disableTextSelection();
19
- if (this.resizeHandle) {
20
- this.optionallyResize('handle');
21
- }
22
- if (this.resizeContainer) {
23
- this.optionallyResize('container');
24
- }
25
- this.initialPosition();
26
- }
27
- iOSCheckbox.prototype.isDisabled = function() {
28
- return this.elem.is(':disabled');
29
- };
30
- iOSCheckbox.prototype.wrapCheckboxWithDivs = function() {
31
- this.elem.wrap("<div class='" + this.containerClass + "' />");
32
- this.container = this.elem.parent();
33
- this.offLabel = $("<label class='" + this.labelOffClass + "'>\n <span>" + this.uncheckedLabel + "</span>\n</label>").appendTo(this.container);
34
- this.offSpan = this.offLabel.children('span');
35
- this.onLabel = $("<label class='" + this.labelOnClass + "'>\n <span>" + this.checkedLabel + "</span>\n</label>").appendTo(this.container);
36
- this.onSpan = this.onLabel.children('span');
37
- return this.handle = $("<div class='" + this.handleClass + "'>\n <div class='" + this.handleRightClass + "'>\n <div class='" + this.handleCenterClass + "' />\n </div>\n</div>").appendTo(this.container);
38
- };
39
- iOSCheckbox.prototype.disableTextSelection = function() {
40
- if ($.browser.msie) {
41
- return $([this.handle, this.offLabel, this.onLabel, this.container]).attr("unselectable", "on");
42
- }
43
- };
44
- iOSCheckbox.prototype._getDimension = function(elem, dimension) {
45
- if ($.fn.actual != null) {
46
- return elem.actual(dimension);
47
- } else {
48
- return elem[dimension]();
49
- }
50
- };
51
- iOSCheckbox.prototype.optionallyResize = function(mode) {
52
- var newWidth, offLabelWidth, onLabelWidth;
53
- onLabelWidth = this._getDimension(this.onLabel, "width");
54
- offLabelWidth = this._getDimension(this.offLabel, "width");
55
- if (mode === "container") {
56
- newWidth = onLabelWidth > offLabelWidth ? onLabelWidth : offLabelWidth;
57
- newWidth += this._getDimension(this.handle, "width") + this.handleMargin;
58
- return this.container.css({
59
- width: newWidth
60
- });
61
- } else {
62
- newWidth = onLabelWidth > offLabelWidth ? onLabelWidth : offLabelWidth;
63
- return this.handle.css({
64
- width: newWidth
65
- });
66
- }
67
- };
68
- iOSCheckbox.prototype.onMouseDown = function(event) {
69
- var x;
70
- event.preventDefault();
71
- if (this.isDisabled()) {
72
- return;
73
- }
74
- x = event.pageX || event.originalEvent.changedTouches[0].pageX;
75
- iOSCheckbox.currentlyClicking = this.handle;
76
- iOSCheckbox.dragStartPosition = x;
77
- return iOSCheckbox.handleLeftOffset = parseInt(this.handle.css('left'), 10) || 0;
78
- };
79
- iOSCheckbox.prototype.onDragMove = function(event, x) {
80
- var newWidth, p;
81
- if (iOSCheckbox.currentlyClicking !== this.handle) {
82
- return;
83
- }
84
- p = (x + iOSCheckbox.handleLeftOffset - iOSCheckbox.dragStartPosition) / this.rightSide;
85
- if (p < 0) {
86
- p = 0;
87
- }
88
- if (p > 1) {
89
- p = 1;
90
- }
91
- newWidth = p * this.rightSide;
92
- this.handle.css({
93
- left: newWidth
94
- });
95
- this.onLabel.css({
96
- width: newWidth + this.handleRadius
97
- });
98
- this.offSpan.css({
99
- marginRight: -newWidth
100
- });
101
- return this.onSpan.css({
102
- marginLeft: -(1 - p) * this.rightSide
103
- });
104
- };
105
- iOSCheckbox.prototype.onDragEnd = function(event, x) {
106
- var p;
107
- if (iOSCheckbox.currentlyClicking !== this.handle) {
108
- return;
109
- }
110
- if (this.isDisabled()) {
111
- return;
112
- }
113
- if (iOSCheckbox.dragging) {
114
- p = (x - iOSCheckbox.dragStartPosition) / this.rightSide;
115
- this.elem.prop('checked', p >= 0.5);
116
- } else {
117
- this.elem.prop('checked', !this.elem.prop('checked'));
118
- }
119
- iOSCheckbox.currentlyClicking = null;
120
- iOSCheckbox.dragging = null;
121
- return this.didChange();
122
- };
123
- iOSCheckbox.prototype.refresh = function() {
124
- return this.didChange();
125
- };
126
- iOSCheckbox.prototype.didChange = function() {
127
- var new_left;
128
- if (typeof this.onChange === "function") {
129
- this.onChange(this.elem, this.elem.prop('checked'));
130
- }
131
- if (this.isDisabled()) {
132
- this.container.addClass(this.disabledClass);
133
- return false;
134
- } else {
135
- this.container.removeClass(this.disabledClass);
136
- }
137
- new_left = this.elem.prop('checked') ? this.rightSide : 0;
138
- this.handle.animate({
139
- left: new_left
140
- }, this.duration);
141
- this.onLabel.animate({
142
- width: new_left + this.handleRadius
143
- }, this.duration);
144
- this.offSpan.animate({
145
- marginRight: -new_left
146
- }, this.duration);
147
- return this.onSpan.animate({
148
- marginLeft: new_left - this.rightSide
149
- }, this.duration);
150
- };
151
- iOSCheckbox.prototype.attachEvents = function() {
152
- var localMouseMove, localMouseUp, self;
153
- self = this;
154
- localMouseMove = function(event) {
155
- return self.onGlobalMove.apply(self, arguments);
156
- };
157
- localMouseUp = function(event) {
158
- self.onGlobalUp.apply(self, arguments);
159
- $(document).unbind('mousemove touchmove', localMouseMove);
160
- return $(document).unbind('mouseup touchend', localMouseUp);
161
- };
162
- return this.container.bind('mousedown touchstart', function(event) {
163
- self.onMouseDown.apply(self, arguments);
164
- $(document).bind('mousemove touchmove', localMouseMove);
165
- return $(document).bind('mouseup touchend', localMouseUp);
166
- });
167
- };
168
- iOSCheckbox.prototype.initialPosition = function() {
169
- var containerWidth, offset;
170
- containerWidth = this._getDimension(this.container, "width");
171
- this.offLabel.css({
172
- width: containerWidth - this.containerRadius
173
- });
174
- offset = this.containerRadius + 1;
175
- if ($.browser.msie && $.browser.version < 7) {
176
- offset -= 3;
177
- }
178
- this.rightSide = containerWidth - this._getDimension(this.handle, "width") - offset;
179
- if (this.elem.is(':checked')) {
180
- this.handle.css({
181
- left: this.rightSide
182
- });
183
- this.onLabel.css({
184
- width: this.rightSide + this.handleRadius
185
- });
186
- this.offSpan.css({
187
- marginRight: -this.rightSide
188
- });
189
- } else {
190
- this.onLabel.css({
191
- width: 0
192
- });
193
- this.onSpan.css({
194
- marginLeft: -this.rightSide
195
- });
196
- }
197
- if (this.isDisabled()) {
198
- return this.container.addClass(this.disabledClass);
199
- }
200
- };
201
- iOSCheckbox.prototype.onGlobalMove = function(event) {
202
- var x;
203
- if (!(!this.isDisabled() && iOSCheckbox.currentlyClicking)) {
204
- return;
205
- }
206
- event.preventDefault();
207
- x = event.pageX || event.originalEvent.changedTouches[0].pageX;
208
- if (!iOSCheckbox.dragging && (Math.abs(iOSCheckbox.dragStartPosition - x) > this.dragThreshold)) {
209
- iOSCheckbox.dragging = true;
210
- }
211
- return this.onDragMove(event, x);
212
- };
213
- iOSCheckbox.prototype.onGlobalUp = function(event) {
214
- var x;
215
- if (!iOSCheckbox.currentlyClicking) {
216
- return;
217
- }
218
- event.preventDefault();
219
- x = event.pageX || event.originalEvent.changedTouches[0].pageX;
220
- this.onDragEnd(event, x);
221
- return false;
222
- };
223
- iOSCheckbox.defaults = {
224
- duration: 200,
225
- checkedLabel: 'ON',
226
- uncheckedLabel: 'OFF',
227
- resizeHandle: true,
228
- resizeContainer: true,
229
- disabledClass: 'iPhoneCheckDisabled',
230
- containerClass: 'iPhoneCheckContainer',
231
- labelOnClass: 'iPhoneCheckLabelOn',
232
- labelOffClass: 'iPhoneCheckLabelOff',
233
- handleClass: 'iPhoneCheckHandle',
234
- handleCenterClass: 'iPhoneCheckHandleCenter',
235
- handleRightClass: 'iPhoneCheckHandleRight',
236
- dragThreshold: 5,
237
- handleMargin: 15,
238
- handleRadius: 4,
239
- containerRadius: 5,
240
- dataName: "iphoneStyle",
241
- onChange: function() {}
242
- };
243
- return iOSCheckbox;
244
- })();
245
- $.iphoneStyle = this.iOSCheckbox = iOSCheckbox;
246
- $.fn.iphoneStyle = function() {
247
- var args, checkbox, dataName, existingControl, method, params, _i, _len, _ref, _ref2, _ref3, _ref4;
248
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
249
- dataName = (_ref = (_ref2 = args[0]) != null ? _ref2.dataName : void 0) != null ? _ref : iOSCheckbox.defaults.dataName;
250
- _ref3 = this.filter(':checkbox');
251
- for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
252
- checkbox = _ref3[_i];
253
- existingControl = $(checkbox).data(dataName);
254
- if (existingControl != null) {
255
- method = args[0], params = 2 <= args.length ? __slice.call(args, 1) : [];
256
- if ((_ref4 = existingControl[method]) != null) {
257
- _ref4.apply(existingControl, params);
258
- }
259
- } else {
260
- new iOSCheckbox(checkbox, args[0]);
261
- }
262
- }
263
- return this;
264
- };
265
- $.fn.iOSCheckbox = function(options) {
266
- var opts;
267
- if (options == null) {
268
- options = {};
269
- }
270
- opts = $.extend({}, options, {
271
- resizeHandle: false,
272
- disabledClass: 'iOSCheckDisabled',
273
- containerClass: 'iOSCheckContainer',
274
- labelOnClass: 'iOSCheckLabelOn',
275
- labelOffClass: 'iOSCheckLabelOff',
276
- handleClass: 'iOSCheckHandle',
277
- handleCenterClass: 'iOSCheckHandleCenter',
278
- handleRightClass: 'iOSCheckHandleRight',
279
- dataName: 'iOSCheckbox'
280
- });
281
- return this.iphoneStyle(opts);
282
- };
283
- }).call(this);
@@ -1,147 +0,0 @@
1
- .iPhoneCheckContainer {
2
- position: relative;
3
- height: 27px;
4
- cursor: pointer;
5
- overflow: hidden; }
6
- .iPhoneCheckContainer input {
7
- position: absolute;
8
- top: 5px;
9
- left: 30px;
10
- filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
11
- opacity: 0; }
12
- .iPhoneCheckContainer label {
13
- white-space: nowrap;
14
- font-size: 17px;
15
- line-height: 17px;
16
- font-weight: bold;
17
- font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
18
- text-transform: uppercase;
19
- cursor: pointer;
20
- display: block;
21
- height: 27px;
22
- position: absolute;
23
- width: auto;
24
- top: 0;
25
- padding-top: 5px;
26
- overflow: hidden; }
27
- .iPhoneCheckContainer, .iPhoneCheckContainer label {
28
- user-select: none;
29
- -moz-user-select: none;
30
- -khtml-user-select: none; }
31
-
32
- .iPhoneCheckDisabled {
33
- filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50);
34
- opacity: 0.5; }
35
-
36
- label.iPhoneCheckLabelOn {
37
- color: white;
38
- background: url('<%= image_path "iphone-style-checkboxes/on.png" %>') no-repeat;
39
- text-shadow: 0px 0px 2px rgba(0, 0, 0, 0.6);
40
- left: 0;
41
- padding-top: 5px; }
42
- label.iPhoneCheckLabelOn span {
43
- padding-left: 8px; }
44
- label.iPhoneCheckLabelOff {
45
- color: #8b8b8b;
46
- background: url('<%= image_path "iphone-style-checkboxes/off.png" %>') no-repeat right 0;
47
- text-shadow: 0px 0px 2px rgba(255, 255, 255, 0.6);
48
- text-align: right;
49
- right: 0; }
50
- label.iPhoneCheckLabelOff span {
51
- padding-right: 8px; }
52
-
53
- .iPhoneCheckHandle {
54
- display: block;
55
- height: 27px;
56
- cursor: pointer;
57
- position: absolute;
58
- top: 0;
59
- left: 0;
60
- width: 0;
61
- background: url('<%= image_path "iphone-style-checkboxes/slider_left.png" %>') no-repeat;
62
- padding-left: 3px; }
63
-
64
- .iPhoneCheckHandleRight {
65
- height: 100%;
66
- width: 100%;
67
- padding-right: 3px;
68
- background: url('<%= image_path "iphone-style-checkboxes/slider_right.png" %>') no-repeat right 0; }
69
-
70
- .iPhoneCheckHandleCenter {
71
- height: 100%;
72
- width: 100%;
73
- background: url('<%= image_path "iphone-style-checkboxes/slider_center.png" %>'); }
74
-
75
- .iOSCheckContainer {
76
- position: relative;
77
- height: 27px;
78
- cursor: pointer;
79
- overflow: hidden; }
80
- .iOSCheckContainer input {
81
- position: absolute;
82
- top: 5px;
83
- left: 30px;
84
- filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
85
- opacity: 0; }
86
- .iOSCheckContainer label {
87
- white-space: nowrap;
88
- font-size: 17px;
89
- line-height: 17px;
90
- font-weight: bold;
91
- font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
92
- text-transform: uppercase;
93
- cursor: pointer;
94
- display: block;
95
- height: 27px;
96
- position: absolute;
97
- width: auto;
98
- top: 0;
99
- padding-top: 5px;
100
- overflow: hidden; }
101
- .iOSCheckContainer, .iOSCheckContainer label {
102
- user-select: none;
103
- -moz-user-select: none;
104
- -khtml-user-select: none; }
105
-
106
- .iOSCheckDisabled {
107
- filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50);
108
- opacity: 0.5; }
109
-
110
- label.iOSCheckLabelOn {
111
- color: white;
112
- background: url('<%= image_path "ios-style-checkboxes/on.png" %>') no-repeat;
113
- text-shadow: 0px 0px 2px rgba(0, 0, 0, 0.6);
114
- left: 0;
115
- padding-top: 5px; }
116
- label.iOSCheckLabelOn span {
117
- padding-left: 8px; }
118
- label.iOSCheckLabelOff {
119
- color: #8b8b8b;
120
- background: url('<%= image_path "ios-style-checkboxes/off.png" %>') no-repeat right 0;
121
- text-shadow: 0px 0px 2px rgba(255, 255, 255, 0.6);
122
- text-align: right;
123
- right: 0; }
124
- label.iOSCheckLabelOff span {
125
- padding-right: 8px; }
126
-
127
- .iOSCheckHandle {
128
- display: block;
129
- height: 27px;
130
- cursor: pointer;
131
- position: absolute;
132
- top: 0;
133
- left: 0;
134
- width: 0;
135
- background: url('<%= image_path "ios-style-checkboxes/slider_left.png" %>') no-repeat;
136
- padding-left: 3px; }
137
-
138
- .iOSCheckHandleRight {
139
- height: 100%;
140
- width: 100%;
141
- padding-right: 3px;
142
- background: url('<%= image_path "ios-style-checkboxes/slider_right.png" %>') no-repeat right 0; }
143
-
144
- .iOSCheckHandleCenter {
145
- height: 100%;
146
- width: 100%;
147
- background: url('<%= image_path "ios-style-checkboxes/slider_center.png" %>'); }