Skip to content

Instantly share code, notes, and snippets.

@jennifer-shehane
Last active March 9, 2018 16:17
Show Gist options
  • Save jennifer-shehane/75759abaa79883097ee4922e3c8f1998 to your computer and use it in GitHub Desktop.
Save jennifer-shehane/75759abaa79883097ee4922e3c8f1998 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.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
}
}();
define("jira/util/top-same-origin-window", function() {
"use strict";
return function(n) {
for (; !function(n) {
return n === n.parent
}(n) && function(n) {
try {
if (void 0 == n.location.href)
return !1
} catch (n) {
return !1
}
return !0
}(n.parent); )
n = n.parent;
return n
}
});
@jennifer-shehane
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment