ios-checkboxes 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
+ require "ios-checkboxes/version"
2
+
3
+ module IOSCheckboxes
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module IOSCheckboxes
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,275 @@
1
+ (function() {
2
+ var iOSCheckbox;
3
+ var __slice = Array.prototype.slice;
4
+ iOSCheckbox = (function() {
5
+ function iOSCheckbox(elem, options) {
6
+ var key, opts, value;
7
+ this.elem = $(elem);
8
+ opts = $.extend({}, iOSCheckbox.defaults, options);
9
+ for (key in opts) {
10
+ value = opts[key];
11
+ this[key] = value;
12
+ }
13
+ this.wrapCheckboxWithDivs();
14
+ this.attachEvents();
15
+ this.disableTextSelection();
16
+ if (this.resizeHandle) {
17
+ this.optionallyResize('handle');
18
+ }
19
+ if (this.resizeContainer) {
20
+ this.optionallyResize('container');
21
+ }
22
+ this.initialPosition();
23
+ }
24
+ iOSCheckbox.prototype.isDisabled = function() {
25
+ return this.elem.is(':disabled');
26
+ };
27
+ iOSCheckbox.prototype.wrapCheckboxWithDivs = function() {
28
+ this.elem.wrap("<div class='" + this.containerClass + "' />");
29
+ this.container = this.elem.parent();
30
+ this.offLabel = $("<label class='" + this.labelOffClass + "'>\n <span>" + this.uncheckedLabel + "</span>\n</label>").appendTo(this.container);
31
+ this.offSpan = this.offLabel.children('span');
32
+ this.onLabel = $("<label class='" + this.labelOnClass + "'>\n <span>" + this.checkedLabel + "</span>\n</label>").appendTo(this.container);
33
+ this.onSpan = this.onLabel.children('span');
34
+ return this.handle = $("<div class='" + this.handleClass + "'>\n <div class='" + this.handleRightClass + "'>\n <div class='" + this.handleCenterClass + "' />\n </div>\n</div>").appendTo(this.container);
35
+ };
36
+ iOSCheckbox.prototype.disableTextSelection = function() {
37
+ if ($.browser.msie) {
38
+ return $([this.handle, this.offLabel, this.onLabel, this.container]).attr("unselectable", "on");
39
+ }
40
+ };
41
+ iOSCheckbox.prototype.optionallyResize = function(mode) {
42
+ var newWidth, offLabelWidth, onLabelWidth;
43
+ onLabelWidth = this.onLabel.width();
44
+ offLabelWidth = this.offLabel.width();
45
+ if (mode === "container") {
46
+ newWidth = onLabelWidth > offLabelWidth ? onLabelWidth : offLabelWidth;
47
+ newWidth += this.handle.width() + this.handleMargin;
48
+ return this.container.css({
49
+ width: newWidth
50
+ });
51
+ } else {
52
+ newWidth = onLabelWidth > offLabelWidth ? onLabelWidth : offLabelWidth;
53
+ return this.handle.css({
54
+ width: newWidth
55
+ });
56
+ }
57
+ };
58
+ iOSCheckbox.prototype.onMouseDown = function(event) {
59
+ var x;
60
+ event.preventDefault();
61
+ if (this.isDisabled()) {
62
+ return;
63
+ }
64
+ x = event.pageX || event.originalEvent.changedTouches[0].pageX;
65
+ iOSCheckbox.currentlyClicking = this.handle;
66
+ iOSCheckbox.dragStartPosition = x;
67
+ return iOSCheckbox.handleLeftOffset = parseInt(this.handle.css('left'), 10) || 0;
68
+ };
69
+ iOSCheckbox.prototype.onDragMove = function(event, x) {
70
+ var newWidth, p;
71
+ if (iOSCheckbox.currentlyClicking !== this.handle) {
72
+ return;
73
+ }
74
+ p = (x + iOSCheckbox.handleLeftOffset - iOSCheckbox.dragStartPosition) / this.rightSide;
75
+ if (p < 0) {
76
+ p = 0;
77
+ }
78
+ if (p > 1) {
79
+ p = 1;
80
+ }
81
+ newWidth = p * this.rightSide;
82
+ this.handle.css({
83
+ left: newWidth
84
+ });
85
+ this.onLabel.css({
86
+ width: newWidth + this.handleRadius
87
+ });
88
+ this.offSpan.css({
89
+ marginRight: -newWidth
90
+ });
91
+ return this.onSpan.css({
92
+ marginLeft: -(1 - p) * this.rightSide
93
+ });
94
+ };
95
+ iOSCheckbox.prototype.onDragEnd = function(event, x) {
96
+ var p;
97
+ if (iOSCheckbox.currentlyClicking !== this.handle) {
98
+ return;
99
+ }
100
+ if (this.isDisabled()) {
101
+ return;
102
+ }
103
+ if (iOSCheckbox.dragging) {
104
+ p = (x - iOSCheckbox.dragStartPosition) / this.rightSide;
105
+ this.elem.prop('checked', p >= 0.5);
106
+ } else {
107
+ this.elem.prop('checked', !this.elem.prop('checked'));
108
+ }
109
+ iOSCheckbox.currentlyClicking = null;
110
+ iOSCheckbox.dragging = null;
111
+ return this.didChange();
112
+ };
113
+ iOSCheckbox.prototype.refresh = function() {
114
+ return this.didChange();
115
+ };
116
+ iOSCheckbox.prototype.didChange = function() {
117
+ var new_left;
118
+ if (typeof this.onChange === "function") {
119
+ this.onChange(this.elem, this.elem.prop('checked'));
120
+ }
121
+ if (this.isDisabled()) {
122
+ this.container.addClass(this.disabledClass);
123
+ return false;
124
+ } else {
125
+ this.container.removeClass(this.disabledClass);
126
+ }
127
+ new_left = this.elem.prop('checked') ? this.rightSide : 0;
128
+ this.handle.animate({
129
+ left: new_left
130
+ }, this.duration);
131
+ this.onLabel.animate({
132
+ width: new_left + this.handleRadius
133
+ }, this.duration);
134
+ this.offSpan.animate({
135
+ marginRight: -new_left
136
+ }, this.duration);
137
+ return this.onSpan.animate({
138
+ marginLeft: new_left - this.rightSide
139
+ }, this.duration);
140
+ };
141
+ iOSCheckbox.prototype.attachEvents = function() {
142
+ var localMouseMove, localMouseUp, self;
143
+ self = this;
144
+ localMouseMove = function(event) {
145
+ return self.onGlobalMove.apply(self, arguments);
146
+ };
147
+ localMouseUp = function(event) {
148
+ self.onGlobalUp.apply(self, arguments);
149
+ $(document).unbind('mousemove touchmove', localMouseMove);
150
+ return $(document).unbind('mouseup touchend', localMouseUp);
151
+ };
152
+ return this.container.bind('mousedown touchstart', function(event) {
153
+ self.onMouseDown.apply(self, arguments);
154
+ $(document).bind('mousemove touchmove', localMouseMove);
155
+ return $(document).bind('mouseup touchend', localMouseUp);
156
+ });
157
+ };
158
+ iOSCheckbox.prototype.initialPosition = function() {
159
+ var offset;
160
+ this.offLabel.css({
161
+ width: this.container.width() - this.containerRadius
162
+ });
163
+ offset = this.containerRadius + 1;
164
+ if ($.browser.msie && $.browser.version < 7) {
165
+ offset -= 3;
166
+ }
167
+ this.rightSide = this.container.width() - this.handle.width() - offset;
168
+ if (this.elem.is(':checked')) {
169
+ this.handle.css({
170
+ left: this.rightSide
171
+ });
172
+ this.onLabel.css({
173
+ width: this.rightSide + this.handleRadius
174
+ });
175
+ this.offSpan.css({
176
+ marginRight: -this.rightSide
177
+ });
178
+ } else {
179
+ this.onLabel.css({
180
+ width: 0
181
+ });
182
+ this.onSpan.css({
183
+ marginLeft: -this.rightSide
184
+ });
185
+ }
186
+ if (this.isDisabled()) {
187
+ return this.container.addClass(this.disabledClass);
188
+ }
189
+ };
190
+ iOSCheckbox.prototype.onGlobalMove = function(event) {
191
+ var x;
192
+ if (!(!this.isDisabled() && iOSCheckbox.currentlyClicking)) {
193
+ return;
194
+ }
195
+ event.preventDefault();
196
+ x = event.pageX || event.originalEvent.changedTouches[0].pageX;
197
+ if (!iOSCheckbox.dragging && (Math.abs(iOSCheckbox.dragStartPosition - x) > this.dragThreshold)) {
198
+ iOSCheckbox.dragging = true;
199
+ }
200
+ return this.onDragMove(event, x);
201
+ };
202
+ iOSCheckbox.prototype.onGlobalUp = function(event) {
203
+ var x;
204
+ if (!iOSCheckbox.currentlyClicking) {
205
+ return;
206
+ }
207
+ event.preventDefault();
208
+ x = event.pageX || event.originalEvent.changedTouches[0].pageX;
209
+ this.onDragEnd(event, x);
210
+ return false;
211
+ };
212
+ iOSCheckbox.defaults = {
213
+ duration: 200,
214
+ checkedLabel: 'ON',
215
+ uncheckedLabel: 'OFF',
216
+ resizeHandle: true,
217
+ resizeContainer: true,
218
+ disabledClass: 'iPhoneCheckDisabled',
219
+ containerClass: 'iPhoneCheckContainer',
220
+ labelOnClass: 'iPhoneCheckLabelOn',
221
+ labelOffClass: 'iPhoneCheckLabelOff',
222
+ handleClass: 'iPhoneCheckHandle',
223
+ handleCenterClass: 'iPhoneCheckHandleCenter',
224
+ handleRightClass: 'iPhoneCheckHandleRight',
225
+ dragThreshold: 5,
226
+ handleMargin: 15,
227
+ handleRadius: 4,
228
+ containerRadius: 5,
229
+ onChange: function() {}
230
+ };
231
+ return iOSCheckbox;
232
+ })();
233
+ $.iphoneStyle = this.iOSCheckbox = iOSCheckbox;
234
+ $.fn.iphoneStyle = function() {
235
+ var args, checkbox, existingControl, method, options, params, _i, _len, _ref, _ref2;
236
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
237
+ _ref = this.filter(':checkbox');
238
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
239
+ checkbox = _ref[_i];
240
+ existingControl = $(checkbox).data("iphoneStyle");
241
+ if (existingControl != null) {
242
+ method = args[0], params = 2 <= args.length ? __slice.call(args, 1) : [];
243
+ if ((_ref2 = existingControl[method]) != null) {
244
+ _ref2.apply(existingControl, params);
245
+ }
246
+ } else {
247
+ options = args[0];
248
+ $(checkbox).data("iphoneStyle", new iOSCheckbox(checkbox, options));
249
+ }
250
+ }
251
+ return this;
252
+ };
253
+ $.fn.iOSCheckbox = function(options) {
254
+ var checkbox, opts, _i, _len, _ref;
255
+ if (options == null) {
256
+ options = {};
257
+ }
258
+ opts = $.extend({}, options, {
259
+ resizeHandle: false,
260
+ disabledClass: 'iOSCheckDisabled',
261
+ containerClass: 'iOSCheckContainer',
262
+ labelOnClass: 'iOSCheckLabelOn',
263
+ labelOffClass: 'iOSCheckLabelOff',
264
+ handleClass: 'iOSCheckHandle',
265
+ handleCenterClass: 'iOSCheckHandleCenter',
266
+ handleRightClass: 'iOSCheckHandleRight'
267
+ });
268
+ _ref = this.filter(':checkbox');
269
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
270
+ checkbox = _ref[_i];
271
+ $(checkbox).data("iOSCheckbox", new iOSCheckbox(checkbox, opts));
272
+ }
273
+ return this;
274
+ };
275
+ }).call(this);
@@ -0,0 +1,147 @@
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('images/iphone-style-checkboxes/on.png?1284697268') 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('images/iphone-style-checkboxes/off.png?1284697268') 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('images/iphone-style-checkboxes/slider_left.png?1284697268') no-repeat;
62
+ padding-left: 3px; }
63
+
64
+ .iPhoneCheckHandleRight {
65
+ height: 100%;
66
+ width: 100%;
67
+ padding-right: 3px;
68
+ background: url('images/iphone-style-checkboxes/slider_right.png?1284697268') no-repeat right 0; }
69
+
70
+ .iPhoneCheckHandleCenter {
71
+ height: 100%;
72
+ width: 100%;
73
+ background: url('images/iphone-style-checkboxes/slider_center.png?1284697268'); }
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('images/ios-style-checkboxes/on.png?1284697268') 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('images/ios-style-checkboxes/off.png?1284697268') 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('images/ios-style-checkboxes/slider_left.png?1284697268') no-repeat;
136
+ padding-left: 3px; }
137
+
138
+ .iOSCheckHandleRight {
139
+ height: 100%;
140
+ width: 100%;
141
+ padding-right: 3px;
142
+ background: url('images/ios-style-checkboxes/slider_right.png?1284697268') no-repeat right 0; }
143
+
144
+ .iOSCheckHandleCenter {
145
+ height: 100%;
146
+ width: 100%;
147
+ background: url('images/ios-style-checkboxes/slider_center.png?1284697268'); }
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ios-checkboxes
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Thomas Reynolds
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-10-09 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: railties
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 1
30
+ version: "3.1"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: iOS-style Checkboxes for Rails asset pipeline.
34
+ email:
35
+ - me@tdreyno.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - lib/ios-checkboxes.rb
44
+ - lib/ios-checkboxes/version.rb
45
+ - vendor/assets/javascripts/ios-checkboxes.js
46
+ - vendor/assets/stylesheets/ios-checkboxes.css
47
+ has_rdoc: true
48
+ homepage: https://github.com/tdreyno/iphone-style-checkboxes
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project: ios-checkboxes
73
+ rubygems_version: 1.3.6
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: iOS-style Checkboxes
77
+ test_files: []
78
+