spinjs-rails 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -50,7 +50,7 @@ $(".abc").spin({
50
50
  ```
51
51
 
52
52
 
53
- See the full usage details at on the [spin.js](http://fgnass.github.com/spin.js/) site
53
+ See the full usage details on the [spin.js](http://fgnass.github.com/spin.js/) site.
54
54
 
55
55
 
56
56
  # License
@@ -1,5 +1,5 @@
1
1
  module Spinjs
2
2
  module Rails
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- //fgnass.github.com/spin.js#v1.2.2
1
+ //fgnass.github.com/spin.js#v1.2.5
2
2
  (function(window, document, undefined) {
3
3
 
4
4
  /**
@@ -6,17 +6,17 @@
6
6
  * Licensed under the MIT license
7
7
  */
8
8
 
9
- var prefixes = ['webkit', 'Moz', 'ms', 'O'], /* Vendor prefixes */
10
- animations = {}, /* Animation rules keyed by their name */
11
- useCssAnimations;
9
+ var prefixes = ['webkit', 'Moz', 'ms', 'O']; /* Vendor prefixes */
10
+ var animations = {}; /* Animation rules keyed by their name */
11
+ var useCssAnimations;
12
12
 
13
13
  /**
14
14
  * Utility function to create elements. If no tag name is given,
15
15
  * a DIV is created. Optionally properties can be passed.
16
16
  */
17
17
  function createEl(tag, prop) {
18
- var el = document.createElement(tag || 'div'),
19
- n;
18
+ var el = document.createElement(tag || 'div');
19
+ var n;
20
20
 
21
21
  for(n in prop) {
22
22
  el[n] = prop[n];
@@ -25,24 +25,23 @@
25
25
  }
26
26
 
27
27
  /**
28
- * Inserts child1 before child2. If child2 is not specified,
29
- * child1 is appended. If child2 has no parentNode, child2 is
30
- * appended first.
28
+ * Appends children and returns the parent.
31
29
  */
32
- function ins(parent, child1, child2) {
33
- if(child2 && !child2.parentNode) ins(parent, child2);
34
- parent.insertBefore(child1, child2||null);
30
+ function ins(parent /* child1, child2, ...*/) {
31
+ for (var i=1, n=arguments.length; i<n; i++) {
32
+ parent.appendChild(arguments[i]);
33
+ }
35
34
  return parent;
36
35
  }
37
36
 
38
37
  /**
39
38
  * Insert a new stylesheet to hold the @keyframe or VML rules.
40
39
  */
41
- var sheet = (function() {
40
+ var sheet = function() {
42
41
  var el = createEl('style');
43
42
  ins(document.getElementsByTagName('head')[0], el);
44
43
  return el.sheet || el.styleSheet;
45
- })();
44
+ }();
46
45
 
47
46
  /**
48
47
  * Creates an opacity keyframe animation rule and returns its name.
@@ -50,11 +49,11 @@
50
49
  * we create separate rules for each line/segment.
51
50
  */
52
51
  function addAnimation(alpha, trail, i, lines) {
53
- var name = ['opacity', trail, ~~(alpha*100), i, lines].join('-'),
54
- start = 0.01 + i/lines*100,
55
- z = Math.max(1-(1-alpha)/trail*(100-start) , alpha),
56
- prefix = useCssAnimations.substring(0, useCssAnimations.indexOf('Animation')).toLowerCase(),
57
- pre = prefix && '-'+prefix+'-' || '';
52
+ var name = ['opacity', trail, ~~(alpha*100), i, lines].join('-');
53
+ var start = 0.01 + i/lines*100;
54
+ var z = Math.max(1-(1-alpha)/trail*(100-start) , alpha);
55
+ var prefix = useCssAnimations.substring(0, useCssAnimations.indexOf('Animation')).toLowerCase();
56
+ var pre = prefix && '-'+prefix+'-' || '';
58
57
 
59
58
  if (!animations[name]) {
60
59
  sheet.insertRule(
@@ -74,9 +73,9 @@
74
73
  * Tries various vendor prefixes and returns the first supported property.
75
74
  **/
76
75
  function vendor(el, prop) {
77
- var s = el.style,
78
- pp,
79
- i;
76
+ var s = el.style;
77
+ var pp;
78
+ var i;
80
79
 
81
80
  if(s[prop] !== undefined) return prop;
82
81
  prop = prop.charAt(0).toUpperCase() + prop.slice(1);
@@ -121,57 +120,69 @@
121
120
  return o;
122
121
  }
123
122
 
123
+ var defaults = {
124
+ lines: 12, // The number of lines to draw
125
+ length: 7, // The length of each line
126
+ width: 5, // The line thickness
127
+ radius: 10, // The radius of the inner circle
128
+ rotate: 0, // rotation offset
129
+ color: '#000', // #rgb or #rrggbb
130
+ speed: 1, // Rounds per second
131
+ trail: 100, // Afterglow percentage
132
+ opacity: 1/4, // Opacity of the lines
133
+ fps: 20, // Frames per second when using setTimeout()
134
+ zIndex: 2e9, // Use a high z-index by default
135
+ className: 'spinner', // CSS class to assign to the element
136
+ top: 'auto', // center vertically
137
+ left: 'auto' // center horizontally
138
+ };
139
+
124
140
  /** The constructor */
125
141
  var Spinner = function Spinner(o) {
126
142
  if (!this.spin) return new Spinner(o);
127
143
  this.opts = merge(o || {}, Spinner.defaults, defaults);
128
- },
129
- defaults = Spinner.defaults = {
130
- lines: 12, // The number of lines to draw
131
- length: 7, // The length of each line
132
- width: 5, // The line thickness
133
- radius: 10, // The radius of the inner circle
134
- color: '#000', // #rgb or #rrggbb
135
- speed: 1, // Rounds per second
136
- trail: 100, // Afterglow percentage
137
- opacity: 1/4,
138
- fps: 20
139
- },
140
- proto = Spinner.prototype = {
144
+ };
145
+
146
+ Spinner.defaults = {};
147
+ merge(Spinner.prototype, {
141
148
  spin: function(target) {
142
149
  this.stop();
143
- var self = this,
144
- el = self.el = css(createEl(), {position: 'relative'}),
145
- ep, // element position
146
- tp; // target position
150
+ var self = this;
151
+ var o = self.opts;
152
+ var el = self.el = css(createEl(0, {className: o.className}), {position: 'relative', zIndex: o.zIndex});
153
+ var mid = o.radius+o.length+o.width;
154
+ var ep; // element position
155
+ var tp; // target position
147
156
 
148
157
  if (target) {
149
- tp = pos(ins(target, el, target.firstChild));
158
+ target.insertBefore(el, target.firstChild||null);
159
+ tp = pos(target);
150
160
  ep = pos(el);
151
161
  css(el, {
152
- left: (target.offsetWidth >> 1) - ep.x+tp.x + 'px',
153
- top: (target.offsetHeight >> 1) - ep.y+tp.y + 'px'
162
+ left: (o.left == 'auto' ? tp.x-ep.x + (target.offsetWidth >> 1) : o.left+mid) + 'px',
163
+ top: (o.top == 'auto' ? tp.y-ep.y + (target.offsetHeight >> 1) : o.top+mid) + 'px'
154
164
  });
155
165
  }
166
+
156
167
  el.setAttribute('aria-role', 'progressbar');
157
168
  self.lines(el, self.opts);
169
+
158
170
  if (!useCssAnimations) {
159
171
  // No CSS animation support, use setTimeout() instead
160
- var o = self.opts,
161
- i = 0,
162
- fps = o.fps,
163
- f = fps/o.speed,
164
- ostep = (1-o.opacity)/(f*o.trail / 100),
165
- astep = f/o.lines;
166
-
167
- (function anim() {
172
+ var i = 0;
173
+ var fps = o.fps;
174
+ var f = fps/o.speed;
175
+ var ostep = (1-o.opacity)/(f*o.trail / 100);
176
+ var astep = f/o.lines;
177
+
178
+ !function anim() {
168
179
  i++;
169
180
  for (var s=o.lines; s; s--) {
170
181
  var alpha = Math.max(1-(i+s*astep)%f * ostep, o.opacity);
171
182
  self.opacity(el, o.lines-s, alpha, o);
172
183
  }
173
184
  self.timeout = self.el && setTimeout(anim, ~~(1000/fps));
174
- })();
185
+ }();
175
186
  }
176
187
  return self;
177
188
  },
@@ -183,81 +194,86 @@
183
194
  this.el = undefined;
184
195
  }
185
196
  return this;
197
+ },
198
+ lines: function(el, o) {
199
+ var i = 0;
200
+ var seg;
201
+
202
+ function fill(color, shadow) {
203
+ return css(createEl(), {
204
+ position: 'absolute',
205
+ width: (o.length+o.width) + 'px',
206
+ height: o.width + 'px',
207
+ background: color,
208
+ boxShadow: shadow,
209
+ transformOrigin: 'left',
210
+ transform: 'rotate(' + ~~(360/o.lines*i+o.rotate) + 'deg) translate(' + o.radius+'px' +',0)',
211
+ borderRadius: (o.width>>1) + 'px'
212
+ });
213
+ }
214
+ for (; i < o.lines; i++) {
215
+ seg = css(createEl(), {
216
+ position: 'absolute',
217
+ top: 1+~(o.width/2) + 'px',
218
+ transform: o.hwaccel ? 'translate3d(0,0,0)' : '',
219
+ opacity: o.opacity,
220
+ animation: useCssAnimations && addAnimation(o.opacity, o.trail, i, o.lines) + ' ' + 1/o.speed + 's linear infinite'
221
+ });
222
+ if (o.shadow) ins(seg, css(fill('#000', '0 0 4px ' + '#000'), {top: 2+'px'}));
223
+ ins(el, ins(seg, fill(o.color, '0 0 1px rgba(0,0,0,.1)')));
224
+ }
225
+ return el;
226
+ },
227
+ opacity: function(el, i, val) {
228
+ if (i < el.childNodes.length) el.childNodes[i].style.opacity = val;
186
229
  }
187
- };
188
- proto.lines = function(el, o) {
189
- var i = 0,
190
- seg;
191
-
192
- function fill(color, shadow) {
193
- return css(createEl(), {
194
- position: 'absolute',
195
- width: (o.length+o.width) + 'px',
196
- height: o.width + 'px',
197
- background: color,
198
- boxShadow: shadow,
199
- transformOrigin: 'left',
200
- transform: 'rotate(' + ~~(360/o.lines*i) + 'deg) translate(' + o.radius+'px' +',0)',
201
- borderRadius: (o.width>>1) + 'px'
202
- });
203
- }
204
- for (; i < o.lines; i++) {
205
- seg = css(createEl(), {
206
- position: 'absolute',
207
- top: 1+~(o.width/2) + 'px',
208
- transform: 'translate3d(0,0,0)',
209
- opacity: o.opacity,
210
- animation: useCssAnimations && addAnimation(o.opacity, o.trail, i, o.lines) + ' ' + 1/o.speed + 's linear infinite'
211
- });
212
- if (o.shadow) ins(seg, css(fill('#000', '0 0 4px ' + '#000'), {top: 2+'px'}));
213
- ins(el, ins(seg, fill(o.color, '0 0 1px rgba(0,0,0,.1)')));
214
- }
215
- return el;
216
- };
217
- proto.opacity = function(el, i, val) {
218
- if (i < el.childNodes.length) el.childNodes[i].style.opacity = val;
219
- };
230
+ });
220
231
 
221
232
  /////////////////////////////////////////////////////////////////////////
222
233
  // VML rendering for IE
223
234
  /////////////////////////////////////////////////////////////////////////
224
235
 
225
- /**
236
+ /**
226
237
  * Check and init VML support
227
238
  */
228
- (function() {
229
- var s = css(createEl('group'), {behavior: 'url(#default#VML)'}),
230
- i;
239
+ !function() {
240
+
241
+ function vml(tag, attr) {
242
+ return createEl('<' + tag + ' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">', attr);
243
+ }
244
+
245
+ var s = css(createEl('group'), {behavior: 'url(#default#VML)'});
231
246
 
232
247
  if (!vendor(s, 'transform') && s.adj) {
233
248
 
234
- // VML support detected. Insert CSS rules ...
235
- for (i=4; i--;) sheet.addRule(['group', 'roundrect', 'fill', 'stroke'][i], 'behavior:url(#default#VML)');
249
+ // VML support detected. Insert CSS rule ...
250
+ sheet.addRule('.spin-vml', 'behavior:url(#default#VML)');
236
251
 
237
- proto.lines = function(el, o) {
238
- var r = o.length+o.width,
239
- s = 2*r;
252
+ Spinner.prototype.lines = function(el, o) {
253
+ var r = o.length+o.width;
254
+ var s = 2*r;
240
255
 
241
256
  function grp() {
242
- return css(createEl('group', {coordsize: s +' '+s, coordorigin: -r +' '+-r}), {width: s, height: s});
257
+ return css(vml('group', {coordsize: s +' '+s, coordorigin: -r +' '+-r}), {width: s, height: s});
243
258
  }
244
259
 
245
- var g = grp(),
246
- margin = ~(o.length+o.radius+o.width)+'px',
247
- i;
260
+ var margin = -(o.width+o.length)*2+'px';
261
+ var g = css(grp(), {position: 'absolute', top: margin, left: margin});
262
+
263
+ var i;
248
264
 
249
265
  function seg(i, dx, filter) {
250
266
  ins(g,
251
267
  ins(css(grp(), {rotation: 360 / o.lines * i + 'deg', left: ~~dx}),
252
- ins(css(createEl('roundrect', {arcsize: 1}), {
268
+ ins(css(vml('roundrect', {arcsize: 1}), {
253
269
  width: r,
254
270
  height: o.width,
255
271
  left: o.radius,
256
272
  top: -o.width>>1,
257
273
  filter: filter
258
274
  }),
259
- createEl('fill', {color: o.color, opacity: o.opacity}),
260
- createEl('stroke', {opacity: 0}) // transparent stroke to fix color bleeding upon opacity change
275
+ vml('fill', {color: o.color, opacity: o.opacity}),
276
+ vml('stroke', {opacity: 0}) // transparent stroke to fix color bleeding upon opacity change
261
277
  )
262
278
  )
263
279
  );
@@ -268,15 +284,10 @@
268
284
  seg(i, -2, 'progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)');
269
285
  }
270
286
  }
271
- for (i = 1; i <= o.lines; i++) {
272
- seg(i);
273
- }
274
- return ins(css(el, {
275
- margin: margin + ' 0 0 ' + margin,
276
- zoom: 1
277
- }), g);
287
+ for (i = 1; i <= o.lines; i++) seg(i);
288
+ return ins(el, g);
278
289
  };
279
- proto.opacity = function(el, i, val, o) {
290
+ Spinner.prototype.opacity = function(el, i, val, o) {
280
291
  var c = el.firstChild;
281
292
  o = o.shadow && o.lines || 0;
282
293
  if (c && i+o < c.childNodes.length) {
@@ -288,7 +299,7 @@
288
299
  else {
289
300
  useCssAnimations = vendor(s, 'animation');
290
301
  }
291
- })();
302
+ }();
292
303
 
293
304
  window.Spinner = Spinner;
294
305
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spinjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2011-12-20 00:00:00.000000000 Z
12
+ date: 2012-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70261413015500 !ruby/object:Gem::Requirement
16
+ requirement: &70113496389260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70261413015500
24
+ version_requirements: *70113496389260
25
25
  description: An animated CSS3 loading spinner with VML fallback for IE.
26
26
  email:
27
27
  - dnagir@gmail.com
@@ -51,21 +51,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
- segments:
55
- - 0
56
- hash: -1085464510167320829
57
54
  required_rubygems_version: !ruby/object:Gem::Requirement
58
55
  none: false
59
56
  requirements:
60
57
  - - ! '>='
61
58
  - !ruby/object:Gem::Version
62
59
  version: '0'
63
- segments:
64
- - 0
65
- hash: -1085464510167320829
66
60
  requirements: []
67
61
  rubyforge_project: spinjs-rails
68
- rubygems_version: 1.8.10
62
+ rubygems_version: 1.8.17
69
63
  signing_key:
70
64
  specification_version: 3
71
65
  summary: A spinning activity indicator for Rails 3 with no images and CSS.