-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaypoints-sticky.js
More file actions
executable file
·54 lines (49 loc) · 1.57 KB
/
waypoints-sticky.js
File metadata and controls
executable file
·54 lines (49 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Generated by CoffeeScript 1.4.0
/*
Sticky Elements Shortcut for jQuery Waypoints - v2.0.2
Copyright (c) 2011-2013 Caleb Troughton
Dual licensed under the MIT license and GPL license.
https://github.com/imakewebthings/jquery-waypoints/blob/master/licenses.txt
*/
(function() {
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
return define(['jquery', 'waypoints'], factory);
} else {
return factory(root.jQuery);
}
})(this, function($) {
var defaults, wrap;
defaults = {
wrapper: '<div class="sticky-wrapper" />',
stuckClass: 'stuck'
};
wrap = function($elements, options) {
$elements.wrap(options.wrapper);
$elements.each(function() {
var $this;
$this = $(this);
$this.parent().height($this.outerHeight());
return true;
});
return $elements.parent();
};
return $.waypoints('extendFn', 'sticky', function(options) {
var $wrap, originalHandler;
options = $.extend({}, $.fn.waypoint.defaults, defaults, options);
$wrap = wrap(this, options);
originalHandler = options.handler;
options.handler = function(direction) {
var $sticky, shouldBeStuck;
$sticky = $(this).children(':first');
shouldBeStuck = direction === 'down' || direction === 'right';
$sticky.toggleClass(options.stuckClass, shouldBeStuck);
if (originalHandler != null) {
return originalHandler.call(this, direction);
}
};
$wrap.waypoint(options);
return this;
});
});
}).call(this);