﻿(function (E) { var D = []; var B = null; var A = function () { for (var F = 0; F < D.length; F++) { var I = D[F]; var G = I.options; if (!I._lastTime) { I._lastTime = new Date().getTime(); I._speed = Math.floor(1000 / G.speed); if (G.auto) { if (G.startTimeout) { I._lastTime += G.startTimeout * 1000 } else { I.go() } } else { } } else { var H = new Date().getTime(); if (I.stopping == false && (H - I._lastTime > I._speed)) { I._lastTime = H; I.go() } } } if (!D.length) { C() } }; var C = function () { clearInterval(B); B = null }; E.widget("ui.scrollit", { options: { auto: true, hoverStop: true, step: false, count: 1, pix: 1, speed: 50, startTimeout: 1, timeout: 1, fx: "scroll", prev: false, next: false, mevent: "hover", direction: "up" }, _create: function () { var G = this.options, F = this, H = this.element; this.sliding = false; this.stopping = false; this._setup(); if (G.hoverStop) { F.innerScrollDiv.hover(function (I) { if (!F.dohover) { F.dohover = true; F.stopping = true; F._trigger("mouseover", I) } }, function (I) { if (F.dohover) { F.dohover = false; F.stopping = false; F._lastTime += G.timeout * 1000; F._trigger("mouseout", I) } }) } if (D.push(this) && !B) { B = setInterval(A, 13) } }, _setup: function () { var H = this.options, G = this, I = this.element; this.wrap = { width: I.width(), height: I.height() }; this._fx = H.direction == "up" || H.direction == "down" ? "scrollTop" : "scrollLeft"; this._op = H.direction == "up" || H.direction == "left" ? 1 : -1; this._dom = { size: function () { return G._fx == "scrollTop" ? "height" : "width" }, outerSize: function () { return G._fx == "scrollTop" ? "outerHeight" : "outerWidth" }, func: function () { return G._op == 1 ? "appendTo" : "prependTo" } }; this.area = { width: 0, height: 0 }; this.items = I.children().each(function () { G.area[G._dom.size()] += G._size(E(this)) }).css(this._fx == "scrollTop" ? { "display": "block", "float": "none", "margin-top": "0", "margin-bottom": "0"} : { "float": "left", "position": "relative" }); this.innerScrollDiv = E("<div class='scrollit-area'/>").css({ position: "relative", height: "auto", width: "auto" }).append(this.items); this.innerWrapDiv = E("<div class='scrollit-wrap'/>").css({ position: "relative", overflow: "hidden", width: this.wrap.width + "px", height: this.wrap.height + "px" }).append(this.innerScrollDiv).appendTo(I); if (H.fx == "slide") { H.step = H.step || 1; H.count = H.count || 1; H.count = H.count > this.items.size() ? this.items.size() : H.count; if (H.step > H.count) { H.step = H.count } this._setWrap() } else { if (this.area[this._dom.size()] < this.wrap[this._dom.size()]) { var F = this.area[this._dom.size()]; while (true) { this.area[this._dom.size()] += F; this.items.clone(true).appendTo(this.innerScrollDiv); if (this.area[this._dom.size()] >= this.wrap[this._dom.size()]) { break } } } this.area[this._dom.size()] += this._size(this.innerScrollDiv.children().filter(this._op == 1 ? ":first" : ":last").data("copyed", true).clone(true)[this._dom.func()](this.innerScrollDiv)); this.innerScrollDiv[this._dom.size()](this.area[this._dom.size()]); this._scroll(this._op == 1 ? 0 : this.area[this._dom.size()] - this.wrap[this._dom.size()]) } if (H.pix >= this.area[this._dom.size()]) { return false } }, _calScope: function (H) { var G = H; var M = G + this.options.step; var F = 0, I = 0, K = 0; var J = this.innerScrollDiv.children(); var N = J.size(); for (var L = 0; L < this.options.count; L++) { var H = G + L; F += this._size(J.eq(H % N)); H = M + L; K += this._size(J.eq(H % N)) } for (var L = 0; L < this.options.step; L++) { var H = M + L; I += this._size(J.eq(H % N)) } return { curScope: F, nextScope: K, overScope: I} }, _setWrap: function (G) { var F = this; this.scope = this._calScope(this.op == 1 ? 0 : this.innerScrollDiv.children().size() - this.options.step); this.innerWrapDiv[this._dom.size()](this.scope.curScope); this.wrap[this._dom.size()] = this.scope.curScope; this._scroll(this._op == 1 ? 0 : this.area[this._dom.size()] - this.wrap[this._dom.size()]); this.overpx = 0 }, _scroll: function (F) { if (arguments.length == 0) { return this.innerWrapDiv[this._fx]() } else { this.innerWrapDiv[this._fx](F) } }, _size: function (F) { return F[this._dom.outerSize()](true) }, stop: function () { this.stopping = true }, prev: function (G) { if (this.sliding) { return false } G = G || 1; this.action = this.action || "prev"; this._op = 1; if (this.action != "prev") { var F = this.innerScrollDiv.children(":last").data("copyed", false); var H = this.innerScrollDiv.children(":first").data("copyed", true) } this.action = "prev"; this._autoScroll(1 * G) }, next: function (G) { if (this.sliding) { return false } G = G || 1; this.action = this.action || "next"; this._op = -1; var H = this; if (this.action != "next") { var F = this.innerScrollDiv.children(":last").data("copyed", true); var I = this.innerScrollDiv.children(":first").data("copyed", false) } this.action = "next"; this._autoScroll(-1 * G) }, go: function (F) { F = F || this._op; this.sliding = true; var L = this; var M = this.options.pix; if (this.options.fx == "slide") { this.overpx += M; if (this.overpx > this.scope.overScope) { M -= this.overpx - this.scope.overScope; this.overpx = this.scope.overScope } } var J = this._scroll() + M * F; if (F > 0) { while (true) { var I = this.innerScrollDiv.children(":first"); var K = this._size(I); if (K <= J) { J -= K; if (I.data("copyed")) { var G = this._size(I.next().data("copyed", true).clone(true)[L._dom.func()](L.innerScrollDiv)); I.remove(); this.innerScrollDiv[this._dom.size()](this.area[this._dom.size()] = this.area[this._dom.size()] + G - K); break } else { I[L._dom.func()](L.innerScrollDiv) } } else { if (!I.data("copyed")) { K = this._size(I.data("copyed", true).clone(true)[L._dom.func()](L.innerScrollDiv)); this.innerScrollDiv[this._dom.size()](this.area[this._dom.size()] = this.area[this._dom.size()] + K) } break } } } else { while (true) { var H = this.area[this._dom.size()] - this.wrap[this._dom.size()] - J; var I = this.innerScrollDiv.children(":last"); var K = this._size(I); var G = 0; if (K <= H) { if (I.data("copyed")) { I.remove(); I = this.innerScrollDiv.children(":last"); G = this._size(I.data("copyed", true).clone(true)[L._dom.func()](L.innerScrollDiv)); this.innerScrollDiv[this._dom.size()](this.area[this._dom.size()] = this.area[this._dom.size()] + G - K) } else { G = this._size(I[L._dom.func()](L.innerScrollDiv)) } J += G } else { if (!I.data("copyed")) { K = this._size(I.data("copyed", true).clone(true)[L._dom.func()](L.innerScrollDiv)); J += K; this.innerScrollDiv[this._dom.size()](this.area[this._dom.size()] = this.area[this._dom.size()] + K) } break } } } this._scroll(J); if (this.options.fx == "slide" && this.overpx == this.scope.overScope && this.options.timeout) { this.sliding = false; this._setWrap(true); L._oldop = this._op; this._lastTime += this.options.timeout * 1000 } } }); E(function () { E(".i-scrollit").scrollit() }) })(jQuery);
