﻿(function (a) { var b; var c = function () { }; var d = function (b, c) { return function () { if (a.isFunction(c)) { return c.apply(b, arguments) } else { return b[c].apply(b, arguments) } } }; animationqueue = {}; animationqueue.AnimationQueue = function () { this.sets = []; this.isRunning = false; this.current = 0; this.totalTime = 0; this.elapsedTime = 0; this.startTime = 1; this.poll = null }; animationqueue.AnimationQueue.prototype = { queue: function (a) { this.sets.push(a) }, start: function (b, d) { this.totalTime = b; this.elapsedTime = 0; this.isRunning = true; d = a.isFunction(d) ? d : c; var e = 1; var f = 1; if (this.sets.length > 0) { e = this.sets.length; f = this.sets[0].totalTime > 0 ? Math.max(0, Math.min(1, 1 - this.sets[0].elapsedTime / this.sets[0].totalTime)) : 1 } var g = (new Date).getTime(); if (this.sets.length > 0) { this.sets[0].start(f / e * this.totalTime) } (function (a, b, c) { function e() { a.elapsedTime = (new Date).getTime() - g; if (a.sets.length && !a.sets[0].isRunning) { a.sets.shift(); if (a.sets.length) { a.sets[0].start(b / c) } } if (a.elapsedTime >= a.totalTime && a.sets.length == 0) { d(a.elapsedTime); a.stop() } } a.poll = setInterval(e, 16) })(this, this.totalTime, e) }, stop: function () { if (this.isRunning) { this.isRunning = false; var a = this.sets.length; while (a--) { this.sets[a].stop() } clearInterval(this.poll) } }, remove: function (a) { var b = this.sets.length; while (b--) { if (this.sets[b] == a) { var c = this.sets.slice(0, b); this.animationSet = c.push(this.sets.slice(b + 1)) } } }, get: function () { return this.sets.slice(0) } }; animationqueue.AnimationSet = function () { this.steps = []; this.isStepsSorted = true; this.currentStep = -1; this.animations = []; this.isRunning = false; this.totalTime = 0; this.elapsedTime = 0; this.poll = null; this.data = {} }; animationqueue.AnimationSet.prototype = { add: function (a) { if (a instanceof animationqueue.AnimationStep) { this.steps.push(a); this.isStepsSorted = false; ++this.currentStep } else if (a instanceof animationqueue.Animation) { this.animations.push(a) } }, start: function (a) { function e(a) { c.elapsedTime = (new Date).getTime() - c.startTime; while (c.currentStep >= 0 && c.steps[c.currentStep].getTime(c.totalTime) <= c.elapsedTime) { c.steps[c.currentStep].doIt(); --c.currentStep } if (c.elapsedTime >= c.totalTime && c.currentStep < 0) { while (d >= 0 && !c.animations[d].isRunning) { --d } if (d < 0) { c.reset(c.elapsedTime) } } } this.elapsedTime = this.totalTime == 0 ? 0 : this.elapsedTime / this.totalTime * a; this.totalTime = a; if (!this.isStepsSorted) { this.steps.sort(function (a, b) { return b.moment - a.moment }); this.isStepsSorted = true } this.isRunning = true; this.startTime = (new Date).getTime() - this.elapsedTime; var b = this.animations.length; while (b--) { this.animations[b].start(this.totalTime) } var c = this; var d = this.animations.length - 1; this.poll = setInterval(e, 16) }, stop: function () { if (this.isRunning) { this.isRunning = false; if (this.poll) { clearInterval(this.poll) } var a = this.animations.length; while (a--) { this.animations[a].stop() } } }, setData: function (a, b) { this.data[a] = b }, getData: function (a) { return this.data[a] }, reset: function () { this.stop(); this.elapsedTime = 0; this.currentStep = this.steps.length - 1 } }; animationqueue.AnimationStep = function (a, b, c) { this.$element = a; this.cssParams = b; this.moment = Math.min(1, Math.max(0, c)) }; animationqueue.AnimationStep.prototype = { getTime: function (a) { return this.moment * a }, doIt: function () { this.$element.css(this.cssParams) } }; animationqueue.Animation = function (a, b) { this.$element = a; this.animateParams = b; this.isRunning = false }; animationqueue.Animation.prototype = { start: function (a) { this.$element.stop(); if (a === 0) { this.$element.css(this.animateParams); self.isRunning = false } else { this.isRunning = true; this.$element.animate(this.animateParams, a, d(this, function () { this.isRunning = false })) } }, stop: function () { this.$element.stop(); this.isRunning = false } }; a.jcoverflip = { animationElement: function (a, b, c) { return { element: a, animate: b, steps: c} }, getItemFromElement: function (b) { b = a(b); var c = b.hasClass("ui-jcoverflip--item") ? b : b.parents(".ui-jcoverflip--item"); if (c.size() == 0) { return null } else { return { element: c, index: c.data("jcoverflip__index")} } } }; a.widget("ui.jcoverflip", { _init: function () { this.animationQueue = new animationqueue.AnimationQueue; this.isInit = false; this.goToPoll = { id: null }; this.goToQueue = []; var a = this.items(); this.element.addClass("ui-jcoverflip"); a.addClass("ui-jcoverflip--item"); var b = a.size(); while (b--) { var c = a.eq(b); c.data("jcoverflip__index", b); var e = this.options; var f = e.titles.create(c); f.css({ display: "none" }).addClass("ui-jcoverflip--title").appendTo(this.element); c.data("jcoverflip__titleElement", f) } this.element.click(d(this, this._clickItem)); this._goTo(this.options.current, 0, true); this.options.controls.create(this.element, this.length()) }, _clickItem: function (b) { if (this.options.disabled == true) { return } var c = a.jcoverflip.getItemFromElement(b.target); if (c !== null && c.index != this.current()) { this.current(c.index, b); b.preventDefault(); return false } return true }, _nextAndPrevParameters: function (b, d, e, f) { if (typeof b == "object") { f = b } else if (typeof d == "object") { f = d } else if (typeof e == "object") { f = e } else if (typeof f == "object") { f = f } else { f = {} } if (a.isFunction(b)) { e = b } else if (a.isFunction(d)) { e = d } else if (a.isFunction(e)) { e = e } else { e = c } if (typeof b == "boolean") { d = b } else if (typeof d == "boolean") { d = d } else { d = true } b = isNaN(parseInt(b)) ? 1 : parseInt(b); return { by: b, wrapAround: d, callback: e, originalEvent: f} }, next: function (a, b, c, d) { if (this.options.disabled == true) { return } var e = this._nextAndPrevParameters(a, b, c, d); return this._nextAux(e.by, e.wrapAround, e.callback, e.originalEvent, "next") }, _nextAux: function (c, d, e, f, g) { c = c === b && isNaN(c) ? 1 : parseInt(c); d = d !== false; var h = this.current(); var i = h; var j = this.length(); if (d) { h = (h + c) % j; h = h < 0 ? h + j : h } else { h = Math.min(j - 1, Math.max(0, h + c)) } if (h != this.current()) { this.current(h, f) } if (g && i != h) { var k = a.Event(f); k.type = this.widgetEventPrefix + g; e.call(this.element, k, { from: i, to: h }); this._trigger(g, f, { from: i, to: h }) } return h }, previous: function (a, b, c, d) { if (this.options.disabled == true) { return } var e = this._nextAndPrevParameters(a, b, c, d); return this._nextAux(-1 * e.by, e.wrapAround, e.callback, e.originalEvent, "previous") }, first: function (b, d) { if (this.options.disabled == true) { return } if (typeof b == "object") { d = b } else if (typeof d == "object") { d = d } else { d = {} } b = a.isFunction(b) ? b : c; var e = this.current(); var f = this.current(0, d); if (e != f) { var g = a.Event(d); g.type = this.widgetEventPrefix + "first"; b.call(this.element, g, { from: e, to: f }); this._trigger("first", d, { from: e, to: f }) } }, last: function (b, d) { if (this.options.disabled == true) { return } if (typeof b == "object") { d = b } else if (typeof d == "object") { d = d } else { d = {} } b = a.isFunction(b) ? b : c; var e = this.current(); var f = this.current(this.length() - 1, d); if (e != f) { var g = a.Event(d); g.type = this.widgetEventPrefix + "last"; b.call(this.element, g, { from: e, to: f }); this._trigger("last", d, { from: e, to: f }) } }, current: function (a, c) { if (a !== b && !isNaN(a) && !this.options.disabled && a != this.options.current) { this._goTo(a, b, false, c) } return this.options.current }, destroy: function () { if (this.options.disabled == true) { return } this._trigger("destroy", {}); this.element.removeClass("ui-jcoverflip"); var b = this.items(); var c; var d = b.length; while (d--) { c = b.eq(d).data("jcoverflip__titleElement"); this.options.titles.destroy(c) } b.removeClass("ui-jcoverflip--item").find("*").add(b.get()).each(function () { this.removeAttribute("style") }); this.options.controls.destroy(this.element); a.Widget.prototype.destroy.apply(this, arguments) }, enable: function () { a.Widget.prototype.enable.apply(this, arguments); this._trigger("enable", {}) }, disable: function () { a.Widget.prototype.disable.apply(this, arguments); this._trigger("disable", {}) }, option: function (b, c) { if (typeof c == "undefined") { return a.Widget.prototype.option.apply(this, arguments) } if (b == "current") { return this.current(c) } if (b in { items: "", titles: "", controls: "" }) { return this.options.items } if (b in { beforeCss: "", afterCss: "", currentCss: "" }) { this.options[b] = c; this._goTo(this.current(), 0, true) } if (b == "time" && isNaN(parseInt(c)) && parseInt(c) < 0) { return this.options.time } return a.Widget.prototype.option.apply(this, arguments) }, _goTo: function (a, e, f, g) { function x(a, b) { return function () { a.css(b) } } if (this.options.disabled == true) { return } f = !!f; g = g == b ? {} : g; e = e === b ? this.options.time : parseInt(e); var h = this.options.current; var i = Math.floor(Math.max(0, Math.min(a, this.length() - 1))); this.options.current = i; this.animationQueue.stop(); var j = this.animationQueue.get(); var k = j.length; while (k--) { var l = j[k].getData("to"); var m = j[k].getData("goingToTheRight"); var n = l > i; if (n != m) { this.animationQueue.remove(j[k]) } } j = this.animationQueue.get(); var o = j.length > 0 ? j.pop().getData("to") : h; var m = o < i; o += m ? 1 : -1; if (f) { o = i } var p = this.items(); while (m && o <= i || !m && o >= i || f && o == i) { var q = new animationqueue.AnimationSet; this.animationQueue.queue(q); q.setData("goingToTheRight", m); q.setData("to", o); var k = p.length; while (k--) { var r = p.eq(k); if (k < o) { var s = this.options.beforeCss(r, this.element, o - k - 1) } else if (k > o) { var s = this.options.afterCss(r, this.element, k - o - 1) } else { var s = this.options.currentCss(r, this.element, k - o - 1) } var t = s.length; while (t--) { var u = s[t]; q.add(new animationqueue.Animation(u.element, u.animate)); for (var v in u.steps) { q.add(new animationqueue.AnimationStep(u.element, u.steps[v], parseFloat(v))) } } } o += m ? 1 : -1 } var w = p.eq(i).data("jcoverflip__titleElement"); if (w) { this.options.titleAnimateIn(w, e, m) } if (i != h) { var w = p.eq(h).data("jcoverflip__titleElement"); if (w) { this.options.titleAnimateOut(w, e, m) } } if (!f) { this._trigger("start", g, { to: i, from: h }); this.animationQueue.start(e, d(this, function (a) { this._trigger("stop", g, { to: i, from: h, time: a }) })); this._trigger("change", g, { to: i, from: h }) } else { this.animationQueue.start(e, c) } }, items: function (a) { if (this.itemsCache === b || !!a) { if (this.options.items) { this.itemsCache = this.element.find(this.options.items) } else { this.itemsCache = this.element.children() } } return this.itemsCache }, length: function () { var a = this.items(); return a.length } }); a.ui.jcoverflip.prototype.options = { items: "", beforeCss: function (b, c, d) { return [a.jcoverflip.animationElement(b, { left: c.width() / 2 - 210 - 110 * d + "px", bottom: "20px" }, {}), a.jcoverflip.animationElement(b.find("img"), { opacity: .5, width: "100px" }, {})] }, afterCss: function (b, c, d) { return [a.jcoverflip.animationElement(b, { left: c.width() / 2 + 110 + 110 * d + "px", bottom: "20px" }, {}), a.jcoverflip.animationElement(b.find("img"), { opacity: .5, width: "100px" }, {})] }, currentCss: function (b, c) { return [a.jcoverflip.animationElement(b, { left: c.width() / 2 - 100 + "px", bottom: 0 }, {}), a.jcoverflip.animationElement(b.find("img"), { opacity: 1, width: "200px" }, {})] }, time: 500, titles: { create: function (b) { var c = ""; var d = a([]); var e = b.find(".title:first"); if (e.size() == 1) { d = e.clone(true); e.css("display", "none"); d.data("jcoverflip__origin", "cloned"); d.data("jcoverflip__source", e) } else if (b.attr("title")) { c = b.attr("title") } else if (b.attr("alt")) { c = b.attr("alt") } else { e = b.find("[title], [alt]").eq(0); if (e.size() == 1) { c = e.attr("title") || e.attr("alt") || "" } } if (d.size()) { d.css({ opacity: 0, display: "block" }) } else { d = a('<span class="title">' + c + "</span>"); d.data("jcoverflip__origin", "attribute") } return d }, destroy: function (a) { if (a.data("jcoverflip__origin") == "cloned") { a.data("jcoverflip__source").css("display", "") } a.remove() } }, titleAnimateIn: function (a, b, c) { if (a.css("display") == "none") { a.css({ opacity: 0, display: "block" }) } a.stop().animate({ opacity: 1 }, b) }, titleAnimateOut: function (b, c, d) { b.stop().animate({ opacity: 0 }, c, function () { a(this).css("display", "none") }) }, controls: { create: c, destroy: c }, current: 0 }; a.ui.jcoverflip.getter = ["length", "current"] })(jQuery)
