jquery.jscroll.min.js 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*!
  2. * jScroll - jQuery Plugin for Infinite Scrolling / Auto-Paging
  3. * @see @link{https://jscroll.com}
  4. *
  5. * @copyright Philip Klauzinski
  6. * @license Dual licensed under the MIT and GPL Version 2 licenses
  7. * @author Philip Klauzinski (https://webtopian.com)
  8. * @version 2.4.1
  9. * @requires jQuery v1.8.0+
  10. * @preserve
  11. */
  12. !function (m) {
  13. "use strict";
  14. m.jscroll = {
  15. defaults: {
  16. debug: !1,
  17. autoTrigger: !0,
  18. autoTriggerUntil: !1,
  19. loadingHtml: "<small>Loading...</small>",
  20. loadingFunction: !1,
  21. padding: 0,
  22. nextSelector: "a:last",
  23. contentSelector: "",
  24. pagingSelector: "",
  25. callback: !1
  26. }
  27. };
  28. var l = function (a, t) {
  29. var n, e = a.data("jscroll"), l = "function" == typeof t ? {callback: t} : t,
  30. s = m.extend({}, m.jscroll.defaults, l, e || {}), d = "visible" === a.css("overflow-y"),
  31. o = a.find(s.nextSelector).first(), r = m(window), i = m("body"), f = d ? r : a,
  32. c = m.trim(o.prop("href") + " " + s.contentSelector), g = function () {
  33. a.find(".jscroll-inner").length || a.contents().wrapAll('<div class="jscroll-inner" />')
  34. }, u = function (t) {
  35. s.pagingSelector ? t.closest(s.pagingSelector).hide() : t.parent().not(".jscroll-inner,.jscroll-added").addClass("jscroll-next-parent").hide().length || t.wrap('<div class="jscroll-next-parent" />').parent().hide()
  36. }, p = function () {
  37. return f.unbind(".jscroll").removeData("jscroll").find(".jscroll-inner").children().unwrap().filter(".jscroll-added").children().unwrap()
  38. }, j = function () {
  39. if (a.is(":visible")) {
  40. g();
  41. var t = a.find("div.jscroll-inner").first(), n = a.data("jscroll"),
  42. e = parseInt(a.css("borderTopWidth"), 10), l = isNaN(e) ? 0 : e,
  43. o = parseInt(a.css("paddingTop"), 10) + l, r = d ? f.scrollTop() : a.offset().top,
  44. i = t.length ? t.offset().top : 0, c = Math.ceil(r - i + f.height() + o);
  45. if (!n.waiting && c + s.padding >= t.outerHeight()) return b("info", "jScroll:", t.outerHeight() - c, "from bottom. Loading next request..."), v()
  46. }
  47. }, h = function () {
  48. var t = a.find(s.nextSelector).first();
  49. if (t.length) if (s.autoTrigger && (!1 === s.autoTriggerUntil || 0 < s.autoTriggerUntil)) {
  50. u(t);
  51. var n = i.height() - a.offset().top;
  52. (a.height() < n ? a.height() : n) <= (0 < a.offset().top - r.scrollTop() ? r.height() - (a.offset().top - m(window).scrollTop()) : r.height()) && j(), f.unbind(".jscroll").bind("scroll.jscroll", function () {
  53. return j()
  54. }), 0 < s.autoTriggerUntil && s.autoTriggerUntil--
  55. } else f.unbind(".jscroll"), t.bind("click.jscroll", function () {
  56. return u(t), v(), !1
  57. })
  58. }, v = function () {
  59. var t = a.find("div.jscroll-inner").first(), r = a.data("jscroll");
  60. return r.waiting = !0, t.append('<div class="jscroll-added" />').children(".jscroll-added").last().html('<div class="jscroll-loading" id="jscroll-loading">' + s.loadingHtml + "</div>").promise().done(function () {
  61. s.loadingFunction && s.loadingFunction()
  62. }), a.animate({scrollTop: t.outerHeight()}, 0, function () {
  63. var o = r.nextHref;
  64. t.find("div.jscroll-added").last().load(o, function (t, n) {
  65. if ("error" === n) return p();
  66. var e, l = m(this).find(s.nextSelector).first();
  67. r.waiting = !1, r.nextHref = !!l.prop("href") && m.trim(l.prop("href") + " " + s.contentSelector), m(".jscroll-next-parent", a).remove(), (e = e || a.data("jscroll")) && e.nextHref ? h() : (b("warn", "jScroll: nextSelector not found - destroying"), p()), s.callback && s.callback.call(this, o), b("dir", r)
  68. })
  69. })
  70. }, b = function (t) {
  71. if (s.debug && "object" == typeof console && ("object" == typeof t || "function" == typeof console[t])) if ("object" == typeof t) {
  72. var n = [];
  73. for (var e in t) "function" == typeof console[e] ? (n = t[e].length ? t[e] : [t[e]], console[e].apply(console, n)) : console.log.apply(console, n)
  74. } else console[t].apply(console, Array.prototype.slice.call(arguments, 1))
  75. };
  76. return a.data("jscroll", m.extend({}, e, {
  77. initialized: !0,
  78. waiting: !1,
  79. nextHref: c
  80. })), g(), (n = m(s.loadingHtml).filter("img").attr("src")) && ((new Image).src = n), h(), m.extend(a.jscroll, {destroy: p}), a
  81. };
  82. m.fn.jscroll = function (e) {
  83. return this.each(function () {
  84. var t = m(this), n = t.data("jscroll");
  85. n && n.initialized || l(t, e)
  86. })
  87. }
  88. }(jQuery);