/* @author constantin saguin - @brutaldesign @link http://bsign.co @github http://github.com/brutaldesign/swipebox @version 1.0 @license mit license */ (function(e, t, n, r) { n.swipebox = function(i, s) { var o = { usecss: true, hidebarsdelay: 3e3 }, u = this, a = n(i), i = i, f = i.selector, l = n(f), c = t.createtouch !== r || "ontouchstart" in e || "onmsgesturechange" in e || navigator.msmaxtouchpoints, h = !!e.svgsvgelement, p = '
'; u.settings = {}; u.init = function() { u.settings = n.extend({}, o, s); l.click(function(e) { e.preventdefault(); e.stoppropagation(); index = a.index(n(this)); d.init(index) }) }; var d = { init: function(e) { this.build(); this.openslide(e); this.openimg(e); this.preloadimg(e + 1); this.preloadimg(e - 1) }, build: function() { var t = this; n("body").append(p); if (t.docsstrans()) { n("#swipebox-slider").css({ "-webkit-transition": "left 0.4s ease", "-moz-transition": "left 0.4s ease", "-o-transition": "left 0.4s ease", "-khtml-transition": "left 0.4s ease", transition: "left 0.4s ease" }); n("#swipebox-overlay").css({ "-webkit-transition": "opacity 1s ease", "-moz-transition": "opacity 1s ease", "-o-transition": "opacity 1s ease", "-khtml-transition": "opacity 1s ease", transition: "opacity 1s ease" }); n("#swipebox-action, #swipebox-caption").css({ "-webkit-transition": "0.5s", "-moz-transition": "0.5s", "-o-transition": "0.5s", "-khtml-transition": "0.5s", transition: "0.5s" }) } if (h) { var r = n("#swipebox-action #swipebox-close").css("background-image"); r = r.replace("png", "svg"); n("#swipebox-action #swipebox-prev,#swipebox-action #swipebox-next,#swipebox-action #swipebox-close").css({ "background-image": r }) } a.each(function() { n("#swipebox-slider").append('
') }); t.setdim(); t.actions(); t.keyboard(); t.gesture(); t.animbars(); n(e).resize(function() { t.setdim() }).resize() }, setdim: function() { var t = { width: n(e).width(), height: e.innerheight ? e.innerheight : n(e).height() }; n("#swipebox-overlay").css(t) }, supporttransition: function() { var e = "transition webkittransition moztransition otransition mstransition khtmltransition".split(" "); for (var n = 0; n < e.length; n++) { if (t.createelement("div").style[e[n]] !== r) { return e[n] } } return false }, docsstrans: function() { if (u.settings.usecss && this.supporttransition()) { return true } }, gesture: function() { if (c) { var e = this, t = null, r = 10, i = {}, s = {}; var o = n("#swipebox-caption, #swipebox-action"); o.addclass("visible-bars"); e.settimeout(); n("body").bind("touchstart", function(e) { n(this).addclass("touching"); s = e.originalevent.targettouches[0]; i.pagex = e.originalevent.targettouches[0].pagex; n(".touching").bind("touchmove", function(e) { e.preventdefault(); e.stoppropagation(); s = e.originalevent.targettouches[0] }); return false }).bind("touchend", function(u) { u.preventdefault(); u.stoppropagation(); t = s.pagex - i.pagex; if (t >= r) { e.getprev() } else if (t <= -r) { e.getnext() } else { if (!o.hasclass("visible-bars")) { e.showbars(); e.settimeout() } else { e.cleartimeout(); e.hidebars() } } n(".touching").off("touchmove").removeclass("touching") }) } }, settimeout: function() { if (u.settings.hidebarsdelay > 0) { var t = this; t.cleartimeout(); t.timeout = e.settimeout(function() { t.hidebars() }, u.settings.hidebarsdelay) } }, cleartimeout: function() { e.cleartimeout(this.timeout); this.timeout = null }, showbars: function() { var e = n("#swipebox-caption, #swipebox-action"); if (this.docsstrans()) { e.addclass("visible-bars") } else { n("#swipebox-caption").animate({ top: 0 }, 500); n("#swipebox-action").animate({ bottom: 0 }, 500); settimeout(function() { e.addclass("visible-bars") }, 1e3) } }, hidebars: function() { var e = n("#swipebox-caption, #swipebox-action"); if (this.docsstrans()) { e.removeclass("visible-bars") } else { n("#swipebox-caption").animate({ top: "-50px" }, 500); n("#swipebox-action").animate({ bottom: "-50px" }, 500); settimeout(function() { e.removeclass("visible-bars") }, 1e3) } }, animbars: function() { var e = this; var t = n("#swipebox-caption, #swipebox-action"); if (!c) { t.addclass("visible-bars"); e.settimeout(); n("#swipebox-slider").click(function(n) { if (!t.hasclass("visible-bars")) { e.showbars(); e.settimeout() } }); n("#swipebox-action").hover(function() { e.showbars(); t.addclass("force-visible-bars"); e.cleartimeout() }, function() { t.removeclass("force-visible-bars"); e.settimeout() }) } }, keyboard: function() { if (!c) { var t = this; n(e).bind("keyup", function(e) { e.preventdefault(); e.stoppropagation(); if (e.keycode == 37) { t.getprev() } else if (e.keycode == 39) { t.getnext() } else if (e.keycode == 27) { t.closeslide() } }) } }, actions: function() { var e = this; if (a.length < 2) { n("#swipebox-prev, #swipebox-next").hide() } else { n("#swipebox-prev").bind("click touchend", function(t) { t.preventdefault(); t.stoppropagation(); e.getprev(); e.settimeout() }); n("#swipebox-next").bind("click touchend", function(t) { t.preventdefault(); t.stoppropagation(); e.getnext(); e.settimeout() }) } n("#swipebox-close").bind("click touchstart", function(t) { e.closeslide() }) }, setslide: function(e) { var t = n("#swipebox-slider"); if (this.docsstrans()) { t.css({ left: -e * 100 + "%" }) } else { t.animate({ left: -e * 100 + "%" }) } n("#swipebox-slider .slide").removeclass("current"); n("#swipebox-slider .slide").eq(e).addclass("current"); this.settitle(e); n("#swipebox-prev, #swipebox-next").removeclass("disabled"); if (e == 0) { n("#swipebox-prev").addclass("disabled") } else if (e == a.length - 1) { n("#swipebox-next").addclass("disabled") } }, openslide: function(e) { n("#swipebox-overlay").show().stop().animate({ opacity: 1 }, "slow").addclass("visible"); settimeout(function() { n("body").addclass("swipebox-overflow-hidden") }, 1500); this.setslide(e) }, preloadimg: function(e) { var t = this; settimeout(function() { t.openimg(e) }, 1e3) }, openimg: function(e) { var t = this; if (e < 0 || e >= a.length) { return false } t.loadimg(a.eq(e).attr("href"), function() { n("#swipebox-slider .slide").eq(e).html(this) }) }, settitle: function(e) { var t = null; if (a.eq(e).attr("title")) { n("#swipebox-caption").empty().append(a.eq(e).attr("title")) //açš„title } }, loadimg: function(e, t) { var r = n("").on("load", function() { t.call(r) }); r.attr("src", e) }, getnext: function() { var e = this; index = n("#swipebox-slider .slide").index(n("#swipebox-slider .slide.current")); if (index + 1 < a.length) { index++; e.setslide(index); e.preloadimg(index + 1) } else { n("#swipebox-slider").addclass("rightspring"); settimeout(function() { n("#swipebox-slider").removeclass("rightspring") }, 500) } }, getprev: function() { var e = this; index = n("#swipebox-slider .slide").index(n("#swipebox-slider .slide.current")); if (index > 0) { index--; e.setslide(index); e.preloadimg(index - 1) } else { n("#swipebox-slider").addclass("leftspring"); settimeout(function() { n("#swipebox-slider").removeclass("leftspring") }, 500) } }, closeslide: function() { var e = this; n("body").removeclass("swipebox-overflow-hidden"); n("#swipebox-overlay").animate({ opacity: 0 }, "fast"); settimeout(function() { n("#swipebox-overlay").removeclass("visible"); e.destroy() }, 1e3) }, destroy: function() { var t = this; n(e).unbind("keyup"); n(e).unbind("resize"); n("body").unbind(); n("#swipebox-slider").unbind(); n("#swipebox-overlay").remove(); a.removedata("_swipebox") } }; u.init() }; n.fn.swipebox = function(e) { if (!n.data(this, "_swipebox")) { var t = new n.swipebox(this, e); this.data("_swipebox", t) } } })(window, document, jquery)