stellar-js-rails 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +67 -0
- data/LICENSE +21 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/lib/stellar-js-rails.rb +1 -0
- data/lib/stellar-js-rails/rails.rb +2 -0
- data/lib/stellar-js-rails/rails/engine.rb +6 -0
- data/lib/stellar-js-rails/rails/version.rb +5 -0
- data/stellar-js-rails.gemspec +25 -0
- data/vendor/assets/javascripts/jquery.stellar.js +660 -0
- data/vendor/assets/javascripts/jquery.stellar.min.js +2 -0
- metadata +132 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
stellar-js-rails (0.6.1)
|
5
|
+
jquery-rails (~> 2.0)
|
6
|
+
railties (>= 3.2.0, < 5.0)
|
7
|
+
thor (~> 0.14)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionpack (3.2.12)
|
13
|
+
activemodel (= 3.2.12)
|
14
|
+
activesupport (= 3.2.12)
|
15
|
+
builder (~> 3.0.0)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
journey (~> 1.0.4)
|
18
|
+
rack (~> 1.4.5)
|
19
|
+
rack-cache (~> 1.2)
|
20
|
+
rack-test (~> 0.6.1)
|
21
|
+
sprockets (~> 2.2.1)
|
22
|
+
activemodel (3.2.12)
|
23
|
+
activesupport (= 3.2.12)
|
24
|
+
builder (~> 3.0.0)
|
25
|
+
activesupport (3.2.12)
|
26
|
+
i18n (~> 0.6)
|
27
|
+
multi_json (~> 1.0)
|
28
|
+
builder (3.0.4)
|
29
|
+
erubis (2.7.0)
|
30
|
+
hike (1.2.1)
|
31
|
+
i18n (0.6.4)
|
32
|
+
journey (1.0.4)
|
33
|
+
jquery-rails (2.2.1)
|
34
|
+
railties (>= 3.0, < 5.0)
|
35
|
+
thor (>= 0.14, < 2.0)
|
36
|
+
json (1.7.7)
|
37
|
+
multi_json (1.6.1)
|
38
|
+
rack (1.4.5)
|
39
|
+
rack-cache (1.2)
|
40
|
+
rack (>= 0.4)
|
41
|
+
rack-ssl (1.3.3)
|
42
|
+
rack
|
43
|
+
rack-test (0.6.2)
|
44
|
+
rack (>= 1.0)
|
45
|
+
railties (3.2.12)
|
46
|
+
actionpack (= 3.2.12)
|
47
|
+
activesupport (= 3.2.12)
|
48
|
+
rack-ssl (~> 1.3.2)
|
49
|
+
rake (>= 0.8.7)
|
50
|
+
rdoc (~> 3.4)
|
51
|
+
thor (>= 0.14.6, < 2.0)
|
52
|
+
rake (10.0.3)
|
53
|
+
rdoc (3.12.2)
|
54
|
+
json (~> 1.4)
|
55
|
+
sprockets (2.2.2)
|
56
|
+
hike (~> 1.2)
|
57
|
+
multi_json (~> 1.0)
|
58
|
+
rack (~> 1.0)
|
59
|
+
tilt (~> 1.1, != 1.3.0)
|
60
|
+
thor (0.17.0)
|
61
|
+
tilt (1.3.4)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
stellar-js-rails!
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2013 Inge Jørgensen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# stellar-js-rails
|
2
|
+
|
3
|
+
Provides [Stellar.js](http://markdalgleish.com/projects/stellar.js/) for your Rails 3 asset pipeline.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the following line to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'stellar-js-rails'
|
11
|
+
```
|
12
|
+
|
13
|
+
Now run `bundle install`.
|
14
|
+
|
15
|
+
To load the script, simply add a require statement to `app/assets/javascripts/application.js` (after jQuery):
|
16
|
+
|
17
|
+
//= require jquery
|
18
|
+
//= require jquery.stellar
|
19
|
+
|
20
|
+
You can also use the minified version:
|
21
|
+
|
22
|
+
//= require jquery
|
23
|
+
//= require jquery.stellar.min
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
See the [Stellar.js documentation](http://markdalgleish.com/projects/stellar.js/docs/).
|
28
|
+
|
29
|
+
## Credits
|
30
|
+
|
31
|
+
Stellar.js was written by [Mark Dalgleish](http://markdalgleish.com/).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
36
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
37
|
+
* Fork the project
|
38
|
+
* Start a feature/bugfix branch
|
39
|
+
* Commit and push until you are happy with your contribution
|
40
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
Copyright (c) 2013 Inge Jørgensen. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'stellar-js-rails/rails'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
APP_NAME = File.basename(__FILE__, '.gemspec')
|
3
|
+
|
4
|
+
require File.expand_path("../lib/#{APP_NAME}/rails/version", __FILE__)
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = APP_NAME
|
8
|
+
s.version = StellarJs::Rails::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Inge Jørgensen"]
|
11
|
+
s.email = ["inge@elektronaut.no"]
|
12
|
+
s.homepage = "http://rubygems.org/gems/#{APP_NAME}"
|
13
|
+
s.summary = "Stellar.js for Rails 3"
|
14
|
+
s.description = "This gem provides Stellar.js for your Rails 3 application."
|
15
|
+
|
16
|
+
s.required_rubygems_version = ">= 1.3.6"
|
17
|
+
|
18
|
+
s.add_dependency "railties", ">= 3.2.0", "< 5.0"
|
19
|
+
s.add_dependency "thor", "~> 0.14"
|
20
|
+
s.add_dependency "jquery-rails", "~> 2.0"
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
24
|
+
s.require_path = 'lib'
|
25
|
+
end
|
@@ -0,0 +1,660 @@
|
|
1
|
+
/*!
|
2
|
+
* Stellar.js v0.6.1
|
3
|
+
* http://markdalgleish.com/projects/stellar.js
|
4
|
+
*
|
5
|
+
* Copyright 2013, Mark Dalgleish
|
6
|
+
* This content is released under the MIT license
|
7
|
+
* http://markdalgleish.mit-license.org
|
8
|
+
*/
|
9
|
+
|
10
|
+
;(function($, window, document, undefined) {
|
11
|
+
|
12
|
+
var pluginName = 'stellar',
|
13
|
+
defaults = {
|
14
|
+
scrollProperty: 'scroll',
|
15
|
+
positionProperty: 'position',
|
16
|
+
horizontalScrolling: true,
|
17
|
+
verticalScrolling: true,
|
18
|
+
horizontalOffset: 0,
|
19
|
+
verticalOffset: 0,
|
20
|
+
responsive: false,
|
21
|
+
parallaxBackgrounds: true,
|
22
|
+
parallaxElements: true,
|
23
|
+
hideDistantElements: true,
|
24
|
+
hideElement: function($elem) { $elem.hide(); },
|
25
|
+
showElement: function($elem) { $elem.show(); }
|
26
|
+
},
|
27
|
+
|
28
|
+
scrollProperty = {
|
29
|
+
scroll: {
|
30
|
+
getLeft: function($elem) { return $elem.scrollLeft(); },
|
31
|
+
setLeft: function($elem, val) { $elem.scrollLeft(val); },
|
32
|
+
|
33
|
+
getTop: function($elem) { return $elem.scrollTop(); },
|
34
|
+
setTop: function($elem, val) { $elem.scrollTop(val); }
|
35
|
+
},
|
36
|
+
position: {
|
37
|
+
getLeft: function($elem) { return parseInt($elem.css('left'), 10) * -1; },
|
38
|
+
getTop: function($elem) { return parseInt($elem.css('top'), 10) * -1; }
|
39
|
+
},
|
40
|
+
margin: {
|
41
|
+
getLeft: function($elem) { return parseInt($elem.css('margin-left'), 10) * -1; },
|
42
|
+
getTop: function($elem) { return parseInt($elem.css('margin-top'), 10) * -1; }
|
43
|
+
},
|
44
|
+
transform: {
|
45
|
+
getLeft: function($elem) {
|
46
|
+
var computedTransform = getComputedStyle($elem[0])[prefixedTransform];
|
47
|
+
return (computedTransform !== 'none' ? parseInt(computedTransform.match(/(-?[0-9]+)/g)[4], 10) * -1 : 0);
|
48
|
+
},
|
49
|
+
getTop: function($elem) {
|
50
|
+
var computedTransform = getComputedStyle($elem[0])[prefixedTransform];
|
51
|
+
return (computedTransform !== 'none' ? parseInt(computedTransform.match(/(-?[0-9]+)/g)[5], 10) * -1 : 0);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
},
|
55
|
+
|
56
|
+
positionProperty = {
|
57
|
+
position: {
|
58
|
+
setLeft: function($elem, left) { $elem.css('left', left); },
|
59
|
+
setTop: function($elem, top) { $elem.css('top', top); }
|
60
|
+
},
|
61
|
+
transform: {
|
62
|
+
setPosition: function($elem, left, startingLeft, top, startingTop) {
|
63
|
+
$elem[0].style[prefixedTransform] = 'translate3d(' + (left - startingLeft) + 'px, ' + (top - startingTop) + 'px, 0)';
|
64
|
+
}
|
65
|
+
}
|
66
|
+
},
|
67
|
+
|
68
|
+
// Returns a function which adds a vendor prefix to any CSS property name
|
69
|
+
vendorPrefix = (function() {
|
70
|
+
var prefixes = /^(Moz|Webkit|Khtml|O|ms|Icab)(?=[A-Z])/,
|
71
|
+
style = $('script')[0].style,
|
72
|
+
prefix = '',
|
73
|
+
prop;
|
74
|
+
|
75
|
+
for (prop in style) {
|
76
|
+
if (prefixes.test(prop)) {
|
77
|
+
prefix = prop.match(prefixes)[0];
|
78
|
+
break;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
if ('WebkitOpacity' in style) { prefix = 'Webkit'; }
|
83
|
+
if ('KhtmlOpacity' in style) { prefix = 'Khtml'; }
|
84
|
+
|
85
|
+
return function(property) {
|
86
|
+
return prefix + (prefix.length > 0 ? property.charAt(0).toUpperCase() + property.slice(1) : property);
|
87
|
+
};
|
88
|
+
}()),
|
89
|
+
|
90
|
+
prefixedTransform = vendorPrefix('transform'),
|
91
|
+
|
92
|
+
supportsBackgroundPositionXY = $('<div />').css('background-position-x') !== undefined,
|
93
|
+
|
94
|
+
setBackgroundPosition = (supportsBackgroundPositionXY ?
|
95
|
+
function($elem, x, y) {
|
96
|
+
$elem.css({
|
97
|
+
'background-position-x': x,
|
98
|
+
'background-position-y': y
|
99
|
+
});
|
100
|
+
} :
|
101
|
+
function($elem, x, y) {
|
102
|
+
$elem.css('background-position', x + ' ' + y);
|
103
|
+
}
|
104
|
+
),
|
105
|
+
|
106
|
+
getBackgroundPosition = (supportsBackgroundPositionXY ?
|
107
|
+
function($elem) {
|
108
|
+
return [
|
109
|
+
$elem.css('background-position-x'),
|
110
|
+
$elem.css('background-position-y')
|
111
|
+
];
|
112
|
+
} :
|
113
|
+
function($elem) {
|
114
|
+
return $elem.css('background-position').split(' ');
|
115
|
+
}
|
116
|
+
),
|
117
|
+
|
118
|
+
requestAnimFrame = (
|
119
|
+
window.requestAnimationFrame ||
|
120
|
+
window.webkitRequestAnimationFrame ||
|
121
|
+
window.mozRequestAnimationFrame ||
|
122
|
+
window.oRequestAnimationFrame ||
|
123
|
+
window.msRequestAnimationFrame ||
|
124
|
+
function(callback) {
|
125
|
+
setTimeout(callback, 1000 / 60);
|
126
|
+
}
|
127
|
+
);
|
128
|
+
|
129
|
+
function Plugin(element, options) {
|
130
|
+
this.element = element;
|
131
|
+
this.options = $.extend({}, defaults, options);
|
132
|
+
|
133
|
+
this._defaults = defaults;
|
134
|
+
this._name = pluginName;
|
135
|
+
|
136
|
+
this.init();
|
137
|
+
}
|
138
|
+
|
139
|
+
Plugin.prototype = {
|
140
|
+
init: function() {
|
141
|
+
this.options.name = pluginName + '_' + Math.floor(Math.random() * 1e9);
|
142
|
+
|
143
|
+
this._defineElements();
|
144
|
+
this._defineGetters();
|
145
|
+
this._defineSetters();
|
146
|
+
this._handleWindowLoadAndResize();
|
147
|
+
this._detectViewport();
|
148
|
+
|
149
|
+
this.refresh({ firstLoad: true });
|
150
|
+
|
151
|
+
if (this.options.scrollProperty === 'scroll') {
|
152
|
+
this._handleScrollEvent();
|
153
|
+
} else {
|
154
|
+
this._startAnimationLoop();
|
155
|
+
}
|
156
|
+
},
|
157
|
+
_defineElements: function() {
|
158
|
+
if (this.element === document.body) this.element = window;
|
159
|
+
this.$scrollElement = $(this.element);
|
160
|
+
this.$element = (this.element === window ? $('body') : this.$scrollElement);
|
161
|
+
this.$viewportElement = (this.options.viewportElement !== undefined ? $(this.options.viewportElement) : (this.$scrollElement[0] === window || this.options.scrollProperty === 'scroll' ? this.$scrollElement : this.$scrollElement.parent()) );
|
162
|
+
},
|
163
|
+
_defineGetters: function() {
|
164
|
+
var self = this,
|
165
|
+
scrollPropertyAdapter = scrollProperty[self.options.scrollProperty];
|
166
|
+
|
167
|
+
this._getScrollLeft = function() {
|
168
|
+
return scrollPropertyAdapter.getLeft(self.$scrollElement);
|
169
|
+
};
|
170
|
+
|
171
|
+
this._getScrollTop = function() {
|
172
|
+
return scrollPropertyAdapter.getTop(self.$scrollElement);
|
173
|
+
};
|
174
|
+
},
|
175
|
+
_defineSetters: function() {
|
176
|
+
var self = this,
|
177
|
+
scrollPropertyAdapter = scrollProperty[self.options.scrollProperty],
|
178
|
+
positionPropertyAdapter = positionProperty[self.options.positionProperty],
|
179
|
+
setScrollLeft = scrollPropertyAdapter.setLeft,
|
180
|
+
setScrollTop = scrollPropertyAdapter.setTop;
|
181
|
+
|
182
|
+
this._setScrollLeft = (typeof setScrollLeft === 'function' ? function(val) {
|
183
|
+
setScrollLeft(self.$scrollElement, val);
|
184
|
+
} : $.noop);
|
185
|
+
|
186
|
+
this._setScrollTop = (typeof setScrollTop === 'function' ? function(val) {
|
187
|
+
setScrollTop(self.$scrollElement, val);
|
188
|
+
} : $.noop);
|
189
|
+
|
190
|
+
this._setPosition = positionPropertyAdapter.setPosition ||
|
191
|
+
function($elem, left, startingLeft, top, startingTop) {
|
192
|
+
if (self.options.horizontalScrolling) {
|
193
|
+
positionPropertyAdapter.setLeft($elem, left, startingLeft);
|
194
|
+
}
|
195
|
+
|
196
|
+
if (self.options.verticalScrolling) {
|
197
|
+
positionPropertyAdapter.setTop($elem, top, startingTop);
|
198
|
+
}
|
199
|
+
};
|
200
|
+
},
|
201
|
+
_handleWindowLoadAndResize: function() {
|
202
|
+
var self = this,
|
203
|
+
$window = $(window);
|
204
|
+
|
205
|
+
if (self.options.responsive) {
|
206
|
+
$window.bind('load.' + this.name, function() {
|
207
|
+
self.refresh();
|
208
|
+
});
|
209
|
+
}
|
210
|
+
|
211
|
+
$window.bind('resize.' + this.name, function() {
|
212
|
+
self._detectViewport();
|
213
|
+
|
214
|
+
if (self.options.responsive) {
|
215
|
+
self.refresh();
|
216
|
+
}
|
217
|
+
});
|
218
|
+
},
|
219
|
+
refresh: function(options) {
|
220
|
+
var self = this,
|
221
|
+
oldLeft = self._getScrollLeft(),
|
222
|
+
oldTop = self._getScrollTop();
|
223
|
+
|
224
|
+
if (!options || !options.firstLoad) {
|
225
|
+
this._reset();
|
226
|
+
}
|
227
|
+
|
228
|
+
this._setScrollLeft(0);
|
229
|
+
this._setScrollTop(0);
|
230
|
+
|
231
|
+
this._setOffsets();
|
232
|
+
this._findParticles();
|
233
|
+
this._findBackgrounds();
|
234
|
+
|
235
|
+
// Fix for WebKit background rendering bug
|
236
|
+
if (options && options.firstLoad && /WebKit/.test(navigator.userAgent)) {
|
237
|
+
$(window).load(function() {
|
238
|
+
var oldLeft = self._getScrollLeft(),
|
239
|
+
oldTop = self._getScrollTop();
|
240
|
+
|
241
|
+
self._setScrollLeft(oldLeft + 1);
|
242
|
+
self._setScrollTop(oldTop + 1);
|
243
|
+
|
244
|
+
self._setScrollLeft(oldLeft);
|
245
|
+
self._setScrollTop(oldTop);
|
246
|
+
});
|
247
|
+
}
|
248
|
+
|
249
|
+
this._setScrollLeft(oldLeft);
|
250
|
+
this._setScrollTop(oldTop);
|
251
|
+
},
|
252
|
+
_detectViewport: function() {
|
253
|
+
var viewportOffsets = this.$viewportElement.offset(),
|
254
|
+
hasOffsets = viewportOffsets !== null && viewportOffsets !== undefined;
|
255
|
+
|
256
|
+
this.viewportWidth = this.$viewportElement.width();
|
257
|
+
this.viewportHeight = this.$viewportElement.height();
|
258
|
+
|
259
|
+
this.viewportOffsetTop = (hasOffsets ? viewportOffsets.top : 0);
|
260
|
+
this.viewportOffsetLeft = (hasOffsets ? viewportOffsets.left : 0);
|
261
|
+
},
|
262
|
+
_findParticles: function() {
|
263
|
+
var self = this,
|
264
|
+
scrollLeft = this._getScrollLeft(),
|
265
|
+
scrollTop = this._getScrollTop();
|
266
|
+
|
267
|
+
if (this.particles !== undefined) {
|
268
|
+
for (var i = this.particles.length - 1; i >= 0; i--) {
|
269
|
+
this.particles[i].$element.data('stellar-elementIsActive', undefined);
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
this.particles = [];
|
274
|
+
|
275
|
+
if (!this.options.parallaxElements) return;
|
276
|
+
|
277
|
+
this.$element.find('[data-stellar-ratio]').each(function(i) {
|
278
|
+
var $this = $(this),
|
279
|
+
horizontalOffset,
|
280
|
+
verticalOffset,
|
281
|
+
positionLeft,
|
282
|
+
positionTop,
|
283
|
+
marginLeft,
|
284
|
+
marginTop,
|
285
|
+
$offsetParent,
|
286
|
+
offsetLeft,
|
287
|
+
offsetTop,
|
288
|
+
parentOffsetLeft = 0,
|
289
|
+
parentOffsetTop = 0,
|
290
|
+
tempParentOffsetLeft = 0,
|
291
|
+
tempParentOffsetTop = 0;
|
292
|
+
|
293
|
+
// Ensure this element isn't already part of another scrolling element
|
294
|
+
if (!$this.data('stellar-elementIsActive')) {
|
295
|
+
$this.data('stellar-elementIsActive', this);
|
296
|
+
} else if ($this.data('stellar-elementIsActive') !== this) {
|
297
|
+
return;
|
298
|
+
}
|
299
|
+
|
300
|
+
self.options.showElement($this);
|
301
|
+
|
302
|
+
// Save/restore the original top and left CSS values in case we refresh the particles or destroy the instance
|
303
|
+
if (!$this.data('stellar-startingLeft')) {
|
304
|
+
$this.data('stellar-startingLeft', $this.css('left'));
|
305
|
+
$this.data('stellar-startingTop', $this.css('top'));
|
306
|
+
} else {
|
307
|
+
$this.css('left', $this.data('stellar-startingLeft'));
|
308
|
+
$this.css('top', $this.data('stellar-startingTop'));
|
309
|
+
}
|
310
|
+
|
311
|
+
positionLeft = $this.position().left;
|
312
|
+
positionTop = $this.position().top;
|
313
|
+
|
314
|
+
// Catch-all for margin top/left properties (these evaluate to 'auto' in IE7 and IE8)
|
315
|
+
marginLeft = ($this.css('margin-left') === 'auto') ? 0 : parseInt($this.css('margin-left'), 10);
|
316
|
+
marginTop = ($this.css('margin-top') === 'auto') ? 0 : parseInt($this.css('margin-top'), 10);
|
317
|
+
|
318
|
+
offsetLeft = $this.offset().left - marginLeft;
|
319
|
+
offsetTop = $this.offset().top - marginTop;
|
320
|
+
|
321
|
+
// Calculate the offset parent
|
322
|
+
$this.parents().each(function() {
|
323
|
+
var $this = $(this);
|
324
|
+
|
325
|
+
if ($this.data('stellar-offset-parent') === true) {
|
326
|
+
parentOffsetLeft = tempParentOffsetLeft;
|
327
|
+
parentOffsetTop = tempParentOffsetTop;
|
328
|
+
$offsetParent = $this;
|
329
|
+
|
330
|
+
return false;
|
331
|
+
} else {
|
332
|
+
tempParentOffsetLeft += $this.position().left;
|
333
|
+
tempParentOffsetTop += $this.position().top;
|
334
|
+
}
|
335
|
+
});
|
336
|
+
|
337
|
+
// Detect the offsets
|
338
|
+
horizontalOffset = ($this.data('stellar-horizontal-offset') !== undefined ? $this.data('stellar-horizontal-offset') : ($offsetParent !== undefined && $offsetParent.data('stellar-horizontal-offset') !== undefined ? $offsetParent.data('stellar-horizontal-offset') : self.horizontalOffset));
|
339
|
+
verticalOffset = ($this.data('stellar-vertical-offset') !== undefined ? $this.data('stellar-vertical-offset') : ($offsetParent !== undefined && $offsetParent.data('stellar-vertical-offset') !== undefined ? $offsetParent.data('stellar-vertical-offset') : self.verticalOffset));
|
340
|
+
|
341
|
+
// Add our object to the particles collection
|
342
|
+
self.particles.push({
|
343
|
+
$element: $this,
|
344
|
+
$offsetParent: $offsetParent,
|
345
|
+
isFixed: $this.css('position') === 'fixed',
|
346
|
+
horizontalOffset: horizontalOffset,
|
347
|
+
verticalOffset: verticalOffset,
|
348
|
+
startingPositionLeft: positionLeft,
|
349
|
+
startingPositionTop: positionTop,
|
350
|
+
startingOffsetLeft: offsetLeft,
|
351
|
+
startingOffsetTop: offsetTop,
|
352
|
+
parentOffsetLeft: parentOffsetLeft,
|
353
|
+
parentOffsetTop: parentOffsetTop,
|
354
|
+
stellarRatio: ($this.data('stellar-ratio') !== undefined ? $this.data('stellar-ratio') : 1),
|
355
|
+
width: $this.outerWidth(true),
|
356
|
+
height: $this.outerHeight(true),
|
357
|
+
isHidden: false
|
358
|
+
});
|
359
|
+
});
|
360
|
+
},
|
361
|
+
_findBackgrounds: function() {
|
362
|
+
var self = this,
|
363
|
+
scrollLeft = this._getScrollLeft(),
|
364
|
+
scrollTop = this._getScrollTop(),
|
365
|
+
$backgroundElements;
|
366
|
+
|
367
|
+
this.backgrounds = [];
|
368
|
+
|
369
|
+
if (!this.options.parallaxBackgrounds) return;
|
370
|
+
|
371
|
+
$backgroundElements = this.$element.find('[data-stellar-background-ratio]');
|
372
|
+
|
373
|
+
if (this.$element.data('stellar-background-ratio')) {
|
374
|
+
$backgroundElements = $backgroundElements.add(this.$element);
|
375
|
+
}
|
376
|
+
|
377
|
+
$backgroundElements.each(function() {
|
378
|
+
var $this = $(this),
|
379
|
+
backgroundPosition = getBackgroundPosition($this),
|
380
|
+
horizontalOffset,
|
381
|
+
verticalOffset,
|
382
|
+
positionLeft,
|
383
|
+
positionTop,
|
384
|
+
marginLeft,
|
385
|
+
marginTop,
|
386
|
+
offsetLeft,
|
387
|
+
offsetTop,
|
388
|
+
$offsetParent,
|
389
|
+
parentOffsetLeft = 0,
|
390
|
+
parentOffsetTop = 0,
|
391
|
+
tempParentOffsetLeft = 0,
|
392
|
+
tempParentOffsetTop = 0;
|
393
|
+
|
394
|
+
// Ensure this element isn't already part of another scrolling element
|
395
|
+
if (!$this.data('stellar-backgroundIsActive')) {
|
396
|
+
$this.data('stellar-backgroundIsActive', this);
|
397
|
+
} else if ($this.data('stellar-backgroundIsActive') !== this) {
|
398
|
+
return;
|
399
|
+
}
|
400
|
+
|
401
|
+
// Save/restore the original top and left CSS values in case we destroy the instance
|
402
|
+
if (!$this.data('stellar-backgroundStartingLeft')) {
|
403
|
+
$this.data('stellar-backgroundStartingLeft', backgroundPosition[0]);
|
404
|
+
$this.data('stellar-backgroundStartingTop', backgroundPosition[1]);
|
405
|
+
} else {
|
406
|
+
setBackgroundPosition($this, $this.data('stellar-backgroundStartingLeft'), $this.data('stellar-backgroundStartingTop'));
|
407
|
+
}
|
408
|
+
|
409
|
+
// Catch-all for margin top/left properties (these evaluate to 'auto' in IE7 and IE8)
|
410
|
+
marginLeft = ($this.css('margin-left') === 'auto') ? 0 : parseInt($this.css('margin-left'), 10);
|
411
|
+
marginTop = ($this.css('margin-top') === 'auto') ? 0 : parseInt($this.css('margin-top'), 10);
|
412
|
+
|
413
|
+
offsetLeft = $this.offset().left - marginLeft - scrollLeft;
|
414
|
+
offsetTop = $this.offset().top - marginTop - scrollTop;
|
415
|
+
|
416
|
+
// Calculate the offset parent
|
417
|
+
$this.parents().each(function() {
|
418
|
+
var $this = $(this);
|
419
|
+
|
420
|
+
if ($this.data('stellar-offset-parent') === true) {
|
421
|
+
parentOffsetLeft = tempParentOffsetLeft;
|
422
|
+
parentOffsetTop = tempParentOffsetTop;
|
423
|
+
$offsetParent = $this;
|
424
|
+
|
425
|
+
return false;
|
426
|
+
} else {
|
427
|
+
tempParentOffsetLeft += $this.position().left;
|
428
|
+
tempParentOffsetTop += $this.position().top;
|
429
|
+
}
|
430
|
+
});
|
431
|
+
|
432
|
+
// Detect the offsets
|
433
|
+
horizontalOffset = ($this.data('stellar-horizontal-offset') !== undefined ? $this.data('stellar-horizontal-offset') : ($offsetParent !== undefined && $offsetParent.data('stellar-horizontal-offset') !== undefined ? $offsetParent.data('stellar-horizontal-offset') : self.horizontalOffset));
|
434
|
+
verticalOffset = ($this.data('stellar-vertical-offset') !== undefined ? $this.data('stellar-vertical-offset') : ($offsetParent !== undefined && $offsetParent.data('stellar-vertical-offset') !== undefined ? $offsetParent.data('stellar-vertical-offset') : self.verticalOffset));
|
435
|
+
|
436
|
+
self.backgrounds.push({
|
437
|
+
$element: $this,
|
438
|
+
$offsetParent: $offsetParent,
|
439
|
+
isFixed: $this.css('background-attachment') === 'fixed',
|
440
|
+
horizontalOffset: horizontalOffset,
|
441
|
+
verticalOffset: verticalOffset,
|
442
|
+
startingValueLeft: backgroundPosition[0],
|
443
|
+
startingValueTop: backgroundPosition[1],
|
444
|
+
startingBackgroundPositionLeft: (isNaN(parseInt(backgroundPosition[0], 10)) ? 0 : parseInt(backgroundPosition[0], 10)),
|
445
|
+
startingBackgroundPositionTop: (isNaN(parseInt(backgroundPosition[1], 10)) ? 0 : parseInt(backgroundPosition[1], 10)),
|
446
|
+
startingPositionLeft: $this.position().left,
|
447
|
+
startingPositionTop: $this.position().top,
|
448
|
+
startingOffsetLeft: offsetLeft,
|
449
|
+
startingOffsetTop: offsetTop,
|
450
|
+
parentOffsetLeft: parentOffsetLeft,
|
451
|
+
parentOffsetTop: parentOffsetTop,
|
452
|
+
stellarRatio: ($this.data('stellar-background-ratio') === undefined ? 1 : $this.data('stellar-background-ratio'))
|
453
|
+
});
|
454
|
+
});
|
455
|
+
},
|
456
|
+
_reset: function() {
|
457
|
+
var particle,
|
458
|
+
startingPositionLeft,
|
459
|
+
startingPositionTop,
|
460
|
+
background,
|
461
|
+
i;
|
462
|
+
|
463
|
+
for (i = this.particles.length - 1; i >= 0; i--) {
|
464
|
+
particle = this.particles[i];
|
465
|
+
startingPositionLeft = particle.$element.data('stellar-startingLeft');
|
466
|
+
startingPositionTop = particle.$element.data('stellar-startingTop');
|
467
|
+
|
468
|
+
this._setPosition(particle.$element, startingPositionLeft, startingPositionLeft, startingPositionTop, startingPositionTop);
|
469
|
+
|
470
|
+
this.options.showElement(particle.$element);
|
471
|
+
|
472
|
+
particle.$element.data('stellar-startingLeft', null).data('stellar-elementIsActive', null).data('stellar-backgroundIsActive', null);
|
473
|
+
}
|
474
|
+
|
475
|
+
for (i = this.backgrounds.length - 1; i >= 0; i--) {
|
476
|
+
background = this.backgrounds[i];
|
477
|
+
|
478
|
+
background.$element.data('stellar-backgroundStartingLeft', null).data('stellar-backgroundStartingTop', null);
|
479
|
+
|
480
|
+
setBackgroundPosition(background.$element, background.startingValueLeft, background.startingValueTop);
|
481
|
+
}
|
482
|
+
},
|
483
|
+
destroy: function() {
|
484
|
+
this._reset();
|
485
|
+
|
486
|
+
this.$scrollElement.unbind('resize.' + this.name).unbind('scroll.' + this.name);
|
487
|
+
this._animationLoop = $.noop;
|
488
|
+
|
489
|
+
$(window).unbind('load.' + this.name).unbind('resize.' + this.name);
|
490
|
+
},
|
491
|
+
_setOffsets: function() {
|
492
|
+
var self = this,
|
493
|
+
$window = $(window);
|
494
|
+
|
495
|
+
$window.unbind('resize.horizontal-' + this.name).unbind('resize.vertical-' + this.name);
|
496
|
+
|
497
|
+
if (typeof this.options.horizontalOffset === 'function') {
|
498
|
+
this.horizontalOffset = this.options.horizontalOffset();
|
499
|
+
$window.bind('resize.horizontal-' + this.name, function() {
|
500
|
+
self.horizontalOffset = self.options.horizontalOffset();
|
501
|
+
});
|
502
|
+
} else {
|
503
|
+
this.horizontalOffset = this.options.horizontalOffset;
|
504
|
+
}
|
505
|
+
|
506
|
+
if (typeof this.options.verticalOffset === 'function') {
|
507
|
+
this.verticalOffset = this.options.verticalOffset();
|
508
|
+
$window.bind('resize.vertical-' + this.name, function() {
|
509
|
+
self.verticalOffset = self.options.verticalOffset();
|
510
|
+
});
|
511
|
+
} else {
|
512
|
+
this.verticalOffset = this.options.verticalOffset;
|
513
|
+
}
|
514
|
+
},
|
515
|
+
_repositionElements: function() {
|
516
|
+
var scrollLeft = this._getScrollLeft(),
|
517
|
+
scrollTop = this._getScrollTop(),
|
518
|
+
horizontalOffset,
|
519
|
+
verticalOffset,
|
520
|
+
particle,
|
521
|
+
fixedRatioOffset,
|
522
|
+
background,
|
523
|
+
bgLeft,
|
524
|
+
bgTop,
|
525
|
+
isVisibleVertical = true,
|
526
|
+
isVisibleHorizontal = true,
|
527
|
+
newPositionLeft,
|
528
|
+
newPositionTop,
|
529
|
+
newOffsetLeft,
|
530
|
+
newOffsetTop,
|
531
|
+
i;
|
532
|
+
|
533
|
+
// First check that the scroll position or container size has changed
|
534
|
+
if (this.currentScrollLeft === scrollLeft && this.currentScrollTop === scrollTop && this.currentWidth === this.viewportWidth && this.currentHeight === this.viewportHeight) {
|
535
|
+
return;
|
536
|
+
} else {
|
537
|
+
this.currentScrollLeft = scrollLeft;
|
538
|
+
this.currentScrollTop = scrollTop;
|
539
|
+
this.currentWidth = this.viewportWidth;
|
540
|
+
this.currentHeight = this.viewportHeight;
|
541
|
+
}
|
542
|
+
|
543
|
+
// Reposition elements
|
544
|
+
for (i = this.particles.length - 1; i >= 0; i--) {
|
545
|
+
particle = this.particles[i];
|
546
|
+
|
547
|
+
fixedRatioOffset = (particle.isFixed ? 1 : 0);
|
548
|
+
|
549
|
+
// Calculate position, then calculate what the particle's new offset will be (for visibility check)
|
550
|
+
if (this.options.horizontalScrolling) {
|
551
|
+
newPositionLeft = (scrollLeft + particle.horizontalOffset + this.viewportOffsetLeft + particle.startingPositionLeft - particle.startingOffsetLeft + particle.parentOffsetLeft) * -(particle.stellarRatio + fixedRatioOffset - 1) + particle.startingPositionLeft;
|
552
|
+
newOffsetLeft = newPositionLeft - particle.startingPositionLeft + particle.startingOffsetLeft;
|
553
|
+
} else {
|
554
|
+
newPositionLeft = particle.startingPositionLeft;
|
555
|
+
newOffsetLeft = particle.startingOffsetLeft;
|
556
|
+
}
|
557
|
+
|
558
|
+
if (this.options.verticalScrolling) {
|
559
|
+
newPositionTop = (scrollTop + particle.verticalOffset + this.viewportOffsetTop + particle.startingPositionTop - particle.startingOffsetTop + particle.parentOffsetTop) * -(particle.stellarRatio + fixedRatioOffset - 1) + particle.startingPositionTop;
|
560
|
+
newOffsetTop = newPositionTop - particle.startingPositionTop + particle.startingOffsetTop;
|
561
|
+
} else {
|
562
|
+
newPositionTop = particle.startingPositionTop;
|
563
|
+
newOffsetTop = particle.startingOffsetTop;
|
564
|
+
}
|
565
|
+
|
566
|
+
// Check visibility
|
567
|
+
if (this.options.hideDistantElements) {
|
568
|
+
isVisibleHorizontal = !this.options.horizontalScrolling || newOffsetLeft + particle.width > (particle.isFixed ? 0 : scrollLeft) && newOffsetLeft < (particle.isFixed ? 0 : scrollLeft) + this.viewportWidth + this.viewportOffsetLeft;
|
569
|
+
isVisibleVertical = !this.options.verticalScrolling || newOffsetTop + particle.height > (particle.isFixed ? 0 : scrollTop) && newOffsetTop < (particle.isFixed ? 0 : scrollTop) + this.viewportHeight + this.viewportOffsetTop;
|
570
|
+
}
|
571
|
+
|
572
|
+
if (isVisibleHorizontal && isVisibleVertical) {
|
573
|
+
if (particle.isHidden) {
|
574
|
+
this.options.showElement(particle.$element);
|
575
|
+
particle.isHidden = false;
|
576
|
+
}
|
577
|
+
|
578
|
+
this._setPosition(particle.$element, newPositionLeft, particle.startingPositionLeft, newPositionTop, particle.startingPositionTop);
|
579
|
+
} else {
|
580
|
+
if (!particle.isHidden) {
|
581
|
+
this.options.hideElement(particle.$element);
|
582
|
+
particle.isHidden = true;
|
583
|
+
}
|
584
|
+
}
|
585
|
+
}
|
586
|
+
|
587
|
+
// Reposition backgrounds
|
588
|
+
for (i = this.backgrounds.length - 1; i >= 0; i--) {
|
589
|
+
background = this.backgrounds[i];
|
590
|
+
|
591
|
+
fixedRatioOffset = (background.isFixed ? 0 : 1);
|
592
|
+
bgLeft = (this.options.horizontalScrolling ? (scrollLeft + background.horizontalOffset - this.viewportOffsetLeft - background.startingOffsetLeft + background.parentOffsetLeft - background.startingBackgroundPositionLeft) * (fixedRatioOffset - background.stellarRatio) + 'px' : background.startingValueLeft);
|
593
|
+
bgTop = (this.options.verticalScrolling ? (scrollTop + background.verticalOffset - this.viewportOffsetTop - background.startingOffsetTop + background.parentOffsetTop - background.startingBackgroundPositionTop) * (fixedRatioOffset - background.stellarRatio) + 'px' : background.startingValueTop);
|
594
|
+
|
595
|
+
setBackgroundPosition(background.$element, bgLeft, bgTop);
|
596
|
+
}
|
597
|
+
},
|
598
|
+
_handleScrollEvent: function() {
|
599
|
+
var self = this,
|
600
|
+
ticking = false;
|
601
|
+
|
602
|
+
var update = function() {
|
603
|
+
self._repositionElements();
|
604
|
+
ticking = false;
|
605
|
+
};
|
606
|
+
|
607
|
+
var requestTick = function() {
|
608
|
+
if (!ticking) {
|
609
|
+
requestAnimFrame(update);
|
610
|
+
ticking = true;
|
611
|
+
}
|
612
|
+
};
|
613
|
+
|
614
|
+
this.$scrollElement.bind('scroll.' + this.name, requestTick);
|
615
|
+
requestTick();
|
616
|
+
},
|
617
|
+
_startAnimationLoop: function() {
|
618
|
+
var self = this;
|
619
|
+
|
620
|
+
this._animationLoop = function() {
|
621
|
+
requestAnimFrame(self._animationLoop);
|
622
|
+
self._repositionElements();
|
623
|
+
};
|
624
|
+
this._animationLoop();
|
625
|
+
}
|
626
|
+
};
|
627
|
+
|
628
|
+
$.fn[pluginName] = function (options) {
|
629
|
+
var args = arguments;
|
630
|
+
if (options === undefined || typeof options === 'object') {
|
631
|
+
return this.each(function () {
|
632
|
+
if (!$.data(this, 'plugin_' + pluginName)) {
|
633
|
+
$.data(this, 'plugin_' + pluginName, new Plugin(this, options));
|
634
|
+
}
|
635
|
+
});
|
636
|
+
} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
|
637
|
+
return this.each(function () {
|
638
|
+
var instance = $.data(this, 'plugin_' + pluginName);
|
639
|
+
if (instance instanceof Plugin && typeof instance[options] === 'function') {
|
640
|
+
instance[options].apply(instance, Array.prototype.slice.call(args, 1));
|
641
|
+
}
|
642
|
+
if (options === 'destroy') {
|
643
|
+
$.data(this, 'plugin_' + pluginName, null);
|
644
|
+
}
|
645
|
+
});
|
646
|
+
}
|
647
|
+
};
|
648
|
+
|
649
|
+
$[pluginName] = function(options) {
|
650
|
+
var $window = $(window);
|
651
|
+
return $window.stellar.apply($window, Array.prototype.slice.call(arguments, 0));
|
652
|
+
};
|
653
|
+
|
654
|
+
// Expose the scroll and position property function hashes so they can be extended
|
655
|
+
$[pluginName].scrollProperty = scrollProperty;
|
656
|
+
$[pluginName].positionProperty = positionProperty;
|
657
|
+
|
658
|
+
// Expose the plugin class so it can be modified
|
659
|
+
window.Stellar = Plugin;
|
660
|
+
}(jQuery, this, document));
|
@@ -0,0 +1,2 @@
|
|
1
|
+
/*! Stellar.js v0.6.1 | Copyright 2013, Mark Dalgleish | http://markdalgleish.com/projects/stellar.js | http://markdalgleish.mit-license.org */
|
2
|
+
(function(e,t,n,r){function d(t,n){this.element=t,this.options=e.extend({},s,n),this._defaults=s,this._name=i,this.init()}var i="stellar",s={scrollProperty:"scroll",positionProperty:"position",horizontalScrolling:!0,verticalScrolling:!0,horizontalOffset:0,verticalOffset:0,responsive:!1,parallaxBackgrounds:!0,parallaxElements:!0,hideDistantElements:!0,hideElement:function(e){e.hide()},showElement:function(e){e.show()}},o={scroll:{getLeft:function(e){return e.scrollLeft()},setLeft:function(e,t){e.scrollLeft(t)},getTop:function(e){return e.scrollTop()},setTop:function(e,t){e.scrollTop(t)}},position:{getLeft:function(e){return parseInt(e.css("left"),10)*-1},getTop:function(e){return parseInt(e.css("top"),10)*-1}},margin:{getLeft:function(e){return parseInt(e.css("margin-left"),10)*-1},getTop:function(e){return parseInt(e.css("margin-top"),10)*-1}},transform:{getLeft:function(e){var t=getComputedStyle(e[0])[f];return t!=="none"?parseInt(t.match(/(-?[0-9]+)/g)[4],10)*-1:0},getTop:function(e){var t=getComputedStyle(e[0])[f];return t!=="none"?parseInt(t.match(/(-?[0-9]+)/g)[5],10)*-1:0}}},u={position:{setLeft:function(e,t){e.css("left",t)},setTop:function(e,t){e.css("top",t)}},transform:{setPosition:function(e,t,n,r,i){e[0].style[f]="translate3d("+(t-n)+"px, "+(r-i)+"px, 0)"}}},a=function(){var t=/^(Moz|Webkit|Khtml|O|ms|Icab)(?=[A-Z])/,n=e("script")[0].style,r="",i;for(i in n)if(t.test(i)){r=i.match(t)[0];break}return"WebkitOpacity"in n&&(r="Webkit"),"KhtmlOpacity"in n&&(r="Khtml"),function(e){return r+(r.length>0?e.charAt(0).toUpperCase()+e.slice(1):e)}}(),f=a("transform"),l=e("<div />").css("background-position-x")!==r,c=l?function(e,t,n){e.css({"background-position-x":t,"background-position-y":n})}:function(e,t,n){e.css("background-position",t+" "+n)},h=l?function(e){return[e.css("background-position-x"),e.css("background-position-y")]}:function(e){return e.css("background-position").split(" ")},p=t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)};d.prototype={init:function(){this.options.name=i+"_"+Math.floor(Math.random()*1e9),this._defineElements(),this._defineGetters(),this._defineSetters(),this._handleWindowLoadAndResize(),this._detectViewport(),this.refresh({firstLoad:!0}),this.options.scrollProperty==="scroll"?this._handleScrollEvent():this._startAnimationLoop()},_defineElements:function(){this.element===n.body&&(this.element=t),this.$scrollElement=e(this.element),this.$element=this.element===t?e("body"):this.$scrollElement,this.$viewportElement=this.options.viewportElement!==r?e(this.options.viewportElement):this.$scrollElement[0]===t||this.options.scrollProperty==="scroll"?this.$scrollElement:this.$scrollElement.parent()},_defineGetters:function(){var e=this,t=o[e.options.scrollProperty];this._getScrollLeft=function(){return t.getLeft(e.$scrollElement)},this._getScrollTop=function(){return t.getTop(e.$scrollElement)}},_defineSetters:function(){var t=this,n=o[t.options.scrollProperty],r=u[t.options.positionProperty],i=n.setLeft,s=n.setTop;this._setScrollLeft=typeof i=="function"?function(e){i(t.$scrollElement,e)}:e.noop,this._setScrollTop=typeof s=="function"?function(e){s(t.$scrollElement,e)}:e.noop,this._setPosition=r.setPosition||function(e,n,i,s,o){t.options.horizontalScrolling&&r.setLeft(e,n,i),t.options.verticalScrolling&&r.setTop(e,s,o)}},_handleWindowLoadAndResize:function(){var n=this,r=e(t);n.options.responsive&&r.bind("load."+this.name,function(){n.refresh()}),r.bind("resize."+this.name,function(){n._detectViewport(),n.options.responsive&&n.refresh()})},refresh:function(n){var r=this,i=r._getScrollLeft(),s=r._getScrollTop();(!n||!n.firstLoad)&&this._reset(),this._setScrollLeft(0),this._setScrollTop(0),this._setOffsets(),this._findParticles(),this._findBackgrounds(),n&&n.firstLoad&&/WebKit/.test(navigator.userAgent)&&e(t).load(function(){var e=r._getScrollLeft(),t=r._getScrollTop();r._setScrollLeft(e+1),r._setScrollTop(t+1),r._setScrollLeft(e),r._setScrollTop(t)}),this._setScrollLeft(i),this._setScrollTop(s)},_detectViewport:function(){var e=this.$viewportElement.offset(),t=e!==null&&e!==r;this.viewportWidth=this.$viewportElement.width(),this.viewportHeight=this.$viewportElement.height(),this.viewportOffsetTop=t?e.top:0,this.viewportOffsetLeft=t?e.left:0},_findParticles:function(){var t=this,n=this._getScrollLeft(),i=this._getScrollTop();if(this.particles!==r)for(var s=this.particles.length-1;s>=0;s--)this.particles[s].$element.data("stellar-elementIsActive",r);this.particles=[];if(!this.options.parallaxElements)return;this.$element.find("[data-stellar-ratio]").each(function(n){var i=e(this),s,o,u,a,f,l,c,h,p,d=0,v=0,m=0,g=0;if(!i.data("stellar-elementIsActive"))i.data("stellar-elementIsActive",this);else if(i.data("stellar-elementIsActive")!==this)return;t.options.showElement(i),i.data("stellar-startingLeft")?(i.css("left",i.data("stellar-startingLeft")),i.css("top",i.data("stellar-startingTop"))):(i.data("stellar-startingLeft",i.css("left")),i.data("stellar-startingTop",i.css("top"))),u=i.position().left,a=i.position().top,f=i.css("margin-left")==="auto"?0:parseInt(i.css("margin-left"),10),l=i.css("margin-top")==="auto"?0:parseInt(i.css("margin-top"),10),h=i.offset().left-f,p=i.offset().top-l,i.parents().each(function(){var t=e(this);if(t.data("stellar-offset-parent")===!0)return d=m,v=g,c=t,!1;m+=t.position().left,g+=t.position().top}),s=i.data("stellar-horizontal-offset")!==r?i.data("stellar-horizontal-offset"):c!==r&&c.data("stellar-horizontal-offset")!==r?c.data("stellar-horizontal-offset"):t.horizontalOffset,o=i.data("stellar-vertical-offset")!==r?i.data("stellar-vertical-offset"):c!==r&&c.data("stellar-vertical-offset")!==r?c.data("stellar-vertical-offset"):t.verticalOffset,t.particles.push({$element:i,$offsetParent:c,isFixed:i.css("position")==="fixed",horizontalOffset:s,verticalOffset:o,startingPositionLeft:u,startingPositionTop:a,startingOffsetLeft:h,startingOffsetTop:p,parentOffsetLeft:d,parentOffsetTop:v,stellarRatio:i.data("stellar-ratio")!==r?i.data("stellar-ratio"):1,width:i.outerWidth(!0),height:i.outerHeight(!0),isHidden:!1})})},_findBackgrounds:function(){var t=this,n=this._getScrollLeft(),i=this._getScrollTop(),s;this.backgrounds=[];if(!this.options.parallaxBackgrounds)return;s=this.$element.find("[data-stellar-background-ratio]"),this.$element.data("stellar-background-ratio")&&(s=s.add(this.$element)),s.each(function(){var s=e(this),o=h(s),u,a,f,l,p,d,v,m,g,y=0,b=0,w=0,E=0;if(!s.data("stellar-backgroundIsActive"))s.data("stellar-backgroundIsActive",this);else if(s.data("stellar-backgroundIsActive")!==this)return;s.data("stellar-backgroundStartingLeft")?c(s,s.data("stellar-backgroundStartingLeft"),s.data("stellar-backgroundStartingTop")):(s.data("stellar-backgroundStartingLeft",o[0]),s.data("stellar-backgroundStartingTop",o[1])),p=s.css("margin-left")==="auto"?0:parseInt(s.css("margin-left"),10),d=s.css("margin-top")==="auto"?0:parseInt(s.css("margin-top"),10),v=s.offset().left-p-n,m=s.offset().top-d-i,s.parents().each(function(){var t=e(this);if(t.data("stellar-offset-parent")===!0)return y=w,b=E,g=t,!1;w+=t.position().left,E+=t.position().top}),u=s.data("stellar-horizontal-offset")!==r?s.data("stellar-horizontal-offset"):g!==r&&g.data("stellar-horizontal-offset")!==r?g.data("stellar-horizontal-offset"):t.horizontalOffset,a=s.data("stellar-vertical-offset")!==r?s.data("stellar-vertical-offset"):g!==r&&g.data("stellar-vertical-offset")!==r?g.data("stellar-vertical-offset"):t.verticalOffset,t.backgrounds.push({$element:s,$offsetParent:g,isFixed:s.css("background-attachment")==="fixed",horizontalOffset:u,verticalOffset:a,startingValueLeft:o[0],startingValueTop:o[1],startingBackgroundPositionLeft:isNaN(parseInt(o[0],10))?0:parseInt(o[0],10),startingBackgroundPositionTop:isNaN(parseInt(o[1],10))?0:parseInt(o[1],10),startingPositionLeft:s.position().left,startingPositionTop:s.position().top,startingOffsetLeft:v,startingOffsetTop:m,parentOffsetLeft:y,parentOffsetTop:b,stellarRatio:s.data("stellar-background-ratio")===r?1:s.data("stellar-background-ratio")})})},_reset:function(){var e,t,n,r,i;for(i=this.particles.length-1;i>=0;i--)e=this.particles[i],t=e.$element.data("stellar-startingLeft"),n=e.$element.data("stellar-startingTop"),this._setPosition(e.$element,t,t,n,n),this.options.showElement(e.$element),e.$element.data("stellar-startingLeft",null).data("stellar-elementIsActive",null).data("stellar-backgroundIsActive",null);for(i=this.backgrounds.length-1;i>=0;i--)r=this.backgrounds[i],r.$element.data("stellar-backgroundStartingLeft",null).data("stellar-backgroundStartingTop",null),c(r.$element,r.startingValueLeft,r.startingValueTop)},destroy:function(){this._reset(),this.$scrollElement.unbind("resize."+this.name).unbind("scroll."+this.name),this._animationLoop=e.noop,e(t).unbind("load."+this.name).unbind("resize."+this.name)},_setOffsets:function(){var n=this,r=e(t);r.unbind("resize.horizontal-"+this.name).unbind("resize.vertical-"+this.name),typeof this.options.horizontalOffset=="function"?(this.horizontalOffset=this.options.horizontalOffset(),r.bind("resize.horizontal-"+this.name,function(){n.horizontalOffset=n.options.horizontalOffset()})):this.horizontalOffset=this.options.horizontalOffset,typeof this.options.verticalOffset=="function"?(this.verticalOffset=this.options.verticalOffset(),r.bind("resize.vertical-"+this.name,function(){n.verticalOffset=n.options.verticalOffset()})):this.verticalOffset=this.options.verticalOffset},_repositionElements:function(){var e=this._getScrollLeft(),t=this._getScrollTop(),n,r,i,s,o,u,a,f=!0,l=!0,h,p,d,v,m;if(this.currentScrollLeft===e&&this.currentScrollTop===t&&this.currentWidth===this.viewportWidth&&this.currentHeight===this.viewportHeight)return;this.currentScrollLeft=e,this.currentScrollTop=t,this.currentWidth=this.viewportWidth,this.currentHeight=this.viewportHeight;for(m=this.particles.length-1;m>=0;m--)i=this.particles[m],s=i.isFixed?1:0,this.options.horizontalScrolling?(h=(e+i.horizontalOffset+this.viewportOffsetLeft+i.startingPositionLeft-i.startingOffsetLeft+i.parentOffsetLeft)*-(i.stellarRatio+s-1)+i.startingPositionLeft,d=h-i.startingPositionLeft+i.startingOffsetLeft):(h=i.startingPositionLeft,d=i.startingOffsetLeft),this.options.verticalScrolling?(p=(t+i.verticalOffset+this.viewportOffsetTop+i.startingPositionTop-i.startingOffsetTop+i.parentOffsetTop)*-(i.stellarRatio+s-1)+i.startingPositionTop,v=p-i.startingPositionTop+i.startingOffsetTop):(p=i.startingPositionTop,v=i.startingOffsetTop),this.options.hideDistantElements&&(l=!this.options.horizontalScrolling||d+i.width>(i.isFixed?0:e)&&d<(i.isFixed?0:e)+this.viewportWidth+this.viewportOffsetLeft,f=!this.options.verticalScrolling||v+i.height>(i.isFixed?0:t)&&v<(i.isFixed?0:t)+this.viewportHeight+this.viewportOffsetTop),l&&f?(i.isHidden&&(this.options.showElement(i.$element),i.isHidden=!1),this._setPosition(i.$element,h,i.startingPositionLeft,p,i.startingPositionTop)):i.isHidden||(this.options.hideElement(i.$element),i.isHidden=!0);for(m=this.backgrounds.length-1;m>=0;m--)o=this.backgrounds[m],s=o.isFixed?0:1,u=this.options.horizontalScrolling?(e+o.horizontalOffset-this.viewportOffsetLeft-o.startingOffsetLeft+o.parentOffsetLeft-o.startingBackgroundPositionLeft)*(s-o.stellarRatio)+"px":o.startingValueLeft,a=this.options.verticalScrolling?(t+o.verticalOffset-this.viewportOffsetTop-o.startingOffsetTop+o.parentOffsetTop-o.startingBackgroundPositionTop)*(s-o.stellarRatio)+"px":o.startingValueTop,c(o.$element,u,a)},_handleScrollEvent:function(){var e=this,t=!1,n=function(){e._repositionElements(),t=!1},r=function(){t||(p(n),t=!0)};this.$scrollElement.bind("scroll."+this.name,r),r()},_startAnimationLoop:function(){var e=this;this._animationLoop=function(){p(e._animationLoop),e._repositionElements()},this._animationLoop()}},e.fn[i]=function(t){var n=arguments;if(t===r||typeof t=="object")return this.each(function(){e.data(this,"plugin_"+i)||e.data(this,"plugin_"+i,new d(this,t))});if(typeof t=="string"&&t[0]!=="_"&&t!=="init")return this.each(function(){var r=e.data(this,"plugin_"+i);r instanceof d&&typeof r[t]=="function"&&r[t].apply(r,Array.prototype.slice.call(n,1)),t==="destroy"&&e.data(this,"plugin_"+i,null)})},e[i]=function(n){var r=e(t);return r.stellar.apply(r,Array.prototype.slice.call(arguments,0))},e[i].scrollProperty=o,e[i].positionProperty=u,t.Stellar=d})(jQuery,this,document);
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stellar-js-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 5
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
- 1
|
10
|
+
version: 0.6.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Inge J\xC3\xB8rgensen"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-03-01 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 15
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
version: 3.2.0
|
32
|
+
- - <
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
hash: 31
|
35
|
+
segments:
|
36
|
+
- 5
|
37
|
+
- 0
|
38
|
+
version: "5.0"
|
39
|
+
prerelease: false
|
40
|
+
type: :runtime
|
41
|
+
name: railties
|
42
|
+
requirement: *id001
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
hash: 23
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
- 14
|
53
|
+
version: "0.14"
|
54
|
+
prerelease: false
|
55
|
+
type: :runtime
|
56
|
+
name: thor
|
57
|
+
requirement: *id002
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ~>
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 2
|
67
|
+
- 0
|
68
|
+
version: "2.0"
|
69
|
+
prerelease: false
|
70
|
+
type: :runtime
|
71
|
+
name: jquery-rails
|
72
|
+
requirement: *id003
|
73
|
+
description: This gem provides Stellar.js for your Rails 3 application.
|
74
|
+
email:
|
75
|
+
- inge@elektronaut.no
|
76
|
+
executables: []
|
77
|
+
|
78
|
+
extensions: []
|
79
|
+
|
80
|
+
extra_rdoc_files: []
|
81
|
+
|
82
|
+
files:
|
83
|
+
- .gitignore
|
84
|
+
- Gemfile
|
85
|
+
- Gemfile.lock
|
86
|
+
- LICENSE
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- lib/stellar-js-rails.rb
|
90
|
+
- lib/stellar-js-rails/rails.rb
|
91
|
+
- lib/stellar-js-rails/rails/engine.rb
|
92
|
+
- lib/stellar-js-rails/rails/version.rb
|
93
|
+
- stellar-js-rails.gemspec
|
94
|
+
- vendor/assets/javascripts/jquery.stellar.js
|
95
|
+
- vendor/assets/javascripts/jquery.stellar.min.js
|
96
|
+
homepage: http://rubygems.org/gems/stellar-js-rails
|
97
|
+
licenses: []
|
98
|
+
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
hash: 23
|
119
|
+
segments:
|
120
|
+
- 1
|
121
|
+
- 3
|
122
|
+
- 6
|
123
|
+
version: 1.3.6
|
124
|
+
requirements: []
|
125
|
+
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.24
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Stellar.js for Rails 3
|
131
|
+
test_files: []
|
132
|
+
|