spinjs-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in spinjs-rails.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Spin.js - spinner with no CSS, Images
2
+
3
+ Provides an easy-to-use Rails 3.1 asset for [Spin.js](http://fgnass.github.com/spin.js/)
4
+
5
+ # Install
6
+
7
+ Add it to your Rails application's `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'spinjs-rails'
11
+ ```
12
+
13
+ Then `bundle install`.
14
+
15
+
16
+ # Usage
17
+
18
+ Require `spin`:
19
+
20
+
21
+ ```javascript
22
+ // application.js
23
+ // require spin
24
+ ```
25
+
26
+ or as jQuery plugin:
27
+
28
+ ```javascript
29
+ // application.js
30
+ // require jquery.spin
31
+
32
+ // Then you can:
33
+
34
+ $(".abc").spin(); // Shows the default spinner
35
+ $(".abc").spin(false); // Hide the spinner
36
+
37
+ // Show customised spinner:
38
+ $(".abc").spin({
39
+ lines: 12, // The number of lines to draw
40
+ length: 7, // The length of each line
41
+ width: 9, // The line thickness
42
+ radius: 30, // The radius of the inner circle
43
+ color: '#000', // #rgb or #rrggbb
44
+ speed: 1, // Rounds per second
45
+ trail: 60, // Afterglow percentage
46
+ shadow: false // Whether to render a shadow
47
+ });
48
+ ```
49
+
50
+
51
+ See the full usage details at on the [spin.js](http://fgnass.github.com/spin.js/) site
52
+
53
+
54
+ # License
55
+
56
+ [MIT](http://www.opensource.org/licenses/mit-license.php) by [@dnagir](https://twitter.com/#!/dnagir).
57
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ module Spinjs
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ module Spinjs
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "spinjs-rails/version"
2
+ require "spinjs-rails/engine"
3
+
4
+ module Spinjs
5
+ module Rails
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "spinjs-rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "spinjs-rails"
7
+ s.version = Spinjs::Rails::VERSION
8
+ s.authors = ["Dmytrii Nagirniak"]
9
+ s.email = ["dnagir@gmail.com"]
10
+ s.homepage = "https://github.com/dnagir/spinjs-rails"
11
+ s.summary = %q{A spinning activity indicator for Rails 3 with no images and CSS.}
12
+ s.description = %q{An animated CSS3 loading spinner with VML fallback for IE.}
13
+
14
+ s.rubyforge_project = "spinjs-rails"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "rails", ">= 3.1"
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,22 @@
1
+ // require jquery
2
+ // require spin
3
+
4
+ (function($) {
5
+
6
+ $.fn.spin = function(opts) {
7
+ this.each(function() {
8
+ var $this = $(this),
9
+ data = $this.data();
10
+
11
+ if (data.spinner) {
12
+ data.spinner.stop();
13
+ delete data.spinner;
14
+ }
15
+ if (opts !== false) {
16
+ data.spinner = new Spinner($.extend({color: $this.css('color')}, opts)).spin(this);
17
+ }
18
+ });
19
+ return this;
20
+ };
21
+
22
+ })(jQuery);
@@ -0,0 +1,295 @@
1
+ //fgnass.github.com/spin.js#v1.2.2
2
+ (function(window, document, undefined) {
3
+
4
+ /**
5
+ * Copyright (c) 2011 Felix Gnass [fgnass at neteye dot de]
6
+ * Licensed under the MIT license
7
+ */
8
+
9
+ var prefixes = ['webkit', 'Moz', 'ms', 'O'], /* Vendor prefixes */
10
+ animations = {}, /* Animation rules keyed by their name */
11
+ useCssAnimations;
12
+
13
+ /**
14
+ * Utility function to create elements. If no tag name is given,
15
+ * a DIV is created. Optionally properties can be passed.
16
+ */
17
+ function createEl(tag, prop) {
18
+ var el = document.createElement(tag || 'div'),
19
+ n;
20
+
21
+ for(n in prop) {
22
+ el[n] = prop[n];
23
+ }
24
+ return el;
25
+ }
26
+
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.
31
+ */
32
+ function ins(parent, child1, child2) {
33
+ if(child2 && !child2.parentNode) ins(parent, child2);
34
+ parent.insertBefore(child1, child2||null);
35
+ return parent;
36
+ }
37
+
38
+ /**
39
+ * Insert a new stylesheet to hold the @keyframe or VML rules.
40
+ */
41
+ var sheet = (function() {
42
+ var el = createEl('style');
43
+ ins(document.getElementsByTagName('head')[0], el);
44
+ return el.sheet || el.styleSheet;
45
+ })();
46
+
47
+ /**
48
+ * Creates an opacity keyframe animation rule and returns its name.
49
+ * Since most mobile Webkits have timing issues with animation-delay,
50
+ * we create separate rules for each line/segment.
51
+ */
52
+ 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+'-' || '';
58
+
59
+ if (!animations[name]) {
60
+ sheet.insertRule(
61
+ '@' + pre + 'keyframes ' + name + '{' +
62
+ '0%{opacity:'+z+'}' +
63
+ start + '%{opacity:'+ alpha + '}' +
64
+ (start+0.01) + '%{opacity:1}' +
65
+ (start+trail)%100 + '%{opacity:'+ alpha + '}' +
66
+ '100%{opacity:'+ z + '}' +
67
+ '}', 0);
68
+ animations[name] = 1;
69
+ }
70
+ return name;
71
+ }
72
+
73
+ /**
74
+ * Tries various vendor prefixes and returns the first supported property.
75
+ **/
76
+ function vendor(el, prop) {
77
+ var s = el.style,
78
+ pp,
79
+ i;
80
+
81
+ if(s[prop] !== undefined) return prop;
82
+ prop = prop.charAt(0).toUpperCase() + prop.slice(1);
83
+ for(i=0; i<prefixes.length; i++) {
84
+ pp = prefixes[i]+prop;
85
+ if(s[pp] !== undefined) return pp;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Sets multiple style properties at once.
91
+ */
92
+ function css(el, prop) {
93
+ for (var n in prop) {
94
+ el.style[vendor(el, n)||n] = prop[n];
95
+ }
96
+ return el;
97
+ }
98
+
99
+ /**
100
+ * Fills in default values.
101
+ */
102
+ function merge(obj) {
103
+ for (var i=1; i < arguments.length; i++) {
104
+ var def = arguments[i];
105
+ for (var n in def) {
106
+ if (obj[n] === undefined) obj[n] = def[n];
107
+ }
108
+ }
109
+ return obj;
110
+ }
111
+
112
+ /**
113
+ * Returns the absolute page-offset of the given element.
114
+ */
115
+ function pos(el) {
116
+ var o = {x:el.offsetLeft, y:el.offsetTop};
117
+ while((el = el.offsetParent)) {
118
+ o.x+=el.offsetLeft;
119
+ o.y+=el.offsetTop;
120
+ }
121
+ return o;
122
+ }
123
+
124
+ /** The constructor */
125
+ var Spinner = function Spinner(o) {
126
+ if (!this.spin) return new Spinner(o);
127
+ 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 = {
141
+ spin: function(target) {
142
+ this.stop();
143
+ var self = this,
144
+ el = self.el = css(createEl(), {position: 'relative'}),
145
+ ep, // element position
146
+ tp; // target position
147
+
148
+ if (target) {
149
+ tp = pos(ins(target, el, target.firstChild));
150
+ ep = pos(el);
151
+ css(el, {
152
+ left: (target.offsetWidth >> 1) - ep.x+tp.x + 'px',
153
+ top: (target.offsetHeight >> 1) - ep.y+tp.y + 'px'
154
+ });
155
+ }
156
+ el.setAttribute('aria-role', 'progressbar');
157
+ self.lines(el, self.opts);
158
+ if (!useCssAnimations) {
159
+ // 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() {
168
+ i++;
169
+ for (var s=o.lines; s; s--) {
170
+ var alpha = Math.max(1-(i+s*astep)%f * ostep, o.opacity);
171
+ self.opacity(el, o.lines-s, alpha, o);
172
+ }
173
+ self.timeout = self.el && setTimeout(anim, ~~(1000/fps));
174
+ })();
175
+ }
176
+ return self;
177
+ },
178
+ stop: function() {
179
+ var el = this.el;
180
+ if (el) {
181
+ clearTimeout(this.timeout);
182
+ if (el.parentNode) el.parentNode.removeChild(el);
183
+ this.el = undefined;
184
+ }
185
+ return this;
186
+ }
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
+ };
220
+
221
+ /////////////////////////////////////////////////////////////////////////
222
+ // VML rendering for IE
223
+ /////////////////////////////////////////////////////////////////////////
224
+
225
+ /**
226
+ * Check and init VML support
227
+ */
228
+ (function() {
229
+ var s = css(createEl('group'), {behavior: 'url(#default#VML)'}),
230
+ i;
231
+
232
+ if (!vendor(s, 'transform') && s.adj) {
233
+
234
+ // VML support detected. Insert CSS rules ...
235
+ for (i=4; i--;) sheet.addRule(['group', 'roundrect', 'fill', 'stroke'][i], 'behavior:url(#default#VML)');
236
+
237
+ proto.lines = function(el, o) {
238
+ var r = o.length+o.width,
239
+ s = 2*r;
240
+
241
+ function grp() {
242
+ return css(createEl('group', {coordsize: s +' '+s, coordorigin: -r +' '+-r}), {width: s, height: s});
243
+ }
244
+
245
+ var g = grp(),
246
+ margin = ~(o.length+o.radius+o.width)+'px',
247
+ i;
248
+
249
+ function seg(i, dx, filter) {
250
+ ins(g,
251
+ ins(css(grp(), {rotation: 360 / o.lines * i + 'deg', left: ~~dx}),
252
+ ins(css(createEl('roundrect', {arcsize: 1}), {
253
+ width: r,
254
+ height: o.width,
255
+ left: o.radius,
256
+ top: -o.width>>1,
257
+ filter: filter
258
+ }),
259
+ createEl('fill', {color: o.color, opacity: o.opacity}),
260
+ createEl('stroke', {opacity: 0}) // transparent stroke to fix color bleeding upon opacity change
261
+ )
262
+ )
263
+ );
264
+ }
265
+
266
+ if (o.shadow) {
267
+ for (i = 1; i <= o.lines; i++) {
268
+ seg(i, -2, 'progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)');
269
+ }
270
+ }
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);
278
+ };
279
+ proto.opacity = function(el, i, val, o) {
280
+ var c = el.firstChild;
281
+ o = o.shadow && o.lines || 0;
282
+ if (c && i+o < c.childNodes.length) {
283
+ c = c.childNodes[i+o]; c = c && c.firstChild; c = c && c.firstChild;
284
+ if (c) c.opacity = val;
285
+ }
286
+ };
287
+ }
288
+ else {
289
+ useCssAnimations = vendor(s, 'animation');
290
+ }
291
+ })();
292
+
293
+ window.Spinner = Spinner;
294
+
295
+ })(window, document);
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spinjs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dmytrii Nagirniak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70244426089200 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70244426089200
25
+ description: An animated CSS3 loading spinner with VML fallback for IE.
26
+ email:
27
+ - dnagir@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - lib/spinjs-rails.rb
37
+ - lib/spinjs-rails/engine.rb
38
+ - lib/spinjs-rails/version.rb
39
+ - spinjs-rails.gemspec
40
+ - vendor/assets/javascripts/jquery.spin.js
41
+ - vendor/assets/javascripts/spin.js
42
+ homepage: https://github.com/dnagir/spinjs-rails
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ segments:
55
+ - 0
56
+ hash: 1031122124930786029
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ segments:
64
+ - 0
65
+ hash: 1031122124930786029
66
+ requirements: []
67
+ rubyforge_project: spinjs-rails
68
+ rubygems_version: 1.8.10
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: A spinning activity indicator for Rails 3 with no images and CSS.
72
+ test_files: []