Advertisement
Guest User

jCarousel plugin code

a guest
Apr 26th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*! jCarousel - v0.3.1 - 2014-04-24
  2.  * http://sorgalla.com/jcarousel
  3.  * Copyright (c) 2014 Jan Sorgalla; Licensed MIT */
  4. (function (t) {
  5.     "use strict";
  6.     var i = t.jCarousel = {};
  7.     i.version = "0.3.1";
  8.     var s = /^([+\-]=)?(.+)$/;
  9.     i.parseTarget = function (t) {
  10.         var i = !1,
  11.             e = "object" != typeof t ? s.exec(t) : null;
  12.         return e ? (t = parseInt(e[2], 10) || 0, e[1] && (i = !0, "-=" === e[1] && (t *= -1))) : "object" != typeof t && (t = parseInt(t, 10) || 0), {
  13.             target: t,
  14.             relative: i
  15.         }
  16.     }, i.detectCarousel = function (t) {
  17.         for (var i; t.length > 0;) {
  18.             if (i = t.filter("[data-jcarousel]"), i.length > 0) return i;
  19.             if (i = t.find("[data-jcarousel]"), i.length > 0) return i;
  20.             t = t.parent()
  21.         }
  22.         return null
  23.     }, i.base = function (s) {
  24.         return {
  25.             version: i.version,
  26.             _options: {},
  27.             _element: null,
  28.             _carousel: null,
  29.             _init: t.noop,
  30.             _create: t.noop,
  31.             _destroy: t.noop,
  32.             _reload: t.noop,
  33.             create: function () {
  34.                 return this._element.attr("data-" + s.toLowerCase(), !0).data(s, this), !1 === this._trigger("create") ? this : (this._create(), this._trigger("createend"), this)
  35.             },
  36.             destroy: function () {
  37.                 return !1 === this._trigger("destroy") ? this : (this._destroy(), this._trigger("destroyend"), this._element.removeData(s).removeAttr("data-" + s.toLowerCase()), this)
  38.             },
  39.             reload: function (t) {
  40.                 return !1 === this._trigger("reload") ? this : (t && this.options(t), this._reload(), this._trigger("reloadend"), this)
  41.             },
  42.             element: function () {
  43.                 return this._element
  44.             },
  45.             options: function (i, s) {
  46.                 if (0 === arguments.length) return t.extend({}, this._options);
  47.                 if ("string" == typeof i) {
  48.                     if (s === void 0) return this._options[i] === void 0 ? null : this._options[i];
  49.                     this._options[i] = s
  50.                 } else this._options = t.extend({}, this._options, i);
  51.                 return this
  52.             },
  53.             carousel: function () {
  54.                 return this._carousel || (this._carousel = i.detectCarousel(this.options("carousel") || this._element), this._carousel || t.error('Could not detect carousel for plugin "' + s + '"')), this._carousel
  55.             },
  56.             _trigger: function (i, e, r) {
  57.                 var n, o = !1;
  58.                 return r = [this].concat(r || []), (e || this._element).each(function () {
  59.                     n = t.Event((s + ":" + i).toLowerCase()), t(this).trigger(n, r), n.isDefaultPrevented() && (o = !0)
  60.                 }), !o
  61.             }
  62.         }
  63.     }, i.plugin = function (s, e) {
  64.         var r = t[s] = function (i, s) {
  65.             this._element = t(i), this.options(s), this._init(), this.create()
  66.         };
  67.         return r.fn = r.prototype = t.extend({}, i.base(s), e), t.fn[s] = function (i) {
  68.             var e = Array.prototype.slice.call(arguments, 1),
  69.                 n = this;
  70.             return "string" == typeof i ? this.each(function () {
  71.                 var r = t(this).data(s);
  72.                 if (!r) return t.error("Cannot call methods on " + s + " prior to initialization; " + 'attempted to call method "' + i + '"');
  73.                 if (!t.isFunction(r[i]) || "_" === i.charAt(0)) return t.error('No such method "' + i + '" for ' + s + " instance");
  74.                 var o = r[i].apply(r, e);
  75.                 return o !== r && o !== void 0 ? (n = o, !1) : void 0
  76.             }) : this.each(function () {
  77.                 var e = t(this).data(s);
  78.                 e instanceof r ? e.reload(i) : new r(this, i)
  79.             }), n
  80.         }, r
  81.     }
  82. })(jQuery),
  83. function (t, i) {
  84.     "use strict";
  85.     var s = function (t) {
  86.         return parseFloat(t) || 0
  87.     };
  88.     t.jCarousel.plugin("jcarousel", {
  89.         animating: !1,
  90.         tail: 0,
  91.         inTail: !1,
  92.         resizeTimer: null,
  93.         lt: null,
  94.         vertical: !1,
  95.         rtl: !1,
  96.         circular: !1,
  97.         underflow: !1,
  98.         relative: !1,
  99.         _options: {
  100.             list: function () {
  101.                 return this.element().children().eq(0)
  102.             },
  103.             items: function () {
  104.                 return this.list().children()
  105.             },
  106.             animation: 400,
  107.             transitions: !1,
  108.             wrap: null,
  109.             vertical: null,
  110.             rtl: null,
  111.             center: !1
  112.         },
  113.         _list: null,
  114.         _items: null,
  115.         _target: null,
  116.         _first: null,
  117.         _last: null,
  118.         _visible: null,
  119.         _fullyvisible: null,
  120.         _init: function () {
  121.             var t = this;
  122.             return this.onWindowResize = function () {
  123.                 t.resizeTimer && clearTimeout(t.resizeTimer), t.resizeTimer = setTimeout(function () {
  124.                     t.reload()
  125.                 }, 100)
  126.             }, this
  127.         },
  128.         _create: function () {
  129.             this._reload(), t(i).on("resize.jcarousel", this.onWindowResize)
  130.         },
  131.         _destroy: function () {
  132.             t(i).off("resize.jcarousel", this.onWindowResize)
  133.         },
  134.         _reload: function () {
  135.             this.vertical = this.options("vertical"), null == this.vertical && (this.vertical = this.list().height() > this.list().width()), this.rtl = this.options("rtl"), null == this.rtl && (this.rtl = function (i) {
  136.                 if ("rtl" === ("" + i.attr("dir")).toLowerCase()) return !0;
  137.                 var s = !1;
  138.                 return i.parents("[dir]").each(function () {
  139.                     return /rtl/i.test(t(this).attr("dir")) ? (s = !0, !1) : void 0
  140.                 }), s
  141.             }(this._element)), this.lt = this.vertical ? "top" : "left", this.relative = "relative" === this.list().css("position"), this._list = null, this._items = null;
  142.             var i = this._target && this.index(this._target) >= 0 ? this._target : this.closest();
  143.             this.circular = "circular" === this.options("wrap"), this.underflow = !1;
  144.             var s = {
  145.                 left: 0,
  146.                 top: 0
  147.             };
  148.             return i.length > 0 && (this._prepare(i), this.list().find("[data-jcarousel-clone]").remove(), this._items = null, this.underflow = this._fullyvisible.length >= this.items().length, this.circular = this.circular && !this.underflow, s[this.lt] = this._position(i) + "px"), this.move(s), this
  149.         },
  150.         list: function () {
  151.             if (null === this._list) {
  152.                 var i = this.options("list");
  153.                 this._list = t.isFunction(i) ? i.call(this) : this._element.find(i)
  154.             }
  155.             return this._list
  156.         },
  157.         items: function () {
  158.             if (null === this._items) {
  159.                 var i = this.options("items");
  160.                 this._items = (t.isFunction(i) ? i.call(this) : this.list().find(i)).not("[data-jcarousel-clone]")
  161.             }
  162.             return this._items
  163.         },
  164.         index: function (t) {
  165.             return this.items().index(t)
  166.         },
  167.         closest: function () {
  168.             var i, e = this,
  169.                 r = this.list().position()[this.lt],
  170.                 n = t(),
  171.                 o = !1,
  172.                 l = this.vertical ? "bottom" : this.rtl && !this.relative ? "left" : "right";
  173.             return this.rtl && this.relative && !this.vertical && (r += this.list().width() - this.clipping()), this.items().each(function () {
  174.                 if (n = t(this), o) return !1;
  175.                 var a = e.dimension(n);
  176.                 if (r += a, r >= 0) {
  177.                     if (i = a - s(n.css("margin-" + l)), !(0 >= Math.abs(r) - a + i / 2)) return !1;
  178.                     o = !0
  179.                 }
  180.             }), n
  181.         },
  182.         target: function () {
  183.             return this._target
  184.         },
  185.         first: function () {
  186.             return this._first
  187.         },
  188.         last: function () {
  189.             return this._last
  190.         },
  191.         visible: function () {
  192.             return this._visible
  193.         },
  194.         fullyvisible: function () {
  195.             return this._fullyvisible
  196.         },
  197.         hasNext: function () {
  198.             if (!1 === this._trigger("hasnext")) return !0;
  199.             var t = this.options("wrap"),
  200.                 i = this.items().length - 1;
  201.             return i >= 0 && !this.underflow && (t && "first" !== t || i > this.index(this._last) || this.tail && !this.inTail) ? !0 : !1
  202.         },
  203.         hasPrev: function () {
  204.             if (!1 === this._trigger("hasprev")) return !0;
  205.             var t = this.options("wrap");
  206.             return this.items().length > 0 && !this.underflow && (t && "last" !== t || this.index(this._first) > 0 || this.tail && this.inTail) ? !0 : !1
  207.         },
  208.         clipping: function () {
  209.             return this._element["inner" + (this.vertical ? "Height" : "Width")]()
  210.         },
  211.         dimension: function (t) {
  212.             return t["outer" + (this.vertical ? "Height" : "Width")](!0)
  213.         },
  214.         scroll: function (i, s, e) {
  215.             if (this.animating) return this;
  216.             if (!1 === this._trigger("scroll", null, [i, s])) return this;
  217.             t.isFunction(s) && (e = s, s = !0);
  218.             var r = t.jCarousel.parseTarget(i);
  219.             if (r.relative) {
  220.                 var n, o, l, a, h, u, c, f, d = this.items().length - 1,
  221.                     _ = Math.abs(r.target),
  222.                     p = this.options("wrap");
  223.                 if (r.target > 0) {
  224.                     var g = this.index(this._last);
  225.                     if (g >= d && this.tail) this.inTail ? "both" === p || "last" === p ? this._scroll(0, s, e) : t.isFunction(e) && e.call(this, !1) : this._scrollTail(s, e);
  226.                     else if (n = this.index(this._target), this.underflow && n === d && ("circular" === p || "both" === p || "last" === p) || !this.underflow && g === d && ("both" === p || "last" === p)) this._scroll(0, s, e);
  227.                     else if (l = n + _, this.circular && l > d) {
  228.                         for (f = d, h = this.items().get(-1); l > f++;) h = this.items().eq(0), u = this._visible.index(h) >= 0, u && h.after(h.clone(!0).attr("data-jcarousel-clone", !0)), this.list().append(h), u || (c = {}, c[this.lt] = this.dimension(h), this.moveBy(c)), this._items = null;
  229.                         this._scroll(h, s, e)
  230.                     } else this._scroll(Math.min(l, d), s, e)
  231.                 } else if (this.inTail) this._scroll(Math.max(this.index(this._first) - _ + 1, 0), s, e);
  232.                 else if (o = this.index(this._first), n = this.index(this._target), a = this.underflow ? n : o, l = a - _, 0 >= a && (this.underflow && "circular" === p || "both" === p || "first" === p)) this._scroll(d, s, e);
  233.                 else if (this.circular && 0 > l) {
  234.                     for (f = l, h = this.items().get(0); 0 > f++;) {
  235.                         h = this.items().eq(-1), u = this._visible.index(h) >= 0, u && h.after(h.clone(!0).attr("data-jcarousel-clone", !0)), this.list().prepend(h), this._items = null;
  236.                         var v = this.dimension(h);
  237.                         c = {}, c[this.lt] = -v, this.moveBy(c)
  238.                     }
  239.                     this._scroll(h, s, e)
  240.                 } else this._scroll(Math.max(l, 0), s, e)
  241.             } else this._scroll(r.target, s, e);
  242.             return this._trigger("scrollend"), this
  243.         },
  244.         moveBy: function (t, i) {
  245.             var e = this.list().position(),
  246.                 r = 1,
  247.                 n = 0;
  248.             return this.rtl && !this.vertical && (r = -1, this.relative && (n = this.list().width() - this.clipping())), t.left && (t.left = e.left + n + s(t.left) * r + "px"), t.top && (t.top = e.top + n + s(t.top) * r + "px"), this.move(t, i)
  249.         },
  250.         move: function (i, s) {
  251.             s = s || {};
  252.             var e = this.options("transitions"),
  253.                 r = !!e,
  254.                 n = !!e.transforms,
  255.                 o = !!e.transforms3d,
  256.                 l = s.duration || 0,
  257.                 a = this.list();
  258.             if (!r && l > 0) return a.animate(i, s), void 0;
  259.             var h = s.complete || t.noop,
  260.                 u = {};
  261.             if (r) {
  262.                 var c = a.css(["transitionDuration", "transitionTimingFunction", "transitionProperty"]),
  263.                     f = h;
  264.                 h = function () {
  265.                     t(this).css(c), f.call(this)
  266.                 }, u = {
  267.                     transitionDuration: (l > 0 ? l / 1e3 : 0) + "s",
  268.                     transitionTimingFunction: e.easing || s.easing,
  269.                     transitionProperty: l > 0 ? function () {
  270.                         return n || o ? "all" : i.left ? "left" : "top"
  271.                     }() : "none",
  272.                     transform: "none"
  273.                 }
  274.             }
  275.             o ? u.transform = "translate3d(" + (i.left || 0) + "," + (i.top || 0) + ",0)" : n ? u.transform = "translate(" + (i.left || 0) + "," + (i.top || 0) + ")" : t.extend(u, i), r && l > 0 && a.one("transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd", h), a.css(u), 0 >= l && a.each(function () {
  276.                 h.call(this)
  277.             })
  278.         },
  279.         _scroll: function (i, s, e) {
  280.             if (this.animating) return t.isFunction(e) && e.call(this, !1), this;
  281.             if ("object" != typeof i ? i = this.items().eq(i) : i.jquery === void 0 && (i = t(i)), 0 === i.length) return t.isFunction(e) && e.call(this, !1), this;
  282.             this.inTail = !1, this._prepare(i);
  283.             var r = this._position(i),
  284.                 n = this.list().position()[this.lt];
  285.             if (r === n) return t.isFunction(e) && e.call(this, !1), this;
  286.             var o = {};
  287.             return o[this.lt] = r + "px", this._animate(o, s, e), this
  288.         },
  289.         _scrollTail: function (i, s) {
  290.             if (this.animating || !this.tail) return t.isFunction(s) && s.call(this, !1), this;
  291.             var e = this.list().position()[this.lt];
  292.             this.rtl && this.relative && !this.vertical && (e += this.list().width() - this.clipping()), this.rtl && !this.vertical ? e += this.tail : e -= this.tail, this.inTail = !0;
  293.             var r = {};
  294.             return r[this.lt] = e + "px", this._update({
  295.                 target: this._target.next(),
  296.                 fullyvisible: this._fullyvisible.slice(1).add(this._visible.last())
  297.             }), this._animate(r, i, s), this
  298.         },
  299.         _animate: function (i, s, e) {
  300.             if (e = e || t.noop, !1 === this._trigger("animate")) return e.call(this, !1), this;
  301.             this.animating = !0;
  302.             var r = this.options("animation"),
  303.                 n = t.proxy(function () {
  304.                     this.animating = !1;
  305.                     var t = this.list().find("[data-jcarousel-clone]");
  306.                     t.length > 0 && (t.remove(), this._reload()), this._trigger("animateend"), e.call(this, !0)
  307.                 }, this),
  308.                 o = "object" == typeof r ? t.extend({}, r) : {
  309.                     duration: r
  310.                 },
  311.                 l = o.complete || t.noop;
  312.             return s === !1 ? o.duration = 0 : t.fx.speeds[o.duration] !== void 0 && (o.duration = t.fx.speeds[o.duration]), o.complete = function () {
  313.                 n(), l.call(this)
  314.             }, this.move(i, o), this
  315.         },
  316.         _prepare: function (i) {
  317.             var e, r, n, o, l = this.index(i),
  318.                 a = l,
  319.                 h = this.dimension(i),
  320.                 u = this.clipping(),
  321.                 c = this.vertical ? "bottom" : this.rtl ? "left" : "right",
  322.                 f = this.options("center"),
  323.                 d = {
  324.                     target: i,
  325.                     first: i,
  326.                     last: i,
  327.                     visible: i,
  328.                     fullyvisible: u >= h ? i : t()
  329.                 };
  330.             if (f && (h /= 2, u /= 2), u > h)
  331.                 for (;;) {
  332.                     if (e = this.items().eq(++a), 0 === e.length) {
  333.                         if (!this.circular) break;
  334.                         if (e = this.items().eq(0), i.get(0) === e.get(0)) break;
  335.                         if (r = this._visible.index(e) >= 0, r && e.after(e.clone(!0).attr("data-jcarousel-clone", !0)), this.list().append(e), !r) {
  336.                             var _ = {};
  337.                             _[this.lt] = this.dimension(e), this.moveBy(_)
  338.                         }
  339.                         this._items = null
  340.                     }
  341.                     if (o = this.dimension(e), 0 === o) break;
  342.                     if (h += o, d.last = e, d.visible = d.visible.add(e), n = s(e.css("margin-" + c)), u >= h - n && (d.fullyvisible = d.fullyvisible.add(e)), h >= u) break
  343.                 }
  344.             if (!this.circular && !f && u > h)
  345.                 for (a = l;;) {
  346.                     if (0 > --a) break;
  347.                     if (e = this.items().eq(a), 0 === e.length) break;
  348.                     if (o = this.dimension(e), 0 === o) break;
  349.                     if (h += o, d.first = e, d.visible = d.visible.add(e), n = s(e.css("margin-" + c)), u >= h - n && (d.fullyvisible = d.fullyvisible.add(e)), h >= u) break
  350.                 }
  351.             return this._update(d), this.tail = 0, f || "circular" === this.options("wrap") || "custom" === this.options("wrap") || this.index(d.last) !== this.items().length - 1 || (h -= s(d.last.css("margin-" + c)), h > u && (this.tail = h - u)), this
  352.         },
  353.         _position: function (t) {
  354.             var i = this._first,
  355.                 s = i.position()[this.lt],
  356.                 e = this.options("center"),
  357.                 r = e ? this.clipping() / 2 - this.dimension(i) / 2 : 0;
  358.             return this.rtl && !this.vertical ? (s -= this.relative ? this.list().width() - this.dimension(i) : this.clipping() - this.dimension(i), s += r) : s -= r, !e && (this.index(t) > this.index(i) || this.inTail) && this.tail ? (s = this.rtl && !this.vertical ? s - this.tail : s + this.tail, this.inTail = !0) : this.inTail = !1, -s
  359.         },
  360.         _update: function (i) {
  361.             var s, e = this,
  362.                 r = {
  363.                     target: this._target || t(),
  364.                     first: this._first || t(),
  365.                     last: this._last || t(),
  366.                     visible: this._visible || t(),
  367.                     fullyvisible: this._fullyvisible || t()
  368.                 },
  369.                 n = this.index(i.first || r.first) < this.index(r.first),
  370.                 o = function (s) {
  371.                     var o = [],
  372.                         l = [];
  373.                     i[s].each(function () {
  374.                         0 > r[s].index(this) && o.push(this)
  375.                     }), r[s].each(function () {
  376.                         0 > i[s].index(this) && l.push(this)
  377.                     }), n ? o = o.reverse() : l = l.reverse(), e._trigger(s + "in", t(o)), e._trigger(s + "out", t(l)), e["_" + s] = i[s]
  378.                 };
  379.             for (s in i) o(s);
  380.             return this
  381.         }
  382.     })
  383. }(jQuery, window),
  384. function (t) {
  385.     "use strict";
  386.     t.jcarousel.fn.scrollIntoView = function (i, s, e) {
  387.         var r, n = t.jCarousel.parseTarget(i),
  388.             o = this.index(this._fullyvisible.first()),
  389.             l = this.index(this._fullyvisible.last());
  390.         if (r = n.relative ? 0 > n.target ? Math.max(0, o + n.target) : l + n.target : "object" != typeof n.target ? n.target : this.index(n.target), o > r) return this.scroll(r, s, e);
  391.         if (r >= o && l >= r) return t.isFunction(e) && e.call(this, !1), this;
  392.         for (var a, h = this.items(), u = this.clipping(), c = this.vertical ? "bottom" : this.rtl ? "left" : "right", f = 0;;) {
  393.             if (a = h.eq(r), 0 === a.length) break;
  394.             if (f += this.dimension(a), f >= u) {
  395.                 var d = parseFloat(a.css("margin-" + c)) || 0;
  396.                 f - d !== u && r++;
  397.                 break
  398.             }
  399.             if (0 >= r) break;
  400.             r--
  401.         }
  402.         return this.scroll(r, s, e)
  403.     }
  404. }(jQuery),
  405. function (t) {
  406.     "use strict";
  407.     t.jCarousel.plugin("jcarouselControl", {
  408.         _options: {
  409.             target: "+=1",
  410.             event: "click",
  411.             method: "scroll"
  412.         },
  413.         _active: null,
  414.         _init: function () {
  415.             this.onDestroy = t.proxy(function () {
  416.                 this._destroy(), this.carousel().one("jcarousel:createend", t.proxy(this._create, this))
  417.             }, this), this.onReload = t.proxy(this._reload, this), this.onEvent = t.proxy(function (i) {
  418.                 i.preventDefault();
  419.                 var s = this.options("method");
  420.                 t.isFunction(s) ? s.call(this) : this.carousel().jcarousel(this.options("method"), this.options("target"))
  421.             }, this)
  422.         },
  423.         _create: function () {
  424.             this.carousel().one("jcarousel:destroy", this.onDestroy).on("jcarousel:reloadend jcarousel:scrollend", this.onReload), this._element.on(this.options("event") + ".jcarouselcontrol", this.onEvent), this._reload()
  425.         },
  426.         _destroy: function () {
  427.             this._element.off(".jcarouselcontrol", this.onEvent), this.carousel().off("jcarousel:destroy", this.onDestroy).off("jcarousel:reloadend jcarousel:scrollend", this.onReload)
  428.         },
  429.         _reload: function () {
  430.             var i, s = t.jCarousel.parseTarget(this.options("target")),
  431.                 e = this.carousel();
  432.             if (s.relative) i = e.jcarousel(s.target > 0 ? "hasNext" : "hasPrev");
  433.             else {
  434.                 var r = "object" != typeof s.target ? e.jcarousel("items").eq(s.target) : s.target;
  435.                 i = e.jcarousel("target").index(r) >= 0
  436.             }
  437.             return this._active !== i && (this._trigger(i ? "active" : "inactive"), this._active = i), this
  438.         }
  439.     })
  440. }(jQuery),
  441. function (t) {
  442.     "use strict";
  443.     t.jCarousel.plugin("jcarouselPagination", {
  444.         _options: {
  445.             perPage: null,
  446.             item: function (t) {
  447.                 return '<a href="#' + t + '">' + t + "</a>"
  448.             },
  449.             event: "click",
  450.             method: "scroll"
  451.         },
  452.         _carouselItems: null,
  453.         _pages: {},
  454.         _items: {},
  455.         _currentPage: null,
  456.         _init: function () {
  457.             this.onDestroy = t.proxy(function () {
  458.                 this._destroy(), this.carousel().one("jcarousel:createend", t.proxy(this._create, this))
  459.             }, this), this.onReload = t.proxy(this._reload, this), this.onScroll = t.proxy(this._update, this)
  460.         },
  461.         _create: function () {
  462.             this.carousel().one("jcarousel:destroy", this.onDestroy).on("jcarousel:reloadend", this.onReload).on("jcarousel:scrollend", this.onScroll), this._reload()
  463.         },
  464.         _destroy: function () {
  465.             this._clear(), this.carousel().off("jcarousel:destroy", this.onDestroy).off("jcarousel:reloadend", this.onReload).off("jcarousel:scrollend", this.onScroll), this.resetCarouselItems()
  466.         },
  467.         _reload: function () {
  468.             var i = this.options("perPage");
  469.             if (this._pages = {}, this._items = {}, t.isFunction(i) && (i = i.call(this)), null == i) this._pages = this._calculatePages();
  470.             else
  471.                 for (var s, e = parseInt(i, 10) || 0, r = this._getCarouselItems(), n = 1, o = 0;;) {
  472.                     if (s = r.eq(o++), 0 === s.length) break;
  473.                     this._pages[n] = this._pages[n] ? this._pages[n].add(s) : s, 0 === o % e && n++
  474.                 }
  475.             this._clear();
  476.             var l = this,
  477.                 a = this.carousel().data("jcarousel"),
  478.                 h = this._element,
  479.                 u = this.options("item"),
  480.                 c = this._getCarouselItems().length;
  481.             t.each(this._pages, function (i, s) {
  482.                 var e = l._items[i] = t(u.call(l, i, s));
  483.                 e.on(l.options("event") + ".jcarouselpagination", t.proxy(function () {
  484.                     var t = s.eq(0);
  485.                     if (a.circular) {
  486.                         var e = a.index(a.target()),
  487.                             r = a.index(t);
  488.                         parseFloat(i) > parseFloat(l._currentPage) ? e > r && (t = "+=" + (c - e + r)) : r > e && (t = "-=" + (e + (c - r)))
  489.                     }
  490.                     a[this.options("method")](t)
  491.                 }, l)), h.append(e)
  492.             }), this._update()
  493.         },
  494.         _update: function () {
  495.             var i, s = this.carousel().jcarousel("target");
  496.             t.each(this._pages, function (t, e) {
  497.                 return e.each(function () {
  498.                     return s.is(this) ? (i = t, !1) : void 0
  499.                 }), i ? !1 : void 0
  500.             }), this._currentPage !== i && (this._trigger("inactive", this._items[this._currentPage]), this._trigger("active", this._items[i])), this._currentPage = i
  501.         },
  502.         items: function () {
  503.             return this._items
  504.         },
  505.         reloadCarouselItems: function () {
  506.             return this._carouselItems = null, this
  507.         },
  508.         _clear: function () {
  509.             this._element.empty(), this._currentPage = null
  510.         },
  511.         _calculatePages: function () {
  512.             for (var t, i = this.carousel().data("jcarousel"), s = this._getCarouselItems(), e = i.clipping(), r = 0, n = 0, o = 1, l = {};;) {
  513.                 if (t = s.eq(n++), 0 === t.length) break;
  514.                 l[o] = l[o] ? l[o].add(t) : t, r += i.dimension(t), r >= e && (o++, r = 0)
  515.             }
  516.             return l
  517.         },
  518.         _getCarouselItems: function () {
  519.             return this._carouselItems || (this._carouselItems = this.carousel().jcarousel("items")), this._carouselItems
  520.         }
  521.     })
  522. }(jQuery),
  523. function (t) {
  524.     "use strict";
  525.     t.jCarousel.plugin("jcarouselAutoscroll", {
  526.         _options: {
  527.             target: "+=1",
  528.             interval: 3e3,
  529.             autostart: !0
  530.         },
  531.         _timer: null,
  532.         _init: function () {
  533.             this.onDestroy = t.proxy(function () {
  534.                 this._destroy(), this.carousel().one("jcarousel:createend", t.proxy(this._create, this))
  535.             }, this), this.onAnimateEnd = t.proxy(this.start, this)
  536.         },
  537.         _create: function () {
  538.             this.carousel().one("jcarousel:destroy", this.onDestroy), this.options("autostart") && this.start()
  539.         },
  540.         _destroy: function () {
  541.             this.stop(), this.carousel().off("jcarousel:destroy", this.onDestroy)
  542.         },
  543.         start: function () {
  544.             return this.stop(), this.carousel().one("jcarousel:animateend", this.onAnimateEnd), this._timer = setTimeout(t.proxy(function () {
  545.                 this.carousel().jcarousel("scroll", this.options("target"))
  546.             }, this), this.options("interval")), this
  547.         },
  548.         stop: function () {
  549.             return this._timer && (this._timer = clearTimeout(this._timer)), this.carousel().off("jcarousel:animateend", this.onAnimateEnd), this
  550.         }
  551.     })
  552. }(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement