Skip to content

Instantly share code, notes, and snippets.

@jennifer-shehane
Last active March 9, 2018 16:05
Show Gist options
  • Save jennifer-shehane/083c9bac52d555124eb0448d68b63dd7 to your computer and use it in GitHub Desktop.
Save jennifer-shehane/083c9bac52d555124eb0448d68b63dd7 to your computer and use it in GitHub Desktop.
! function() {
function t(t) {
t = t || {}, t.marginTop = t.marginTop || t.margin || 0, t.marginBottom = t.marginBottom || t.margin || 0;
var e = r(o),
n = r("#stalker"),
l = e.scrollTop(),
a = e.height(),
s = Math.max(0, i(this[0]) - t.marginTop),
h = t.marginTop + this.outerHeight() + t.marginBottom,
c = l;
if (c + a < s + h && (c = s + h - a), 0 !== n.length) {
var g = this[0],
p = null;
do {
"absolute" === r(g).css("position") && (p = g)
} while (g = g.offsetParent);
p && i(p) > i(n[0]) && (s -= n.outerHeight())
}
return c > s && (c = s), c
}
function i(t) {
var i = t,
o = 0;
do {
o += i.offsetTop
} while (i = i.offsetParent);
i = t;
do {
i && i.scrollTop && (o -= i.scrollTop), i = i.parentNode
} while (i && i != document.body);
return o
}
var o = require("jira/util/top-same-origin-window")(window),
r = o.jQuery;
window.jQuery.fn.scrollIntoView = function(i) {
if (0 === this.length) return this;
var e = this.hasFixedParent();
if (e) {
var n = r(this),
l = r(e),
a = l.outerHeight(),
s = l.scrollTop(),
h = s + a,
c = n.position(),
g = c.top + n.height(),
p = g + s > h,
u = c.top < 0;
p ? l.scrollTop(s + g - a) : u && l.scrollTop(s + c.top)
} else {
if (i = i || {}, !this.is(":visible") && i.callback) return i.callback(), this;
var f = r(o).scrollTop(),
d = t.call(this, i),
m = r("#stalker");
if (d !== f) {
var T = this,
v = r(o.document);
v.trigger("moveToStarted", T), i.duration ? v.find("body, html").stop(!0).animate({
scrollTop: d
}, i.duration, "swing", function() {
i.callback && i.callback(), v.trigger("moveToFinished", T), m.trigger("positionChanged")
}) : v.find("body, html").prop("scrollTop", d)
} else i.callback && i.callback()
}
return this
// r is undefined here
}, r.fn.isInView = function(i) {
if (this.length > 0 && !this.hasFixedParent()) {
i = i || {};
var e = r(o).scrollTop();
return t.call(this, i) === e
}
return this
}
}();;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment