jquery-waypoints-rails 0.0.2.alpha → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/app/assets/javascripts/jquery.waypoints.infinite.js +70 -0
- data/app/assets/javascripts/jquery.waypoints.js +517 -0
- data/app/assets/javascripts/jquery.waypoints.sticky.js +65 -0
- data/jquery-waypoints-rails.gemspec +2 -2
- data/lib/jquery-waypoints-rails/version.rb +1 -1
- metadata +18 -20
- data/app/assets/javascripts/waypoints.js +0 -676
@@ -0,0 +1,65 @@
|
|
1
|
+
// Generated by CoffeeScript 1.6.2
|
2
|
+
/*
|
3
|
+
Sticky Elements Shortcut for jQuery Waypoints - v2.0.5
|
4
|
+
Copyright (c) 2011-2014 Caleb Troughton
|
5
|
+
Licensed under the MIT license.
|
6
|
+
https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt
|
7
|
+
*/
|
8
|
+
|
9
|
+
|
10
|
+
(function() {
|
11
|
+
(function(root, factory) {
|
12
|
+
if (typeof define === 'function' && define.amd) {
|
13
|
+
return define(['jquery', 'waypoints'], factory);
|
14
|
+
} else {
|
15
|
+
return factory(root.jQuery);
|
16
|
+
}
|
17
|
+
})(window, function($) {
|
18
|
+
var defaults, wrap;
|
19
|
+
|
20
|
+
defaults = {
|
21
|
+
wrapper: '<div class="sticky-wrapper" />',
|
22
|
+
stuckClass: 'stuck',
|
23
|
+
direction: 'down right'
|
24
|
+
};
|
25
|
+
wrap = function($elements, options) {
|
26
|
+
var $parent;
|
27
|
+
|
28
|
+
$elements.wrap(options.wrapper);
|
29
|
+
$parent = $elements.parent();
|
30
|
+
return $parent.data('isWaypointStickyWrapper', true);
|
31
|
+
};
|
32
|
+
$.waypoints('extendFn', 'sticky', function(opt) {
|
33
|
+
var $wrap, options, originalHandler;
|
34
|
+
|
35
|
+
options = $.extend({}, $.fn.waypoint.defaults, defaults, opt);
|
36
|
+
$wrap = wrap(this, options);
|
37
|
+
originalHandler = options.handler;
|
38
|
+
options.handler = function(direction) {
|
39
|
+
var $sticky, shouldBeStuck;
|
40
|
+
|
41
|
+
$sticky = $(this).children(':first');
|
42
|
+
shouldBeStuck = options.direction.indexOf(direction) !== -1;
|
43
|
+
$sticky.toggleClass(options.stuckClass, shouldBeStuck);
|
44
|
+
$wrap.height(shouldBeStuck ? $sticky.outerHeight() : '');
|
45
|
+
if (originalHandler != null) {
|
46
|
+
return originalHandler.call(this, direction);
|
47
|
+
}
|
48
|
+
};
|
49
|
+
$wrap.waypoint(options);
|
50
|
+
return this.data('stuckClass', options.stuckClass);
|
51
|
+
});
|
52
|
+
return $.waypoints('extendFn', 'unsticky', function() {
|
53
|
+
var $parent;
|
54
|
+
|
55
|
+
$parent = this.parent();
|
56
|
+
if (!$parent.data('isWaypointStickyWrapper')) {
|
57
|
+
return this;
|
58
|
+
}
|
59
|
+
$parent.waypoint('destroy');
|
60
|
+
this.unwrap();
|
61
|
+
return this.removeClass(this.data('stuckClass'));
|
62
|
+
});
|
63
|
+
});
|
64
|
+
|
65
|
+
}).call(this);
|
@@ -5,8 +5,8 @@ require "jquery-waypoints-rails/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "jquery-waypoints-rails"
|
7
7
|
s.version = JqueryWaypoints::Rails::VERSION
|
8
|
-
s.authors = ["Wagner Amaral", "Daniel Libanori"]
|
9
|
-
s.email = ["wamaral@wamaral.org", "daniellibanori@gmail.com"]
|
8
|
+
s.authors = ["Wagner Amaral", "Daniel Libanori", "Albert Bellonch Llargués"]
|
9
|
+
s.email = ["wamaral@wamaral.org", "daniellibanori@gmail.com", "albert@itnig.net"]
|
10
10
|
s.homepage = "http://github.com/wamaral/jquery-waypoints-rails"
|
11
11
|
s.summary = "This gem just adds jquery-waypoints to your ASSets"
|
12
12
|
|
metadata
CHANGED
@@ -1,87 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jquery-waypoints-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease: 6
|
4
|
+
version: 2.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Wagner Amaral
|
9
8
|
- Daniel Libanori
|
9
|
+
- Albert Bellonch Llargués
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
18
|
requirements:
|
20
|
-
- -
|
19
|
+
- - ">="
|
21
20
|
- !ruby/object:Gem::Version
|
22
21
|
version: 3.1.0
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
24
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
25
|
requirements:
|
28
|
-
- -
|
26
|
+
- - ">="
|
29
27
|
- !ruby/object:Gem::Version
|
30
28
|
version: 3.1.0
|
31
29
|
- !ruby/object:Gem::Dependency
|
32
30
|
name: bundler
|
33
31
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
32
|
requirements:
|
36
|
-
- -
|
33
|
+
- - ">="
|
37
34
|
- !ruby/object:Gem::Version
|
38
35
|
version: '0'
|
39
36
|
type: :development
|
40
37
|
prerelease: false
|
41
38
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
39
|
requirements:
|
44
|
-
- -
|
40
|
+
- - ">="
|
45
41
|
- !ruby/object:Gem::Version
|
46
42
|
version: '0'
|
47
43
|
description:
|
48
44
|
email:
|
49
45
|
- wamaral@wamaral.org
|
50
46
|
- daniellibanori@gmail.com
|
47
|
+
- albert@itnig.net
|
51
48
|
executables: []
|
52
49
|
extensions: []
|
53
50
|
extra_rdoc_files: []
|
54
51
|
files:
|
55
|
-
- .gitignore
|
52
|
+
- ".gitignore"
|
56
53
|
- Gemfile
|
57
54
|
- README.md
|
58
55
|
- Rakefile
|
59
|
-
- app/assets/javascripts/waypoints.js
|
56
|
+
- app/assets/javascripts/jquery.waypoints.infinite.js
|
57
|
+
- app/assets/javascripts/jquery.waypoints.js
|
58
|
+
- app/assets/javascripts/jquery.waypoints.sticky.js
|
60
59
|
- jquery-waypoints-rails.gemspec
|
61
60
|
- lib/jquery-waypoints-rails.rb
|
62
61
|
- lib/jquery-waypoints-rails/version.rb
|
63
62
|
homepage: http://github.com/wamaral/jquery-waypoints-rails
|
64
63
|
licenses: []
|
64
|
+
metadata: {}
|
65
65
|
post_install_message:
|
66
66
|
rdoc_options: []
|
67
67
|
require_paths:
|
68
68
|
- lib
|
69
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
70
|
requirements:
|
72
|
-
- -
|
71
|
+
- - ">="
|
73
72
|
- !ruby/object:Gem::Version
|
74
73
|
version: '0'
|
75
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
75
|
requirements:
|
78
|
-
- -
|
76
|
+
- - ">="
|
79
77
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
78
|
+
version: '0'
|
81
79
|
requirements: []
|
82
80
|
rubyforge_project: jquery-waypoints-rails
|
83
|
-
rubygems_version:
|
81
|
+
rubygems_version: 2.2.2
|
84
82
|
signing_key:
|
85
|
-
specification_version:
|
83
|
+
specification_version: 4
|
86
84
|
summary: This gem just adds jquery-waypoints to your ASSets
|
87
85
|
test_files: []
|
@@ -1,676 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
jQuery Waypoints - v1.1.7
|
3
|
-
Copyright (c) 2011-2012 Caleb Troughton
|
4
|
-
Dual licensed under the MIT license and GPL license.
|
5
|
-
https://github.com/imakewebthings/jquery-waypoints/blob/master/MIT-license.txt
|
6
|
-
https://github.com/imakewebthings/jquery-waypoints/blob/master/GPL-license.txt
|
7
|
-
*/
|
8
|
-
|
9
|
-
/*
|
10
|
-
Waypoints is a small jQuery plugin that makes it easy to execute a function
|
11
|
-
whenever you scroll to an element.
|
12
|
-
|
13
|
-
GitHub Repository: https://github.com/imakewebthings/jquery-waypoints
|
14
|
-
Documentation and Examples: http://imakewebthings.github.com/jquery-waypoints
|
15
|
-
|
16
|
-
Changelog:
|
17
|
-
v1.1.7
|
18
|
-
- Actually fix the post-load bug in Issue #28 from v1.1.3.
|
19
|
-
v1.1.6
|
20
|
-
- Fix potential memory leak by unbinding events on empty context elements.
|
21
|
-
v1.1.5
|
22
|
-
- Make plugin compatible with Browserify/RequireJS. (Thanks @cjroebuck)
|
23
|
-
v1.1.4
|
24
|
-
- Add handler option to give alternate binding method. (Issue #34)
|
25
|
-
v1.1.3
|
26
|
-
- Fix cases where waypoints are added post-load and should be triggered
|
27
|
-
immediately. (Issue #28)
|
28
|
-
v1.1.2
|
29
|
-
- Fixed error thrown by waypoints with triggerOnce option that were
|
30
|
-
triggered via resize refresh.
|
31
|
-
v1.1.1
|
32
|
-
- Fixed bug in initialization where all offsets were being calculated
|
33
|
-
as if set to 0 initially, causing unwarranted triggers during the
|
34
|
-
subsequent refresh.
|
35
|
-
- Added onlyOnScroll, an option for individual waypoints that disables
|
36
|
-
triggers due to an offset refresh that crosses the current scroll
|
37
|
-
point. (All credit to @knuton on this one.)
|
38
|
-
v1.1
|
39
|
-
- Moved the continuous option out of global settings and into the options
|
40
|
-
object for individual waypoints.
|
41
|
-
- Added the context option, which allows for using waypoints within any
|
42
|
-
scrollable element, not just the window.
|
43
|
-
v1.0.2
|
44
|
-
- Moved scroll and resize handler bindings out of load. Should play nicer
|
45
|
-
with async loaders like Head JS and LABjs.
|
46
|
-
- Fixed a 1px off error when using certain % offsets.
|
47
|
-
- Added unit tests.
|
48
|
-
v1.0.1
|
49
|
-
- Added $.waypoints('viewportHeight').
|
50
|
-
- Fixed iOS bug (using the new viewportHeight method).
|
51
|
-
- Added offset function alias: 'bottom-in-view'.
|
52
|
-
v1.0
|
53
|
-
- Initial release.
|
54
|
-
|
55
|
-
Support:
|
56
|
-
- jQuery versions 1.4.3+
|
57
|
-
- IE6+, FF3+, Chrome 6+, Safari 4+, Opera 11
|
58
|
-
- Other versions and browsers may work, these are just the ones I've looked at.
|
59
|
-
*/
|
60
|
-
|
61
|
-
(function($, wp, wps, window, undefined){
|
62
|
-
'$:nomunge';
|
63
|
-
|
64
|
-
var $w = $(window),
|
65
|
-
|
66
|
-
// Keeping common strings as variables = better minification
|
67
|
-
eventName = 'waypoint.reached',
|
68
|
-
|
69
|
-
/*
|
70
|
-
For the waypoint and direction passed in, trigger the waypoint.reached
|
71
|
-
event and deal with the triggerOnce option.
|
72
|
-
*/
|
73
|
-
triggerWaypoint = function(way, dir) {
|
74
|
-
way.element.trigger(eventName, dir);
|
75
|
-
if (way.options.triggerOnce) {
|
76
|
-
way.element[wp]('destroy');
|
77
|
-
}
|
78
|
-
},
|
79
|
-
|
80
|
-
/*
|
81
|
-
Given a jQuery element and Context, returns the index of that element in the waypoints
|
82
|
-
array. Returns the index, or -1 if the element is not a waypoint.
|
83
|
-
*/
|
84
|
-
waypointIndex = function(el, context) {
|
85
|
-
if (!context) return -1;
|
86
|
-
var i = context.waypoints.length - 1;
|
87
|
-
while (i >= 0 && context.waypoints[i].element[0] !== el[0]) {
|
88
|
-
i -= 1;
|
89
|
-
}
|
90
|
-
return i;
|
91
|
-
},
|
92
|
-
|
93
|
-
// Private list of all elements used as scrolling contexts for waypoints.
|
94
|
-
contexts = [],
|
95
|
-
|
96
|
-
/*
|
97
|
-
Context Class - represents a scrolling context. Properties include:
|
98
|
-
element: jQuery object containing a single HTML element.
|
99
|
-
waypoints: Array of waypoints operating under this scroll context.
|
100
|
-
oldScroll: Keeps the previous scroll position to determine scroll direction.
|
101
|
-
didScroll: Flag used in scrolling the context's scroll event.
|
102
|
-
didResize: Flag used in scrolling the context's resize event.
|
103
|
-
doScroll: Function that checks for crossed waypoints. Called from throttler.
|
104
|
-
*/
|
105
|
-
Context = function(context) {
|
106
|
-
$.extend(this, {
|
107
|
-
element: $(context),
|
108
|
-
oldScroll: 0,
|
109
|
-
|
110
|
-
/*
|
111
|
-
List of all elements that have been registered as waypoints.
|
112
|
-
Each object in the array contains:
|
113
|
-
element: jQuery object containing a single HTML element.
|
114
|
-
offset: The window scroll offset, in px, that triggers the waypoint event.
|
115
|
-
options: Options object that was passed to the waypoint fn function.
|
116
|
-
*/
|
117
|
-
'waypoints': [],
|
118
|
-
|
119
|
-
didScroll: false,
|
120
|
-
didResize: false,
|
121
|
-
|
122
|
-
doScroll: $.proxy(function() {
|
123
|
-
var newScroll = this.element.scrollTop(),
|
124
|
-
|
125
|
-
// Are we scrolling up or down? Used for direction argument in callback.
|
126
|
-
isDown = newScroll > this.oldScroll,
|
127
|
-
that = this,
|
128
|
-
|
129
|
-
// Get a list of all waypoints that were crossed since last scroll move.
|
130
|
-
pointsHit = $.grep(this.waypoints, function(el, i) {
|
131
|
-
return isDown ?
|
132
|
-
(el.offset > that.oldScroll && el.offset <= newScroll) :
|
133
|
-
(el.offset <= that.oldScroll && el.offset > newScroll);
|
134
|
-
}),
|
135
|
-
len = pointsHit.length;
|
136
|
-
|
137
|
-
// iOS adjustment
|
138
|
-
if (!this.oldScroll || !newScroll) {
|
139
|
-
$[wps]('refresh');
|
140
|
-
}
|
141
|
-
|
142
|
-
// Done with scroll comparisons, store new scroll before ejection
|
143
|
-
this.oldScroll = newScroll;
|
144
|
-
|
145
|
-
// No waypoints crossed? Eject.
|
146
|
-
if (!len) return;
|
147
|
-
|
148
|
-
// If several waypoints triggered, need to do so in reverse order going up
|
149
|
-
if (!isDown) pointsHit.reverse();
|
150
|
-
|
151
|
-
/*
|
152
|
-
One scroll move may cross several waypoints. If the waypoint's continuous
|
153
|
-
option is true it should fire even if it isn't the last waypoint. If false,
|
154
|
-
it will only fire if it's the last one.
|
155
|
-
*/
|
156
|
-
$.each(pointsHit, function(i, point) {
|
157
|
-
if (point.options.continuous || i === len - 1) {
|
158
|
-
triggerWaypoint(point, [isDown ? 'down' : 'up']);
|
159
|
-
}
|
160
|
-
});
|
161
|
-
}, this)
|
162
|
-
});
|
163
|
-
|
164
|
-
// Setup scroll and resize handlers. Throttled at the settings-defined rate limits.
|
165
|
-
$(context).bind('scroll.waypoints', $.proxy(function() {
|
166
|
-
if (!this.didScroll) {
|
167
|
-
this.didScroll = true;
|
168
|
-
window.setTimeout($.proxy(function() {
|
169
|
-
this.doScroll();
|
170
|
-
this.didScroll = false;
|
171
|
-
}, this), $[wps].settings.scrollThrottle);
|
172
|
-
}
|
173
|
-
}, this)).bind('resize.waypoints', $.proxy(function() {
|
174
|
-
if (!this.didResize) {
|
175
|
-
this.didResize = true;
|
176
|
-
window.setTimeout($.proxy(function() {
|
177
|
-
$[wps]('refresh');
|
178
|
-
this.didResize = false;
|
179
|
-
}, this), $[wps].settings.resizeThrottle);
|
180
|
-
}
|
181
|
-
}, this));
|
182
|
-
|
183
|
-
$w.load($.proxy(function() {
|
184
|
-
/*
|
185
|
-
Fire a scroll check, should the page be loaded at a non-zero scroll value,
|
186
|
-
as with a fragment id link or a page refresh.
|
187
|
-
*/
|
188
|
-
this.doScroll();
|
189
|
-
}, this));
|
190
|
-
},
|
191
|
-
|
192
|
-
/* Returns a Context object from the contexts array, given the raw HTML element
|
193
|
-
for that context. */
|
194
|
-
getContextByElement = function(element) {
|
195
|
-
var found = null;
|
196
|
-
|
197
|
-
$.each(contexts, function(i, c) {
|
198
|
-
if (c.element[0] === element) {
|
199
|
-
found = c;
|
200
|
-
return false;
|
201
|
-
}
|
202
|
-
});
|
203
|
-
|
204
|
-
return found;
|
205
|
-
},
|
206
|
-
|
207
|
-
// Methods exposed to the effin' object
|
208
|
-
methods = {
|
209
|
-
/*
|
210
|
-
jQuery.fn.waypoint([handler], [options])
|
211
|
-
|
212
|
-
handler
|
213
|
-
function, optional
|
214
|
-
A callback function called when the user scrolls past the element.
|
215
|
-
The function signature is function(event, direction) where event is
|
216
|
-
a standard jQuery Event Object and direction is a string, either 'down'
|
217
|
-
or 'up' indicating which direction the user is scrolling.
|
218
|
-
|
219
|
-
options
|
220
|
-
object, optional
|
221
|
-
A map of options to apply to this set of waypoints, including where on
|
222
|
-
the browser window the waypoint is triggered. For a full list of
|
223
|
-
options and their defaults, see $.fn.waypoint.defaults.
|
224
|
-
|
225
|
-
This is how you register an element as a waypoint. When the user scrolls past
|
226
|
-
that element it triggers waypoint.reached, a custom event. Since the
|
227
|
-
parameters for creating a waypoint are optional, we have a few different
|
228
|
-
possible signatures. Let’s look at each of them.
|
229
|
-
|
230
|
-
someElements.waypoint();
|
231
|
-
|
232
|
-
Calling .waypoint with no parameters will register the elements as waypoints
|
233
|
-
using the default options. The elements will fire the waypoint.reached event,
|
234
|
-
but calling it in this way does not bind any handler to the event. You can
|
235
|
-
bind to the event yourself, as with any other event, like so:
|
236
|
-
|
237
|
-
someElements.bind('waypoint.reached', function(event, direction) {
|
238
|
-
// make it rain
|
239
|
-
});
|
240
|
-
|
241
|
-
You will usually want to create a waypoint and immediately bind a function to
|
242
|
-
waypoint.reached, and can do so by passing a handler as the first argument to
|
243
|
-
.waypoint:
|
244
|
-
|
245
|
-
someElements.waypoint(function(event, direction) {
|
246
|
-
if (direction === 'down') {
|
247
|
-
// do this on the way down
|
248
|
-
}
|
249
|
-
else {
|
250
|
-
// do this on the way back up through the waypoint
|
251
|
-
}
|
252
|
-
});
|
253
|
-
|
254
|
-
This will still use the default options, which will trigger the waypoint when
|
255
|
-
the top of the element hits the top of the window. We can pass .waypoint an
|
256
|
-
options object to customize things:
|
257
|
-
|
258
|
-
someElements.waypoint(function(event, direction) {
|
259
|
-
// do something amazing
|
260
|
-
}, {
|
261
|
-
offset: '50%' // middle of the page
|
262
|
-
});
|
263
|
-
|
264
|
-
You can also pass just an options object.
|
265
|
-
|
266
|
-
someElements.waypoint({
|
267
|
-
offset: 100 // 100px from the top
|
268
|
-
});
|
269
|
-
|
270
|
-
This behaves like .waypoint(), in that it registers the elements as waypoints
|
271
|
-
but binds no event handlers.
|
272
|
-
|
273
|
-
Calling .waypoint on an existing waypoint will extend the previous options.
|
274
|
-
If the call includes a handler, it will be bound to waypoint.reached without
|
275
|
-
unbinding any other handlers.
|
276
|
-
*/
|
277
|
-
init: function(f, options) {
|
278
|
-
// Register each element as a waypoint, add to array.
|
279
|
-
this.each(function() {
|
280
|
-
var cElement = $.fn[wp].defaults.context,
|
281
|
-
context,
|
282
|
-
$this = $(this);
|
283
|
-
|
284
|
-
// Default window context or a specific element?
|
285
|
-
if (options && options.context) {
|
286
|
-
cElement = options.context;
|
287
|
-
}
|
288
|
-
|
289
|
-
// Find the closest element that matches the context
|
290
|
-
if (!$.isWindow(cElement)) {
|
291
|
-
cElement = $this.closest(cElement)[0];
|
292
|
-
}
|
293
|
-
context = getContextByElement(cElement);
|
294
|
-
|
295
|
-
// Not a context yet? Create and push.
|
296
|
-
if (!context) {
|
297
|
-
context = new Context(cElement);
|
298
|
-
contexts.push(context);
|
299
|
-
}
|
300
|
-
|
301
|
-
// Extend default and preexisting options
|
302
|
-
var ndx = waypointIndex($this, context),
|
303
|
-
base = ndx < 0 ? $.fn[wp].defaults : context.waypoints[ndx].options,
|
304
|
-
opts = $.extend({}, base, options);
|
305
|
-
|
306
|
-
// Offset aliases
|
307
|
-
opts.offset = opts.offset === "bottom-in-view" ?
|
308
|
-
function() {
|
309
|
-
var cHeight = $.isWindow(cElement) ? $[wps]('viewportHeight')
|
310
|
-
: $(cElement).height();
|
311
|
-
return cHeight - $(this).outerHeight();
|
312
|
-
} : opts.offset;
|
313
|
-
|
314
|
-
// Update, or create new waypoint
|
315
|
-
if (ndx < 0) {
|
316
|
-
context.waypoints.push({
|
317
|
-
'element': $this,
|
318
|
-
'offset': null,
|
319
|
-
'options': opts
|
320
|
-
});
|
321
|
-
}
|
322
|
-
else {
|
323
|
-
context.waypoints[ndx].options = opts;
|
324
|
-
}
|
325
|
-
|
326
|
-
// Bind the function if it was passed in.
|
327
|
-
if (f) {
|
328
|
-
$this.bind(eventName, f);
|
329
|
-
}
|
330
|
-
// Bind the function in the handler option if it exists.
|
331
|
-
if (options && options.handler) {
|
332
|
-
$this.bind(eventName, options.handler);
|
333
|
-
}
|
334
|
-
});
|
335
|
-
|
336
|
-
// Need to re-sort+refresh the waypoints array after new elements are added.
|
337
|
-
$[wps]('refresh');
|
338
|
-
|
339
|
-
return this;
|
340
|
-
},
|
341
|
-
|
342
|
-
|
343
|
-
/*
|
344
|
-
jQuery.fn.waypoint('remove')
|
345
|
-
|
346
|
-
Passing the string 'remove' to .waypoint unregisters the elements as waypoints
|
347
|
-
and wipes any custom options, but leaves the waypoint.reached events bound.
|
348
|
-
Calling .waypoint again in the future would reregister the waypoint and the old
|
349
|
-
handlers would continue to work.
|
350
|
-
*/
|
351
|
-
remove: function() {
|
352
|
-
return this.each(function(i, el) {
|
353
|
-
var $el = $(el);
|
354
|
-
|
355
|
-
$.each(contexts, function(i, c) {
|
356
|
-
var ndx = waypointIndex($el, c);
|
357
|
-
|
358
|
-
if (ndx >= 0) {
|
359
|
-
c.waypoints.splice(ndx, 1);
|
360
|
-
|
361
|
-
if (!c.waypoints.length) {
|
362
|
-
c.element.unbind('scroll.waypoints resize.waypoints');
|
363
|
-
contexts.splice(i, 1);
|
364
|
-
}
|
365
|
-
}
|
366
|
-
});
|
367
|
-
});
|
368
|
-
},
|
369
|
-
|
370
|
-
/*
|
371
|
-
jQuery.fn.waypoint('destroy')
|
372
|
-
|
373
|
-
Passing the string 'destroy' to .waypoint will unbind all waypoint.reached
|
374
|
-
event handlers on those elements and unregisters them as waypoints.
|
375
|
-
*/
|
376
|
-
destroy: function() {
|
377
|
-
return this.unbind(eventName)[wp]('remove');
|
378
|
-
}
|
379
|
-
},
|
380
|
-
|
381
|
-
/*
|
382
|
-
Methods used by the jQuery object extension.
|
383
|
-
*/
|
384
|
-
jQMethods = {
|
385
|
-
|
386
|
-
/*
|
387
|
-
jQuery.waypoints('refresh')
|
388
|
-
|
389
|
-
This will force a recalculation of each waypoint’s trigger point based on
|
390
|
-
its offset option and context. This is called automatically whenever the window
|
391
|
-
(or other defined context) is resized, new waypoints are added, or a waypoint’s
|
392
|
-
options are modified. If your project is changing the DOM or page layout without
|
393
|
-
doing one of these things, you may want to manually call this refresh.
|
394
|
-
*/
|
395
|
-
refresh: function() {
|
396
|
-
$.each(contexts, function(i, c) {
|
397
|
-
var isWin = $.isWindow(c.element[0]),
|
398
|
-
contextOffset = isWin ? 0 : c.element.offset().top,
|
399
|
-
contextHeight = isWin ? $[wps]('viewportHeight') : c.element.height(),
|
400
|
-
contextScroll = isWin ? 0 : c.element.scrollTop();
|
401
|
-
|
402
|
-
$.each(c.waypoints, function(j, o) {
|
403
|
-
/* $.each isn't safe from element removal due to triggerOnce.
|
404
|
-
Should rewrite the loop but this is way easier. */
|
405
|
-
if (!o) return;
|
406
|
-
|
407
|
-
// Adjustment is just the offset if it's a px value
|
408
|
-
var adjustment = o.options.offset,
|
409
|
-
oldOffset = o.offset;
|
410
|
-
|
411
|
-
// Set adjustment to the return value if offset is a function.
|
412
|
-
if (typeof o.options.offset === "function") {
|
413
|
-
adjustment = o.options.offset.apply(o.element);
|
414
|
-
}
|
415
|
-
// Calculate the adjustment if offset is a percentage.
|
416
|
-
else if (typeof o.options.offset === "string") {
|
417
|
-
var amount = parseFloat(o.options.offset);
|
418
|
-
adjustment = o.options.offset.indexOf("%") ?
|
419
|
-
Math.ceil(contextHeight * (amount / 100)) : amount;
|
420
|
-
}
|
421
|
-
|
422
|
-
/*
|
423
|
-
Set the element offset to the window scroll offset, less
|
424
|
-
all our adjustments.
|
425
|
-
*/
|
426
|
-
o.offset = o.element.offset().top - contextOffset
|
427
|
-
+ contextScroll - adjustment;
|
428
|
-
|
429
|
-
/*
|
430
|
-
An element offset change across the current scroll point triggers
|
431
|
-
the event, just as if we scrolled past it unless prevented by an
|
432
|
-
optional flag.
|
433
|
-
*/
|
434
|
-
if (o.options.onlyOnScroll) return;
|
435
|
-
|
436
|
-
if (oldOffset !== null && c.oldScroll > oldOffset && c.oldScroll <= o.offset) {
|
437
|
-
triggerWaypoint(o, ['up']);
|
438
|
-
}
|
439
|
-
else if (oldOffset !== null && c.oldScroll < oldOffset && c.oldScroll >= o.offset) {
|
440
|
-
triggerWaypoint(o, ['down']);
|
441
|
-
}
|
442
|
-
/* For new waypoints added after load, check that down should have
|
443
|
-
already been triggered */
|
444
|
-
else if (!oldOffset && c.element.scrollTop() > o.offset) {
|
445
|
-
triggerWaypoint(o, ['down']);
|
446
|
-
}
|
447
|
-
});
|
448
|
-
|
449
|
-
// Keep waypoints sorted by offset value.
|
450
|
-
c.waypoints.sort(function(a, b) {
|
451
|
-
return a.offset - b.offset;
|
452
|
-
});
|
453
|
-
});
|
454
|
-
},
|
455
|
-
|
456
|
-
|
457
|
-
/*
|
458
|
-
jQuery.waypoints('viewportHeight')
|
459
|
-
|
460
|
-
This will return the height of the viewport, adjusting for inconsistencies
|
461
|
-
that come with calling $(window).height() in iOS. Recommended for use
|
462
|
-
within any offset functions.
|
463
|
-
*/
|
464
|
-
viewportHeight: function() {
|
465
|
-
return (window.innerHeight ? window.innerHeight : $w.height());
|
466
|
-
},
|
467
|
-
|
468
|
-
|
469
|
-
/*
|
470
|
-
jQuery.waypoints()
|
471
|
-
|
472
|
-
This will return a jQuery object with a collection of all registered waypoint
|
473
|
-
elements.
|
474
|
-
|
475
|
-
$('.post').waypoint();
|
476
|
-
$('.ad-unit').waypoint(function(event, direction) {
|
477
|
-
// Passed an ad unit
|
478
|
-
});
|
479
|
-
console.log($.waypoints());
|
480
|
-
|
481
|
-
The example above would log a jQuery object containing all .post and .ad-unit
|
482
|
-
elements.
|
483
|
-
*/
|
484
|
-
aggregate: function() {
|
485
|
-
var points = $();
|
486
|
-
$.each(contexts, function(i, c) {
|
487
|
-
$.each(c.waypoints, function(i, e) {
|
488
|
-
points = points.add(e.element);
|
489
|
-
});
|
490
|
-
});
|
491
|
-
return points;
|
492
|
-
}
|
493
|
-
};
|
494
|
-
|
495
|
-
|
496
|
-
/*
|
497
|
-
fn extension. Delegates to appropriate method.
|
498
|
-
*/
|
499
|
-
$.fn[wp] = function(method) {
|
500
|
-
|
501
|
-
if (methods[method]) {
|
502
|
-
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
503
|
-
}
|
504
|
-
else if (typeof method === "function" || !method) {
|
505
|
-
return methods.init.apply(this, arguments);
|
506
|
-
}
|
507
|
-
else if (typeof method === "object") {
|
508
|
-
return methods.init.apply(this, [null, method]);
|
509
|
-
}
|
510
|
-
else {
|
511
|
-
$.error( 'Method ' + method + ' does not exist on jQuery ' + wp );
|
512
|
-
}
|
513
|
-
};
|
514
|
-
|
515
|
-
|
516
|
-
/*
|
517
|
-
The default options object that is extended when calling .waypoint. It has the
|
518
|
-
following properties:
|
519
|
-
|
520
|
-
context
|
521
|
-
string | element | jQuery*
|
522
|
-
default: window
|
523
|
-
The context defines which scrollable element the waypoint belongs to and acts
|
524
|
-
within. The default, window, means the waypoint offset is calculated with relation
|
525
|
-
to the whole viewport. You can set this to another element to use the waypoints
|
526
|
-
within that element. Accepts a selector string, *but if you use jQuery 1.6+ it
|
527
|
-
also accepts a raw HTML element or jQuery object.
|
528
|
-
|
529
|
-
continuous
|
530
|
-
boolean
|
531
|
-
default: true
|
532
|
-
If true, and multiple waypoints are triggered in one scroll, this waypoint will
|
533
|
-
trigger even if it is not the last waypoint reached. If false, it will only
|
534
|
-
trigger if it is the last waypoint.
|
535
|
-
|
536
|
-
handler
|
537
|
-
function
|
538
|
-
default: undefined
|
539
|
-
An alternative way to bind functions to the waypoint, without using the function
|
540
|
-
as the first argument to the waypoint function.
|
541
|
-
|
542
|
-
offset
|
543
|
-
number | string | function
|
544
|
-
default: 0
|
545
|
-
Determines how far the top of the element must be from the top of the browser
|
546
|
-
window to trigger a waypoint. It can be a number, which is taken as a number
|
547
|
-
of pixels, a string representing a percentage of the viewport height, or a
|
548
|
-
function that will return a number of pixels.
|
549
|
-
|
550
|
-
onlyOnScroll
|
551
|
-
boolean
|
552
|
-
default: false
|
553
|
-
If true, this waypoint will not trigger if an offset change during a refresh
|
554
|
-
causes it to pass the current scroll point.
|
555
|
-
|
556
|
-
triggerOnce
|
557
|
-
boolean
|
558
|
-
default: false
|
559
|
-
If true, the waypoint will be destroyed when triggered.
|
560
|
-
|
561
|
-
An offset of 250 would trigger the waypoint when the top of the element is 250px
|
562
|
-
from the top of the viewport. Negative values for any offset work as you might
|
563
|
-
expect. A value of -100 would trigger the waypoint when the element is 100px above
|
564
|
-
the top of the window.
|
565
|
-
|
566
|
-
offset: '100%'
|
567
|
-
|
568
|
-
A string percentage will determine the pixel offset based on the height of the
|
569
|
-
window. When resizing the window, this offset will automatically be recalculated
|
570
|
-
without needing to call $.waypoints('refresh').
|
571
|
-
|
572
|
-
// The bottom of the element is in view
|
573
|
-
offset: function() {
|
574
|
-
return $.waypoints('viewportHeight') - $(this).outerHeight();
|
575
|
-
}
|
576
|
-
|
577
|
-
Offset can take a function, which must return a number of pixels from the top of
|
578
|
-
the window. The this value will always refer to the raw HTML element of the
|
579
|
-
waypoint. As with % values, functions are recalculated automatically when the
|
580
|
-
window resizes. For more on recalculating offsets, see $.waypoints('refresh').
|
581
|
-
|
582
|
-
An offset value of 'bottom-in-view' will act as an alias for the function in the
|
583
|
-
example above, as this is a common usage.
|
584
|
-
|
585
|
-
offset: 'bottom-in-view'
|
586
|
-
|
587
|
-
You can see this alias in use on the Scroll Analytics example page.
|
588
|
-
|
589
|
-
The triggerOnce flag, if true, will destroy the waypoint after the first trigger.
|
590
|
-
This is just a shortcut for calling .waypoint('destroy') within the waypoint
|
591
|
-
handler. This is useful in situations such as scroll analytics, where you only
|
592
|
-
want to record an event once for each page visit.
|
593
|
-
|
594
|
-
The context option lets you use Waypoints within an element other than the window.
|
595
|
-
You can define the context with a selector string and the waypoint will act within
|
596
|
-
the nearest ancestor that matches this selector.
|
597
|
-
|
598
|
-
$('.something-scrollable .waypoint').waypoint({
|
599
|
-
context: '.something-scrollable'
|
600
|
-
});
|
601
|
-
|
602
|
-
You can see this in action on the Dial Controls example.
|
603
|
-
|
604
|
-
The handler option gives authors an alternative way to bind functions when
|
605
|
-
creating a waypoint. In place of:
|
606
|
-
|
607
|
-
$('.item').waypoint(function(event, direction) {
|
608
|
-
// make things happen
|
609
|
-
});
|
610
|
-
|
611
|
-
You may instead write:
|
612
|
-
|
613
|
-
$('.item').waypoint({
|
614
|
-
handler: function(event, direction) {
|
615
|
-
// make things happen
|
616
|
-
}
|
617
|
-
});
|
618
|
-
|
619
|
-
*/
|
620
|
-
$.fn[wp].defaults = {
|
621
|
-
continuous: true,
|
622
|
-
offset: 0,
|
623
|
-
triggerOnce: false,
|
624
|
-
context: window
|
625
|
-
};
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
/*
|
632
|
-
jQuery object extension. Delegates to appropriate methods above.
|
633
|
-
*/
|
634
|
-
$[wps] = function(method) {
|
635
|
-
if (jQMethods[method]) {
|
636
|
-
return jQMethods[method].apply(this);
|
637
|
-
}
|
638
|
-
else {
|
639
|
-
return jQMethods['aggregate']();
|
640
|
-
}
|
641
|
-
};
|
642
|
-
|
643
|
-
|
644
|
-
/*
|
645
|
-
$.waypoints.settings
|
646
|
-
|
647
|
-
Settings object that determines some of the plugin’s behavior.
|
648
|
-
|
649
|
-
resizeThrottle
|
650
|
-
number
|
651
|
-
default: 200
|
652
|
-
For performance reasons, the refresh performed during resizes is
|
653
|
-
throttled. This value is the rate-limit in milliseconds between resize
|
654
|
-
refreshes. For more information on throttling, check out Ben Alman’s
|
655
|
-
throttle / debounce plugin.
|
656
|
-
http://benalman.com/projects/jquery-throttle-debounce-plugin/
|
657
|
-
|
658
|
-
scrollThrottle
|
659
|
-
number
|
660
|
-
default: 100
|
661
|
-
For performance reasons, checking for any crossed waypoints during a
|
662
|
-
scroll event is throttled. This value is the rate-limit in milliseconds
|
663
|
-
between scroll checks. For more information on throttling, check out Ben
|
664
|
-
Alman’s throttle / debounce plugin.
|
665
|
-
http://benalman.com/projects/jquery-throttle-debounce-plugin/
|
666
|
-
*/
|
667
|
-
$[wps].settings = {
|
668
|
-
resizeThrottle: 200,
|
669
|
-
scrollThrottle: 100
|
670
|
-
};
|
671
|
-
|
672
|
-
$w.load(function() {
|
673
|
-
// Calculate everything once on load.
|
674
|
-
$[wps]('refresh');
|
675
|
-
});
|
676
|
-
})(jQuery, 'waypoint', 'waypoints', window);
|