Skip to content

Commit e49da54

Browse files
committed
initial commit
0 parents  commit e49da54

5 files changed

+724
-0
lines changed

jquery.espy.min.js

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
2+
(function(b, u, v) {
3+
function x(b, f, e) {
4+
b = (b + "").match(/^(-?[0-9]+)(%)?$/);
5+
if (!b) return !1;
6+
var c = parseInt(b[1], 10);
7+
b[2] && (c *= f / 100);
8+
return 0 > c ? f + c + (e || 0) : c
9+
}
10+
11+
function y(k, f) {
12+
function e() {
13+
function b() {
14+
g = +new Date;
15+
f.apply(e, t);
16+
c && (c = clearTimeout(c))
17+
}
18+
var e = this,
19+
q = +new Date - g,
20+
t = arguments;
21+
c && (c = clearTimeout(c));
22+
q > k ? b() : c = setTimeout(b, k - q)
23+
}
24+
var c, g = 0;
25+
b.guid && (e.guid = f.guid = f.guid || b.guid++);
26+
return e
27+
}
28+
b.Espy = function(k, f, e) {
29+
function c(a, d) {
30+
b.isPlainObject(a) && (d = a, a = null);
31+
b.extend(t.prototype, d);
32+
null !== a && (w = a)
33+
}
34+
35+
function g(a) {
36+
if (a =
37+
q(a)) {
38+
var d = a.$el.offset()[a.settings.horizontal ? "left" : "top"] - p.offset[a.settings.horizontal ? "left" : "top"],
39+
h = a.$el[a.settings.horizontal ? "outerWidth" : "outerHeight"]();
40+
b.extend(a, {
41+
start: d,
42+
elSize: h,
43+
end: d + h
44+
})
45+
}
46+
}
47+
48+
function r(a) {
49+
// console.log("r(a) with a = ", a);
50+
if (a === v) b.each(m, r);
51+
else if (a = q(a)) {
52+
var d = p[a.settings.horizontal ? "width" : "height"],
53+
h = x(a.settings.size, d),
54+
d = p[a.settings.horizontal ? "left" : "top"] + x(a.settings.offset, d, -h),
55+
c = d + h,
56+
h = a.settings.contain ? d <= a.start && c >= a.end ? "inside" : d + h / 2 > a.start + a.elSize / 2 ? a.settings.horizontal ? "left" :
57+
"up" : a.settings.horizontal ? "right" : "down" : d > a.start && d < a.end || c > a.start && c < a.end || d <= a.start && c >= a.start || d <= a.end && c >= a.end ? "inside" : d > a.end ? a.settings.horizontal ? "left" : "up" : a.settings.horizontal ? "right" : "down";
58+
a.state !== h && (a.state = h, "function" === typeof w && w.call(a.el, "inside" === h, h), "function" === typeof a.callback && a.callback.call(a.el, "inside" === h, h))
59+
}
60+
}
61+
62+
function s(a) {
63+
if (m.hasOwnProperty(a)) return a;
64+
if (b.isPlainObject(a) && m.hasOwnProperty(a.id)) return a.id;
65+
a = b(a)[0];
66+
var d = !1;
67+
b.each(m, function(b,
68+
c) {
69+
c.el === a && (d = b)
70+
});
71+
return d
72+
}
73+
74+
// console.log("nothing yet");
75+
function q(a) {
76+
return (a = s(a)) ? m[a] : !1
77+
}
78+
"function" !== typeof f && (e = f, f = 0);
79+
// console.log("k was", k);
80+
var t = function(a) {
81+
b.extend(this, a)
82+
},
83+
u = function(a, d, c, e) {
84+
this.id = a;
85+
this.el = d;
86+
this.$el = b(d);
87+
this.callback = c;
88+
this.settings = new t(e);
89+
this.configure = function(a, d) {
90+
b.isPlainObject(a) && (d = a, a = null);
91+
b.extend(this.settings, d);
92+
null !== a && (this.callback = a)
93+
}
94+
},
95+
n = this,
96+
l = b(k);
97+
// console.log("l", l, "l==window", l[0]==window);
98+
k = b.fn.espy.defaults;
99+
// console.log("k is", k);
100+
var w, m = {},
101+
z = 0;
102+
// because window.offset() is not defined in jQuery 3 (why?!?!?!),
103+
// we have to treat that as a special case (DF 1/28/19)
104+
if (l[0]==window) { offSET = { top: 0, left: 0 } }
105+
else { offSET = l.offset() }
106+
var p = {
107+
top: l.scrollTop(),
108+
left: l.scrollLeft(),
109+
width: l.innerWidth(),
110+
height: l.innerHeight(),
111+
offset: offSET
112+
/*
113+
offset: l.offset() || {
114+
top: 0,
115+
left: 0
116+
}
117+
*/
118+
};
119+
// console.log("p", p);
120+
c(f, b.extend({}, k, e));
121+
n.add = function(a, d, c) {
122+
b.isPlainObject(d) && (c = d, d = 0);
123+
b(a).each(function(a, b) {
124+
var e = s(b) || "s" + z++;
125+
m[e] = new u(e, b, d, c);
126+
g(e);
127+
r(e)
128+
})
129+
};
130+
n.configure = function(a, d, e) {
131+
"function" === typeof a ? (d = a, a = null, b.isPlainObject(d) && (e = d, d = null)) : b.isPlainObject(a) ? (e = a, d = a = null) : b.isPlainObject(d) && (e = d, d = null);
132+
null === a ? (c(d, e), b.each(m, function(a, b) {
133+
g(b)
134+
})) : b(a).each(function(a, b) {
135+
var c = q(b);
136+
c && (c.configure(d, e), g(b))
137+
})
138+
};
139+
n.reload = function(a) {
140+
a === v ? b.each(m, function() {
141+
g(this.id)
142+
}) :
143+
b(a).each(function(a, b) {
144+
var c = s(b);
145+
c && (g(c), r(c))
146+
})
147+
};
148+
n.remove = function(a) {
149+
b(a).each(function(a, b) {
150+
var c = s(b);
151+
c && delete m[c]
152+
})
153+
};
154+
n.destroy = function() {
155+
l.off(".espy");
156+
m = {};
157+
n = v
158+
};
159+
n.resize = function() {
160+
b.each(m, function() {
161+
this.reloadOnResize && g(this)
162+
});
163+
p.width = l.innerWidth();
164+
p.height = l.innerHeight();
165+
r()
166+
};
167+
l.on("scroll.espy", y(k.delay, function() {
168+
p.top = l.scrollTop();
169+
p.left = l.scrollLeft();
170+
r()
171+
}));
172+
l.on("resize.espy", y(k.delay, function() {
173+
n.resize()
174+
}))
175+
};
176+
b.fn.espy = function(k, f) {
177+
var e, c;
178+
e = f && f.context || u;
179+
var g = b.data(e,
180+
"espy") || b.data(e, "espy", new b.Espy(e));
181+
"string" !== typeof k ? g.add(this, k, f) : (e = k, c = Array.prototype.slice.call(arguments), c[0] = this, "function" === typeof g[e] && g[e].apply(g, c));
182+
return this
183+
};
184+
b.fn.espy.defaults = {
185+
delay: 100,
186+
context: window,
187+
horizontal: 0,
188+
offset: 0,
189+
size: "100%",
190+
contain: 0,
191+
reloadOnResize: !0
192+
}
193+
})(jQuery, window);
194+

