/* plugin: jquery parallax version 1.1.3 author: ian lunn twitter: @ianlunn author url: http://www.ianlunn.co.uk/ plugin url: http://www.ianlunn.co.uk/plugins/jquery-parallax/ dual licensed under the mit and gpl licenses: http://www.opensource.org/licenses/mit-license.php http://www.gnu.org/licenses/gpl.html */ (function( $ ){ var $window = $(window); var windowheight = $window.height(); $window.resize(function () { windowheight = $window.height(); }); $.fn.parallax = function(xpos, speedfactor, outerheight) { var $this = $(this); var getheight; var firsttop; var paddingtop = 0; //get the starting position of each element to have parallax applied to it $this.each(function(){ firsttop = $this.offset().top; }); if (outerheight) { getheight = function(jqo) { return jqo.outerheight(true); }; } else { getheight = function(jqo) { return jqo.height(); }; } // setup defaults if arguments aren't specified if (arguments.length < 1 || xpos === null) xpos = "50%"; if (arguments.length < 2 || speedfactor === null) speedfactor = 0.1; if (arguments.length < 3 || outerheight === null) outerheight = true; // function to be called whenever the window is scrolled or resized function update(){ var pos = $window.scrolltop(); $this.each(function(){ var $element = $(this); var top = $element.offset().top; var height = getheight($element); // check if totally above or totally below viewport if (top + height < pos || top > pos + windowheight) { return; } $this.css('backgroundposition', xpos + " " + math.round((firsttop - pos) * speedfactor) + "px"); }); } $window.bind('scroll', update).resize(update); update(); }; })(jquery); /* * jquery owlcarousel v1.3.3 * * copyright (c) 2013 bartosz wojciechowski * http://www.owlgraphic.com/owlcarousel/ * * licensed under mit * */ /*js lint helpers: */ /*global dragmove: false, dragend: false, $, jquery, alert, window, document */ /*jslint nomen: true, continue:true */ if (typeof object.create !== "function") { object.create = function (obj) { function f() {} f.prototype = obj; return new f(); }; } (function ($, window, document) { var carousel = { init : function (options, el) { var base = this; base.$elem = $(el); base.options = $.extend({}, $.fn.owlcarousel.options, base.$elem.data(), options); base.useroptions = options; base.loadcontent(); }, loadcontent : function () { var base = this, url; function getdata(data) { var i, content = ""; if (typeof base.options.jsonsuccess === "function") { base.options.jsonsuccess.apply(this, [data]); } else { for (i in data.owl) { if (data.owl.hasownproperty(i)) { content += data.owl[i].item; } } base.$elem.html(content); } base.login(); } if (typeof base.options.beforeinit === "function") { base.options.beforeinit.apply(this, [base.$elem]); } if (typeof base.options.jsonpath === "string") { url = base.options.jsonpath; $.getjson(url, getdata); } else { base.login(); } }, login : function () { var base = this; base.$elem.data("owl-originalstyles", base.$elem.attr("style")); base.$elem.data("owl-originalclasses", base.$elem.attr("class")); base.$elem.css({opacity: 0}); base.orignalitems = base.options.items; base.checkbrowser(); base.wrapperwidth = 0; base.checkvisible = null; base.setvars(); }, setvars : function () { var base = this; if (base.$elem.children().length === 0) {return false; } base.baseclass(); base.eventtypes(); base.$useritems = base.$elem.children(); base.itemsamount = base.$useritems.length; base.wrapitems(); base.$owlitems = base.$elem.find(".owl-item"); base.$owlwrapper = base.$elem.find(".owl-wrapper"); base.playdirection = "next"; base.previtem = 0; base.prevarr = [0]; base.currentitem = 0; base.customevents(); base.onstartup(); }, onstartup : function () { var base = this; base.updateitems(); base.calculateall(); base.buildcontrols(); base.updatecontrols(); base.response(); base.moveevents(); base.stoponhover(); base.owlstatus(); if (base.options.transitionstyle !== false) { base.transitiontypes(base.options.transitionstyle); } if (base.options.autoplay === true) { base.options.autoplay = 5000; } base.play(); base.$elem.find(".owl-wrapper").css("display", "block"); if (!base.$elem.is(":visible")) { base.watchvisibility(); } else { base.$elem.css("opacity", 1); } base.onstartup = false; base.eachmoveupdate(); if (typeof base.options.afterinit === "function") { base.options.afterinit.apply(this, [base.$elem]); } }, eachmoveupdate : function () { var base = this; if (base.options.lazyload === true) { base.lazyload(); } if (base.options.autoheight === true) { base.autoheight(); } base.onvisibleitems(); if (typeof base.options.afteraction === "function") { base.options.afteraction.apply(this, [base.$elem]); } }, updatevars : function () { var base = this; if (typeof base.options.beforeupdate === "function") { base.options.beforeupdate.apply(this, [base.$elem]); } base.watchvisibility(); base.updateitems(); base.calculateall(); base.updateposition(); base.updatecontrols(); base.eachmoveupdate(); if (typeof base.options.afterupdate === "function") { base.options.afterupdate.apply(this, [base.$elem]); } }, reload : function () { var base = this; window.settimeout(function () { base.updatevars(); }, 0); }, watchvisibility : function () { var base = this; if (base.$elem.is(":visible") === false) { base.$elem.css({opacity: 0}); window.clearinterval(base.autoplayinterval); window.clearinterval(base.checkvisible); } else { return false; } base.checkvisible = window.setinterval(function () { if (base.$elem.is(":visible")) { base.reload(); base.$elem.animate({opacity: 1}, 200); window.clearinterval(base.checkvisible); } }, 500); }, wrapitems : function () { var base = this; base.$useritems.wrapall("
").wrap("
"); base.$elem.find(".owl-wrapper").wrap("
"); base.wrapperouter = base.$elem.find(".owl-wrapper-outer"); base.$elem.css("display", "block"); }, baseclass : function () { var base = this, hasbaseclass = base.$elem.hasclass(base.options.baseclass), hasthemeclass = base.$elem.hasclass(base.options.theme); if (!hasbaseclass) { base.$elem.addclass(base.options.baseclass); } if (!hasthemeclass) { base.$elem.addclass(base.options.theme); } }, updateitems : function () { var base = this, width, i; if (base.options.responsive === false) { return false; } if (base.options.singleitem === true) { base.options.items = base.orignalitems = 1; base.options.itemscustom = false; base.options.itemsdesktop = false; base.options.itemsdesktopsmall = false; base.options.itemstablet = false; base.options.itemstabletsmall = false; base.options.itemsmobile = false; return false; } width = $(base.options.responsivebasewidth).width(); if (width > (base.options.itemsdesktop[0] || base.orignalitems)) { base.options.items = base.orignalitems; } if (base.options.itemscustom !== false) { //reorder array by screen size base.options.itemscustom.sort(function (a, b) {return a[0] - b[0]; }); for (i = 0; i < base.options.itemscustom.length; i += 1) { if (base.options.itemscustom[i][0] <= width) { base.options.items = base.options.itemscustom[i][1]; } } } else { if (width <= base.options.itemsdesktop[0] && base.options.itemsdesktop !== false) { base.options.items = base.options.itemsdesktop[1]; } if (width <= base.options.itemsdesktopsmall[0] && base.options.itemsdesktopsmall !== false) { base.options.items = base.options.itemsdesktopsmall[1]; } if (width <= base.options.itemstablet[0] && base.options.itemstablet !== false) { base.options.items = base.options.itemstablet[1]; } if (width <= base.options.itemstabletsmall[0] && base.options.itemstabletsmall !== false) { base.options.items = base.options.itemstabletsmall[1]; } if (width <= base.options.itemsmobile[0] && base.options.itemsmobile !== false) { base.options.items = base.options.itemsmobile[1]; } } //if number of items is less than declared if (base.options.items > base.itemsamount && base.options.itemsscaleup === true) { base.options.items = base.itemsamount; } }, response : function () { var base = this, smalldelay, lastwindowwidth; if (base.options.responsive !== true) { return false; } lastwindowwidth = $(window).width(); base.resizer = function () { if ($(window).width() !== lastwindowwidth) { if (base.options.autoplay !== false) { window.clearinterval(base.autoplayinterval); } window.cleartimeout(smalldelay); smalldelay = window.settimeout(function () { lastwindowwidth = $(window).width(); base.updatevars(); }, base.options.responsiverefreshrate); } }; $(window).resize(base.resizer); }, updateposition : function () { var base = this; base.jumpto(base.currentitem); if (base.options.autoplay !== false) { base.checkap(); } }, appenditemssizes : function () { var base = this, roundpages = 0, lastitem = base.itemsamount - base.options.items; base.$owlitems.each(function (index) { var $this = $(this); $this .css({"width": base.itemwidth}) .data("owl-item", number(index)); if (index % base.options.items === 0 || index === lastitem) { if (!(index > lastitem)) { roundpages += 1; } } $this.data("owl-roundpages", roundpages); }); }, appendwrappersizes : function () { var base = this, width = base.$owlitems.length * base.itemwidth; base.$owlwrapper.css({ "width": width * 2, "left": 0 }); base.appenditemssizes(); }, calculateall : function () { var base = this; base.calculatewidth(); base.appendwrappersizes(); base.loops(); base.max(); }, calculatewidth : function () { var base = this; base.itemwidth = math.round(base.$elem.width() / base.options.items); }, max : function () { var base = this, maximum = ((base.itemsamount * base.itemwidth) - base.options.items * base.itemwidth) * -1; if (base.options.items > base.itemsamount) { base.maximumitem = 0; maximum = 0; base.maximumpixels = 0; } else { base.maximumitem = base.itemsamount - base.options.items; base.maximumpixels = maximum; } return maximum; }, min : function () { return 0; }, loops : function () { var base = this, prev = 0, elwidth = 0, i, item, roundpagenum; base.positionsinarray = [0]; base.pagesinarray = []; for (i = 0; i < base.itemsamount; i += 1) { elwidth += base.itemwidth; base.positionsinarray.push(-elwidth); if (base.options.scrollperpage === true) { item = $(base.$owlitems[i]); roundpagenum = item.data("owl-roundpages"); if (roundpagenum !== prev) { base.pagesinarray[prev] = base.positionsinarray[i]; prev = roundpagenum; } } } }, buildcontrols : function () { var base = this; if (base.options.navigation === true || base.options.pagination === true) { base.owlcontrols = $("
").toggleclass("clickable", !base.browser.istouch).appendto(base.$elem); } if (base.options.pagination === true) { base.buildpagination(); } if (base.options.navigation === true) { base.buildbuttons(); } }, buildbuttons : function () { var base = this, buttonswrapper = $("
"); base.owlcontrols.append(buttonswrapper); base.buttonprev = $("
", { "class" : "owl-prev", "html" : base.options.navigationtext[0] || "" }); base.buttonnext = $("
", { "class" : "owl-next", "html" : base.options.navigationtext[1] || "" }); buttonswrapper .append(base.buttonprev) .append(base.buttonnext); buttonswrapper.on("touchstart.owlcontrols mousedown.owlcontrols", "div[class^=\"owl\"]", function (event) { event.preventdefault(); }); buttonswrapper.on("touchend.owlcontrols mouseup.owlcontrols", "div[class^=\"owl\"]", function (event) { event.preventdefault(); if ($(this).hasclass("owl-next")) { base.next(); } else { base.prev(); } }); }, buildpagination : function () { var base = this; base.paginationwrapper = $("
"); base.owlcontrols.append(base.paginationwrapper); base.paginationwrapper.on("touchend.owlcontrols mouseup.owlcontrols", ".owl-page", function (event) { event.preventdefault(); if (number($(this).data("owl-page")) !== base.currentitem) { base.goto(number($(this).data("owl-page")), true); } }); }, updatepagination : function () { var base = this, counter, lastpage, lastitem, i, paginationbutton, paginationbuttoninner; if (base.options.pagination === false) { return false; } base.paginationwrapper.html(""); counter = 0; lastpage = base.itemsamount - base.itemsamount % base.options.items; for (i = 0; i < base.itemsamount; i += 1) { if (i % base.options.items === 0) { counter += 1; if (lastpage === i) { lastitem = base.itemsamount - base.options.items; } paginationbutton = $("
", { "class" : "owl-page" }); paginationbuttoninner = $("", { "text": base.options.paginationnumbers === true ? counter : "", "class": base.options.paginationnumbers === true ? "owl-numbers" : "" }); paginationbutton.append(paginationbuttoninner); paginationbutton.data("owl-page", lastpage === i ? lastitem : i); paginationbutton.data("owl-roundpages", counter); base.paginationwrapper.append(paginationbutton); } } base.checkpagination(); }, checkpagination : function () { var base = this; if (base.options.pagination === false) { return false; } base.paginationwrapper.find(".owl-page").each(function () { if ($(this).data("owl-roundpages") === $(base.$owlitems[base.currentitem]).data("owl-roundpages")) { base.paginationwrapper .find(".owl-page") .removeclass("active"); $(this).addclass("active"); } }); }, checknavigation : function () { var base = this; if (base.options.navigation === false) { return false; } if (base.options.rewindnav === false) { if (base.currentitem === 0 && base.maximumitem === 0) { base.buttonprev.addclass("disabled"); base.buttonnext.addclass("disabled"); } else if (base.currentitem === 0 && base.maximumitem !== 0) { base.buttonprev.addclass("disabled"); base.buttonnext.removeclass("disabled"); } else if (base.currentitem === base.maximumitem) { base.buttonprev.removeclass("disabled"); base.buttonnext.addclass("disabled"); } else if (base.currentitem !== 0 && base.currentitem !== base.maximumitem) { base.buttonprev.removeclass("disabled"); base.buttonnext.removeclass("disabled"); } } }, updatecontrols : function () { var base = this; base.updatepagination(); base.checknavigation(); if (base.owlcontrols) { if (base.options.items >= base.itemsamount) { base.owlcontrols.hide(); } else { base.owlcontrols.show(); } } }, destroycontrols : function () { var base = this; if (base.owlcontrols) { base.owlcontrols.remove(); } }, next : function (speed) { var base = this; if (base.istransition) { return false; } base.currentitem += base.options.scrollperpage === true ? base.options.items : 1; if (base.currentitem > base.maximumitem + (base.options.scrollperpage === true ? (base.options.items - 1) : 0)) { if (base.options.rewindnav === true) { base.currentitem = 0; speed = "rewind"; } else { base.currentitem = base.maximumitem; return false; } } base.goto(base.currentitem, speed); }, prev : function (speed) { var base = this; if (base.istransition) { return false; } if (base.options.scrollperpage === true && base.currentitem > 0 && base.currentitem < base.options.items) { base.currentitem = 0; } else { base.currentitem -= base.options.scrollperpage === true ? base.options.items : 1; } if (base.currentitem < 0) { if (base.options.rewindnav === true) { base.currentitem = base.maximumitem; speed = "rewind"; } else { base.currentitem = 0; return false; } } base.goto(base.currentitem, speed); }, goto : function (position, speed, drag) { var base = this, gotopixel; if (base.istransition) { return false; } if (typeof base.options.beforemove === "function") { base.options.beforemove.apply(this, [base.$elem]); } if (position >= base.maximumitem) { position = base.maximumitem; } else if (position <= 0) { position = 0; } base.currentitem = base.owl.currentitem = position; if (base.options.transitionstyle !== false && drag !== "drag" && base.options.items === 1 && base.browser.support3d === true) { base.swapspeed(0); if (base.browser.support3d === true) { base.transition3d(base.positionsinarray[position]); } else { base.css2slide(base.positionsinarray[position], 1); } base.aftergo(); base.singleitemtransition(); return false; } gotopixel = base.positionsinarray[position]; if (base.browser.support3d === true) { base.iscss3finish = false; if (speed === true) { base.swapspeed("paginationspeed"); window.settimeout(function () { base.iscss3finish = true; }, base.options.paginationspeed); } else if (speed === "rewind") { base.swapspeed(base.options.rewindspeed); window.settimeout(function () { base.iscss3finish = true; }, base.options.rewindspeed); } else { base.swapspeed("slidespeed"); window.settimeout(function () { base.iscss3finish = true; }, base.options.slidespeed); } base.transition3d(gotopixel); } else { if (speed === true) { base.css2slide(gotopixel, base.options.paginationspeed); } else if (speed === "rewind") { base.css2slide(gotopixel, base.options.rewindspeed); } else { base.css2slide(gotopixel, base.options.slidespeed); } } base.aftergo(); }, jumpto : function (position) { var base = this; if (typeof base.options.beforemove === "function") { base.options.beforemove.apply(this, [base.$elem]); } if (position >= base.maximumitem || position === -1) { position = base.maximumitem; } else if (position <= 0) { position = 0; } base.swapspeed(0); if (base.browser.support3d === true) { base.transition3d(base.positionsinarray[position]); } else { base.css2slide(base.positionsinarray[position], 1); } base.currentitem = base.owl.currentitem = position; base.aftergo(); }, aftergo : function () { var base = this; base.prevarr.push(base.currentitem); base.previtem = base.owl.previtem = base.prevarr[base.prevarr.length - 2]; base.prevarr.shift(0); if (base.previtem !== base.currentitem) { base.checkpagination(); base.checknavigation(); base.eachmoveupdate(); if (base.options.autoplay !== false) { base.checkap(); } } if (typeof base.options.aftermove === "function" && base.previtem !== base.currentitem) { base.options.aftermove.apply(this, [base.$elem]); } }, stop : function () { var base = this; base.apstatus = "stop"; window.clearinterval(base.autoplayinterval); }, checkap : function () { var base = this; if (base.apstatus !== "stop") { base.play(); } }, play : function () { var base = this; base.apstatus = "play"; if (base.options.autoplay === false) { return false; } window.clearinterval(base.autoplayinterval); base.autoplayinterval = window.setinterval(function () { base.next(true); }, base.options.autoplay); }, swapspeed : function (action) { var base = this; if (action === "slidespeed") { base.$owlwrapper.css(base.addcssspeed(base.options.slidespeed)); } else if (action === "paginationspeed") { base.$owlwrapper.css(base.addcssspeed(base.options.paginationspeed)); } else if (typeof action !== "string") { base.$owlwrapper.css(base.addcssspeed(action)); } }, addcssspeed : function (speed) { return { "-webkit-transition": "all " + speed + "ms ease", "-moz-transition": "all " + speed + "ms ease", "-o-transition": "all " + speed + "ms ease", "transition": "all " + speed + "ms ease" }; }, removetransition : function () { return { "-webkit-transition": "", "-moz-transition": "", "-o-transition": "", "transition": "" }; }, dotranslate : function (pixels) { return { "-webkit-transform": "translate3d(" + pixels + "px, 0px, 0px)", "-moz-transform": "translate3d(" + pixels + "px, 0px, 0px)", "-o-transform": "translate3d(" + pixels + "px, 0px, 0px)", "-ms-transform": "translate3d(" + pixels + "px, 0px, 0px)", "transform": "translate3d(" + pixels + "px, 0px,0px)" }; }, transition3d : function (value) { var base = this; base.$owlwrapper.css(base.dotranslate(value)); }, css2move : function (value) { var base = this; base.$owlwrapper.css({"left" : value}); }, css2slide : function (value, speed) { var base = this; base.iscssfinish = false; base.$owlwrapper.stop(true, true).animate({ "left" : value }, { duration : speed || base.options.slidespeed, complete : function () { base.iscssfinish = true; } }); }, checkbrowser : function () { var base = this, translate3d = "translate3d(0px, 0px, 0px)", tempelem = document.createelement("div"), regex, assupport, support3d, istouch; tempelem.style.csstext = " -moz-transform:" + translate3d + "; -ms-transform:" + translate3d + "; -o-transform:" + translate3d + "; -webkit-transform:" + translate3d + "; transform:" + translate3d; regex = /translate3d\(0px, 0px, 0px\)/g; assupport = tempelem.style.csstext.match(regex); support3d = (assupport !== null && assupport.length === 1); istouch = "ontouchstart" in window || window.navigator.msmaxtouchpoints; base.browser = { "support3d" : support3d, "istouch" : istouch }; }, moveevents : function () { var base = this; if (base.options.mousedrag !== false || base.options.touchdrag !== false) { base.gestures(); base.disabledevents(); } }, eventtypes : function () { var base = this, types = ["s", "e", "x"]; base.ev_types = {}; if (base.options.mousedrag === true && base.options.touchdrag === true) { types = [ "touchstart.owl mousedown.owl", "touchmove.owl mousemove.owl", "touchend.owl touchcancel.owl mouseup.owl" ]; } else if (base.options.mousedrag === false && base.options.touchdrag === true) { types = [ "touchstart.owl", "touchmove.owl", "touchend.owl touchcancel.owl" ]; } else if (base.options.mousedrag === true && base.options.touchdrag === false) { types = [ "mousedown.owl", "mousemove.owl", "mouseup.owl" ]; } base.ev_types.start = types[0]; base.ev_types.move = types[1]; base.ev_types.end = types[2]; }, disabledevents : function () { var base = this; base.$elem.on("dragstart.owl", function (event) { event.preventdefault(); }); base.$elem.on("mousedown.disabletextselect", function (e) { return $(e.target).is('input, textarea, select, option'); }); }, gestures : function () { /*jslint unparam: true*/ var base = this, locals = { offsetx : 0, offsety : 0, baseelwidth : 0, relativepos : 0, position: null, minswipe : null, maxswipe: null, sliding : null, dargging: null, targetelement : null }; base.iscssfinish = true; function gettouches(event) { if (event.touches !== undefined) { return { x : event.touches[0].pagex, y : event.touches[0].pagey }; } if (event.touches === undefined) { if (event.pagex !== undefined) { return { x : event.pagex, y : event.pagey }; } if (event.pagex === undefined) { return { x : event.clientx, y : event.clienty }; } } } function swapevents(type) { if (type === "on") { $(document).on(base.ev_types.move, dragmove); $(document).on(base.ev_types.end, dragend); } else if (type === "off") { $(document).off(base.ev_types.move); $(document).off(base.ev_types.end); } } function dragstart(event) { var ev = event.originalevent || event || window.event, position; if (ev.which === 3) { return false; } if (base.itemsamount <= base.options.items) { return; } if (base.iscssfinish === false && !base.options.dragbeforeanimfinish) { return false; } if (base.iscss3finish === false && !base.options.dragbeforeanimfinish) { return false; } if (base.options.autoplay !== false) { window.clearinterval(base.autoplayinterval); } if (base.browser.istouch !== true && !base.$owlwrapper.hasclass("grabbing")) { base.$owlwrapper.addclass("grabbing"); } base.newposx = 0; base.newrelativex = 0; $(this).css(base.removetransition()); position = $(this).position(); locals.relativepos = position.left; locals.offsetx = gettouches(ev).x - position.left; locals.offsety = gettouches(ev).y - position.top; swapevents("on"); locals.sliding = false; locals.targetelement = ev.target || ev.srcelement; } function dragmove(event) { var ev = event.originalevent || event || window.event, minswipe, maxswipe; base.newposx = gettouches(ev).x - locals.offsetx; base.newposy = gettouches(ev).y - locals.offsety; base.newrelativex = base.newposx - locals.relativepos; if (typeof base.options.startdragging === "function" && locals.dragging !== true && base.newrelativex !== 0) { locals.dragging = true; base.options.startdragging.apply(base, [base.$elem]); } if ((base.newrelativex > 8 || base.newrelativex < -8) && (base.browser.istouch === true)) { if (ev.preventdefault !== undefined) { ev.preventdefault(); } else { ev.returnvalue = false; } locals.sliding = true; } if ((base.newposy > 10 || base.newposy < -10) && locals.sliding === false) { $(document).off("touchmove.owl"); } minswipe = function () { return base.newrelativex / 5; }; maxswipe = function () { return base.maximumpixels + base.newrelativex / 5; }; base.newposx = math.max(math.min(base.newposx, minswipe()), maxswipe()); if (base.browser.support3d === true) { base.transition3d(base.newposx); } else { base.css2move(base.newposx); } } function dragend(event) { var ev = event.originalevent || event || window.event, newposition, handlers, owlstopevent; ev.target = ev.target || ev.srcelement; locals.dragging = false; if (base.browser.istouch !== true) { base.$owlwrapper.removeclass("grabbing"); } if (base.newrelativex < 0) { base.dragdirection = base.owl.dragdirection = "left"; } else { base.dragdirection = base.owl.dragdirection = "right"; } if (base.newrelativex !== 0) { newposition = base.getnewposition(); base.goto(newposition, false, "drag"); if (locals.targetelement === ev.target && base.browser.istouch !== true) { $(ev.target).on("click.disable", function (ev) { ev.stopimmediatepropagation(); ev.stoppropagation(); ev.preventdefault(); $(ev.target).off("click.disable"); }); handlers = $._data(ev.target, "events").click; owlstopevent = handlers.pop(); handlers.splice(0, 0, owlstopevent); } } swapevents("off"); } base.$elem.on(base.ev_types.start, ".owl-wrapper", dragstart); }, getnewposition : function () { var base = this, newposition = base.closestitem(); if (newposition > base.maximumitem) { base.currentitem = base.maximumitem; newposition = base.maximumitem; } else if (base.newposx >= 0) { newposition = 0; base.currentitem = 0; } return newposition; }, closestitem : function () { var base = this, array = base.options.scrollperpage === true ? base.pagesinarray : base.positionsinarray, goal = base.newposx, closest = null; $.each(array, function (i, v) { if (goal - (base.itemwidth / 20) > array[i + 1] && goal - (base.itemwidth / 20) < v && base.movedirection() === "left") { closest = v; if (base.options.scrollperpage === true) { base.currentitem = $.inarray(closest, base.positionsinarray); } else { base.currentitem = i; } } else if (goal + (base.itemwidth / 20) < v && goal + (base.itemwidth / 20) > (array[i + 1] || array[i] - base.itemwidth) && base.movedirection() === "right") { if (base.options.scrollperpage === true) { closest = array[i + 1] || array[array.length - 1]; base.currentitem = $.inarray(closest, base.positionsinarray); } else { closest = array[i + 1]; base.currentitem = i + 1; } } }); return base.currentitem; }, movedirection : function () { var base = this, direction; if (base.newrelativex < 0) { direction = "right"; base.playdirection = "next"; } else { direction = "left"; base.playdirection = "prev"; } return direction; }, customevents : function () { /*jslint unparam: true*/ var base = this; base.$elem.on("owl.next", function () { base.next(); }); base.$elem.on("owl.prev", function () { base.prev(); }); base.$elem.on("owl.play", function (event, speed) { base.options.autoplay = speed; base.play(); base.hoverstatus = "play"; }); base.$elem.on("owl.stop", function () { base.stop(); base.hoverstatus = "stop"; }); base.$elem.on("owl.goto", function (event, item) { base.goto(item); }); base.$elem.on("owl.jumpto", function (event, item) { base.jumpto(item); }); }, stoponhover : function () { var base = this; if (base.options.stoponhover === true && base.browser.istouch !== true && base.options.autoplay !== false) { base.$elem.on("mouseover", function () { base.stop(); }); base.$elem.on("mouseout", function () { if (base.hoverstatus !== "stop") { base.play(); } }); } }, lazyload : function () { var base = this, i, $item, itemnumber, $lazyimg, follow; if (base.options.lazyload === false) { return false; } for (i = 0; i < base.itemsamount; i += 1) { $item = $(base.$owlitems[i]); if ($item.data("owl-loaded") === "loaded") { continue; } itemnumber = $item.data("owl-item"); $lazyimg = $item.find(".lazyowl"); if (typeof $lazyimg.data("src") !== "string") { $item.data("owl-loaded", "loaded"); continue; } if ($item.data("owl-loaded") === undefined) { $lazyimg.hide(); $item.addclass("loading").data("owl-loaded", "checked"); } if (base.options.lazyfollow === true) { follow = itemnumber >= base.currentitem; } else { follow = true; } if (follow && itemnumber < base.currentitem + base.options.items && $lazyimg.length) { base.lazypreload($item, $lazyimg); } } }, lazypreload : function ($item, $lazyimg) { var base = this, iterations = 0, isbackgroundimg; if ($lazyimg.prop("tagname") === "div") { $lazyimg.css("background-image", "url(" + $lazyimg.data("src") + ")"); isbackgroundimg = true; } else { $lazyimg[0].src = $lazyimg.data("src"); } function showimage() { $item.data("owl-loaded", "loaded").removeclass("loading"); $lazyimg.removeattr("data-src"); if (base.options.lazyeffect === "fade") { $lazyimg.fadein(400); } else { $lazyimg.show(); } if (typeof base.options.afterlazyload === "function") { base.options.afterlazyload.apply(this, [base.$elem]); } } function checklazyimage() { iterations += 1; if (base.completeimg($lazyimg.get(0)) || isbackgroundimg === true) { showimage(); } else if (iterations <= 100) {//if image loads in less than 10 seconds window.settimeout(checklazyimage, 100); } else { showimage(); } } checklazyimage(); }, autoheight : function () { var base = this, $currentimg = $(base.$owlitems[base.currentitem]).find("img"), iterations; function addheight() { var $currentitem = $(base.$owlitems[base.currentitem]).height(); base.wrapperouter.css("height", $currentitem + "px"); if (!base.wrapperouter.hasclass("autoheight")) { window.settimeout(function () { base.wrapperouter.addclass("autoheight"); }, 0); } } function checkimage() { iterations += 1; if (base.completeimg($currentimg.get(0))) { addheight(); } else if (iterations <= 100) { //if image loads in less than 10 seconds window.settimeout(checkimage, 100); } else { base.wrapperouter.css("height", ""); //else remove height attribute } } if ($currentimg.get(0) !== undefined) { iterations = 0; checkimage(); } else { addheight(); } }, completeimg : function (img) { var naturalwidthtype; if (!img.complete) { return false; } naturalwidthtype = typeof img.naturalwidth; if (naturalwidthtype !== "undefined" && img.naturalwidth === 0) { return false; } return true; }, onvisibleitems : function () { var base = this, i; if (base.options.addclassactive === true) { base.$owlitems.removeclass("active"); } base.visibleitems = []; for (i = base.currentitem; i < base.currentitem + base.options.items; i += 1) { base.visibleitems.push(i); if (base.options.addclassactive === true) { $(base.$owlitems[i]).addclass("active"); } } base.owl.visibleitems = base.visibleitems; }, transitiontypes : function (classname) { var base = this; //currently available: "fade", "backslide", "godown", "fadeup" base.outclass = "owl-" + classname + "-out"; base.inclass = "owl-" + classname + "-in"; }, singleitemtransition : function () { var base = this, outclass = base.outclass, inclass = base.inclass, $currentitem = base.$owlitems.eq(base.currentitem), $previtem = base.$owlitems.eq(base.previtem), prevpos = math.abs(base.positionsinarray[base.currentitem]) + base.positionsinarray[base.previtem], origin = math.abs(base.positionsinarray[base.currentitem]) + base.itemwidth / 2, animend = 'webkitanimationend oanimationend msanimationend animationend'; base.istransition = true; base.$owlwrapper .addclass('owl-origin') .css({ "-webkit-transform-origin" : origin + "px", "-moz-perspective-origin" : origin + "px", "perspective-origin" : origin + "px" }); function transstyles(prevpos) { return { "position" : "relative", "left" : prevpos + "px" }; } $previtem .css(transstyles(prevpos, 10)) .addclass(outclass) .on(animend, function () { base.endprev = true; $previtem.off(animend); base.cleartransstyle($previtem, outclass); }); $currentitem .addclass(inclass) .on(animend, function () { base.endcurrent = true; $currentitem.off(animend); base.cleartransstyle($currentitem, inclass); }); }, cleartransstyle : function (item, classtoremove) { var base = this; item.css({ "position" : "", "left" : "" }).removeclass(classtoremove); if (base.endprev && base.endcurrent) { base.$owlwrapper.removeclass('owl-origin'); base.endprev = false; base.endcurrent = false; base.istransition = false; } }, owlstatus : function () { var base = this; base.owl = { "useroptions" : base.useroptions, "baseelement" : base.$elem, "useritems" : base.$useritems, "owlitems" : base.$owlitems, "currentitem" : base.currentitem, "previtem" : base.previtem, "visibleitems" : base.visibleitems, "istouch" : base.browser.istouch, "browser" : base.browser, "dragdirection" : base.dragdirection }; }, clearevents : function () { var base = this; base.$elem.off(".owl owl mousedown.disabletextselect"); $(document).off(".owl owl"); $(window).off("resize", base.resizer); }, unwrap : function () { var base = this; if (base.$elem.children().length !== 0) { base.$owlwrapper.unwrap(); base.$useritems.unwrap().unwrap(); if (base.owlcontrols) { base.owlcontrols.remove(); } } base.clearevents(); base.$elem .attr("style", base.$elem.data("owl-originalstyles") || "") .attr("class", base.$elem.data("owl-originalclasses")); }, destroy : function () { var base = this; base.stop(); window.clearinterval(base.checkvisible); base.unwrap(); base.$elem.removedata(); }, reinit : function (newoptions) { var base = this, options = $.extend({}, base.useroptions, newoptions); base.unwrap(); base.init(options, base.$elem); }, additem : function (htmlstring, targetposition) { var base = this, position; if (!htmlstring) {return false; } if (base.$elem.children().length === 0) { base.$elem.append(htmlstring); base.setvars(); return false; } base.unwrap(); if (targetposition === undefined || targetposition === -1) { position = -1; } else { position = targetposition; } if (position >= base.$useritems.length || position === -1) { base.$useritems.eq(-1).after(htmlstring); } else { base.$useritems.eq(position).before(htmlstring); } base.setvars(); }, removeitem : function (targetposition) { var base = this, position; if (base.$elem.children().length === 0) { return false; } if (targetposition === undefined || targetposition === -1) { position = -1; } else { position = targetposition; } base.unwrap(); base.$useritems.eq(position).remove(); base.setvars(); } }; $.fn.owlcarousel = function (options) { return this.each(function () { if ($(this).data("owl-init") === true) { return false; } $(this).data("owl-init", true); var carousel = object.create(carousel); carousel.init(options, this); $.data(this, "owlcarousel", carousel); }); }; $.fn.owlcarousel.options = { items : 5, itemscustom : false, itemsdesktop : [1199, 3], itemsdesktopsmall : [1024, 3], itemstablet : [860, 2], itemstabletsmall : false, itemsmobile : [480, 1], singleitem : false, itemsscaleup : false, slidespeed : 200, paginationspeed : 800, rewindspeed : 1000, autoplay : false, stoponhover : false, navigation : false, navigationtext : ["prev", "next"], rewindnav : true, scrollperpage : false, pagination : true, paginationnumbers : false, responsive : true, responsiverefreshrate : 200, responsivebasewidth : window, baseclass : "owl-carousel", theme : "owl-theme", lazyload : false, lazyfollow : true, lazyeffect : "fade", autoheight : false, jsonpath : false, jsonsuccess : false, dragbeforeanimfinish : true, mousedrag : true, touchdrag : true, addclassactive : false, transitionstyle : false, beforeupdate : false, afterupdate : false, beforeinit : false, afterinit : false, beforemove : false, aftermove : false, afteraction : false, startdragging : false, afterlazyload: false }; }(jquery, window, document)); /** * owl carousel * @version 2.0.0 * @author bartosz wojciechowski * @license the mit license (mit) * @todo lazy load icon * @todo prevent animationend bubling * @todo itemsscaleup * @todo test zepto * @todo stagepadding calculate wrong active classes */ ;(function($, window, document, undefined) { var drag, state, e; /** * template for status information about drag and touch events. * @private */ drag = { start: 0, startx: 0, starty: 0, current: 0, currentx: 0, currenty: 0, offsetx: 0, offsety: 0, distance: null, starttime: 0, endtime: 0, updatedx: 0, targetel: null }; /** * template for some status informations. * @private */ state = { istouch: false, isscrolling: false, isswiping: false, direction: false, inmotion: false }; /** * event functions references. * @private */ e = { _ondragstart: null, _ondragmove: null, _ondragend: null, _transitionend: null, _resizer: null, _responsivecall: null, _gotoloop: null, _checkvisibile: null }; /** * creates a carousel. * @class the owl carousel. * @public * @param {htmlelement|jquery} element - the element to create the carousel for. * @param {object} [options] - the options */ function owl(element, options) { /** * current settings for the carousel. * @public */ this.settings = null; /** * current options set by the caller including defaults. * @public */ this.options = $.extend({}, owl.defaults, options); /** * plugin element. * @public */ this.$element = $(element); /** * caches informations about drag and touch events. */ this.drag = $.extend({}, drag); /** * caches some status informations. * @protected */ this.state = $.extend({}, state); /** * @protected * @todo must be documented */ this.e = $.extend({}, e); /** * references to the running plugins of this carousel. * @protected */ this._plugins = {}; /** * currently suppressed events to prevent them from beeing retriggered. * @protected */ this._supress = {}; /** * absolute current position. * @protected */ this._current = null; /** * animation speed in milliseconds. * @protected */ this._speed = null; /** * coordinates of all items in pixel. * @todo the name of this member is missleading. * @protected */ this._coordinates = []; /** * current breakpoint. * @todo real media queries would be nice. * @protected */ this._breakpoint = null; /** * current width of the plugin element. */ this._width = null; /** * all real items. * @protected */ this._items = []; /** * all cloned items. * @protected */ this._clones = []; /** * merge values of all items. * @todo maybe this could be part of a plugin. * @protected */ this._mergers = []; /** * invalidated parts within the update process. * @protected */ this._invalidated = {}; /** * ordered list of workers for the update process. * @protected */ this._pipe = []; $.each(owl.plugins, $.proxy(function(key, plugin) { this._plugins[key[0].tolowercase() + key.slice(1)] = new plugin(this); }, this)); $.each(owl.pipe, $.proxy(function(priority, worker) { this._pipe.push({ 'filter': worker.filter, 'run': $.proxy(worker.run, this) }); }, this)); this.setup(); this.initialize(); } /** * default options for the carousel. * @public */ owl.defaults = { items: 3, loop: false, center: false, mousedrag: true, touchdrag: true, pulldrag: true, freedrag: false, margin: 0, stagepadding: 0, merge: false, mergefit: true, autowidth: false, startposition: 0, rtl: false, smartspeed: 250, fluidspeed: false, dragendspeed: false, responsive: {}, responsiverefreshrate: 200, responsivebaseelement: window, responsiveclass: false, fallbackeasing: 'swing', info: false, nesteditemselector: false, itemelement: 'div', stageelement: 'div', // classes and names themeclass: 'owl-theme', baseclass: 'owl-carousel2', itemclass: 'owl-item', centerclass: 'center', activeclass: 'active' }; /** * enumeration for width. * @public * @readonly * @enum {string} */ owl.width = { default: 'default', inner: 'inner', outer: 'outer' }; /** * contains all registered plugins. * @public */ owl.plugins = {}; /** * update pipe. */ owl.pipe = [ { filter: [ 'width', 'items', 'settings' ], run: function(cache) { cache.current = this._items && this._items[this.relative(this._current)]; } }, { filter: [ 'items', 'settings' ], run: function() { var cached = this._clones, clones = this.$stage.children('.cloned'); if (clones.length !== cached.length || (!this.settings.loop && cached.length > 0)) { this.$stage.children('.cloned').remove(); this._clones = []; } } }, { filter: [ 'items', 'settings' ], run: function() { var i, n, clones = this._clones, items = this._items, delta = this.settings.loop ? clones.length - math.max(this.settings.items * 2, 4) : 0; for (i = 0, n = math.abs(delta / 2); i < n; i++) { if (delta > 0) { this.$stage.children().eq(items.length + clones.length - 1).remove(); clones.pop(); this.$stage.children().eq(0).remove(); clones.pop(); } else { clones.push(clones.length / 2); this.$stage.append(items[clones[clones.length - 1]].clone().addclass('cloned')); clones.push(items.length - 1 - (clones.length - 1) / 2); this.$stage.prepend(items[clones[clones.length - 1]].clone().addclass('cloned')); } } } }, { filter: [ 'width', 'items', 'settings' ], run: function() { var rtl = (this.settings.rtl ? 1 : -1), width = (this.width() / this.settings.items).tofixed(3), coordinate = 0, merge, i, n; this._coordinates = []; for (i = 0, n = this._clones.length + this._items.length; i < n; i++) { merge = this._mergers[this.relative(i)]; merge = (this.settings.mergefit && math.min(merge, this.settings.items)) || merge; coordinate += (this.settings.autowidth ? this._items[this.relative(i)].width() + this.settings.margin : width * merge) * rtl; this._coordinates.push(coordinate); } } }, { filter: [ 'width', 'items', 'settings' ], run: function() { var i, n, width = (this.width() / this.settings.items).tofixed(3), css = { 'width': math.abs(this._coordinates[this._coordinates.length - 1]) + this.settings.stagepadding * 2, 'padding-left': this.settings.stagepadding || '', 'padding-right': this.settings.stagepadding || '' }; this.$stage.css(css); css = { 'width': this.settings.autowidth ? 'auto' : width - this.settings.margin }; css[this.settings.rtl ? 'margin-left' : 'margin-right'] = this.settings.margin; if (!this.settings.autowidth && $.grep(this._mergers, function(v) { return v > 1 }).length > 0) { for (i = 0, n = this._coordinates.length; i < n; i++) { css.width = math.abs(this._coordinates[i]) - math.abs(this._coordinates[i - 1] || 0) - this.settings.margin; this.$stage.children().eq(i).css(css); } } else { this.$stage.children().css(css); } } }, { filter: [ 'width', 'items', 'settings' ], run: function(cache) { cache.current && this.reset(this.$stage.children().index(cache.current)); } }, { filter: [ 'position' ], run: function() { this.animate(this.coordinates(this._current)); } }, { filter: [ 'width', 'position', 'items', 'settings' ], run: function() { var rtl = this.settings.rtl ? 1 : -1, padding = this.settings.stagepadding * 2, begin = this.coordinates(this.current()) + padding, end = begin + this.width() * rtl, inner, outer, matches = [], i, n; for (i = 0, n = this._coordinates.length; i < n; i++) { inner = this._coordinates[i - 1] || 0; outer = math.abs(this._coordinates[i]) + padding * rtl; if ((this.op(inner, '<=', begin) && (this.op(inner, '>', end))) || (this.op(outer, '<', begin) && this.op(outer, '>', end))) { matches.push(i); } } this.$stage.children('.' + this.settings.activeclass).removeclass(this.settings.activeclass); this.$stage.children(':eq(' + matches.join('), :eq(') + ')').addclass(this.settings.activeclass); if (this.settings.center) { this.$stage.children('.' + this.settings.centerclass).removeclass(this.settings.centerclass); this.$stage.children().eq(this.current()).addclass(this.settings.centerclass); } } } ]; /** * initializes the carousel. * @protected */ owl.prototype.initialize = function() { this.trigger('initialize'); this.$element .addclass(this.settings.baseclass) .addclass(this.settings.themeclass) .toggleclass('owl-rtl', this.settings.rtl); // check support this.browsersupport(); if (this.settings.autowidth && this.state.imagesloaded !== true) { var imgs, nestedselector, width; imgs = this.$element.find('img'); nestedselector = this.settings.nesteditemselector ? '.' + this.settings.nesteditemselector : undefined; width = this.$element.children(nestedselector).width(); if (imgs.length && width <= 0) { this.preloadautowidthimages(imgs); return false; } } this.$element.addclass('owl-loading'); // create stage this.$stage = $('<' + this.settings.stageelement + ' class="owl-stage"/>') .wrap('
'); // append stage this.$element.append(this.$stage.parent()); // append content this.replace(this.$element.children().not(this.$stage.parent())); // set view width this._width = this.$element.width(); // update view this.refresh(); this.$element.removeclass('owl-loading').addclass('owl-loaded'); // attach generic events this.eventscall(); // attach generic events this.internalevents(); // attach custom control events this.addtriggerableevents(); this.trigger('initialized'); }; /** * setups the current settings. * @todo remove responsive classes. why should adaptive designs be brought into ie8? * @todo support for media queries by using `matchmedia` would be nice. * @public */ owl.prototype.setup = function() { var viewport = this.viewport(), overwrites = this.options.responsive, match = -1, settings = null; if (!overwrites) { settings = $.extend({}, this.options); } else { $.each(overwrites, function(breakpoint) { if (breakpoint <= viewport && breakpoint > match) { match = number(breakpoint); } }); settings = $.extend({}, this.options, overwrites[match]); delete settings.responsive; // responsive class if (settings.responsiveclass) { this.$element.attr('class', function(i, c) { return c.replace(/\b owl-responsive-\s+/g, ''); }).addclass('owl-responsive-' + match); } } if (this.settings === null || this._breakpoint !== match) { this.trigger('change', { property: { name: 'settings', value: settings } }); this._breakpoint = match; this.settings = settings; this.invalidate('settings'); this.trigger('changed', { property: { name: 'settings', value: this.settings } }); } }; /** * updates option logic if necessery. * @protected */ owl.prototype.optionslogic = function() { // toggle center class this.$element.toggleclass('owl-center', this.settings.center); // if items number is less than in body if (this.settings.loop && this._items.length < this.settings.items) { this.settings.loop = false; } if (this.settings.autowidth) { this.settings.stagepadding = false; this.settings.merge = false; } }; /** * prepares an item before add. * @todo rename event parameter `content` to `item`. * @protected * @returns {jquery|htmlelement} - the item container. */ owl.prototype.prepare = function(item) { var event = this.trigger('prepare', { content: item }); if (!event.data) { event.data = $('<' + this.settings.itemelement + '/>') .addclass(this.settings.itemclass).append(item) } this.trigger('prepared', { content: event.data }); return event.data; }; /** * updates the view. * @public */ owl.prototype.update = function() { var i = 0, n = this._pipe.length, filter = $.proxy(function(p) { return this[p] }, this._invalidated), cache = {}; while (i < n) { if (this._invalidated.all || $.grep(this._pipe[i].filter, filter).length > 0) { this._pipe[i].run(cache); } i++; } this._invalidated = {}; }; /** * gets the width of the view. * @public * @param {owl.width} [dimension=owl.width.default] - the dimension to return. * @returns {number} - the width of the view in pixel. */ owl.prototype.width = function(dimension) { dimension = dimension || owl.width.default; switch (dimension) { case owl.width.inner: case owl.width.outer: return this._width; default: return this._width - this.settings.stagepadding * 2 + this.settings.margin; } }; /** * refreshes the carousel primarily for adaptive purposes. * @public */ owl.prototype.refresh = function() { if (this._items.length === 0) { return false; } var start = new date().gettime(); this.trigger('refresh'); this.setup(); this.optionslogic(); // hide and show methods helps here to set a proper widths, // this prevents scrollbar to be calculated in stage width this.$stage.addclass('owl-refresh'); this.update(); this.$stage.removeclass('owl-refresh'); this.state.orientation = window.orientation; this.watchvisibility(); this.trigger('refreshed'); }; /** * save internal event references and add event based functions. * @protected */ owl.prototype.eventscall = function() { // save events references this.e._ondragstart = $.proxy(function(e) { this.ondragstart(e); }, this); this.e._ondragmove = $.proxy(function(e) { this.ondragmove(e); }, this); this.e._ondragend = $.proxy(function(e) { this.ondragend(e); }, this); this.e._onresize = $.proxy(function(e) { this.onresize(e); }, this); this.e._transitionend = $.proxy(function(e) { this.transitionend(e); }, this); this.e._preventclick = $.proxy(function(e) { this.preventclick(e); }, this); }; /** * checks window `resize` event. * @protected */ owl.prototype.onthrottledresize = function() { window.cleartimeout(this.resizetimer); this.resizetimer = window.settimeout(this.e._onresize, this.settings.responsiverefreshrate); }; /** * checks window `resize` event. * @protected */ owl.prototype.onresize = function() { if (!this._items.length) { return false; } if (this._width === this.$element.width()) { return false; } if (this.trigger('resize').isdefaultprevented()) { return false; } this._width = this.$element.width(); this.invalidate('width'); this.refresh(); this.trigger('resized'); }; /** * checks for touch/mouse drag event type and add run event handlers. * @protected */ owl.prototype.eventsrouter = function(event) { var type = event.type; if (type === "mousedown" || type === "touchstart") { this.ondragstart(event); } else if (type === "mousemove" || type === "touchmove") { this.ondragmove(event); } else if (type === "mouseup" || type === "touchend") { this.ondragend(event); } else if (type === "touchcancel") { this.ondragend(event); } }; /** * checks for touch/mouse drag options and add necessery event handlers. * @protected */ owl.prototype.internalevents = function() { var istouch = istouchsupport(), istouchie = istouchsupportie(); if (this.settings.mousedrag){ this.$stage.on('mousedown', $.proxy(function(event) { this.eventsrouter(event) }, this)); this.$stage.on('dragstart', function() { return false }); this.$stage.get(0).onselectstart = function() { return false }; } else { this.$element.addclass('owl-text-select-on'); } if (this.settings.touchdrag && !istouchie){ this.$stage.on('touchstart touchcancel', $.proxy(function(event) { this.eventsrouter(event) }, this)); } // catch transitionend event if (this.transitionendvendor) { this.on(this.$stage.get(0), this.transitionendvendor, this.e._transitionend, false); } // responsive if (this.settings.responsive !== false) { this.on(window, 'resize', $.proxy(this.onthrottledresize, this)); } }; /** * handles touchstart/mousedown event. * @protected * @param {event} event - the event arguments. */ owl.prototype.ondragstart = function(event) { var ev, istouchevent, pagex, pagey, animatedpos; ev = event.originalevent || event || window.event; // prevent right click if (ev.which === 3 || this.state.istouch) { return false; } if (ev.type === 'mousedown') { this.$stage.addclass('owl-grab'); } this.trigger('drag'); this.drag.starttime = new date().gettime(); this.speed(0); this.state.istouch = true; this.state.isscrolling = false; this.state.isswiping = false; this.drag.distance = 0; pagex = gettouches(ev).x; pagey = gettouches(ev).y; // get stage position left this.drag.offsetx = this.$stage.position().left; this.drag.offsety = this.$stage.position().top; if (this.settings.rtl) { this.drag.offsetx = this.$stage.position().left + this.$stage.width() - this.width() + this.settings.margin; } // catch position // ie to fix if (this.state.inmotion && this.support3d) { animatedpos = this.gettransformproperty(); this.drag.offsetx = animatedpos; this.animate(animatedpos); this.state.inmotion = true; } else if (this.state.inmotion && !this.support3d) { this.state.inmotion = false; return false; } this.drag.startx = pagex - this.drag.offsetx; this.drag.starty = pagey - this.drag.offsety; this.drag.start = pagex - this.drag.startx; this.drag.targetel = ev.target || ev.srcelement; this.drag.updatedx = this.drag.start; // to do/check // prevent links and images dragging; if (this.drag.targetel.tagname === "img" || this.drag.targetel.tagname === "a") { this.drag.targetel.draggable = false; } $(document).on('mousemove.owl.dragevents mouseup.owl.dragevents touchmove.owl.dragevents touchend.owl.dragevents', $.proxy(function(event) {this.eventsrouter(event)},this)); }; /** * handles the touchmove/mousemove events. * @todo simplify * @protected * @param {event} event - the event arguments. */ owl.prototype.ondragmove = function(event) { var ev, istouchevent, pagex, pagey, minvalue, maxvalue, pull; if (!this.state.istouch) { return; } if (this.state.isscrolling) { return; } ev = event.originalevent || event || window.event; pagex = gettouches(ev).x; pagey = gettouches(ev).y; // drag direction this.drag.currentx = pagex - this.drag.startx; this.drag.currenty = pagey - this.drag.starty; this.drag.distance = this.drag.currentx - this.drag.offsetx; // check move direction if (this.drag.distance < 0) { this.state.direction = this.settings.rtl ? 'right' : 'left'; } else if (this.drag.distance > 0) { this.state.direction = this.settings.rtl ? 'left' : 'right'; } // loop if (this.settings.loop) { if (this.op(this.drag.currentx, '>', this.coordinates(this.minimum())) && this.state.direction === 'right') { this.drag.currentx -= (this.settings.center && this.coordinates(0)) - this.coordinates(this._items.length); } else if (this.op(this.drag.currentx, '<', this.coordinates(this.maximum())) && this.state.direction === 'left') { this.drag.currentx += (this.settings.center && this.coordinates(0)) - this.coordinates(this._items.length); } } else { // pull minvalue = this.settings.rtl ? this.coordinates(this.maximum()) : this.coordinates(this.minimum()); maxvalue = this.settings.rtl ? this.coordinates(this.minimum()) : this.coordinates(this.maximum()); pull = this.settings.pulldrag ? this.drag.distance / 5 : 0; this.drag.currentx = math.max(math.min(this.drag.currentx, minvalue + pull), maxvalue + pull); } // lock browser if swiping horizontal if ((this.drag.distance > 8 || this.drag.distance < -8)) { if (ev.preventdefault !== undefined) { ev.preventdefault(); } else { ev.returnvalue = false; } this.state.isswiping = true; } this.drag.updatedx = this.drag.currentx; // lock owl if scrolling if ((this.drag.currenty > 16 || this.drag.currenty < -16) && this.state.isswiping === false) { this.state.isscrolling = true; this.drag.updatedx = this.drag.start; } this.animate(this.drag.updatedx); }; /** * handles the touchend/mouseup events. * @protected */ owl.prototype.ondragend = function(event) { var comparetimes, distanceabs, closest; if (!this.state.istouch) { return; } if (event.type === 'mouseup') { this.$stage.removeclass('owl-grab'); } this.trigger('dragged'); // prevent links and images dragging; this.drag.targetel.removeattribute("draggable"); // remove drag event listeners this.state.istouch = false; this.state.isscrolling = false; this.state.isswiping = false; // to check if (this.drag.distance === 0 && this.state.inmotion !== true) { this.state.inmotion = false; return false; } // prevent clicks while scrolling this.drag.endtime = new date().gettime(); comparetimes = this.drag.endtime - this.drag.starttime; distanceabs = math.abs(this.drag.distance); // to test if (distanceabs > 3 || comparetimes > 300) { this.removeclick(this.drag.targetel); } closest = this.closest(this.drag.updatedx); this.speed(this.settings.dragendspeed || this.settings.smartspeed); this.current(closest); this.invalidate('position'); this.update(); // if pulldrag is off then fire transitionend event manually when stick // to border if (!this.settings.pulldrag && this.drag.updatedx === this.coordinates(closest)) { this.transitionend(); } this.drag.distance = 0; $(document).off('.owl.dragevents'); }; /** * attaches `preventclick` to disable link while swipping. * @protected * @param {htmlelement} [target] - the target of the `click` event. */ owl.prototype.removeclick = function(target) { this.drag.targetel = target; $(target).on('click.preventclick', this.e._preventclick); // to make sure click is removed: window.settimeout(function() { $(target).off('click.preventclick'); }, 300); }; /** * suppresses click event. * @protected * @param {event} ev - the event arguments. */ owl.prototype.preventclick = function(ev) { if (ev.preventdefault) { ev.preventdefault(); } else { ev.returnvalue = false; } if (ev.stoppropagation) { ev.stoppropagation(); } $(ev.target).off('click.preventclick'); }; /** * catches stage position while animate (only css3). * @protected * @returns */ owl.prototype.gettransformproperty = function() { var transform, matrix3d; transform = window.getcomputedstyle(this.$stage.get(0), null).getpropertyvalue(this.vendorname + 'transform'); // var transform = this.$stage.css(this.vendorname + 'transform') transform = transform.replace(/matrix(3d)?\(|\)/g, '').split(','); matrix3d = transform.length === 16; return matrix3d !== true ? transform[4] : transform[12]; }; /** * gets absolute position of the closest item for a coordinate. * @todo setting `freedrag` makes `closest` not reusable. see #165. * @protected * @param {number} coordinate - the coordinate in pixel. * @return {number} - the absolute position of the closest item. */ owl.prototype.closest = function(coordinate) { var position = -1, pull = 30, width = this.width(), coordinates = this.coordinates(); if (!this.settings.freedrag) { // check closest item $.each(coordinates, $.proxy(function(index, value) { if (coordinate > value - pull && coordinate < value + pull) { position = index; } else if (this.op(coordinate, '<', value) && this.op(coordinate, '>', coordinates[index + 1] || value - width)) { position = this.state.direction === 'left' ? index + 1 : index; } return position === -1; }, this)); } if (!this.settings.loop) { // non loop boundries if (this.op(coordinate, '>', coordinates[this.minimum()])) { position = coordinate = this.minimum(); } else if (this.op(coordinate, '<', coordinates[this.maximum()])) { position = coordinate = this.maximum(); } } return position; }; /** * animates the stage. * @public * @param {number} coordinate - the coordinate in pixels. */ owl.prototype.animate = function(coordinate) { this.trigger('translate'); this.state.inmotion = this.speed() > 0; if (this.support3d) { this.$stage.css({ transform: 'translate3d(' + coordinate + 'px' + ',0px, 0px)', transition: (this.speed() / 1000) + 's' }); } else if (this.state.istouch) { this.$stage.css({ left: coordinate + 'px' }); } else { this.$stage.animate({ left: coordinate }, this.speed() / 1000, this.settings.fallbackeasing, $.proxy(function() { if (this.state.inmotion) { this.transitionend(); } }, this)); } }; /** * sets the absolute position of the current item. * @public * @param {number} [position] - the new absolute position or nothing to leave it unchanged. * @returns {number} - the absolute position of the current item. */ owl.prototype.current = function(position) { if (position === undefined) { return this._current; } if (this._items.length === 0) { return undefined; } position = this.normalize(position); if (this._current !== position) { var event = this.trigger('change', { property: { name: 'position', value: position } }); if (event.data !== undefined) { position = this.normalize(event.data); } this._current = position; this.invalidate('position'); this.trigger('changed', { property: { name: 'position', value: this._current } }); } return this._current; }; /** * invalidates the given part of the update routine. * @param {string} part - the part to invalidate. */ owl.prototype.invalidate = function(part) { this._invalidated[part] = true; } /** * resets the absolute position of the current item. * @public * @param {number} position - the absolute position of the new item. */ owl.prototype.reset = function(position) { position = this.normalize(position); if (position === undefined) { return; } this._speed = 0; this._current = position; this.suppress([ 'translate', 'translated' ]); this.animate(this.coordinates(position)); this.release([ 'translate', 'translated' ]); }; /** * normalizes an absolute or a relative position for an item. * @public * @param {number} position - the absolute or relative position to normalize. * @param {boolean} [relative=false] - whether the given position is relative or not. * @returns {number} - the normalized position. */ owl.prototype.normalize = function(position, relative) { var n = (relative ? this._items.length : this._items.length + this._clones.length); if (!$.isnumeric(position) || n < 1) { return undefined; } if (this._clones.length) { position = ((position % n) + n) % n; } else { position = math.max(this.minimum(relative), math.min(this.maximum(relative), position)); } return position; }; /** * converts an absolute position for an item into a relative position. * @public * @param {number} position - the absolute position to convert. * @returns {number} - the converted position. */ owl.prototype.relative = function(position) { position = this.normalize(position); position = position - this._clones.length / 2; return this.normalize(position, true); }; /** * gets the maximum position for an item. * @public * @param {boolean} [relative=false] - whether to return an absolute position or a relative position. * @returns {number} */ owl.prototype.maximum = function(relative) { var maximum, width, i = 0, coordinate, settings = this.settings; if (relative) { return this._items.length - 1; } if (!settings.loop && settings.center) { maximum = this._items.length - 1; } else if (!settings.loop && !settings.center) { maximum = this._items.length - settings.items; } else if (settings.loop || settings.center) { maximum = this._items.length + settings.items; } else if (settings.autowidth || settings.merge) { revert = settings.rtl ? 1 : -1; width = this.$stage.width() - this.$element.width(); while (coordinate = this.coordinates(i)) { if (coordinate * revert >= width) { break; } maximum = ++i; } } else { throw 'can not detect maximum absolute position.' } return maximum; }; /** * gets the minimum position for an item. * @public * @param {boolean} [relative=false] - whether to return an absolute position or a relative position. * @returns {number} */ owl.prototype.minimum = function(relative) { if (relative) { return 0; } return this._clones.length / 2; }; /** * gets an item at the specified relative position. * @public * @param {number} [position] - the relative position of the item. * @return {jquery|array.} - the item at the given position or all items if no position was given. */ owl.prototype.items = function(position) { if (position === undefined) { return this._items.slice(); } position = this.normalize(position, true); return this._items[position]; }; /** * gets an item at the specified relative position. * @public * @param {number} [position] - the relative position of the item. * @return {jquery|array.} - the item at the given position or all items if no position was given. */ owl.prototype.mergers = function(position) { if (position === undefined) { return this._mergers.slice(); } position = this.normalize(position, true); return this._mergers[position]; }; /** * gets the absolute positions of clones for an item. * @public * @param {number} [position] - the relative position of the item. * @returns {array.} - the absolute positions of clones for the item or all if no position was given. */ owl.prototype.clones = function(position) { var odd = this._clones.length / 2, even = odd + this._items.length, map = function(index) { return index % 2 === 0 ? even + index / 2 : odd - (index + 1) / 2 }; if (position === undefined) { return $.map(this._clones, function(v, i) { return map(i) }); } return $.map(this._clones, function(v, i) { return v === position ? map(i) : null }); }; /** * sets the current animation speed. * @public * @param {number} [speed] - the animation speed in milliseconds or nothing to leave it unchanged. * @returns {number} - the current animation speed in milliseconds. */ owl.prototype.speed = function(speed) { if (speed !== undefined) { this._speed = speed; } return this._speed; }; /** * gets the coordinate of an item. * @todo the name of this method is missleanding. * @public * @param {number} position - the absolute position of the item within `minimum()` and `maximum()`. * @returns {number|array.} - the coordinate of the item in pixel or all coordinates. */ owl.prototype.coordinates = function(position) { var coordinate = null; if (position === undefined) { return $.map(this._coordinates, $.proxy(function(coordinate, index) { return this.coordinates(index); }, this)); } if (this.settings.center) { coordinate = this._coordinates[position]; coordinate += (this.width() - coordinate + (this._coordinates[position - 1] || 0)) / 2 * (this.settings.rtl ? -1 : 1); } else { coordinate = this._coordinates[position - 1] || 0; } return coordinate; }; /** * calculates the speed for a translation. * @protected * @param {number} from - the absolute position of the start item. * @param {number} to - the absolute position of the target item. * @param {number} [factor=undefined] - the time factor in milliseconds. * @returns {number} - the time in milliseconds for the translation. */ owl.prototype.duration = function(from, to, factor) { return math.min(math.max(math.abs(to - from), 1), 6) * math.abs((factor || this.settings.smartspeed)); }; /** * slides to the specified item. * @public * @param {number} position - the position of the item. * @param {number} [speed] - the time in milliseconds for the transition. */ owl.prototype.to = function(position, speed) { if (this.settings.loop) { var distance = position - this.relative(this.current()), revert = this.current(), before = this.current(), after = this.current() + distance, direction = before - after < 0 ? true : false, items = this._clones.length + this._items.length; if (after < this.settings.items && direction === false) { revert = before + this._items.length; this.reset(revert); } else if (after >= items - this.settings.items && direction === true) { revert = before - this._items.length; this.reset(revert); } window.cleartimeout(this.e._gotoloop); this.e._gotoloop = window.settimeout($.proxy(function() { this.speed(this.duration(this.current(), revert + distance, speed)); this.current(revert + distance); this.update(); }, this), 30); } else { this.speed(this.duration(this.current(), position, speed)); this.current(position); this.update(); } }; /** * slides to the next item. * @public * @param {number} [speed] - the time in milliseconds for the transition. */ owl.prototype.next = function(speed) { speed = speed || false; this.to(this.relative(this.current()) + 1, speed); }; /** * slides to the previous item. * @public * @param {number} [speed] - the time in milliseconds for the transition. */ owl.prototype.prev = function(speed) { speed = speed || false; this.to(this.relative(this.current()) - 1, speed); }; /** * handles the end of an animation. * @protected * @param {event} event - the event arguments. */ owl.prototype.transitionend = function(event) { // if css2 animation then event object is undefined if (event !== undefined) { event.stoppropagation(); // catch only owl-stage transitionend event if ((event.target || event.srcelement || event.originaltarget) !== this.$stage.get(0)) { return false; } } this.state.inmotion = false; this.trigger('translated'); }; /** * gets viewport width. * @protected * @return {number} - the width in pixel. */ owl.prototype.viewport = function() { var width; if (this.options.responsivebaseelement !== window) { width = $(this.options.responsivebaseelement).width(); } else if (window.innerwidth) { width = window.innerwidth; } else if (document.documentelement && document.documentelement.clientwidth) { width = document.documentelement.clientwidth; } else { throw 'can not detect viewport width.'; } return width; }; /** * replaces the current content. * @public * @param {htmlelement|jquery|string} content - the new content. */ owl.prototype.replace = function(content) { this.$stage.empty(); this._items = []; if (content) { content = (content instanceof jquery) ? content : $(content); } if (this.settings.nesteditemselector) { content = content.find('.' + this.settings.nesteditemselector); } content.filter(function() { return this.nodetype === 1; }).each($.proxy(function(index, item) { item = this.prepare(item); this.$stage.append(item); this._items.push(item); this._mergers.push(item.find('[data-merge]').andself('[data-merge]').attr('data-merge') * 1 || 1); }, this)); this.reset($.isnumeric(this.settings.startposition) ? this.settings.startposition : 0); this.invalidate('items'); }; /** * adds an item. * @todo use `item` instead of `content` for the event arguments. * @public * @param {htmlelement|jquery|string} content - the item content to add. * @param {number} [position] - the relative position at which to insert the item otherwise the item will be added to the end. */ owl.prototype.add = function(content, position) { position = position === undefined ? this._items.length : this.normalize(position, true); this.trigger('add', { content: content, position: position }); if (this._items.length === 0 || position === this._items.length) { this.$stage.append(content); this._items.push(content); this._mergers.push(content.find('[data-merge]').andself('[data-merge]').attr('data-merge') * 1 || 1); } else { this._items[position].before(content); this._items.splice(position, 0, content); this._mergers.splice(position, 0, content.find('[data-merge]').andself('[data-merge]').attr('data-merge') * 1 || 1); } this.invalidate('items'); this.trigger('added', { content: content, position: position }); }; /** * removes an item by its position. * @todo use `item` instead of `content` for the event arguments. * @public * @param {number} position - the relative position of the item to remove. */ owl.prototype.remove = function(position) { position = this.normalize(position, true); if (position === undefined) { return; } this.trigger('remove', { content: this._items[position], position: position }); this._items[position].remove(); this._items.splice(position, 1); this._mergers.splice(position, 1); this.invalidate('items'); this.trigger('removed', { content: null, position: position }); }; /** * adds triggerable events. * @protected */ owl.prototype.addtriggerableevents = function() { var handler = $.proxy(function(callback, event) { return $.proxy(function(e) { if (e.relatedtarget !== this) { this.suppress([ event ]); callback.apply(this, [].slice.call(arguments, 1)); this.release([ event ]); } }, this); }, this); $.each({ 'next': this.next, 'prev': this.prev, 'to': this.to, 'destroy': this.destroy, 'refresh': this.refresh, 'replace': this.replace, 'add': this.add, 'remove': this.remove }, $.proxy(function(event, callback) { this.$element.on(event + '.owl.carousel', handler(callback, event + '.owl.carousel')); }, this)); }; /** * watches the visibility of the carousel element. * @protected */ owl.prototype.watchvisibility = function() { // test on zepto if (!iselvisible(this.$element.get(0))) { this.$element.addclass('owl-hidden'); window.clearinterval(this.e._checkvisibile); this.e._checkvisibile = window.setinterval($.proxy(checkvisible, this), 500); } function iselvisible(el) { return el.offsetwidth > 0 && el.offsetheight > 0; } function checkvisible() { if (iselvisible(this.$element.get(0))) { this.$element.removeclass('owl-hidden'); this.refresh(); window.clearinterval(this.e._checkvisibile); } } }; /** * preloads images with auto width. * @protected * @todo still to test */ owl.prototype.preloadautowidthimages = function(imgs) { var loaded, that, $el, img; loaded = 0; that = this; imgs.each(function(i, el) { $el = $(el); img = new image(); img.onload = function() { loaded++; $el.attr('src', img.src); $el.css('opacity', 1); if (loaded >= imgs.length) { that.state.imagesloaded = true; that.initialize(); } }; img.src = $el.attr('src') || $el.attr('data-src') || $el.attr('data-src-retina'); }); }; /** * destroys the carousel. * @public */ owl.prototype.destroy = function() { if (this.$element.hasclass(this.settings.themeclass)) { this.$element.removeclass(this.settings.themeclass); } if (this.settings.responsive !== false) { $(window).off('resize.owl.carousel'); } if (this.transitionendvendor) { this.off(this.$stage.get(0), this.transitionendvendor, this.e._transitionend); } for ( var i in this._plugins) { this._plugins[i].destroy(); } if (this.settings.mousedrag || this.settings.touchdrag) { this.$stage.off('mousedown touchstart touchcancel'); $(document).off('.owl.dragevents'); this.$stage.get(0).onselectstart = function() {}; this.$stage.off('dragstart', function() { return false }); } // remove event handlers in the ".owl.carousel" namespace this.$element.off('.owl'); this.$stage.children('.cloned').remove(); this.e = null; this.$element.removedata('owlcarousel2'); this.$stage.children().contents().unwrap(); this.$stage.children().unwrap(); this.$stage.unwrap(); }; /** * operators to calculate right-to-left and left-to-right. * @protected * @param {number} [a] - the left side operand. * @param {string} [o] - the operator. * @param {number} [b] - the right side operand. */ owl.prototype.op = function(a, o, b) { var rtl = this.settings.rtl; switch (o) { case '<': return rtl ? a > b : a < b; case '>': return rtl ? a < b : a > b; case '>=': return rtl ? a <= b : a >= b; case '<=': return rtl ? a >= b : a <= b; default: break; } }; /** * attaches to an internal event. * @protected * @param {htmlelement} element - the event source. * @param {string} event - the event name. * @param {function} listener - the event handler to attach. * @param {boolean} capture - wether the event should be handled at the capturing phase or not. */ owl.prototype.on = function(element, event, listener, capture) { if (element.addeventlistener) { element.addeventlistener(event, listener, capture); } else if (element.attachevent) { element.attachevent('on' + event, listener); } }; /** * detaches from an internal event. * @protected * @param {htmlelement} element - the event source. * @param {string} event - the event name. * @param {function} listener - the attached event handler to detach. * @param {boolean} capture - wether the attached event handler was registered as a capturing listener or not. */ owl.prototype.off = function(element, event, listener, capture) { if (element.removeeventlistener) { element.removeeventlistener(event, listener, capture); } else if (element.detachevent) { element.detachevent('on' + event, listener); } }; /** * triggers an public event. * @protected * @param {string} name - the event name. * @param {*} [data=null] - the event data. * @param {string} [namespace=.owl.carousel] - the event namespace. * @returns {event} - the event arguments. */ owl.prototype.trigger = function(name, data, namespace) { var status = { item: { count: this._items.length, index: this.current() } }, handler = $.camelcase( $.grep([ 'on', name, namespace ], function(v) { return v }) .join('-').tolowercase() ), event = $.event( [ name, 'owl', namespace || 'carousel' ].join('.').tolowercase(), $.extend({ relatedtarget: this }, status, data) ); if (!this._supress[name]) { $.each(this._plugins, function(name, plugin) { if (plugin.ontrigger) { plugin.ontrigger(event); } }); this.$element.trigger(event); if (this.settings && typeof this.settings[handler] === 'function') { this.settings[handler].apply(this, event); } } return event; }; /** * suppresses events. * @protected * @param {array.} events - the events to suppress. */ owl.prototype.suppress = function(events) { $.each(events, $.proxy(function(index, event) { this._supress[event] = true; }, this)); } /** * releases suppressed events. * @protected * @param {array.} events - the events to release. */ owl.prototype.release = function(events) { $.each(events, $.proxy(function(index, event) { delete this._supress[event]; }, this)); } /** * checks the availability of some browser features. * @protected */ owl.prototype.browsersupport = function() { this.support3d = isperspective(); if (this.support3d) { this.transformvendor = istransform(); // take transitionend event name by detecting transition var endvendors = [ 'transitionend', 'webkittransitionend', 'transitionend', 'otransitionend' ]; this.transitionendvendor = endvendors[istransition()]; // take vendor name from transform name this.vendorname = this.transformvendor.replace(/transform/i, ''); this.vendorname = this.vendorname !== '' ? '-' + this.vendorname.tolowercase() + '-' : ''; } this.state.orientation = window.orientation; }; /** * get touch/drag coordinats. * @private * @param {event} - mousedown/touchstart event * @returns {object} - contains x and y of current mouse/touch position */ function gettouches(event) { if (event.touches !== undefined) { return { x: event.touches[0].pagex, y: event.touches[0].pagey }; } if (event.touches === undefined) { if (event.pagex !== undefined) { return { x: event.pagex, y: event.pagey }; } if (event.pagex === undefined) { return { x: event.clientx, y: event.clienty }; } } } /** * checks for css support. * @private * @param {array} array - the css properties to check for. * @returns {array} - contains the supported css property name and its index or `false`. */ function isstylesupported(array) { var p, s, fake = document.createelement('div'), list = array; for (p in list) { s = list[p]; if (typeof fake.style[s] !== 'undefined') { fake = null; return [ s, p ]; } } return [ false ]; } /** * checks for css transition support. * @private * @todo realy bad design * @returns {number} */ function istransition() { return isstylesupported([ 'transition', 'webkittransition', 'moztransition', 'otransition' ])[1]; } /** * checks for css transform support. * @private * @returns {string} the supported property name or false. */ function istransform() { return isstylesupported([ 'transform', 'webkittransform', 'moztransform', 'otransform', 'mstransform' ])[0]; } /** * checks for css perspective support. * @private * @returns {string} the supported property name or false. */ function isperspective() { return isstylesupported([ 'perspective', 'webkitperspective', 'mozperspective', 'operspective', 'msperspective' ])[0]; } /** * checks wether touch is supported or not. * @private * @returns {boolean} */ function istouchsupport() { return 'ontouchstart' in window || !!(navigator.msmaxtouchpoints); } /** * checks wether touch is supported or not for ie. * @private * @returns {boolean} */ function istouchsupportie() { return window.navigator.mspointerenabled; } /** * the jquery plugin for the owl carousel * @public */ $.fn.owlcarousel2 = function(options) { return this.each(function() { if (!$(this).data('owlcarousel2')) { $(this).data('owlcarousel2', new owl(this, options)); } }); }; /** * the constructor for the jquery plugin * @public */ $.fn.owlcarousel2.constructor = owl; })(window.zepto || window.jquery, window, document); /** * lazy plugin * @version 2.0.0 * @author bartosz wojciechowski * @license the mit license (mit) */ ;(function($, window, document, undefined) { /** * creates the lazy plugin. * @class the lazy plugin * @param {owl} carousel - the owl carousel */ var lazy = function(carousel) { /** * reference to the core. * @protected * @type {owl} */ this._core = carousel; /** * already loaded items. * @protected * @type {array.} */ this._loaded = []; /** * event handlers. * @protected * @type {object} */ this._handlers = { 'initialized.owl.carousel change.owl.carousel': $.proxy(function(e) { if (!e.namespace) { return; } if (!this._core.settings || !this._core.settings.lazyload) { return; } if ((e.property && e.property.name == 'position') || e.type == 'initialized') { var settings = this._core.settings, n = (settings.center && math.ceil(settings.items / 2) || settings.items), i = ((settings.center && n * -1) || 0), position = ((e.property && e.property.value) || this._core.current()) + i, clones = this._core.clones().length, load = $.proxy(function(i, v) { this.load(v) }, this); while (i++ < n) { this.load(clones / 2 + this._core.relative(position)); clones && $.each(this._core.clones(this._core.relative(position++)), load); } } }, this) }; // set the default options this._core.options = $.extend({}, lazy.defaults, this._core.options); // register event handler this._core.$element.on(this._handlers); } /** * default options. * @public */ lazy.defaults = { lazyload: false } /** * loads all resources of an item at the specified position. * @param {number} position - the absolute position of the item. * @protected */ lazy.prototype.load = function(position) { var $item = this._core.$stage.children().eq(position), $elements = $item && $item.find('.owl-lazy'); if (!$elements || $.inarray($item.get(0), this._loaded) > -1) { return; } $elements.each($.proxy(function(index, element) { var $element = $(element), image, url = (window.devicepixelratio > 1 && $element.attr('data-src-retina')) || $element.attr('data-src'); this._core.trigger('load', { element: $element, url: url }, 'lazy'); if ($element.is('img')) { $element.one('load.owl.lazy', $.proxy(function() { $element.css('opacity', 1); this._core.trigger('loaded', { element: $element, url: url }, 'lazy'); }, this)).attr('src', url); } else { image = new image(); image.onload = $.proxy(function() { $element.css({ 'background-image': 'url(' + url + ')', 'opacity': '1' }); this._core.trigger('loaded', { element: $element, url: url }, 'lazy'); }, this); image.src = url; } }, this)); this._loaded.push($item.get(0)); } /** * destroys the plugin. * @public */ lazy.prototype.destroy = function() { var handler, property; for (handler in this.handlers) { this._core.$element.off(handler, this.handlers[handler]); } for (property in object.getownpropertynames(this)) { typeof this[property] != 'function' && (this[property] = null); } } $.fn.owlcarousel2.constructor.plugins.lazy = lazy; })(window.zepto || window.jquery, window, document); /** * autoheight plugin * @version 2.0.0 * @author bartosz wojciechowski * @license the mit license (mit) */ ;(function($, window, document, undefined) { /** * creates the auto height plugin. * @class the auto height plugin * @param {owl} carousel - the owl carousel */ var autoheight = function(carousel) { /** * reference to the core. * @protected * @type {owl} */ this._core = carousel; /** * all event handlers. * @protected * @type {object} */ this._handlers = { 'initialized.owl.carousel': $.proxy(function() { if (this._core.settings.autoheight) { this.update(); } }, this), 'changed.owl.carousel': $.proxy(function(e) { if (this._core.settings.autoheight && e.property.name == 'position'){ this.update(); } }, this), 'loaded.owl.lazy': $.proxy(function(e) { if (this._core.settings.autoheight && e.element.closest('.' + this._core.settings.itemclass) === this._core.$stage.children().eq(this._core.current())) { this.update(); } }, this) }; // set default options this._core.options = $.extend({}, autoheight.defaults, this._core.options); // register event handlers this._core.$element.on(this._handlers); }; /** * default options. * @public */ autoheight.defaults = { autoheight: false, autoheightclass: 'owl-height' }; /** * updates the view. */ autoheight.prototype.update = function() { this._core.$stage.parent() .height(this._core.$stage.children().eq(this._core.current()).height()) .addclass(this._core.settings.autoheightclass); }; autoheight.prototype.destroy = function() { var handler, property; for (handler in this._handlers) { this._core.$element.off(handler, this._handlers[handler]); } for (property in object.getownpropertynames(this)) { typeof this[property] != 'function' && (this[property] = null); } }; $.fn.owlcarousel2.constructor.plugins.autoheight = autoheight; })(window.zepto || window.jquery, window, document); /** * video plugin * @version 2.0.0 * @author bartosz wojciechowski * @license the mit license (mit) */ ;(function($, window, document, undefined) { /** * creates the video plugin. * @class the video plugin * @param {owl} carousel - the owl carousel */ var video = function(carousel) { /** * reference to the core. * @protected * @type {owl} */ this._core = carousel; /** * cache all video urls. * @protected * @type {object} */ this._videos = {}; /** * current playing item. * @protected * @type {jquery} */ this._playing = null; /** * whether this is in fullscreen or not. * @protected * @type {boolean} */ this._fullscreen = false; /** * all event handlers. * @protected * @type {object} */ this._handlers = { 'resize.owl.carousel': $.proxy(function(e) { if (this._core.settings.video && !this.isinfullscreen()) { e.preventdefault(); } }, this), 'refresh.owl.carousel changed.owl.carousel': $.proxy(function(e) { if (this._playing) { this.stop(); } }, this), 'prepared.owl.carousel': $.proxy(function(e) { var $element = $(e.content).find('.owl-video'); if ($element.length) { $element.css('display', 'none'); this.fetch($element, $(e.content)); } }, this) }; // set default options this._core.options = $.extend({}, video.defaults, this._core.options); // register event handlers this._core.$element.on(this._handlers); this._core.$element.on('click.owl.video', '.owl-video-play-icon', $.proxy(function(e) { this.play(e); }, this)); }; /** * default options. * @public */ video.defaults = { video: false, videoheight: false, videowidth: false }; /** * gets the video id and the type (youtube/vimeo only). * @protected * @param {jquery} target - the target containing the video data. * @param {jquery} item - the item containing the video. */ video.prototype.fetch = function(target, item) { var type = target.attr('data-vimeo-id') ? 'vimeo' : 'youtube', id = target.attr('data-vimeo-id') || target.attr('data-youtube-id'), width = target.attr('data-width') || this._core.settings.videowidth, height = target.attr('data-height') || this._core.settings.videoheight, url = target.attr('href'); if (url) { id = url.match(/(http:|https:|)\/\/(player.|www.)?(vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|watch\?v=|v\/)?([a-za-z0-9._%-]*)(\&\s+)?/); if (id[3].indexof('youtu') > -1) { type = 'youtube'; } else if (id[3].indexof('vimeo') > -1) { type = 'vimeo'; } else { throw new error('video url not supported.'); } id = id[6]; } else { throw new error('missing video url.'); } this._videos[url] = { type: type, id: id, width: width, height: height }; item.attr('data-video', url); this.thumbnail(target, this._videos[url]); }; /** * creates video thumbnail. * @protected * @param {jquery} target - the target containing the video data. * @param {object} info - the video info object. * @see `fetch` */ video.prototype.thumbnail = function(target, video) { var tnlink, icon, path, dimensions = video.width && video.height ? 'style="width:' + video.width + 'px;height:' + video.height + 'px;"' : '', customtn = target.find('img'), srctype = 'src', lazyclass = '', settings = this._core.settings, create = function(path) { icon = '
'; if (settings.lazyload) { tnlink = '
'; } else { tnlink = '
'; } target.after(tnlink); target.after(icon); }; // wrap video content into owl-video-wrapper div target.wrap('
'); if (this._core.settings.lazyload) { srctype = 'data-src'; lazyclass = 'owl-lazy'; } // custom thumbnail if (customtn.length) { create(customtn.attr(srctype)); customtn.remove(); return false; } if (video.type === 'youtube') { path = "http://img.youtube.com/vi/" + video.id + "/hqdefault.jpg"; create(path); } else if (video.type === 'vimeo') { $.ajax({ type: 'get', url: 'http://vimeo.com/api/v2/video/' + video.id + '.json', jsonp: 'callback', datatype: 'jsonp', success: function(data) { path = data[0].thumbnail_large; create(path); } }); } }; /** * stops the current video. * @public */ video.prototype.stop = function() { this._core.trigger('stop', null, 'video'); this._playing.find('.owl-video-frame').remove(); this._playing.removeclass('owl-video-playing'); this._playing = null; }; /** * starts the current video. * @public * @param {event} ev - the event arguments. */ video.prototype.play = function(ev) { this._core.trigger('play', null, 'video'); if (this._playing) { this.stop(); } var target = $(ev.target || ev.srcelement), item = target.closest('.' + this._core.settings.itemclass), video = this._videos[item.attr('data-video')], width = video.width || '100%', height = video.height || this._core.$stage.height(), html, wrap; if (video.type === 'youtube') { html = ''; } else if (video.type === 'vimeo') { html = ''; } item.addclass('owl-video-playing'); this._playing = item; wrap = $('
' + html + '
'); target.after(wrap); }; /** * checks whether an video is currently in full screen mode or not. * @todo bad style because looks like a readonly method but changes members. * @protected * @returns {boolean} */ video.prototype.isinfullscreen = function() { // if vimeo fullscreen mode var element = document.fullscreenelement || document.mozfullscreenelement || document.webkitfullscreenelement; if (element && $(element).parent().hasclass('owl-video-frame')) { this._core.speed(0); this._fullscreen = true; } if (element && this._fullscreen && this._playing) { return false; } // comming back from fullscreen if (this._fullscreen) { this._fullscreen = false; return false; } // check full screen mode and window orientation if (this._playing) { if (this._core.state.orientation !== window.orientation) { this._core.state.orientation = window.orientation; return false; } } return true; }; /** * destroys the plugin. */ video.prototype.destroy = function() { var handler, property; this._core.$element.off('click.owl.video'); for (handler in this._handlers) { this._core.$element.off(handler, this._handlers[handler]); } for (property in object.getownpropertynames(this)) { typeof this[property] != 'function' && (this[property] = null); } }; $.fn.owlcarousel2.constructor.plugins.video = video; })(window.zepto || window.jquery, window, document); /** * animate plugin * @version 2.0.0 * @author bartosz wojciechowski * @license the mit license (mit) */ ;(function($, window, document, undefined) { /** * creates the animate plugin. * @class the navigation plugin * @param {owl} scope - the owl carousel */ var animate = function(scope) { this.core = scope; this.core.options = $.extend({}, animate.defaults, this.core.options); this.swapping = true; this.previous = undefined; this.next = undefined; this.handlers = { 'change.owl.carousel': $.proxy(function(e) { if (e.property.name == 'position') { this.previous = this.core.current(); this.next = e.property.value; } }, this), 'drag.owl.carousel dragged.owl.carousel translated.owl.carousel': $.proxy(function(e) { this.swapping = e.type == 'translated'; }, this), 'translate.owl.carousel': $.proxy(function(e) { if (this.swapping && (this.core.options.animateout || this.core.options.animatein)) { this.swap(); } }, this) }; this.core.$element.on(this.handlers); }; /** * default options. * @public */ animate.defaults = { animateout: false, animatein: false }; /** * toggles the animation classes whenever an translations starts. * @protected * @returns {boolean|undefined} */ animate.prototype.swap = function() { if (this.core.settings.items !== 1 || !this.core.support3d) { return; } this.core.speed(0); var left, clear = $.proxy(this.clear, this), previous = this.core.$stage.children().eq(this.previous), next = this.core.$stage.children().eq(this.next), incoming = this.core.settings.animatein, outgoing = this.core.settings.animateout; if (this.core.current() === this.previous) { return; } if (outgoing) { left = this.core.coordinates(this.previous) - this.core.coordinates(this.next); previous.css( { 'left': left + 'px' } ) .addclass('animated owl-animated-out') .addclass(outgoing) .one('webkitanimationend mozanimationend msanimationend oanimationend animationend', clear); } if (incoming) { next.addclass('animated owl-animated-in') .addclass(incoming) .one('webkitanimationend mozanimationend msanimationend oanimationend animationend', clear); } }; animate.prototype.clear = function(e) { $(e.target).css( { 'left': '' } ) .removeclass('animated owl-animated-out owl-animated-in') .removeclass(this.core.settings.animatein) .removeclass(this.core.settings.animateout); this.core.transitionend(); } /** * destroys the plugin. * @public */ animate.prototype.destroy = function() { var handler, property; for (handler in this.handlers) { this.core.$element.off(handler, this.handlers[handler]); } for (property in object.getownpropertynames(this)) { typeof this[property] != 'function' && (this[property] = null); } }; $.fn.owlcarousel2.constructor.plugins.animate = animate; })(window.zepto || window.jquery, window, document); /** * autoplay plugin * @version 2.0.0 * @author bartosz wojciechowski * @license the mit license (mit) */ ;(function($, window, document, undefined) { /** * creates the autoplay plugin. * @class the autoplay plugin * @param {owl} scope - the owl carousel */ var autoplay = function(scope) { this.core = scope; this.core.options = $.extend({}, autoplay.defaults, this.core.options); this.handlers = { 'translated.owl.carousel refreshed.owl.carousel': $.proxy(function() { this.autoplay(); }, this), 'play.owl.autoplay': $.proxy(function(e, t, s) { this.play(t, s); }, this), 'stop.owl.autoplay': $.proxy(function() { this.stop(); }, this), 'mouseover.owl.autoplay': $.proxy(function() { if (this.core.settings.autoplayhoverpause) { this.pause(); } }, this), 'mouseleave.owl.autoplay': $.proxy(function() { if (this.core.settings.autoplayhoverpause) { this.autoplay(); } }, this) }; this.core.$element.on(this.handlers); }; /** * default options. * @public */ autoplay.defaults = { autoplay: false, autoplaytimeout: 5000, autoplayhoverpause: false, autoplayspeed: false }; /** * @protected * @todo must be documented. */ autoplay.prototype.autoplay = function() { if (this.core.settings.autoplay && !this.core.state.videoplay) { window.clearinterval(this.interval); this.interval = window.setinterval($.proxy(function() { this.play(); }, this), this.core.settings.autoplaytimeout); } else { window.clearinterval(this.interval); } }; /** * starts the autoplay. * @public * @param {number} [timeout] - ... * @param {number} [speed] - ... * @returns {boolean|undefined} - ... * @todo must be documented. */ autoplay.prototype.play = function(timeout, speed) { // if tab is inactive - doesnt work in } */ this._templates = []; /** * the carousel element. * @type {jquery} */ this.$element = this._core.$element; /** * overridden methods of the carousel. * @protected * @type {object} */ this._overrides = { next: this._core.next, prev: this._core.prev, to: this._core.to }; /** * all event handlers. * @protected * @type {object} */ this._handlers = { 'prepared.owl.carousel': $.proxy(function(e) { if (this._core.settings.dotsdata) { this._templates.push($(e.content).find('[data-dot]').andself('[data-dot]').attr('data-dot')); } }, this), 'add.owl.carousel': $.proxy(function(e) { if (this._core.settings.dotsdata) { this._templates.splice(e.position, 0, $(e.content).find('[data-dot]').andself('[data-dot]').attr('data-dot')); } }, this), 'remove.owl.carousel prepared.owl.carousel': $.proxy(function(e) { if (this._core.settings.dotsdata) { this._templates.splice(e.position, 1); } }, this), 'change.owl.carousel': $.proxy(function(e) { if (e.property.name == 'position') { if (!this._core.state.revert && !this._core.settings.loop && this._core.settings.navrewind) { var current = this._core.current(), maximum = this._core.maximum(), minimum = this._core.minimum(); e.data = e.property.value > maximum ? current >= maximum ? minimum : maximum : e.property.value < minimum ? maximum : e.property.value; } } }, this), 'changed.owl.carousel': $.proxy(function(e) { if (e.property.name == 'position') { this.draw(); } }, this), 'refreshed.owl.carousel': $.proxy(function() { if (!this._initialized) { this.initialize(); this._initialized = true; } this._core.trigger('refresh', null, 'navigation'); this.update(); this.draw(); this._core.trigger('refreshed', null, 'navigation'); }, this) }; // set default options this._core.options = $.extend({}, navigation.defaults, this._core.options); // register event handlers this.$element.on(this._handlers); } /** * default options. * @public * @todo rename `slideby` to `navby` */ navigation.defaults = { nav: false, navrewind: true, navtext: [ 'prev', 'next' ], navspeed: false, navelement: 'div', navcontainer: false, navcontainerclass: 'owl-nav', navclass: [ 'owl-prev', 'owl-next' ], slideby: 1, dotclass: 'owl-dot', dotsclass: 'owl-dots', dots: true, dotseach: false, dotdata: false, dotsspeed: false, dotscontainer: false, controlsclass: 'owl-controls2' } /** * initializes the layout of the plugin and extends the carousel. * @protected */ navigation.prototype.initialize = function() { var $container, override, options = this._core.settings; // create the indicator template if (!options.dotsdata) { this._templates = [ $('
') .addclass(options.dotclass) .append($('')) .prop('outerhtml') ]; } // create controls container if needed if (!options.navcontainer || !options.dotscontainer) { this._controls.$container = $('
') .addclass(options.controlsclass) .appendto(this.$element); } // create dom structure for absolute navigation this._controls.$indicators = options.dotscontainer ? $(options.dotscontainer) : $('
').hide().addclass(options.dotsclass).appendto(this._controls.$container); this._controls.$indicators.on('click', 'div', $.proxy(function(e) { var index = $(e.target).parent().is(this._controls.$indicators) ? $(e.target).index() : $(e.target).parent().index(); e.preventdefault(); this.to(index, options.dotsspeed); }, this)); // create dom structure for relative navigation $container = options.navcontainer ? $(options.navcontainer) : $('
').addclass(options.navcontainerclass).prependto(this._controls.$container); this._controls.$next = $('<' + options.navelement + '>'); this._controls.$previous = this._controls.$next.clone(); this._controls.$previous .addclass(options.navclass[0]) .html(options.navtext[0]) .hide() .prependto($container) .on('click', $.proxy(function(e) { this.prev(options.navspeed); }, this)); this._controls.$next .addclass(options.navclass[1]) .html(options.navtext[1]) .hide() .appendto($container) .on('click', $.proxy(function(e) { this.next(options.navspeed); }, this)); // override public methods of the carousel for (override in this._overrides) { this._core[override] = $.proxy(this[override], this); } } /** * destroys the plugin. * @protected */ navigation.prototype.destroy = function() { var handler, control, property, override; for (handler in this._handlers) { this.$element.off(handler, this._handlers[handler]); } for (control in this._controls) { this._controls[control].remove(); } for (override in this.overides) { this._core[override] = this._overrides[override]; } for (property in object.getownpropertynames(this)) { typeof this[property] != 'function' && (this[property] = null); } } /** * updates the internal state. * @protected */ navigation.prototype.update = function() { var i, j, k, options = this._core.settings, lower = this._core.clones().length / 2, upper = lower + this._core.items().length, size = options.center || options.autowidth || options.dotdata ? 1 : options.dotseach || options.items; if (options.slideby !== 'page') { options.slideby = math.min(options.slideby, options.items); } if (options.dots || options.slideby == 'page') { this._pages = []; for (i = lower, j = 0, k = 0; i < upper; i++) { if (j >= size || j === 0) { this._pages.push({ start: i - lower, end: i - lower + size - 1 }); j = 0, ++k; } j += this._core.mergers(this._core.relative(i)); } } } /** * draws the user interface. * @todo the option `dotdata` wont work. * @protected */ navigation.prototype.draw = function() { var difference, i, html = '', options = this._core.settings, $items = this._core.$stage.children(), index = this._core.relative(this._core.current()); if (options.nav && !options.loop && !options.navrewind) { this._controls.$previous.toggleclass('disabled', index <= 0); this._controls.$next.toggleclass('disabled', index >= this._core.maximum()); } this._controls.$previous.toggle(options.nav); this._controls.$next.toggle(options.nav); if (options.dots) { difference = this._pages.length - this._controls.$indicators.children().length; if (options.dotdata && difference !== 0) { for (i = 0; i < this._controls.$indicators.children().length; i++) { html += this._templates[this._core.relative(i)]; } this._controls.$indicators.html(html); } else if (difference > 0) { html = new array(difference + 1).join(this._templates[0]); this._controls.$indicators.append(html); } else if (difference < 0) { this._controls.$indicators.children().slice(difference).remove(); } this._controls.$indicators.find('.active').removeclass('active'); this._controls.$indicators.children().eq($.inarray(this.current(), this._pages)).addclass('active'); } this._controls.$indicators.toggle(options.dots); } /** * extends event data. * @protected * @param {event} event - the event object which gets thrown. */ navigation.prototype.ontrigger = function(event) { var settings = this._core.settings; event.page = { index: $.inarray(this.current(), this._pages), count: this._pages.length, size: settings && (settings.center || settings.autowidth || settings.dotdata ? 1 : settings.dotseach || settings.items) }; } /** * gets the current page position of the carousel. * @protected * @returns {number} */ navigation.prototype.current = function() { var index = this._core.relative(this._core.current()); return $.grep(this._pages, function(o) { return o.start <= index && o.end >= index; }).pop(); } /** * gets the current succesor/predecessor position. * @protected * @returns {number} */ navigation.prototype.getposition = function(successor) { var position, length, options = this._core.settings; if (options.slideby == 'page') { position = $.inarray(this.current(), this._pages); length = this._pages.length; successor ? ++position : --position; position = this._pages[((position % length) + length) % length].start; } else { position = this._core.relative(this._core.current()); length = this._core.items().length; successor ? position += options.slideby : position -= options.slideby; } return position; } /** * slides to the next item or page. * @public * @param {number} [speed=false] - the time in milliseconds for the transition. */ navigation.prototype.next = function(speed) { $.proxy(this._overrides.to, this._core)(this.getposition(true), speed); } /** * slides to the previous item or page. * @public * @param {number} [speed=false] - the time in milliseconds for the transition. */ navigation.prototype.prev = function(speed) { $.proxy(this._overrides.to, this._core)(this.getposition(false), speed); } /** * slides to the specified item or page. * @public * @param {number} position - the position of the item or page. * @param {number} [speed] - the time in milliseconds for the transition. * @param {boolean} [standard=false] - whether to use the standard behaviour or not. */ navigation.prototype.to = function(position, speed, standard) { var length; if (!standard) { length = this._pages.length; $.proxy(this._overrides.to, this._core)(this._pages[((position % length) + length) % length].start, speed); } else { $.proxy(this._overrides.to, this._core)(position, speed); } } $.fn.owlcarousel2.constructor.plugins.navigation = navigation; })(window.zepto || window.jquery, window, document); /** * hash plugin * @version 2.0.0 * @author artus kolanowski * @license the mit license (mit) */ ;(function($, window, document, undefined) { 'use strict'; /** * creates the hash plugin. * @class the hash plugin * @param {owl} carousel - the owl carousel */ var hash = function(carousel) { /** * reference to the core. * @protected * @type {owl} */ this._core = carousel; /** * hash table for the hashes. * @protected * @type {object} */ this._hashes = {}; /** * the carousel element. * @type {jquery} */ this.$element = this._core.$element; /** * all event handlers. * @protected * @type {object} */ this._handlers = { 'initialized.owl.carousel': $.proxy(function() { if (this._core.settings.startposition == 'urlhash') { $(window).trigger('hashchange.owl.navigation'); } }, this), 'prepared.owl.carousel': $.proxy(function(e) { var hash = $(e.content).find('[data-hash]').andself('[data-hash]').attr('data-hash'); this._hashes[hash] = e.content; }, this) }; // set default options this._core.options = $.extend({}, hash.defaults, this._core.options); // register the event handlers this.$element.on(this._handlers); // register event listener for hash navigation $(window).on('hashchange.owl.navigation', $.proxy(function() { var hash = window.location.hash.substring(1), items = this._core.$stage.children(), position = this._hashes[hash] && items.index(this._hashes[hash]) || 0; if (!hash) { return false; } this._core.to(position, false, true); }, this)); } /** * default options. * @public */ hash.defaults = { urlhashlistener: false } /** * destroys the plugin. * @public */ hash.prototype.destroy = function() { var handler, property; $(window).off('hashchange.owl.navigation'); for (handler in this._handlers) { this._core.$element.off(handler, this._handlers[handler]); } for (property in object.getownpropertynames(this)) { typeof this[property] != 'function' && (this[property] = null); } } $.fn.owlcarousel2.constructor.plugins.hash = hash; })(window.zepto || window.jquery, window, document); /** * bxslider v4.1.2 - fully loaded, responsive content slider * http://bxslider.com * * copyright 2014, steven wanderski - http://stevenwanderski.com - http://bxcreative.com * written while drinking belgian ales and listening to jazz * * released under the mit license - http://opensource.org/licenses/mit */ ;(function($){ var plugin = {}; var defaults = { // general mode: 'horizontal', slideselector: '', infiniteloop: true, hidecontrolonend: false, speed: 500, easing: null, slidemargin: 0, startslide: 0, randomstart: false, captions: false, ticker: false, tickerhover: false, adaptiveheight: false, adaptiveheightspeed: 500, video: false, usecss: true, preloadimages: 'visible', responsive: true, slidezindex: 50, wrapperclass: 'bx-wrapper', // touch touchenabled: true, swipethreshold: 50, onetoonetouch: true, preventdefaultswipex: true, preventdefaultswipey: true, // pager pager: true, pagertype: 'full', pagershortseparator: ' / ', pagerselector: null, buildpager: null, pagercustom: null, // controls controls: true, nexttext: 'next', prevtext: 'prev', nextselector: null, prevselector: null, autocontrols: false, starttext: 'start', stoptext: 'stop', autocontrolscombine: false, autocontrolsselector: null, // auto auto: false, pause: 4000, autostart: true, autodirection: 'next', autohover: false, autodelay: 0, autoslideforonepage: false, // carousel minslides: 1, maxslides: 1, moveslides: 0, slidewidth: 0, // callbacks onsliderload: function() {}, onslidebefore: function() {}, onslideafter: function() {}, onslidenext: function() {}, onslideprev: function() {}, onsliderresize: function() {} } $.fn.bxslider = function(options){ if(this.length == 0) return this; // support mutltiple elements if(this.length > 1){ this.each(function(){$(this).bxslider(options)}); return this; } // create a namespace to be used throughout the plugin var slider = {}; // set a reference to our slider element var el = this; plugin.el = this; /** * makes slideshow responsive */ // first get the original window dimens (thanks alot ie) var windowwidth = $(window).width(); var windowheight = $(window).height(); /** * =================================================================================== * = private functions * =================================================================================== */ /** * initializes namespace settings to be used throughout plugin */ var init = function(){ // merge user-supplied options with the defaults slider.settings = $.extend({}, defaults, options); // parse slidewidth setting slider.settings.slidewidth = parseint(slider.settings.slidewidth); // store the original children slider.children = el.children(slider.settings.slideselector); // check if actual number of slides is less than minslides / maxslides if(slider.children.length < slider.settings.minslides) slider.settings.minslides = slider.children.length; if(slider.children.length < slider.settings.maxslides) slider.settings.maxslides = slider.children.length; // if random start, set the startslide setting to random number if(slider.settings.randomstart) slider.settings.startslide = math.floor(math.random() * slider.children.length); // store active slide information slider.active = { index: slider.settings.startslide } // store if the slider is in carousel mode (displaying / moving multiple slides) slider.carousel = slider.settings.minslides > 1 || slider.settings.maxslides > 1; // if carousel, force preloadimages = 'all' if(slider.carousel) slider.settings.preloadimages = 'all'; // calculate the min / max width thresholds based on min / max number of slides // used to setup and update carousel slides dimensions slider.minthreshold = (slider.settings.minslides * slider.settings.slidewidth) + ((slider.settings.minslides - 1) * slider.settings.slidemargin); slider.maxthreshold = (slider.settings.maxslides * slider.settings.slidewidth) + ((slider.settings.maxslides - 1) * slider.settings.slidemargin); // store the current state of the slider (if currently animating, working is true) slider.working = false; // initialize the controls object slider.controls = {}; // initialize an auto interval slider.interval = null; // determine which property to use for transitions slider.animprop = slider.settings.mode == 'vertical' ? 'top' : 'left'; // determine if hardware acceleration can be used slider.usingcss = slider.settings.usecss && slider.settings.mode != 'fade' && (function(){ // create our test div element var div = document.createelement('div'); // css transition properties var props = ['webkitperspective', 'mozperspective', 'operspective', 'msperspective']; // test for each property for(var i in props){ if(div.style[props[i]] !== undefined){ slider.cssprefix = props[i].replace('perspective', '').tolowercase(); slider.animprop = '-' + slider.cssprefix + '-transform'; return true; } } return false; }()); // if vertical mode always make maxslides and minslides equal if(slider.settings.mode == 'vertical') slider.settings.maxslides = slider.settings.minslides; // save original style data el.data("origstyle", el.attr("style")); el.children(slider.settings.slideselector).each(function() { $(this).data("origstyle", $(this).attr("style")); }); // perform all dom / css modifications setup(); } /** * performs all dom and css modifications */ var setup = function(){ // wrap el in a wrapper el.wrap('
'); // store a namspace reference to .bx-viewport slider.viewport = el.parent(); // add a loading div to display while images are loading slider.loader = $('
'); slider.viewport.prepend(slider.loader); // set el to a massive width, to hold any needed slides // also strip any margin and padding from el el.css({ width: slider.settings.mode == 'horizontal' ? (slider.children.length * 100 + 215) + '%' : 'auto', position: 'relative' }); // if using css, add the easing property if(slider.usingcss && slider.settings.easing){ el.css('-' + slider.cssprefix + '-transition-timing-function', slider.settings.easing); // if not using css and no easing value was supplied, use the default js animation easing (swing) }else if(!slider.settings.easing){ slider.settings.easing = 'swing'; } var slidesshowing = getnumberslidesshowing(); // make modifications to the viewport (.bx-viewport) slider.viewport.css({ width: '100%', overflow: 'hidden', position: 'relative' }); slider.viewport.parent().css({ maxwidth: getviewportmaxwidth() }); // make modification to the wrapper (.bx-wrapper) if(!slider.settings.pager) { slider.viewport.parent().css({ margin: '0 auto 0px' }); } // apply css to all slider children slider.children.css({ 'float': slider.settings.mode == 'horizontal' ? 'left' : 'none', liststyle: 'none', position: 'relative' }); // apply the calculated width after the float is applied to prevent scrollbar interference slider.children.css('width', getslidewidth()); // if slidemargin is supplied, add the css if(slider.settings.mode == 'horizontal' && slider.settings.slidemargin > 0) slider.children.css('marginright', slider.settings.slidemargin); if(slider.settings.mode == 'vertical' && slider.settings.slidemargin > 0) slider.children.css('marginbottom', slider.settings.slidemargin); // if "fade" mode, add positioning and z-index css if(slider.settings.mode == 'fade'){ slider.children.css({ position: 'absolute', zindex: 0, display: 'none' }); // prepare the z-index on the showing element slider.children.eq(slider.settings.startslide).css({zindex: slider.settings.slidezindex, display: 'block'}); } // create an element to contain all slider controls (pager, start / stop, etc) slider.controls.el = $('
'); // if captions are requested, add them if(slider.settings.captions) appendcaptions(); // check if startslide is last slide slider.active.last = slider.settings.startslide == getpagerqty() - 1; // if video is true, set up the fitvids plugin if(slider.settings.video) el.fitvids(); // set the default preload selector (visible) var preloadselector = slider.children.eq(slider.settings.startslide); if (slider.settings.preloadimages == "all") preloadselector = slider.children; // only check for control addition if not in "ticker" mode if(!slider.settings.ticker){ // if pager is requested, add it if(slider.settings.pager) appendpager(); // if controls are requested, add them if(slider.settings.controls) appendcontrols(); // if auto is true, and auto controls are requested, add them if(slider.settings.auto && slider.settings.autocontrols) appendcontrolsauto(); // if any control option is requested, add the controls wrapper if(slider.settings.controls || slider.settings.autocontrols || slider.settings.pager) slider.viewport.after(slider.controls.el); // if ticker mode, do not allow a pager }else{ slider.settings.pager = false; } // preload all images, then perform final dom / css modifications that depend on images being loaded loadelements(preloadselector, start); } var loadelements = function(selector, callback){ var total = selector.find('img, iframe').length; if (total == 0){ callback(); return; } var count = 0; selector.find('img, iframe').each(function(){ $(this).one('load', function() { if(++count == total) callback(); }).each(function() { if(this.complete) $(this).load(); }); }); } /** * start the slider */ var start = function(){ // if infinite loop, prepare additional slides if(slider.settings.infiniteloop && slider.settings.mode != 'fade' && !slider.settings.ticker){ var slice = slider.settings.mode == 'vertical' ? slider.settings.minslides : slider.settings.maxslides; var sliceappend = slider.children.slice(0, slice).clone().addclass('bx-clone'); var sliceprepend = slider.children.slice(-slice).clone().addclass('bx-clone'); el.append(sliceappend).prepend(sliceprepend); } // remove the loading dom element slider.loader.remove(); // set the left / top position of "el" setslideposition(); // if "vertical" mode, always use adaptiveheight to prevent odd behavior if (slider.settings.mode == 'vertical') slider.settings.adaptiveheight = true; // set the viewport height slider.viewport.height(getviewportheight()); // make sure everything is positioned just right (same as a window resize) el.redrawslider(); // onsliderload callback slider.settings.onsliderload(slider.active.index); // slider has been fully initialized slider.initialized = true; // bind the resize call to the window if (slider.settings.responsive) $(window).bind('resize', resizewindow); // if auto is true and has more than 1 page, start the show if (slider.settings.auto && slider.settings.autostart && (getpagerqty() > 1 || slider.settings.autoslideforonepage)) initauto(); // if ticker is true, start the ticker if (slider.settings.ticker) initticker(); // if pager is requested, make the appropriate pager link active if (slider.settings.pager) updatepageractive(slider.settings.startslide); // check for any updates to the controls (like hidecontrolonend updates) if (slider.settings.controls) updatedirectioncontrols(); // if touchenabled is true, setup the touch events if (slider.settings.touchenabled && !slider.settings.ticker) inittouch(); } /** * returns the calculated height of the viewport, used to determine either adaptiveheight or the maxheight value */ var getviewportheight = function(){ var height = 0; // first determine which children (slides) should be used in our height calculation var children = $(); // if mode is not "vertical" and adaptiveheight is false, include all children if(slider.settings.mode != 'vertical' && !slider.settings.adaptiveheight){ children = slider.children; }else{ // if not carousel, return the single active child if(!slider.carousel){ children = slider.children.eq(slider.active.index); // if carousel, return a slice of children }else{ // get the individual slide index var currentindex = slider.settings.moveslides == 1 ? slider.active.index : slider.active.index * getmoveby(); // add the current slide to the children children = slider.children.eq(currentindex); // cycle through the remaining "showing" slides for (i = 1; i <= slider.settings.maxslides - 1; i++){ // if looped back to the start if(currentindex + i >= slider.children.length){ children = children.add(slider.children.eq(i - 1)); }else{ children = children.add(slider.children.eq(currentindex + i)); } } } } // if "vertical" mode, calculate the sum of the heights of the children if(slider.settings.mode == 'vertical'){ children.each(function(index) { height += $(this).outerheight(); }); // add user-supplied margins if(slider.settings.slidemargin > 0){ height += slider.settings.slidemargin * (slider.settings.minslides - 1); } // if not "vertical" mode, calculate the max height of the children }else{ height = math.max.apply(math, children.map(function(){ return $(this).outerheight(false); }).get()); } if(slider.viewport.css('box-sizing') == 'border-box'){ height += parsefloat(slider.viewport.css('padding-top')) + parsefloat(slider.viewport.css('padding-bottom')) + parsefloat(slider.viewport.css('border-top-width')) + parsefloat(slider.viewport.css('border-bottom-width')); }else if(slider.viewport.css('box-sizing') == 'padding-box'){ height += parsefloat(slider.viewport.css('padding-top')) + parsefloat(slider.viewport.css('padding-bottom')); } return height; } /** * returns the calculated width to be used for the outer wrapper / viewport */ var getviewportmaxwidth = function(){ var width = '100%'; if(slider.settings.slidewidth > 0){ if(slider.settings.mode == 'horizontal'){ width = (slider.settings.maxslides * slider.settings.slidewidth) + ((slider.settings.maxslides - 1) * slider.settings.slidemargin); }else{ width = slider.settings.slidewidth; } } return width; } /** * returns the calculated width to be applied to each slide */ var getslidewidth = function(){ // start with any user-supplied slide width var newelwidth = slider.settings.slidewidth; // get the current viewport width var wrapwidth = slider.viewport.width(); // if slide width was not supplied, or is larger than the viewport use the viewport width if(slider.settings.slidewidth == 0 || (slider.settings.slidewidth > wrapwidth && !slider.carousel) || slider.settings.mode == 'vertical'){ newelwidth = wrapwidth; // if carousel, use the thresholds to determine the width }else if(slider.settings.maxslides > 1 && slider.settings.mode == 'horizontal'){ if(wrapwidth > slider.maxthreshold){ // newelwidth = (wrapwidth - (slider.settings.slidemargin * (slider.settings.maxslides - 1))) / slider.settings.maxslides; }else if(wrapwidth < slider.minthreshold){ newelwidth = (wrapwidth - (slider.settings.slidemargin * (slider.settings.minslides - 1))) / slider.settings.minslides; } } return newelwidth; } /** * returns the number of slides currently visible in the viewport (includes partially visible slides) */ var getnumberslidesshowing = function(){ var slidesshowing = 1; if(slider.settings.mode == 'horizontal' && slider.settings.slidewidth > 0){ // if viewport is smaller than minthreshold, return minslides if(slider.viewport.width() < slider.minthreshold){ slidesshowing = slider.settings.minslides; // if viewport is larger than minthreshold, return maxslides }else if(slider.viewport.width() > slider.maxthreshold){ slidesshowing = slider.settings.maxslides; // if viewport is between min / max thresholds, divide viewport width by first child width }else{ var childwidth = slider.children.first().width() + slider.settings.slidemargin; slidesshowing = math.floor((slider.viewport.width() + slider.settings.slidemargin) / childwidth); } // if "vertical" mode, slides showing will always be minslides }else if(slider.settings.mode == 'vertical'){ slidesshowing = slider.settings.minslides; } return slidesshowing; } /** * returns the number of pages (one full viewport of slides is one "page") */ var getpagerqty = function(){ var pagerqty = 0; // if moveslides is specified by the user if(slider.settings.moveslides > 0){ if(slider.settings.infiniteloop){ pagerqty = math.ceil(slider.children.length / getmoveby()); }else{ // use a while loop to determine pages var breakpoint = 0; var counter = 0 // when breakpoint goes above children length, counter is the number of pages while (breakpoint < slider.children.length){ ++pagerqty; breakpoint = counter + getnumberslidesshowing(); counter += slider.settings.moveslides <= getnumberslidesshowing() ? slider.settings.moveslides : getnumberslidesshowing(); } } // if moveslides is 0 (auto) divide children length by sides showing, then round up }else{ pagerqty = math.ceil(slider.children.length / getnumberslidesshowing()); } return pagerqty; } /** * returns the number of indivual slides by which to shift the slider */ var getmoveby = function(){ // if moveslides was set by the user and moveslides is less than number of slides showing if(slider.settings.moveslides > 0 && slider.settings.moveslides <= getnumberslidesshowing()){ return slider.settings.moveslides; } // if moveslides is 0 (auto) return getnumberslidesshowing(); } /** * sets the slider's (el) left or top position */ var setslideposition = function(){ // if last slide, not infinite loop, and number of children is larger than specified maxslides if(slider.children.length > slider.settings.maxslides && slider.active.last && !slider.settings.infiniteloop){ if (slider.settings.mode == 'horizontal'){ // get the last child's position var lastchild = slider.children.last(); var position = lastchild.position(); // set the left position setpositionproperty(-(position.left - (slider.viewport.width() - lastchild.outerwidth())), 'reset', 0); }else if(slider.settings.mode == 'vertical'){ // get the last showing index's position var lastshowingindex = slider.children.length - slider.settings.minslides; var position = slider.children.eq(lastshowingindex).position(); // set the top position setpositionproperty(-position.top, 'reset', 0); } // if not last slide }else{ // get the position of the first showing slide var position = slider.children.eq(slider.active.index * getmoveby()).position(); // check for last slide if (slider.active.index == getpagerqty() - 1) slider.active.last = true; // set the repective position if (position != undefined){ if (slider.settings.mode == 'horizontal') setpositionproperty(-position.left, 'reset', 0); else if (slider.settings.mode == 'vertical') setpositionproperty(-position.top, 'reset', 0); } } } /** * sets the el's animating property position (which in turn will sometimes animate el). * if using css, sets the transform property. if not using css, sets the top / left property. * * @param value (int) * - the animating property's value * * @param type (string) 'slider', 'reset', 'ticker' * - the type of instance for which the function is being * * @param duration (int) * - the amount of time (in ms) the transition should occupy * * @param params (array) optional * - an optional parameter containing any variables that need to be passed in */ var setpositionproperty = function(value, type, duration, params){ // use css transform if(slider.usingcss){ // determine the translate3d value var propvalue = slider.settings.mode == 'vertical' ? 'translate3d(0, ' + value + 'px, 0)' : 'translate3d(' + value + 'px, 0, 0)'; // add the css transition-duration el.css('-' + slider.cssprefix + '-transition-duration', duration / 1000 + 's'); if(type == 'slide'){ // set the property value el.css(slider.animprop, propvalue); // bind a callback method - executes when css transition completes el.bind('transitionend webkittransitionend otransitionend mstransitionend', function(){ // unbind the callback el.unbind('transitionend webkittransitionend otransitionend mstransitionend'); updateafterslidetransition(); }); }else if(type == 'reset'){ el.css(slider.animprop, propvalue); }else if(type == 'ticker'){ // make the transition use 'linear' el.css('-' + slider.cssprefix + '-transition-timing-function', 'linear'); el.css(slider.animprop, propvalue); // bind a callback method - executes when css transition completes el.bind('transitionend webkittransitionend otransitionend mstransitionend', function(){ // unbind the callback el.unbind('transitionend webkittransitionend otransitionend mstransitionend'); // reset the position setpositionproperty(params['resetvalue'], 'reset', 0); // start the loop again tickerloop(); }); } // use js animate }else{ var animateobj = {}; animateobj[slider.animprop] = value; if(type == 'slide'){ el.animate(animateobj, duration, slider.settings.easing, function(){ updateafterslidetransition(); }); }else if(type == 'reset'){ el.css(slider.animprop, value) }else if(type == 'ticker'){ el.animate(animateobj, speed, 'linear', function(){ setpositionproperty(params['resetvalue'], 'reset', 0); // run the recursive loop after animation tickerloop(); }); } } } /** * populates the pager with proper amount of pages */ var populatepager = function(){ var pagerhtml = ''; var pagerqty = getpagerqty(); // loop through each pager item for(var i=0; i < pagerqty; i++){ var linkcontent = ''; // if a buildpager function is supplied, use it to get pager link value, else use index + 1 if(slider.settings.buildpager && $.isfunction(slider.settings.buildpager)){ linkcontent = slider.settings.buildpager(i); slider.pagerel.addclass('bx-custom-pager'); }else{ linkcontent = i + 1; slider.pagerel.addclass('bx-default-pager'); } // var linkcontent = slider.settings.buildpager && $.isfunction(slider.settings.buildpager) ? slider.settings.buildpager(i) : i + 1; // add the markup to the string pagerhtml += ''; }; // populate the pager element with pager links slider.pagerel.html(pagerhtml); } /** * appends the pager to the controls element */ var appendpager = function(){ if(!slider.settings.pagercustom){ // create the pager dom element slider.pagerel = $('
'); // if a pager selector was supplied, populate it with the pager if(slider.settings.pagerselector){ $(slider.settings.pagerselector).html(slider.pagerel); // if no pager selector was supplied, add it after the wrapper }else{ slider.controls.el.addclass('bx-has-pager').append(slider.pagerel); } // populate the pager populatepager(); }else{ slider.pagerel = $(slider.settings.pagercustom); } // assign the pager click binding slider.pagerel.on('click', 'a', clickpagerbind); } /** * appends prev / next controls to the controls element */ var appendcontrols = function(){ slider.controls.next = $('' + slider.settings.nexttext + ''); slider.controls.prev = $('' + slider.settings.prevtext + ''); // bind click actions to the controls slider.controls.next.bind('click', clicknextbind); slider.controls.prev.bind('click', clickprevbind); // if nextslector was supplied, populate it if(slider.settings.nextselector){ $(slider.settings.nextselector).append(slider.controls.next); } // if prevslector was supplied, populate it if(slider.settings.prevselector){ $(slider.settings.prevselector).append(slider.controls.prev); } // if no custom selectors were supplied if(!slider.settings.nextselector && !slider.settings.prevselector){ // add the controls to the dom slider.controls.directionel = $('
'); // add the control elements to the directionel slider.controls.directionel.append(slider.controls.prev).append(slider.controls.next); // slider.viewport.append(slider.controls.directionel); slider.controls.el.addclass('bx-has-controls-direction').append(slider.controls.directionel); } } /** * appends start / stop auto controls to the controls element */ var appendcontrolsauto = function(){ slider.controls.start = $(''); slider.controls.stop = $(''); // add the controls to the dom slider.controls.autoel = $('
'); // bind click actions to the controls slider.controls.autoel.on('click', '.bx-start', clickstartbind); slider.controls.autoel.on('click', '.bx-stop', clickstopbind); // if autocontrolscombine, insert only the "start" control if(slider.settings.autocontrolscombine){ slider.controls.autoel.append(slider.controls.start); // if autocontrolscombine is false, insert both controls }else{ slider.controls.autoel.append(slider.controls.start).append(slider.controls.stop); } // if auto controls selector was supplied, populate it with the controls if(slider.settings.autocontrolsselector){ $(slider.settings.autocontrolsselector).html(slider.controls.autoel); // if auto controls selector was not supplied, add it after the wrapper }else{ slider.controls.el.addclass('bx-has-controls-auto').append(slider.controls.autoel); } // update the auto controls updateautocontrols(slider.settings.autostart ? 'stop' : 'start'); } /** * appends image captions to the dom */ var appendcaptions = function(){ // cycle through each child slider.children.each(function(index){ // get the image title attribute var title = $(this).find('img:first').attr('title'); // append the caption if (title != undefined && ('' + title).length) { $(this).append('
' + title + '
'); } }); } /** * click next binding * * @param e (event) * - dom event object */ var clicknextbind = function(e){ // if auto show is running, stop it if (slider.settings.auto) el.stopauto(); el.gotonextslide(); e.preventdefault(); } /** * click prev binding * * @param e (event) * - dom event object */ var clickprevbind = function(e){ // if auto show is running, stop it if (slider.settings.auto) el.stopauto(); el.gotoprevslide(); e.preventdefault(); } /** * click start binding * * @param e (event) * - dom event object */ var clickstartbind = function(e){ el.startauto(); e.preventdefault(); } /** * click stop binding * * @param e (event) * - dom event object */ var clickstopbind = function(e){ el.stopauto(); e.preventdefault(); } /** * click pager binding * * @param e (event) * - dom event object */ var clickpagerbind = function(e){ // if auto show is running, stop it if (slider.settings.auto) el.stopauto(); var pagerlink = $(e.currenttarget); if(pagerlink.attr('data-slide-index') !== undefined){ var pagerindex = parseint(pagerlink.attr('data-slide-index')); // if clicked pager link is not active, continue with the gotoslide call if(pagerindex != slider.active.index) el.gotoslide(pagerindex); e.preventdefault(); } } /** * updates the pager links with an active class * * @param slideindex (int) * - index of slide to make active */ var updatepageractive = function(slideindex){ // if "short" pager type var len = slider.children.length; // nb of children if(slider.settings.pagertype == 'short'){ if(slider.settings.maxslides > 1) { len = math.ceil(slider.children.length/slider.settings.maxslides); } slider.pagerel.html( (slideindex + 1) + slider.settings.pagershortseparator + len); return; } // remove all pager active classes slider.pagerel.find('a').removeclass('active'); // apply the active class for all pagers slider.pagerel.each(function(i, el) { $(el).find('a').eq(slideindex).addclass('active'); }); } /** * performs needed actions after a slide transition */ var updateafterslidetransition = function(){ // if infinte loop is true if(slider.settings.infiniteloop){ var position = ''; // first slide if(slider.active.index == 0){ // set the new position position = slider.children.eq(0).position(); // carousel, last slide }else if(slider.active.index == getpagerqty() - 1 && slider.carousel){ position = slider.children.eq((getpagerqty() - 1) * getmoveby()).position(); // last slide }else if(slider.active.index == slider.children.length - 1){ position = slider.children.eq(slider.children.length - 1).position(); } if(position){ if (slider.settings.mode == 'horizontal') { setpositionproperty(-position.left, 'reset', 0); } else if (slider.settings.mode == 'vertical') { setpositionproperty(-position.top, 'reset', 0); } } } // declare that the transition is complete slider.working = false; // onslideafter callback slider.settings.onslideafter(slider.children.eq(slider.active.index), slider.oldindex, slider.active.index); } /** * updates the auto controls state (either active, or combined switch) * * @param state (string) "start", "stop" * - the new state of the auto show */ var updateautocontrols = function(state){ // if autocontrolscombine is true, replace the current control with the new state if(slider.settings.autocontrolscombine){ slider.controls.autoel.html(slider.controls[state]); // if autocontrolscombine is false, apply the "active" class to the appropriate control }else{ slider.controls.autoel.find('a').removeclass('active'); slider.controls.autoel.find('a:not(.bx-' + state + ')').addclass('active'); } } /** * updates the direction controls (checks if either should be hidden) */ var updatedirectioncontrols = function(){ if(getpagerqty() == 1){ slider.controls.prev.addclass('disabled'); slider.controls.next.addclass('disabled'); }else if(!slider.settings.infiniteloop && slider.settings.hidecontrolonend){ // if first slide if (slider.active.index == 0){ slider.controls.prev.addclass('disabled'); slider.controls.next.removeclass('disabled'); // if last slide }else if(slider.active.index == getpagerqty() - 1){ slider.controls.next.addclass('disabled'); slider.controls.prev.removeclass('disabled'); // if any slide in the middle }else{ slider.controls.prev.removeclass('disabled'); slider.controls.next.removeclass('disabled'); } } } /** * initialzes the auto process */ var initauto = function(){ // if autodelay was supplied, launch the auto show using a settimeout() call if(slider.settings.autodelay > 0){ var timeout = settimeout(el.startauto, slider.settings.autodelay); // if autodelay was not supplied, start the auto show normally }else{ el.startauto(); } // if autohover is requested if(slider.settings.autohover){ // on el hover el.hover(function(){ // if the auto show is currently playing (has an active interval) if(slider.interval){ // stop the auto show and pass true agument which will prevent control update el.stopauto(true); // create a new autopaused value which will be used by the relative "mouseout" event slider.autopaused = true; } }, function(){ // if the autopaused value was created be the prior "mouseover" event if(slider.autopaused){ // start the auto show and pass true agument which will prevent control update el.startauto(true); // reset the autopaused value slider.autopaused = null; } }); } } /** * initialzes the ticker process */ var initticker = function(){ var startposition = 0; // if autodirection is "next", append a clone of the entire slider if(slider.settings.autodirection == 'next'){ el.append(slider.children.clone().addclass('bx-clone')); // if autodirection is "prev", prepend a clone of the entire slider, and set the left position }else{ el.prepend(slider.children.clone().addclass('bx-clone')); var position = slider.children.first().position(); startposition = slider.settings.mode == 'horizontal' ? -position.left : -position.top; } setpositionproperty(startposition, 'reset', 0); // do not allow controls in ticker mode slider.settings.pager = false; slider.settings.controls = false; slider.settings.autocontrols = false; // if autohover is requested if(slider.settings.tickerhover && !slider.usingcss){ // on el hover slider.viewport.hover(function(){ el.stop(); }, function(){ // calculate the total width of children (used to calculate the speed ratio) var totaldimens = 0; slider.children.each(function(index){ totaldimens += slider.settings.mode == 'horizontal' ? $(this).outerwidth(true) : $(this).outerheight(true); }); // calculate the speed ratio (used to determine the new speed to finish the paused animation) var ratio = slider.settings.speed / totaldimens; // determine which property to use var property = slider.settings.mode == 'horizontal' ? 'left' : 'top'; // calculate the new speed var newspeed = ratio * (totaldimens - (math.abs(parseint(el.css(property))))); tickerloop(newspeed); }); } // start the ticker loop tickerloop(); } /** * runs a continuous loop, news ticker-style */ var tickerloop = function(resumespeed){ speed = resumespeed ? resumespeed : slider.settings.speed; var position = {left: 0, top: 0}; var reset = {left: 0, top: 0}; // if "next" animate left position to last child, then reset left to 0 if(slider.settings.autodirection == 'next'){ position = el.find('.bx-clone').first().position(); // if "prev" animate left position to 0, then reset left to first non-clone child }else{ reset = slider.children.first().position(); } var animateproperty = slider.settings.mode == 'horizontal' ? -position.left : -position.top; var resetvalue = slider.settings.mode == 'horizontal' ? -reset.left : -reset.top; var params = {resetvalue: resetvalue}; setpositionproperty(animateproperty, 'ticker', speed, params); } /** * initializes touch events */ var inittouch = function(){ // initialize object to contain all touch values slider.touch = { start: {x: 0, y: 0}, end: {x: 0, y: 0} } slider.viewport.bind('touchstart', ontouchstart); } /** * event handler for "touchstart" * * @param e (event) * - dom event object */ var ontouchstart = function(e){ if(slider.working){ e.preventdefault(); }else{ // record the original position when touch starts slider.touch.originalpos = el.position(); var orig = e.originalevent; // record the starting touch x, y coordinates slider.touch.start.x = orig.changedtouches[0].pagex; slider.touch.start.y = orig.changedtouches[0].pagey; // bind a "touchmove" event to the viewport slider.viewport.bind('touchmove', ontouchmove); // bind a "touchend" event to the viewport slider.viewport.bind('touchend', ontouchend); } } /** * event handler for "touchmove" * * @param e (event) * - dom event object */ var ontouchmove = function(e){ var orig = e.originalevent; // if scrolling on y axis, do not prevent default var xmovement = math.abs(orig.changedtouches[0].pagex - slider.touch.start.x); var ymovement = math.abs(orig.changedtouches[0].pagey - slider.touch.start.y); // x axis swipe if((xmovement * 3) > ymovement && slider.settings.preventdefaultswipex){ e.preventdefault(); // y axis swipe }else if((ymovement * 3) > xmovement && slider.settings.preventdefaultswipey){ e.preventdefault(); } if(slider.settings.mode != 'fade' && slider.settings.onetoonetouch){ var value = 0; // if horizontal, drag along x axis if(slider.settings.mode == 'horizontal'){ var change = orig.changedtouches[0].pagex - slider.touch.start.x; value = slider.touch.originalpos.left + change; // if vertical, drag along y axis } // else{ // var change = orig.changedtouches[0].pagey - slider.touch.start.y; // value = slider.touch.originalpos.top + change; // } setpositionproperty(value, 'reset', 0); } } /** * event handler for "touchend" * * @param e (event) * - dom event object */ var ontouchend = function(e){ slider.viewport.unbind('touchmove', ontouchmove); var orig = e.originalevent; var value = 0; // record end x, y positions slider.touch.end.x = orig.changedtouches[0].pagex; slider.touch.end.y = orig.changedtouches[0].pagey; // if fade mode, check if absolute x distance clears the threshold if(slider.settings.mode == 'fade'){ var distance = math.abs(slider.touch.start.x - slider.touch.end.x); if(distance >= slider.settings.swipethreshold){ slider.touch.start.x > slider.touch.end.x ? el.gotonextslide() : el.gotoprevslide(); el.stopauto(); } // not fade mode }else{ var distance = 0; // calculate distance and el's animate property if(slider.settings.mode == 'horizontal'){ distance = slider.touch.end.x - slider.touch.start.x; value = slider.touch.originalpos.left; }else{ distance = slider.touch.end.y - slider.touch.start.y; value = slider.touch.originalpos.top; } // if not infinite loop and first / last slide, do not attempt a slide transition if(!slider.settings.infiniteloop && ((slider.active.index == 0 && distance > 0) || (slider.active.last && distance < 0))){ setpositionproperty(value, 'reset', 200); }else{ // check if distance clears threshold if(math.abs(distance) >= slider.settings.swipethreshold){ distance < 0 ? el.gotonextslide() : el.gotoprevslide(); el.stopauto(); }else{ // el.animate(property, 200); setpositionproperty(value, 'reset', 200); } } } slider.viewport.unbind('touchend', ontouchend); } /** * window resize event callback */ var resizewindow = function(e){ // don't do anything if slider isn't initialized. if(!slider.initialized) return; // get the new window dimens (again, thank you ie) var windowwidthnew = $(window).width(); var windowheightnew = $(window).height(); // make sure that it is a true window resize // *we must check this because our dinosaur friend ie fires a window resize event when certain dom elements // are resized. can you just die already?* if(windowwidth != windowwidthnew || windowheight != windowheightnew){ // set the new window dimens windowwidth = windowwidthnew; windowheight = windowheightnew; // update all dynamic elements el.redrawslider(); // call user resize handler slider.settings.onsliderresize.call(el, slider.active.index); } } /** * =================================================================================== * = public functions * =================================================================================== */ /** * performs slide transition to the specified slide * * @param slideindex (int) * - the destination slide's index (zero-based) * * @param direction (string) * - internal use only - the direction of travel ("prev" / "next") */ el.gotoslide = function(slideindex, direction){ // if plugin is currently in motion, ignore request if(slider.working || slider.active.index == slideindex) return; // declare that plugin is in motion slider.working = true; // store the old index slider.oldindex = slider.active.index; // if slideindex is less than zero, set active index to last child (this happens during infinite loop) if(slideindex < 0){ slider.active.index = getpagerqty() - 1; // if slideindex is greater than children length, set active index to 0 (this happens during infinite loop) }else if(slideindex >= getpagerqty()){ slider.active.index = 0; // set active index to requested slide }else{ slider.active.index = slideindex; } // onslidebefore, onslidenext, onslideprev callbacks slider.settings.onslidebefore(slider.children.eq(slider.active.index), slider.oldindex, slider.active.index); if(direction == 'next'){ slider.settings.onslidenext(slider.children.eq(slider.active.index), slider.oldindex, slider.active.index); }else if(direction == 'prev'){ slider.settings.onslideprev(slider.children.eq(slider.active.index), slider.oldindex, slider.active.index); } // check if last slide slider.active.last = slider.active.index >= getpagerqty() - 1; // update the pager with active class if(slider.settings.pager) updatepageractive(slider.active.index); // // check for direction control update if(slider.settings.controls) updatedirectioncontrols(); // if slider is set to mode: "fade" if(slider.settings.mode == 'fade'){ // if adaptiveheight is true and next height is different from current height, animate to the new height if(slider.settings.adaptiveheight && slider.viewport.height() != getviewportheight()){ slider.viewport.animate({height: getviewportheight()}, slider.settings.adaptiveheightspeed); } // fade out the visible child and reset its z-index value slider.children.filter(':visible').fadeout(1000).css({zindex: 0});//slider.settings.speed // fade in the newly requested slide slider.children.eq(slider.active.index).css('zindex', slider.settings.slidezindex+1).stop(true,true).fadein(700, function(){ $(this).css('zindex', slider.settings.slidezindex); updateafterslidetransition(); }); // slider mode is not "fade" }else{ // if adaptiveheight is true and next height is different from current height, animate to the new height if(slider.settings.adaptiveheight && slider.viewport.height() != getviewportheight()){ slider.viewport.animate({height: getviewportheight()}, slider.settings.adaptiveheightspeed); } var moveby = 0; var position = {left: 0, top: 0}; // if carousel and not infinite loop if(!slider.settings.infiniteloop && slider.carousel && slider.active.last){ if(slider.settings.mode == 'horizontal'){ // get the last child position var lastchild = slider.children.eq(slider.children.length - 1); position = lastchild.position(); // calculate the position of the last slide moveby = slider.viewport.width() - lastchild.outerwidth(); }else{ // get last showing index position var lastshowingindex = slider.children.length - slider.settings.minslides; position = slider.children.eq(lastshowingindex).position(); } // horizontal carousel, going previous while on first slide (infiniteloop mode) }else if(slider.carousel && slider.active.last && direction == 'prev'){ // get the last child position var eq = slider.settings.moveslides == 1 ? slider.settings.maxslides - getmoveby() : ((getpagerqty() - 1) * getmoveby()) - (slider.children.length - slider.settings.maxslides); var lastchild = el.children('.bx-clone').eq(eq); position = lastchild.position(); // if infinite loop and "next" is clicked on the last slide }else if(direction == 'next' && slider.active.index == 0){ // get the last clone position position = el.find('> .bx-clone').eq(slider.settings.maxslides).position(); slider.active.last = false; // normal non-zero requests }else if(slideindex >= 0){ var requestel = slideindex * getmoveby(); position = slider.children.eq(requestel).position(); } /* if the position doesn't exist * (e.g. if you destroy the slider on a next click), * it doesn't throw an error. */ if ("undefined" !== typeof(position)) { var value = slider.settings.mode == 'horizontal' ? -(position.left - moveby) : -position.top; // plugin values to be animated setpositionproperty(value, 'slide', slider.settings.speed); } } } /** * transitions to the next slide in the show */ el.gotonextslide = function(){ // if infiniteloop is false and last page is showing, disregard call if (!slider.settings.infiniteloop && slider.active.last) return; var pagerindex = parseint(slider.active.index) + 1; el.gotoslide(pagerindex, 'next'); } /** * transitions to the prev slide in the show */ el.gotoprevslide = function(){ // if infiniteloop is false and last page is showing, disregard call if (!slider.settings.infiniteloop && slider.active.index == 0) return; var pagerindex = parseint(slider.active.index) - 1; el.gotoslide(pagerindex, 'prev'); } /** * starts the auto show * * @param preventcontrolupdate (boolean) * - if true, auto controls state will not be updated */ el.startauto = function(preventcontrolupdate){ // if an interval already exists, disregard call if(slider.interval) return; // create an interval slider.interval = setinterval(function(){ slider.settings.autodirection == 'next' ? el.gotonextslide() : el.gotoprevslide(); }, slider.settings.pause); // if auto controls are displayed and preventcontrolupdate is not true if (slider.settings.autocontrols && preventcontrolupdate != true) updateautocontrols('stop'); } /** * stops the auto show * * @param preventcontrolupdate (boolean) * - if true, auto controls state will not be updated */ el.stopauto = function(preventcontrolupdate){ // if no interval exists, disregard call if(!slider.interval) return; // clear the interval clearinterval(slider.interval); slider.interval = null; // if auto controls are displayed and preventcontrolupdate is not true if (slider.settings.autocontrols && preventcontrolupdate != true) updateautocontrols('start'); } /** * returns current slide index (zero-based) */ el.getcurrentslide = function(){ return slider.active.index; } /** * returns current slide element */ el.getcurrentslideelement = function(){ return slider.children.eq(slider.active.index); } /** * returns number of slides in show */ el.getslidecount = function(){ return slider.children.length; } /** * update all dynamic slider elements */ el.redrawslider = function(){ // resize all children in ratio to new screen size slider.children.add(el.find('.bx-clone')).width(getslidewidth()); // adjust the height slider.viewport.css('height', getviewportheight()); // update the slide position if(!slider.settings.ticker) setslideposition(); // if active.last was true before the screen resize, we want // to keep it last no matter what screen size we end on if (slider.active.last) slider.active.index = getpagerqty() - 1; // if the active index (page) no longer exists due to the resize, simply set the index as last if (slider.active.index >= getpagerqty()) slider.active.last = true; // if a pager is being displayed and a custom pager is not being used, update it if(slider.settings.pager && !slider.settings.pagercustom){ populatepager(); updatepageractive(slider.active.index); } } /** * destroy the current instance of the slider (revert everything back to original state) */ el.destroyslider = function(){ // don't do anything if slider has already been destroyed if(!slider.initialized) return; slider.initialized = false; $('.bx-clone', this).remove(); slider.children.each(function() { $(this).data("origstyle") != undefined ? $(this).attr("style", $(this).data("origstyle")) : $(this).removeattr('style'); }); $(this).data("origstyle") != undefined ? this.attr("style", $(this).data("origstyle")) : $(this).removeattr('style'); $(this).unwrap().unwrap(); if(slider.controls.el) slider.controls.el.remove(); if(slider.controls.next) slider.controls.next.remove(); if(slider.controls.prev) slider.controls.prev.remove(); if(slider.pagerel && slider.settings.controls) slider.pagerel.remove(); $('.bx-caption', this).remove(); if(slider.controls.autoel) slider.controls.autoel.remove(); clearinterval(slider.interval); if(slider.settings.responsive) $(window).unbind('resize', resizewindow); } /** * reload the slider (revert all dom changes, and re-initialize) */ el.reloadslider = function(settings){ if (settings != undefined) options = settings; el.destroyslider(); init(); } init(); // returns the current jquery object return this; } })(jquery); /*********************************************************************************************/ // 渐入效果 /*********************************************************************************************/ (function(jquery){ $.fn.scrollclass = function(config){ var defaults = {}; var config = jquery.extend(defaults, config); var target = this; function addaction(){ var length = target.length; for(var i=0; i