} 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("<div class=\"owl-wrapper\">").wrap("<div class=\"owl-item\"></div>");
base.$elem.find(".owl-wrapper").wrap("<div class=\"owl-wrapper-outer\">");
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 = $("<div class=\"owl-controls\"/>").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 = $("<div class=\"owl-buttons\"/>");
base.owlControls.append(buttonsWrapper);
base.buttonPrev = $("<div/>", {
"class" : "owl-prev",
"html" : base.options.navigationText[0] || ""
});
base.buttonNext = $("<div/>", {
"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 = $("<div class=\"owl-pagination\"/>");
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 = $("<div/>", {
"class" : "owl-page"
});
paginationButtonInner = $("<span></span>", {
"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);