(function(factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('jquery'));
} else {
factory(jQuery);
}
}(function($) {
var instanceNum = 0,
$html = $('html'),
$document = $(document),
$window = $(window);
function SimpleLightbox(options) {
this.init.apply(this, arguments);
}
SimpleLightbox.defaults = {
// add custom classes to lightbox elements
elementClass: '',
elementLoadingClass: 'slbLoading',
htmlClass: 'slbActive',
closeBtnClass: '',
nextBtnClass: '',
prevBtnClass: '',
loadingTextClass: '',
// customize / localize controls captions
closeBtnCaption: 'Close',
nextBtnCaption: 'Next',
prevBtnCaption: 'Previous',
loadingCaption: 'Loading...',
bindToItems: true, // set click event handler to trigger lightbox on provided $items
closeOnOverlayClick: true,
closeOnEscapeKey: true,
nextOnImageClick: true,
showCaptions: true,
captionAttribute: 'title', // choose data source for library to glean image caption from
urlAttribute: 'href', // where to expect large image
startAt: 0, // start gallery at custom index
loadingTimeout: 100, // time after loading element will appear
appendTarget: 'body', // append elsewhere if needed
beforeSetContent: null, // convenient hooks for extending library behavoiur
beforeClose: null,
beforeDestroy: null,
videoRegex: new RegExp(/youtube.com|vimeo.com/) // regex which tests load url for iframe content
};
$.extend(SimpleLightbox.prototype, {
init: function(options) {
this.options = $.extend({}, SimpleLightbox.defaults, options);
this.ens = '.slb' + (++instanceNum);
this.items = [];
this.captions = [];
var self = this;
if (this.options.$items) {
this.$items = this.options.$items;
this.$items.each(function() {
var $item = $(this);
self.items.push($item.attr(self.options.urlAttribute));
self.captions.push($item.attr(self.options.captionAttribute));
});
this.options.bindToItems && this.$items.on('click' + this.ens, function(e) {
e.preventDefault();
self.showPosition(self.$items.index($(e.currentTarget)));
});
} else if (this.options.items) {
this.items = this.options.items;
}
if (this.options.captions) {
this.captions = this.options.captions;
}
},
next: function() {
return this.showPosition(this.currentPosition + 1);
},
prev: function() {
return this.showPosition(this.currentPosition - 1);
},
normalizePosition: function(position) {
if (position >= this.items.length) {
position = 0;
} else if (position < 0) {
position = this.items.length - 1;
}
return position;
},
showPosition: function(position) {
var self = this;
this.currentPosition = this.normalizePosition(position);
return this.setupLightboxHtml().prepareItem(this.currentPosition, this.setContent).show();
},
loading: function(on) {
var self = this;
if (on) {
this.loadingTimeout = setTimeout(function() {
self.$el.addClass(self.options.elementLoadingClass);
self.$content.html('
' + self.options.loadingCaption + '
');
self.show();
}, this.options.loadingTimeout);
} else {
this.$el && this.$el.removeClass(this.options.elementLoadingClass);
clearTimeout(this.loadingTimeout);
}
},
prepareItem: function(position, callback) {
var self = this,
url = this.items[position];
this.loading(true);
if (this.options.videoRegex.test(url)) {
callback.call(self, $(''));
} else {
var $imageCont = $('');
this.$currentImage = $imageCont.find('.slbImage');
if (this.options.showCaptions && this.captions[position]) {
$imageCont.append('' + this.captions[position] + '
');
}
this.loadImage(url, function() {
self.setImageDimensions();
callback.call(self, $imageCont);
self.loadImage(self.items[self.normalizePosition(self.currentPosition + 1)]);
});
}
return this;
},
loadImage: function(url, callback) {
if (!this.options.videoRegex.test(url)) {
var image = new Image();
callback && (image.onload = callback);
image.src = url;
}
},
setupLightboxHtml: function() {
var o = this.options;
if (!this.$el) {
this.$el = $(
''
);
if (this.items.length > 1) {
$(
'' +
'' +
'' +
'
'
).appendTo(this.$el.find('.slbContentOuter'));
}
this.$content = this.$el.find('.slbContent');
}
this.$content.empty();
return this;
},
show: function() {
if (!this.modalInDom) {
this.$el.appendTo($(this.options.appendTarget));
$html.addClass(this.options.htmlClass);
this.setupLightboxEvents();
this.modalInDom = true;
}
return this;
},
setContent: function(content) {
var $content = $(content);
this.loading(false);
this.setupLightboxHtml();
this.options.beforeSetContent && this.options.beforeSetContent($content, this);
this.$content.html($content);
return this;
},
setImageDimensions: function() {
this.$currentImage && this.$currentImage.css('max-height', $window.height() + 'px');
},
setupLightboxEvents: function() {
var self = this;
if (!this.lightboxEventsSetuped) {
this.$el.on('click' + this.ens, function(e) {
var $target = $(e.target);
if ($target.is('.slbCloseBtn') || (self.options.closeOnOverlayClick && $target.is('.slbWrap'))) {
self.close();
} else if ($target.is('.slbArrow')) {
$target.hasClass('next') ? self.next() : self.prev();
} else if (self.options.nextOnImageClick && self.items.length > 1 && $target.is('.slbImage')) {
self.next();
}
});
$document.on('keyup' + this.ens, function(e) {
self.options.closeOnEscapeKey && e.keyCode === 27 && self.close();
if (self.items.length > 1) {
(e.keyCode === 39 || e.keyCode === 68) && self.next();
(e.keyCode === 37 || e.keyCode === 65) && self.prev();
}
});
$window.on('resize' + this.ens, function() {
self.setImageDimensions();
});
this.lightboxEventsSetuped = true;
}
},
close: function() {
if (this.modalInDom) {
this.options.beforeClose && this.options.beforeClose(this);
this.$el && this.$el.off(this.ens);
$document.off(this.ens);
$window.off(this.ens);
this.lightboxEventsSetuped = false;
this.$el.detach();
$html.removeClass(this.options.htmlClass);
this.modalInDom = false;
}
},
destroy: function() {
this.close();
this.options.beforeDestroy && this.options.beforeDestroy(this);
this.$items && this.$items.off(this.ens);
this.$el && this.$el.remove();
}
});
SimpleLightbox.open = function(options) {
var instance = new SimpleLightbox(options);
return options.content ? instance.setContent(options.content).show() : instance.showPosition(instance.options.startAt);
};
$.fn.simpleLightbox = function(options) {
var lightboxInstance,
$items = this;
return this.each(function() {
if (!$.data(this, 'simpleLightbox')) {
lightboxInstance = lightboxInstance || new SimpleLightbox($.extend({}, options, {$items: $items}));
$.data(this, 'simpleLightbox', lightboxInstance);
}
});
};
$.simpleLightbox = $.SimpleLightbox = SimpleLightbox;
return $;
}));
/*
* 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 = $("