jquery.min.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jquery.sticky.js

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// Sticky Plugin v1.0.0 for jQuery
2+
// =============
3+
// Author: Anthony Garand
4+
// Improvements by German M. Bravo (Kronuz) and Ruud Kamphuis (ruudk)
5+
// Improvements by Leonardo C. Daronco (daronco)
6+
// Created: 2/14/2011
7+
// Date: 2/12/2012
8+
// Website: http://labs.anthonygarand.com/sticky
9+
// Description: Makes an element on the page stick on the screen as you scroll
10+
// It will only set the 'top' and 'position' of your element, you
11+
// might need to adjust the width in some cases.
12+
13+
(function($) {
14+
var defaults = {
15+
topSpacing: 0,
16+
bottomSpacing: 0,
17+
className: 'is-sticky',
18+
wrapperClassName: 'sticky-wrapper',
19+
center: false,
20+
getWidthFrom: ''
21+
},
22+
$window = $(window),
23+
$document = $(document),
24+
sticked = [],
25+
windowHeight = $window.height(),
26+
scroller = function() {
27+
var scrollTop = $window.scrollTop(),
28+
documentHeight = $document.height(),
29+
dwh = documentHeight - windowHeight,
30+
extra = (scrollTop > dwh) ? dwh - scrollTop : 0;
31+
32+
for (var i = 0; i < sticked.length; i++) {
33+
var s = sticked[i],
34+
elementTop = s.stickyWrapper.offset().top,
35+
etse = elementTop - s.topSpacing - extra;
36+
37+
if (scrollTop <= etse) {
38+
if (s.currentTop !== null) {
39+
s.stickyElement
40+
.css('position', '')
41+
.css('top', '');
42+
s.stickyElement.parent().removeClass(s.className);
43+
s.currentTop = null;
44+
}
45+
}
46+
else {
47+
var newTop = documentHeight - s.stickyElement.outerHeight()
48+
- s.topSpacing - s.bottomSpacing - scrollTop - extra;
49+
if (newTop < 0) {
50+
newTop = newTop + s.topSpacing;
51+
} else {
52+
newTop = s.topSpacing;
53+
}
54+
if (s.currentTop != newTop) {
55+
s.stickyElement
56+
.css('position', 'fixed')
57+
.css('top', newTop);
58+
59+
if (typeof s.getWidthFrom !== 'undefined') {
60+
s.stickyElement.css('width', $(s.getWidthFrom).width());
61+
}
62+
63+
s.stickyElement.parent().addClass(s.className);
64+
s.currentTop = newTop;
65+
}
66+
}
67+
}
68+
},
69+
resizer = function() {
70+
windowHeight = $window.height();
71+
},
72+
methods = {
73+
init: function(options) {
74+
var o = $.extend({}, defaults, options);
75+
return this.each(function() {
76+
var stickyElement = $(this);
77+
78+
var stickyId = stickyElement.attr('id');
79+
var wrapperId = stickyId ? stickyId + '-' + defaults.wrapperClassName : defaults.wrapperClassName
80+
var wrapper = $('<div></div>')
81+
.attr('id', stickyId + '-sticky-wrapper')
82+
.addClass(o.wrapperClassName);
83+
stickyElement.wrapAll(wrapper);
84+
85+
if (o.center) {
86+
stickyElement.parent().css({width:stickyElement.outerWidth(),marginLeft:"auto",marginRight:"auto"});
87+
}
88+
89+
if (stickyElement.css("float") == "right") {
90+
stickyElement.css({"float":"none"}).parent().css({"float":"right"});
91+
}
92+
93+
var stickyWrapper = stickyElement.parent();
94+
stickyWrapper.css('height', stickyElement.outerHeight());
95+
sticked.push({
96+
topSpacing: o.topSpacing,
97+
bottomSpacing: o.bottomSpacing,
98+
stickyElement: stickyElement,
99+
currentTop: null,
100+
stickyWrapper: stickyWrapper,
101+
className: o.className,
102+
getWidthFrom: o.getWidthFrom
103+
});
104+
});
105+
},
106+
update: scroller,
107+
unstick: function(options) {
108+
return this.each(function() {
109+
var unstickyElement = $(this);
110+
111+
var removeIdx = -1;
112+
for (var i = 0; i < sticked.length; i++)
113+
{
114+
if (sticked[i].stickyElement.get(0) == unstickyElement.get(0))
115+
{
116+
removeIdx = i;
117+
}
118+
}
119+
if(removeIdx != -1)
120+
{
121+
sticked.splice(removeIdx,1);
122+
unstickyElement.unwrap();
123+
unstickyElement.removeAttr('style');
124+
}
125+
});
126+
}
127+
};
128+
129+
// should be more efficient than using $window.scroll(scroller) and $window.resize(resizer):
130+
if (window.addEventListener) {
131+
window.addEventListener('scroll', scroller, false);
132+
window.addEventListener('resize', resizer, false);
133+
} else if (window.attachEvent) {
134+
window.attachEvent('onscroll', scroller);
135+
window.attachEvent('onresize', resizer);
136+
}
137+
138+
$.fn.sticky = function(method) {
139+
if (methods[method]) {
140+
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
141+
} else if (typeof method === 'object' || !method ) {
142+
return methods.init.apply( this, arguments );
143+
} else {
144+
$.error('Method ' + method + ' does not exist on jQuery.sticky');
145+
}
146+
};
147+
148+
$.fn.unstick = function(method) {
149+
if (methods[method]) {
150+
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
151+
} else if (typeof method === 'object' || !method ) {
152+
return methods.unstick.apply( this, arguments );
153+
} else {
154+
$.error('Method ' + method + ' does not exist on jQuery.sticky');
155+
}
156+
157+
};
158+
$(function() {
159+
setTimeout(scroller, 0);
160+
});
161+
})(jQuery);

0 commit comments

Comments
 (0)