Skip to content

Commit

Permalink
Update jquery.smooth-scroll.min.js
Browse files Browse the repository at this point in the history
added more functions
  • Loading branch information
tanm-sys authored Mar 4, 2024
1 parent b771252 commit b41facb
Showing 1 changed file with 184 additions and 1 deletion.
185 changes: 184 additions & 1 deletion jquery.smooth-scroll.min.js
Original file line number Diff line number Diff line change
@@ -1 +1,184 @@
!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):t("object"==typeof module&&module.exports?require("jquery"):jQuery)}(function(m){function e(t){var e=[],l=t.dir&&"left"===t.dir?"scrollLeft":"scrollTop";return this.each(function(){var t=m(this);if(this!==document&&this!==window){if(document.scrollingElement&&(this===document.documentElement||this===document.body))return e.push(document.scrollingElement),!1;0<t[l]()?e.push(this):(t[l](1),0<t[l]()&&e.push(this),t[l](0))}}),e.length||this.each(function(){this===document.documentElement&&"smooth"===m(this).css("scrollBehavior")&&(e=[this]),e.length||"BODY"!==this.nodeName||(e=[this])}),"first"===t.el&&1<e.length&&(e=[e[0]]),e}var h={},o=/^([\-\+]=)(\d+)/;m.fn.extend({scrollable:function(t){t=e.call(this,{dir:t});return this.pushStack(t)},firstScrollable:function(t){t=e.call(this,{el:"first",dir:t});return this.pushStack(t)},smoothScroll:function(t,l){if("options"===(t=t||{}))return l?this.each(function(){var t=m(this),e=m.extend(t.data("ssOpts")||{},l);t.data("ssOpts",e)}):this.first().data("ssOpts");function e(t){function e(t){return t.replace(/(:|\.|\/)/g,"\\$1")}var l=m(this),o=m.extend({},d,l.data("ssOpts")||{}),n=d.exclude,s=o.excludeWithin,r=0,i=0,c=!0,a={},f=m.smoothScroll.filterPath(location.pathname),h=m.smoothScroll.filterPath(this.pathname),u=location.hostname===this.hostname||!this.hostname,h=o.scrollTarget||h===f;if((f=e(this.hash))&&!m(f).length&&(c=!1),o.scrollTarget||u&&h&&f){for(;c&&r<n.length;)l.is(e(n[r++]))&&(c=!1);for(;c&&i<s.length;)l.closest(s[i++]).length&&(c=!1)}else c=!1;c&&(o.preventDefault&&t.preventDefault(),m.extend(a,o,{scrollTarget:o.scrollTarget||f,link:this}),m.smoothScroll(a))}var d=m.extend({},m.fn.smoothScroll.defaults,t);return null!==t.delegateSelector?this.off("click.smoothscroll",t.delegateSelector).on("click.smoothscroll",t.delegateSelector,e):this.off("click.smoothscroll").on("click.smoothscroll",e),this}});function u(t){var e={relative:""},l="string"==typeof t&&o.exec(t);return"number"==typeof t?e.px=t:l&&(e.relative=l[1],e.px=parseFloat(l[2])||0),e}function d(t){var e=m(t.scrollTarget);t.autoFocus&&e.length&&(e[0].focus(),e.is(document.activeElement)||(e.prop({tabIndex:-1}),e[0].focus())),t.afterScroll.call(t.link,t)}m.smoothScroll=function(t,e){if("options"===t&&"object"==typeof e)return m.extend(h,e);var l,o,n,s=u(t),r=0,i="offset",c="scrollTop",a={},f={};s.px?l=m.extend({link:null},m.fn.smoothScroll.defaults,h):((l=m.extend({link:null},m.fn.smoothScroll.defaults,t||{},h)).scrollElement&&(i="position","static"===l.scrollElement.css("position")&&l.scrollElement.css("position","relative")),e&&(s=u(e))),c="left"===l.direction?"scrollLeft":c,l.scrollElement?(o=l.scrollElement,!s.px&&/^(?:HTML|BODY)$/.test(o[0].nodeName)&&(r=o[c]())):o=m("html, body").firstScrollable(l.direction),l.beforeScroll.call(o,l),n=s.px?s:{relative:"",px:m(l.scrollTarget)[i]()&&m(l.scrollTarget)[i]()[l.direction]||0},a[c]=n.relative+(n.px+r+l.offset),"auto"===(r=l.speed)&&(r=Math.abs(a[c]-o[c]())/l.autoCoefficient),f={duration:r,easing:l.easing,complete:function(){d(l)}},l.step&&(f.step=l.step),o.length?o.stop().animate(a,f):d(l)},m.smoothScroll.version="2.2.0",m.smoothScroll.filterPath=function(t){return(t=t||"").replace(/^\//,"").replace(/(?:index|default).[a-zA-Z]{3,4}$/,"").replace(/\/$/,"")},m.fn.smoothScroll.defaults={exclude:[],excludeWithin:[],offset:0,direction:"top",delegateSelector:null,scrollElement:null,scrollTarget:null,autoFocus:!1,beforeScroll:function(){},afterScroll:function(){},easing:"swing",speed:400,autoCoefficient:2,preventDefault:!0}});
!(function (t) {
"function" == typeof define && define.amd
? define(["jquery"], t)
: t(
"object" == typeof module && module.exports ? require("jquery") : jQuery
);
})(function (m) {
function e(t) {
var e = [],
l = t.dir && "left" === t.dir ? "scrollLeft" : "scrollTop";
return (
this.each(function () {
var t = m(this);
if (this !== document && this !== window) {
if (
document.scrollingElement &&
(this === document.documentElement || this === document.body)
)
return e.push(document.scrollingElement), !1;
0 < t[l]()
? e.push(this)
: (t[l](1), 0 < t[l]() && e.push(this), t[l](0));
}
}),
e.length ||
this.each(function () {
this === document.documentElement &&
"smooth" === m(this).css("scrollBehavior") &&
(e = [this]),
e.length || "BODY" !== this.nodeName || (e = [this]);
}),
"first" === t.el && 1 < e.length && (e = [e[0]]),
e
);
}
var h = {},
o = /^([\-\+]=)(\d+)/;
m.fn.extend({
scrollable: function (t) {
t = e.call(this, { dir: t });
return this.pushStack(t);
},
firstScrollable: function (t) {
t = e.call(this, { el: "first", dir: t });
return this.pushStack(t);
},
smoothScroll: function (t, l) {
if ("options" === (t = t || {}))
return l
? this.each(function () {
var t = m(this),
e = m.extend(t.data("ssOpts") || {}, l);
t.data("ssOpts", e);
})
: this.first().data("ssOpts");
function e(t) {
function e(t) {
return t.replace(/(:|\.|\/)/g, "\\$1");
}
var l = m(this),
o = m.extend({}, d, l.data("ssOpts") || {}),
n = d.exclude,
s = o.excludeWithin,
r = 0,
i = 0,
c = !0,
a = {},
f = m.smoothScroll.filterPath(location.pathname),
h = m.smoothScroll.filterPath(this.pathname),
u = location.hostname === this.hostname || !this.hostname,
h = o.scrollTarget || h === f;
if (
((f = e(this.hash)) && !m(f).length && (c = !1),
o.scrollTarget || (u && h && f))
) {
for (; c && r < n.length; ) l.is(e(n[r++])) && (c = !1);
for (; c && i < s.length; ) l.closest(s[i++]).length && (c = !1);
} else c = !1;
c &&
(o.preventDefault && t.preventDefault(),
m.extend(a, o, { scrollTarget: o.scrollTarget || f, link: this }),
m.smoothScroll(a));
}
var d = m.extend({}, m.fn.smoothScroll.defaults, t);
return (
null !== t.delegateSelector
? this.off("click.smoothscroll", t.delegateSelector).on(
"click.smoothscroll",
t.delegateSelector,
e
)
: this.off("click.smoothscroll").on("click.smoothscroll", e),
this
);
},
});
function u(t) {
var e = { relative: "" },
l = "string" == typeof t && o.exec(t);
return (
"number" == typeof t
? (e.px = t)
: l && ((e.relative = l[1]), (e.px = parseFloat(l[2]) || 0)),
e
);
}
function d(t) {
var e = m(t.scrollTarget);
t.autoFocus &&
e.length &&
(e[0].focus(),
e.is(document.activeElement) || (e.prop({ tabIndex: -1 }), e[0].focus())),
t.afterScroll.call(t.link, t);
}
(m.smoothScroll = function (t, e) {
if ("options" === t && "object" == typeof e) return m.extend(h, e);
var l,
o,
n,
s = u(t),
r = 0,
i = "offset",
c = "scrollTop",
a = {},
f = {};
s.px
? (l = m.extend({ link: null }, m.fn.smoothScroll.defaults, h))
: ((l = m.extend({ link: null }, m.fn.smoothScroll.defaults, t || {}, h))
.scrollElement &&
((i = "position"),
"static" === l.scrollElement.css("position") &&
l.scrollElement.css("position", "relative")),
e && (s = u(e))),
(c = "left" === l.direction ? "scrollLeft" : c),
l.scrollElement
? ((o = l.scrollElement),
!s.px && /^(?:HTML|BODY)$/.test(o[0].nodeName) && (r = o[c]()))
: (o = m("html, body").firstScrollable(l.direction)),
l.beforeScroll.call(o, l),
(n = s.px
? s
: {
relative: "",
px:
(m(l.scrollTarget)[i]() && m(l.scrollTarget)[i]()[l.direction]) ||
0,
}),
(a[c] = n.relative + (n.px + r + l.offset)),
"auto" === (r = l.speed) &&
(r = Math.abs(a[c] - o[c]()) / l.autoCoefficient),
(f = {
duration: r,
easing: l.easing,
complete: function () {
d(l);
},
}),
l.step && (f.step = l.step),
o.length ? o.stop().animate(a, f) : d(l);
}),
(m.smoothScroll.version = "2.2.0"),
(m.smoothScroll.filterPath = function (t) {
return (t = t || "")
.replace(/^\//, "")
.replace(/(?:index|default).[a-zA-Z]{3,4}$/, "")
.replace(/\/$/, "");
}),
(m.fn.smoothScroll.defaults = {
exclude: [],
excludeWithin: [],
offset: 0,
direction: "top",
delegateSelector: null,
scrollElement: null,
scrollTarget: null,
autoFocus: !1,
beforeScroll: function () {},
afterScroll: function () {},
easing: "swing",
speed: 400,
autoCoefficient: 2,
preventDefault: !0,
});
});

0 comments on commit b41facb

Please sign in to comment.