﻿// @author Dan Gidman (danatcofo at gmail dot com) http://www.gnu.org/licenses/gpl.html V 2.4
(function (e) { var p = "$autoscroll", b = "$tAutoscroll", i = "$autoscrollInterval", l = "$edgeAutoscroll", r = "$lastEdgeAutoscroll", j = { up: 90, left: 180, right: 360, upleft: 135, upright: 45, downleft: 225, downright: 315, leftup: 135, rightup: 45, leftdown: 225, rightdown: 315, down: 270 }, g = { init: function (d) { return this.each(function () { if (s(this)) { e(this).data(p, c(e.extend(s(this), d))) } else { e(this).data(p, c(e.extend({ e: false, fr: false }, e.fn.autoscroll.defaults.settings, d))); e(this).hover(function () { var k = s(this); if (k) { if (k.scroll) { q(this); e(this).stop(true) } k.e = true } }, function () { var k = s(this); if (k && k.e) { if (k.scroll) { h(this) } k.e = false } }); h(this) } }) }, destroy: function () { return this.each(function () { if (s(this)) { q(this); e(this).stop(true).data(i, null).data(p, null).data(b, null) } }) }, delay: function (d) { return this.each(function () { var k = s(this); if (k && k.scroll) { e(this).autoscroll("pause"); e(this).oneTime(d || e.fn.autoscroll.defaults.delay, p, function () { e(this).autoscroll("resume") }) } }) }, fastforward: function (d) { return a(this, "f", d) }, rewind: function (d) { return a(this, "r", d) }, pause: function () { return this.each(function () { var d = s(this); if (d && d.scroll) { d.scroll = false; e(this).stop(true); q(this) } }) }, resume: function () { return this.each(function () { var d = s(this); if (d) { d.scroll = true; h(this) } }) }, reverse: function () { return this.each(function () { var d = s(this); if (d && (d.direction += 180) > 360) { d.direction -= 360 } e(this).stop(true) }) }, toggle: function () { return this.each(function () { var d = s(this); if (d) { if (d.scroll) { e(this).autoscroll("pause") } else { e(this).autoscroll("resume") } } }) }, get: function () { return this.each(function () { if (s(this)) { return s(this) } }) }, addpausesource: function (k) { if (typeof k == "undefined") { return this } if (!(k instanceof jQuery)) { if ((k = e(k)).length == 0) { return this } } var d = this.selector; k.each(function () { e(this).hover(function () { e(d).each(function () { var u = s(this); if (u) { if (u.scroll) { q(this); e(this).stop(true) } u.e = true } }) }, function () { e(d).each(function () { var u = s(this); if (u && u.e) { if (u.scroll) { h(this) } u.e = false } }) }) }); return this } }, h = function (d) { e(d).data(i, setInterval(function () { var k, u = s(d); if (u) { if (typeof u.onEvaluate == "function") { u.onEvaluate.apply(d) } if (!n(d)) { if (u.scroll && !u.e && !u.fr) { if ((k = e(d).data(b)) && !m(k, u)) { e(d).stop(true).animate(f(u.step, u.direction, d), 1000, "linear") } else { e(d).animate(f(u.step, u.direction), 1000, "linear") } } } e(d).data(b, e.extend(true, {}, u)) } }, 50)) }, q = function (d) { clearInterval(e(d).data(i)) }, s = function (d) { return e(d).data(p) }, m = function (k, d) { return k.step === d.step && k.direction === d.direction && k.scroll === d.scroll }, a = function (d, u, k) { var v = c(e.extend(e.fn.autoscroll.defaults.ffrw, k)); return d.each(function () { var y = s(this); if (y) { var x = y.scroll, w = y.direction; y.fr = true; if (u == "r" && (w += 180) > 360) { w -= 360 } if (y.scroll) { q(this) } e(this).stop(true).animate(f(v.step, w), v.speed, "swing", function () { s(this).fr = false; if (y.scroll) { h(this) } }) } }) }, c = function (d) { if (e.inArray(typeof d.scroll, ["undefined", "boolean"]) < 0) { e.error("scroll is not a boolean") } if (e.inArray(typeof d.step, ["undefined", "number"]) < 0 && isNaN(d.step = Number(d.step))) { e.error("step is not a valid number") } if (d.direction) { d.direction = o(d.direction) } return d }, t = function (d) { return d * Math.PI / 180 }, o = function (d) { if (typeof d === "string" && isNaN(Number(d))) { if (j[d]) { d = j[d] } else { if (d.indexOf("rad") == d.length - 3 && !isNaN(d = Number(d.substring(0, d.length - 3)))) { d = d * 180 / Math.PI } } } if (isNaN(d = Number(d))) { e.error("Invalid direction on jQuery.autoscroll") } while (d < 0) { d += 360 } return d }, f = function (u, k) { var d = Math.round(u * Math.cos(k = t(k))), w = Math.round(u * Math.sin(k)) * -1, v = arguments[2]; return (v && e(v).length > 0) ? { scrollTop: v.scrollTop + w, scrollLeft: v.scrollLeft + d} : { scrollTop: ((w < 0) ? "-=" : "+=") + Math.abs(w), scrollLeft: ((d < 0) ? "-=" : "+=") + Math.abs(d)} }, n = function (z) { var A = s(z); if (A && typeof A.onEdge == "function") { var w = e(z).data(l) || { x: null, y: null }, F = A.step, u = z.scrollLeft, D = t(A.direction), C = Math.round(F * Math.cos(D)), d = u + C, E = z.scrollTop, B = Math.round(F * Math.sin(D)) * -1; nt = E + B, _e = e(z).data(r); if (u > d && u == 0) { if (!w.x || w.x != "left") { w.x = "left" } } else { if (u < d && u == z.scrollWidth - z.clientWidth) { if (!w.x || w.x != "right") { w.x = "right" } } else { w.x = null } } if (E > nt && E == 0) { if (!w.y || w.y != "top") { w.y = "top" } } else { if (E < nt && E == z.scrollHeight - z.clientHeight) { if (!w.y || w.y != "bottom") { w.y = "bottom" } } else { w.y = null } } try { if (!_e || (w.x && w.x != _e.x) || (w.y && w.y != _e.y)) { A.onEdge.apply(z, [w]); return true } } catch (k) { throw k } finally { e(z).data(r, e.extend(true, {}, w)).data(l, w) } } return false }; e.fn.autoscroll = function (k, d) { if (g[k]) { return g[k].apply(this, Array.prototype.slice.call(arguments, 1)) } else { if (typeof k === "object" || !k) { return g.init.apply(this, arguments) } else { e.error("Method " + k + " does not exist on jQuery.autoscroll") } } }; e.fn.autoscroll.defaults = { settings: { step: 50, scroll: true, direction: "down" }, delay: 5000, ffrw: { speed: "fast", step: 100}} })(jQuery);
