rails-bootstrap-toggle-buttons 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
File without changes
data/README.md CHANGED
File without changes
File without changes
@@ -1,10 +1,13 @@
1
1
  !function ($) {
2
2
  "use strict";
3
- // version: 2.3
3
+ // version: 2.8.2
4
4
  // by Mattia Larentis - follow me on twitter! @SpiritualGuru
5
5
 
6
6
  var addToAttribute = function (obj, array, value) {
7
- for (var i = 0, length = array.length; i < length; i++) {
7
+ var i = 0
8
+ , length = array.length;
9
+
10
+ for (; i < length; i++) {
8
11
  obj = obj[array[i]] = obj[array[i]] || i == ( length - 1) ? value : {}
9
12
  }
10
13
  };
@@ -12,6 +15,7 @@
12
15
  $.fn.toggleButtons = function (method) {
13
16
  var $element
14
17
  , $div
18
+ , $cb
15
19
  , transitionSpeed = 0.05
16
20
  , methods = {
17
21
  init: function (opt) {
@@ -31,7 +35,7 @@
31
35
 
32
36
  if (i.indexOf("togglebutton") === 0) {
33
37
  key = i.match(/[A-Z][a-z]+/g);
34
- key = jQuery.map(key, function (n) {
38
+ key = $.map(key, function (n) {
35
39
  return (n.toLowerCase());
36
40
  });
37
41
 
@@ -48,12 +52,14 @@
48
52
  $spanRight = $('<span></span>').addClass("labelRight").text(options.label.disabled === undefined ? "OFF " : options.label.disabled);
49
53
 
50
54
  // html layout
51
- $div = $element.find('input').wrap($('<div></div>')).parent();
55
+ $cb = $element.find('input:checkbox')
56
+
57
+ $div = $cb.wrap($('<div></div>')).parent();
52
58
  $div.append($spanLeft);
53
- $div.append($('<label></label>').attr('for', $element.find('input').attr('id')));
59
+ $div.append($('<label></label>').attr('for', $cb.attr('id') || ''));
54
60
  $div.append($spanRight);
55
61
 
56
- if ($element.find('input').is(':checked'))
62
+ if ($cb.is(':checked'))
57
63
  $element.find('>div').css('left', "0");
58
64
  else $element.find('>div').css('left', "-50%");
59
65
 
@@ -85,7 +91,7 @@
85
91
  .filter('span')
86
92
  .css('line-height', options.height + "px");
87
93
 
88
- if ($element.find('input').is(':disabled'))
94
+ if ($cb.is(':disabled'))
89
95
  $(this).addClass('deactivate');
90
96
 
91
97
  $element.find('span').css(options.font);
@@ -98,6 +104,7 @@
98
104
  if (options.style.custom.enabled.gradient === undefined)
99
105
  $spanLeft.css('background', options.style.custom.enabled.background);
100
106
  else $.each(["-webkit-", "-moz-", "-o-", ""], function (i, el) {
107
+ $spanLeft.css('background-color', options.style.custom.enabled.background);
101
108
  $spanLeft.css('background-image', el + 'linear-gradient(top, ' + options.style.custom.enabled.background + ',' + options.style.custom.enabled.gradient + ')');
102
109
  });
103
110
  }
@@ -111,6 +118,7 @@
111
118
  if (options.style.custom.disabled.gradient === undefined)
112
119
  $spanRight.css('background', options.style.custom.disabled.background);
113
120
  else $.each(["-webkit-", "-moz-", "-o-", ""], function (i, el) {
121
+ $spanRight.css('background-color', options.style.custom.disabled.background);
114
122
  $spanRight.css('background-image', el + 'linear-gradient(top, ' + options.style.custom.disabled.background + ',' + options.style.custom.disabled.gradient + ')');
115
123
  });
116
124
  }
@@ -118,7 +126,10 @@
118
126
  else $spanRight.addClass(options.style.disabled);
119
127
 
120
128
  var changeStatus = function ($this) {
121
- $this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
129
+ $this.siblings('label')
130
+ .trigger('mousedown')
131
+ .trigger('mouseup')
132
+ .trigger('click');
122
133
  };
123
134
 
124
135
  $spanLeft.on('click', function (e) {
@@ -128,50 +139,51 @@
128
139
  changeStatus($(this));
129
140
  });
130
141
 
131
- $('.toggle-button').find('input').on('change', function (e) {
142
+ $element.find('input:checkbox').on('change', function (e, skipOnChange) {
132
143
  var $element = $(this).parent()
133
144
  , active = $(this).is(':checked')
134
145
  , $toggleButton = $(this).closest('.toggle-button');
135
146
 
136
- e.preventDefault();
137
- e.stopImmediatePropagation();
138
-
139
147
  $element.stop().animate({'left': active ? '0' : '-50%'}, $toggleButton.data('transitionSpeed'));
140
148
 
141
149
  options = $toggleButton.data('options');
142
- options.onChange($element, active, e);
150
+
151
+ if (!skipOnChange)
152
+ options.onChange($element, active, e);
143
153
  });
144
154
 
145
- $('.toggle-button').find('label').on('mousedown', function (e) {
155
+ $element.find('label').on('mousedown touchstart', function (e) {
146
156
  moving = false;
147
-
148
157
  e.preventDefault();
149
158
  e.stopImmediatePropagation();
150
159
 
151
160
  if ($(this).closest('.toggle-button').is('.deactivate'))
152
- $(this).unbind('click');
161
+ $(this).off('click');
153
162
  else {
154
- $(this).on('mousemove', function (e) {
163
+ $(this).on('mousemove touchmove', function (e) {
155
164
  var $element = $(this).closest('.toggle-button')
156
- , relativeX = e.pageX - $element.offset().left
165
+ , relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left
157
166
  , percent = ((relativeX / (options.width * 2)) * 100);
158
167
  moving = true;
159
168
 
169
+ e.stopImmediatePropagation();
170
+ e.preventDefault();
171
+
160
172
  if (percent < 25)
161
173
  percent = 25;
162
174
  else if (percent > 75)
163
175
  percent = 75;
164
176
 
165
- $element.find('>div').css('left', (percent - 75) + "%")
177
+ $element.find('>div').css('left', (percent - 75) + "%");
166
178
  });
167
179
 
168
- $(this).on('click', function (e) {
180
+ $(this).on('click touchend', function (e) {
169
181
  var $target = $(e.target)
170
- , $myCheckBox = $target.siblings('input');
182
+ , $myCheckBox = $target.siblings('input:checkbox');
171
183
 
172
184
  e.stopImmediatePropagation();
173
185
  e.preventDefault();
174
- $(this).unbind('mouseleave');
186
+ $(this).off('mouseleave');
175
187
 
176
188
  if (moving)
177
189
  if (parseInt($(this).parent().css('left')) < -25)
@@ -183,12 +195,12 @@
183
195
  });
184
196
 
185
197
  $(this).on('mouseleave', function (e) {
186
- var $myCheckBox = $(this).siblings('input');
198
+ var $myCheckBox = $(this).siblings('input:checkbox');
187
199
 
188
200
  e.preventDefault();
189
201
  e.stopImmediatePropagation();
190
202
 
191
- $(this).unbind('mouseleave');
203
+ $(this).off('mouseleave');
192
204
  $(this).trigger('mouseup');
193
205
 
194
206
  if (parseInt($(this).parent().css('left')) < -25)
@@ -201,16 +213,39 @@
201
213
  $(this).on('mouseup', function (e) {
202
214
  e.stopImmediatePropagation();
203
215
  e.preventDefault();
204
- $(this).unbind('mousemove');
216
+ $(this).off('mousemove');
205
217
  });
206
218
  }
207
219
  });
208
220
  }
209
- )
210
- ;
221
+ );
222
+ return this;
211
223
  },
212
224
  toggleActivation: function () {
213
225
  $(this).toggleClass('deactivate');
226
+ },
227
+ toggleState: function (skipOnChange) {
228
+ var $input = $(this).find('input:checkbox');
229
+ $input.attr('checked', !$input.is(':checked')).trigger('change', skipOnChange);
230
+ },
231
+ setState: function(value, skipOnChange) {
232
+ $(this).find('input:checkbox').attr('checked', value).trigger('change', skipOnChange);
233
+ },
234
+ status: function () {
235
+ return $(this).find('input:checkbox').is(':checked');
236
+ },
237
+ destroy: function () {
238
+ var $div = $(this).find('div')
239
+ , $checkbox;
240
+
241
+ $div.find(':not(input:checkbox)').remove();
242
+
243
+ $checkbox = $div.children();
244
+ $checkbox.unwrap().unwrap();
245
+
246
+ $checkbox.unbind('change');
247
+
248
+ return $checkbox;
214
249
  }
215
250
  };
216
251
 
@@ -219,7 +254,7 @@
219
254
  else if (typeof method === 'object' || !method)
220
255
  return methods.init.apply(this, arguments);
221
256
  else
222
- $.error('Method ' + method + ' does not exist on jQuery.tooltip');
257
+ $.error('Method ' + method + ' does not exist!');
223
258
  };
224
259
 
225
260
  $.fn.toggleButtons.defaults = {
@@ -251,4 +286,4 @@
251
286
  }
252
287
  }
253
288
  };
254
- }($);
289
+ }(jQuery);
@@ -96,60 +96,60 @@
96
96
  -webkit-border-bottom-right-radius: 4px;
97
97
  border-bottom-right-radius: 4px;
98
98
  color: black;
99
- background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #fefefe), color-stop(100%, #e6e6e6));
100
- background-image: -webkit-linear-gradient(top, #fefefe, #e6e6e6);
101
- background-image: -moz-linear-gradient(top, #fefefe, #e6e6e6);
102
- background-image: -o-linear-gradient(top, #fefefe, #e6e6e6);
103
- background-image: linear-gradient(top, #fefefe, #e6e6e6);
99
+ background-image: -webkit-gradient(linear, 50% 100%, 50% 0%, color-stop(0%, #fefefe), color-stop(100%, #e6e6e6));
100
+ background-image: -webkit-linear-gradient(bottom, #fefefe, #e6e6e6);
101
+ background-image: -moz-linear-gradient(bottom, #fefefe, #e6e6e6);
102
+ background-image: -o-linear-gradient(bottom, #fefefe, #e6e6e6);
103
+ background-image: linear-gradient(bottom, #fefefe, #e6e6e6);
104
104
  padding-right: 3px;
105
105
  }
106
106
  /* line 91, ../sass/bootstrap-toggle-buttons.scss */
107
107
  .toggle-button span.primary, .toggle-button span.labelLeft {
108
108
  color: #fefefe;
109
109
  background: #0088cc;
110
- background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #0088cc), color-stop(100%, #0055cc));
111
- background-image: -webkit-linear-gradient(top, #0088cc, #0055cc);
112
- background-image: -moz-linear-gradient(top, #0088cc, #0055cc);
113
- background-image: -o-linear-gradient(top, #0088cc, #0055cc);
114
- background-image: linear-gradient(top, #0088cc, #0055cc);
110
+ background-image: -webkit-gradient(linear, 50% 100%, 50% 0%, color-stop(0%, #0088cc), color-stop(100%, #0055cc));
111
+ background-image: -webkit-linear-gradient(bottom, #0088cc, #0055cc);
112
+ background-image: -moz-linear-gradient(bottom, #0088cc, #0055cc);
113
+ background-image: -o-linear-gradient(bottom, #0088cc, #0055cc);
114
+ background-image: linear-gradient(bottom, #0088cc, #0055cc);
115
115
  }
116
116
  /* line 96, ../sass/bootstrap-toggle-buttons.scss */
117
117
  .toggle-button span.info {
118
118
  color: #fefefe;
119
119
  background: #5bc0de;
120
- background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #5bc0de), color-stop(100%, #2f96b4));
121
- background-image: -webkit-linear-gradient(top, #5bc0de, #2f96b4);
122
- background-image: -moz-linear-gradient(top, #5bc0de, #2f96b4);
123
- background-image: -o-linear-gradient(top, #5bc0de, #2f96b4);
124
- background-image: linear-gradient(top, #5bc0de, #2f96b4);
120
+ background-image: -webkit-gradient(linear, 50% 100%, 50% 0%, color-stop(0%, #5bc0de), color-stop(100%, #2f96b4));
121
+ background-image: -webkit-linear-gradient(bottom, #5bc0de, #2f96b4);
122
+ background-image: -moz-linear-gradient(bottom, #5bc0de, #2f96b4);
123
+ background-image: -o-linear-gradient(bottom, #5bc0de, #2f96b4);
124
+ background-image: linear-gradient(bottom, #5bc0de, #2f96b4);
125
125
  }
126
126
  /* line 102, ../sass/bootstrap-toggle-buttons.scss */
127
127
  .toggle-button span.success {
128
128
  color: #fefefe;
129
129
  background: #62c462;
130
- background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #62c462), color-stop(100%, #51a351));
131
- background-image: -webkit-linear-gradient(top, #62c462, #51a351);
132
- background-image: -moz-linear-gradient(top, #62c462, #51a351);
133
- background-image: -o-linear-gradient(top, #62c462, #51a351);
134
- background-image: linear-gradient(top, #62c462, #51a351);
130
+ background-image: -webkit-gradient(linear, 50% 100%, 50% 0%, color-stop(0%, #62c462), color-stop(100%, #51a351));
131
+ background-image: -webkit-linear-gradient(bottom, #62c462, #51a351);
132
+ background-image: -moz-linear-gradient(bottom, #62c462, #51a351);
133
+ background-image: -o-linear-gradient(bottom, #62c462, #51a351);
134
+ background-image: linear-gradient(bottom, #62c462, #51a351);
135
135
  }
136
136
  /* line 108, ../sass/bootstrap-toggle-buttons.scss */
137
137
  .toggle-button span.warning {
138
138
  color: #fefefe;
139
139
  background: #dbb450;
140
- background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #dbb450), color-stop(100%, #f89406));
141
- background-image: -webkit-linear-gradient(top, #dbb450, #f89406);
142
- background-image: -moz-linear-gradient(top, #dbb450, #f89406);
143
- background-image: -o-linear-gradient(top, #dbb450, #f89406);
144
- background-image: linear-gradient(top, #dbb450, #f89406);
140
+ background-image: -webkit-gradient(linear, 50% 100%, 50% 0%, color-stop(0%, #dbb450), color-stop(100%, #f89406));
141
+ background-image: -webkit-linear-gradient(bottom, #dbb450, #f89406);
142
+ background-image: -moz-linear-gradient(bottom, #dbb450, #f89406);
143
+ background-image: -o-linear-gradient(bottom, #dbb450, #f89406);
144
+ background-image: linear-gradient(bottom, #dbb450, #f89406);
145
145
  }
146
146
  /* line 114, ../sass/bootstrap-toggle-buttons.scss */
147
147
  .toggle-button span.danger {
148
148
  color: #fefefe;
149
149
  background: #ee5f5b;
150
- background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ee5f5b), color-stop(100%, #bd362f));
151
- background-image: -webkit-linear-gradient(top, #ee5f5b, #bd362f);
152
- background-image: -moz-linear-gradient(top, #ee5f5b, #bd362f);
153
- background-image: -o-linear-gradient(top, #ee5f5b, #bd362f);
154
- background-image: linear-gradient(top, #ee5f5b, #bd362f);
155
- }
150
+ background-image: -webkit-gradient(linear, 50% 100%, 50% 0%, color-stop(0%, #ee5f5b), color-stop(100%, #bd362f));
151
+ background-image: -webkit-linear-gradient(bottom, #ee5f5b, #bd362f);
152
+ background-image: -moz-linear-gradient(bottom, #ee5f5b, #bd362f);
153
+ background-image: -o-linear-gradient(bottom, #ee5f5b, #bd362f);
154
+ background-image: linear-gradient(bottom, #ee5f5b, #bd362f);
155
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-bootstrap-toggle-buttons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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: 2012-10-03 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Just providing the bootstrap-toggle-buttons from https://github.com/nostalgiaz/bootstrap-toggle-buttons
15
15
  into a gem.
@@ -20,8 +20,8 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - lib/rails-bootstrap-toggle-buttons.rb
23
- - vendor/assets/javascripts/bootstrap-toggle-buttons.js
24
23
  - vendor/assets/stylesheets/bootstrap-toggle-buttons.css
24
+ - vendor/assets/javascripts/bootstrap-toggle-buttons.js
25
25
  - LICENSE.txt
26
26
  - README.md
27
27
  homepage: https://github.com/caarlos0/rails-bootstrap-toggle-buttons.git
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  version: '0'
45
45
  requirements: []
46
46
  rubyforge_project:
47
- rubygems_version: 1.8.24
47
+ rubygems_version: 1.8.23
48
48
  signing_key:
49
49
  specification_version: 3
50
50
  summary: A simple gem for https://github.com/nostalgiaz/bootstrap-toggle-buttons