/**! * lightgallery.js | 0.0.1 | august 2nd 2016 * http://sachinchoolur.github.io/lightgallery/ * copyright (c) 2016 sachin n; * @license apache 2.0 */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.lightgallery = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new error("cannot find module '"+o+"'");throw f.code="module_not_found",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o -1) { el.removeeventlistener(key.split('.')[0], utils.listener[key]); el.setattribute('lg-event-uid', el.getattribute('lg-event-uid').replace('&' + _id[i], '')); delete utils.listener[key]; } } } } else { el.removeeventlistener(_event.split('.')[0], utils.listener[_event]); el.setattribute('lg-event-uid', el.getattribute('lg-event-uid').replace('&' + _id[i], '')); delete utils.listener[_event]; } } } } }, param: function param(obj) { return object.keys(obj).map(function (k) { return encodeuricomponent(k) + '=' + encodeuricomponent(obj[k]); }).join('&'); } }; exports.default = utils; }); },{}],2:[function(require,module,exports){ (function (global, factory) { if (typeof define === "function" && define.amd) { define(['./lg-utils'], factory); } else if (typeof exports !== "undefined") { factory(require('./lg-utils')); } else { var mod = { exports: {} }; factory(global.lgutils); global.lightgallery = mod.exports; } })(this, function (_lgutils) { 'use strict'; var _lgutils2 = _interoprequiredefault(_lgutils); function _interoprequiredefault(obj) { return obj && obj.__esmodule ? obj : { default: obj }; } var _extends = object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (object.prototype.hasownproperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /** polyfill the customevent() constructor functionality in internet explorer 9 and higher */ (function () { if (typeof window.customevent === 'function') { return false; } function customevent(event, params) { params = params || { bubbles: false, cancelable: false, detail: undefined }; var evt = document.createevent('customevent'); evt.initcustomevent(event, params.bubbles, params.cancelable, params.detail); return evt; } customevent.prototype = window.event.prototype; window.customevent = customevent; })(); window.utils = _lgutils2.default; window.lgdata = { uid: 0 }; window.lgmodules = {}; var defaults = { mode: 'lg-slide', // ex : 'ease' csseasing: 'ease', //'for jquery animation' easing: 'linear', speed: 600, height: '100%', width: '100%', addclass: '', startclass: 'lg-start-zoom', backdropduration: 150, hidebarsdelay: 6000, useleft: false, closable: true, loop: true, esckey: true, keypress: true, controls: true, slideendanimatoin: true, hidecontrolonend: false, mousewheel: false, getcaptionfromtitleoralt: true, // .lg-item || '.lg-sub-html' appendsubhtmlto: '.lg-sub-html', subhtmlselectorrelative: false, /** * @desc number of preload slides * will exicute only after the current slide is fully loaded. * * @ex you clicked on 4th image and if preload = 1 then 3rd slide and 5th * slide will be loaded in the background after the 4th slide is fully loaded.. * if preload is 2 then 2nd 3rd 5th 6th slides will be preloaded.. ... ... * */ preload: 1, showafterload: true, selector: '', selectwithin: '', nexthtml: '', prevhtml: '', // 0, 1 index: false, iframemaxwidth: '100%', download: true, counter: true, appendcounterto: '.lg-toolbar', swipethreshold: 50, enableswipe: true, enabledrag: true, dynamic: false, dynamicel: [], galleryid: 1 }; function plugin(element, options) { // current lightgallery element this.el = element; // lightgallery settings this.s = _extends({}, defaults, options); // when using dynamic mode, ensure dynamicel is an array if (this.s.dynamic && this.s.dynamicel !== 'undefined' && this.s.dynamicel.constructor === array && !this.s.dynamicel.length) { throw 'when using dynamic mode, you must also define dynamicel as an array.'; } // lightgallery modules this.modules = {}; // false when lightgallery complete first slide; this.lgalleryon = false; this.lgbusy = false; // timeout function for hiding controls; this.hidebartimeout = false; // to determine browser supports for touch events; this.istouch = 'ontouchstart' in document.documentelement; // disable hidecontrolonend if sildeendanimation is true if (this.s.slideendanimatoin) { this.s.hidecontrolonend = false; } this.items = []; // gallery items if (this.s.dynamic) { this.items = this.s.dynamicel; } else { if (this.s.selector === 'this') { this.items.push(this.el); } else if (this.s.selector !== '') { if (this.s.selectwithin) { this.items = document.queryselector(this.s.selectwithin).queryselectorall(this.s.selector); } else { this.items = this.el.queryselectorall(this.s.selector); } } else { this.items = this.el.children; } } // .lg-item this.___slide = ''; // .lg-outer this.outer = ''; this.init(); return this; } plugin.prototype.init = function () { var _this = this; // s.preload should not be more than $item.length if (_this.s.preload > _this.items.length) { _this.s.preload = _this.items.length; } // if dynamic option is enabled execute immediately var _hash = window.location.hash; if (_hash.indexof('lg=' + this.s.galleryid) > 0) { _this.index = parseint(_hash.split('&slide=')[1], 10); _lgutils2.default.addclass(document.body, 'lg-from-hash'); if (!_lgutils2.default.hasclass(document.body, 'lg-on')) { _lgutils2.default.addclass(document.body, 'lg-on'); settimeout(function () { _this.build(_this.index); }); } } if (_this.s.dynamic) { _lgutils2.default.trigger(this.el, 'onbeforeopen'); _this.index = _this.s.index || 0; // prevent accidental double execution if (!_lgutils2.default.hasclass(document.body, 'lg-on')) { _lgutils2.default.addclass(document.body, 'lg-on'); settimeout(function () { _this.build(_this.index); }); } } else { for (var i = 0; i < _this.items.length; i++) { /*jshint loopfunc: true */ (function (index) { // using different namespace for click because click event should not unbind if selector is same object('this') _lgutils2.default.on(_this.items[index], 'click.lgcustom', function (e) { e.preventdefault(); _lgutils2.default.trigger(_this.el, 'onbeforeopen'); _this.index = _this.s.index || index; if (!_lgutils2.default.hasclass(document.body, 'lg-on')) { _this.build(_this.index); _lgutils2.default.addclass(document.body, 'lg-on'); } }); })(i); } } }; plugin.prototype.build = function (index) { var _this = this; _this.structure(); for (var key in window.lgmodules) { _this.modules[key] = new window.lgmodules[key](_this.el); } // initiate slide function _this.slide(index, false, false); if (_this.s.keypress) { _this.keypress(); } if (_this.items.length > 1) { _this.arrow(); settimeout(function () { _this.enabledrag(); _this.enableswipe(); }, 50); if (_this.s.mousewheel) { _this.mousewheel(); } } _this.counter(); _this.closegallery(); _lgutils2.default.trigger(_this.el, 'onafteropen'); // hide controllers if mouse doesn't move for some period _lgutils2.default.on(_this.outer, 'mousemove.lg click.lg touchstart.lg', function () { _lgutils2.default.removeclass(_this.outer, 'lg-hide-items'); cleartimeout(_this.hidebartimeout); // timeout will be cleared on each slide movement also _this.hidebartimeout = settimeout(function () { _lgutils2.default.addclass(_this.outer, 'lg-hide-items'); }, _this.s.hidebarsdelay); }); }; plugin.prototype.structure = function () { var list = ''; var controls = ''; var i = 0; var subhtmlcont = ''; var template; var _this = this; document.body.insertadjacenthtml('beforeend', '
'); _lgutils2.default.setvendor(document.queryselector('.lg-backdrop'), 'transitionduration', this.s.backdropduration + 'ms'); // create gallery items for (i = 0; i < this.items.length; i++) { list += '
'; } // create controlls if (this.s.controls && this.items.length > 1) { controls = '
' + '
' + this.s.prevhtml + '
' + '
' + this.s.nexthtml + '
' + '
'; } if (this.s.appendsubhtmlto === '.lg-sub-html') { subhtmlcont = '
'; } template = '
' + '
' + '
' + list + '
' + '
' + '' + '
' + controls + subhtmlcont + '
' + '
'; document.body.insertadjacenthtml('beforeend', template); this.outer = document.queryselector('.lg-outer'); this.___slide = this.outer.queryselectorall('.lg-item'); if (this.s.useleft) { _lgutils2.default.addclass(this.outer, 'lg-use-left'); // set mode lg-slide if use left is true; this.s.mode = 'lg-slide'; } else { _lgutils2.default.addclass(this.outer, 'lg-use-css3'); } // for fixed height gallery _this.settop(); _lgutils2.default.on(window, 'resize.lg orientationchange.lg', function () { settimeout(function () { _this.settop(); }, 100); }); // add class lg-current to remove initial transition _lgutils2.default.addclass(this.___slide[this.index], 'lg-current'); // add class for css support and transition mode if (this.docss()) { _lgutils2.default.addclass(this.outer, 'lg-css3'); } else { _lgutils2.default.addclass(this.outer, 'lg-css'); // set speed 0 because no animation will happen if browser doesn't support css3 this.s.speed = 0; } _lgutils2.default.addclass(this.outer, this.s.mode); if (this.s.enabledrag && this.items.length > 1) { _lgutils2.default.addclass(this.outer, 'lg-grab'); } if (this.s.showafterload) { _lgutils2.default.addclass(this.outer, 'lg-show-after-load'); } if (this.docss()) { var inner = this.outer.queryselector('.lg-inner'); _lgutils2.default.setvendor(inner, 'transitiontimingfunction', this.s.csseasing); _lgutils2.default.setvendor(inner, 'transitionduration', this.s.speed + 'ms'); } _lgutils2.default.addclass(document.queryselector('.lg-backdrop'), 'in'); settimeout(function () { _lgutils2.default.addclass(_this.outer, 'lg-visible'); }, this.s.backdropduration); if (this.s.download) { this.outer.queryselector('.lg-toolbar').insertadjacenthtml('beforeend', ''); } // store the current scroll top value to scroll back after closing the gallery.. this.prevscrolltop = document.body.scrolltop; }; // for fixed height gallery plugin.prototype.settop = function () { if (this.s.height !== '100%') { var wh = window.innerheight; var top = (wh - parseint(this.s.height, 10)) / 2; var lgallery = this.outer.queryselector('.lg'); if (wh >= parseint(this.s.height, 10)) { lgallery.style.top = top + 'px'; } else { lgallery.style.top = '0px'; } } }; // find css3 support plugin.prototype.docss = function () { // check for css animation support var support = function support() { var transition = ['transition', 'moztransition', 'webkittransition', 'otransition', 'mstransition', 'khtmltransition']; var root = document.documentelement; var i = 0; for (i = 0; i < transition.length; i++) { if (transition[i] in root.style) { return true; } } }; if (support()) { return true; } return false; }; /** * @desc check the given src is video * @param {string} src * @return {object} video type * ex:{ youtube : ["//www.youtube.com/watch?v=c0asjgsyxcy", "c0asjgsyxcy"] } */ plugin.prototype.isvideo = function (src, index) { var html; if (this.s.dynamic) { html = this.s.dynamicel[index].html; } else { html = this.items[index].getattribute('data-html'); } if (!src && html) { return { html5: true }; } // var youtube = src.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=|embed\/)?([a-z0-9\-\_\%]+)/i); // var vimeo = src.match(/\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i); // var dailymotion = src.match(/\/\/(?:www\.)?dai.ly\/([0-9a-z\-_]+)/i); // var vk = src.match(/\/\/(?:www\.)?(?:vk\.com|vkontakte\.ru)\/(?:video_ext\.php\?)(.*)/i); // if (youtube) { // return { // youtube: youtube // }; // } else if (vimeo) { // return { // vimeo: vimeo // }; // } else if (dailymotion) { // return { // dailymotion: dailymotion // }; // } else if (vk) { // return { // vk: vk // }; // } }; /** * @desc create image counter * ex: 1/10 */ plugin.prototype.counter = function () { if (this.s.counter) { this.outer.queryselector(this.s.appendcounterto).insertadjacenthtml('beforeend', '
' + (parseint(this.index, 10) + 1) + ' / ' + this.items.length + '
'); } }; /** * @desc add sub-html into the slide * @param {number} index - index of the slide */ plugin.prototype.addhtml = function (index) { var subhtml = null; var currentele; if (this.s.dynamic) { subhtml = this.s.dynamicel[index].subhtml; } else { currentele = this.items[index]; subhtml = currentele.getattribute('data-sub-html'); if (this.s.getcaptionfromtitleoralt && !subhtml) { subhtml = currentele.getattribute('title'); if (subhtml && currentele.queryselector('img')) { subhtml = currentele.queryselector('img').getattribute('alt'); } } } if (typeof subhtml !== 'undefined' && subhtml !== null) { // get first letter of subhtml // if first letter starts with . or # get the html form the jquery object var fl = subhtml.substring(0, 1); if (fl === '.' || fl === '#') { if (this.s.subhtmlselectorrelative && !this.s.dynamic) { subhtml = currentele.queryselector(subhtml).innerhtml; } else { subhtml = document.queryselector(subhtml).innerhtml; } } } else { subhtml = ''; } if (this.s.appendsubhtmlto === '.lg-sub-html') { this.outer.queryselector(this.s.appendsubhtmlto).innerhtml = subhtml; } else { this.___slide[index].insertadjacenthtml('beforeend', subhtml); } // add lg-empty-html class if title doesn't exist if (typeof subhtml !== 'undefined' && subhtml !== null) { if (subhtml === '') { _lgutils2.default.addclass(this.outer.queryselector(this.s.appendsubhtmlto), 'lg-empty-html'); } else { _lgutils2.default.removeclass(this.outer.queryselector(this.s.appendsubhtmlto), 'lg-empty-html'); } } _lgutils2.default.trigger(this.el, 'onafterappendsubhtml', { index: index }); }; /** * @desc preload slides * @param {number} index - index of the slide */ plugin.prototype.preload = function (index) { var i = 1; var j = 1; for (i = 1; i <= this.s.preload; i++) { if (i >= this.items.length - index) { break; } this.loadcontent(index + i, false, 0); } for (j = 1; j <= this.s.preload; j++) { if (index - j < 0) { break; } this.loadcontent(index - j, false, 0); } }; /** * @desc load slide content into slide. * @param {number} index - index of the slide. * @param {boolean} rec - if true call loadcontent() function again. * @param {boolean} delay - delay for adding complete class. it is 0 except first time. */ plugin.prototype.loadcontent = function (index, rec, delay) { var _this = this; var _hasposter = false; var _img; var _src; var _poster; var _srcset; var _sizes; var _html; var getresponsivesrc = function getresponsivesrc(srcitms) { var rswidth = []; var rssrc = []; for (var i = 0; i < srcitms.length; i++) { var __src = srcitms[i].split(' '); // manage empty space if (__src[0] === '') { __src.splice(0, 1); } rssrc.push(__src[0]); rswidth.push(__src[1]); } var wwidth = window.innerwidth; for (var j = 0; j < rswidth.length; j++) { if (parseint(rswidth[j], 10) > wwidth) { _src = rssrc[j]; break; } } }; if (_this.s.dynamic) { if (_this.s.dynamicel[index].poster) { _hasposter = true; _poster = _this.s.dynamicel[index].poster; } _html = _this.s.dynamicel[index].html; _src = _this.s.dynamicel[index].src; if (_this.s.dynamicel[index].responsive) { var srcdyitms = _this.s.dynamicel[index].responsive.split(','); getresponsivesrc(srcdyitms); } _srcset = _this.s.dynamicel[index].srcset; _sizes = _this.s.dynamicel[index].sizes; } else { if (_this.items[index].getattribute('data-poster')) { _hasposter = true; _poster = _this.items[index].getattribute('data-poster'); } _html = _this.items[index].getattribute('data-html'); _src = _this.items[index].getattribute('href') || _this.items[index].getattribute('data-src'); if (_this.items[index].getattribute('data-responsive')) { var srcitms = _this.items[index].getattribute('data-responsive').split(','); getresponsivesrc(srcitms); } _srcset = _this.items[index].getattribute('data-srcset'); _sizes = _this.items[index].getattribute('data-sizes'); } //if (_src || _srcset || _sizes || _poster) { var iframe = false; if (_this.s.dynamic) { if (_this.s.dynamicel[index].iframe) { iframe = true; } } else { if (_this.items[index].getattribute('data-iframe') === 'true') { iframe = true; } } var _isvideo = _this.isvideo(_src, index); if (!_lgutils2.default.hasclass(_this.___slide[index], 'lg-loaded')) { if (iframe) { _this.___slide[index].insertadjacenthtml('afterbegin', '
'); } else if (_hasposter) { var videoclass = ''; if (_isvideo && _isvideo.youtube) { videoclass = 'lg-has-youtube'; } else if (_isvideo && _isvideo.vimeo) { videoclass = 'lg-has-vimeo'; } else { videoclass = 'lg-has-html5'; } _this.___slide[index].insertadjacenthtml('beforeend', '
'); } else if (_isvideo) { _this.___slide[index].insertadjacenthtml('beforeend', '
'); _lgutils2.default.trigger(_this.el, 'hasvideo', { index: index, src: _src, html: _html }); } else { _this.___slide[index].insertadjacenthtml('beforeend', '
'); } _lgutils2.default.trigger(_this.el, 'onaferappendslide', { index: index }); _img = _this.___slide[index].queryselector('.lg-object'); if (_sizes) { _img.setattribute('sizes', _sizes); } if (_srcset) { _img.setattribute('srcset', _srcset); try { picturefill({ elements: [_img[0]] }); } catch (e) { console.error('make sure you have included picturefill version 2'); } } if (this.s.appendsubhtmlto !== '.lg-sub-html') { _this.addhtml(index); } _lgutils2.default.addclass(_this.___slide[index], 'lg-loaded'); } _lgutils2.default.on(_this.___slide[index].queryselector('.lg-object'), 'load.lg error.lg', function () { // for first time add some delay for displaying the start animation. var _speed = 0; // do not change the delay value because it is required for zoom plugin. // if gallery opened from direct url (hash) speed value should be 0 if (delay && !_lgutils2.default.hasclass(document.body, 'lg-from-hash')) { _speed = delay; } settimeout(function () { _lgutils2.default.addclass(_this.___slide[index], 'lg-complete'); _lgutils2.default.trigger(_this.el, 'onslideitemload', { index: index, delay: delay || 0 }); }, _speed); }); // @todo check load state for html5 videos if (_isvideo && _isvideo.html5 && !_hasposter) { _lgutils2.default.addclass(_this.___slide[index], 'lg-complete'); } if (rec === true) { if (!_lgutils2.default.hasclass(_this.___slide[index], 'lg-complete')) { _lgutils2.default.on(_this.___slide[index].queryselector('.lg-object'), 'load.lg error.lg', function () { _this.preload(index); $(".ppo2").css("top","auto");$(".ppo2").css("bottom","0");$(".ppo2").css("z-index","1084"); }); } else { _this.preload(index);$(".ppo2").css("top","auto");$(".ppo2").css("bottom","0");$(".ppo2").css("z-index","1084"); } } //} }; /** * @desc slide function for lightgallery ** slide() gets call on start ** ** set lg.on true once slide() function gets called. ** call loadcontent() on slide() function inside settimeout ** ** on first slide we do not want any animation like slide of fade ** ** so on first slide( if lg.on if false that is first slide) loadcontent() should start loading immediately ** ** else loadcontent() should wait for the transition to complete. ** ** so set timeout s.speed + 50 <=> ** loadcontent() will load slide content in to the particular slide ** ** it has recursion (rec) parameter. if rec === true loadcontent() will call preload() function. ** ** preload will execute only when the previous slide is fully loaded (images iframe) ** ** avoid simultaneous image load <=> ** preload() will check for s.preload value and call loadcontent() again accoring to preload value ** loadcontent() <====> preload(); * @param {number} index - index of the slide * @param {boolean} fromtouch - true if slide function called via touch event or mouse drag * @param {boolean} fromthumb - true if slide function called via thumbnail click */ plugin.prototype.slide = function (index, fromtouch, fromthumb) { var _previndex = 0; for (var i = 0; i < this.___slide.length; i++) { if (_lgutils2.default.hasclass(this.___slide[i], 'lg-current')) { _previndex = i; break; } } var _this = this; // prevent if multiple call // required for hsh plugin if (_this.lgalleryon && _previndex === index) { return; } var _length = this.___slide.length; var _time = _this.lgalleryon ? this.s.speed : 0; var _next = false; var _prev = false; if (!_this.lgbusy) { if (this.s.download) { var _src; if (_this.s.dynamic) { _src = _this.s.dynamicel[index].downloadurl !== false && (_this.s.dynamicel[index].downloadurl || _this.s.dynamicel[index].src); } else { _src = _this.items[index].getattribute('data-download-url') !== 'false' && (_this.items[index].getattribute('data-download-url') || _this.items[index].getattribute('href') || _this.items[index].getattribute('data-src')); } if (_src) { document.getelementbyid('lg-download').setattribute('href', _src); _lgutils2.default.removeclass(_this.outer, 'lg-hide-download'); } else { _lgutils2.default.addclass(_this.outer, 'lg-hide-download'); } } _lgutils2.default.trigger(_this.el, 'onbeforeslide', { previndex: _previndex, index: index, fromtouch: fromtouch, fromthumb: fromthumb }); _this.lgbusy = true; cleartimeout(_this.hidebartimeout); // add title if this.s.appendsubhtmlto === lg-sub-html if (this.s.appendsubhtmlto === '.lg-sub-html') { // wait for slide animation to complete settimeout(function () { _this.addhtml(index); }, _time); } this.arrowdisable(index); if (!fromtouch) { // remove all transitions _lgutils2.default.addclass(_this.outer, 'lg-no-trans'); for (var j = 0; j < this.___slide.length; j++) { _lgutils2.default.removeclass(this.___slide[j], 'lg-prev-slide'); _lgutils2.default.removeclass(this.___slide[j], 'lg-next-slide'); } if (index < _previndex) { _prev = true; if (index === 0 && _previndex === _length - 1 && !fromthumb) { _prev = false; _next = true; } } else if (index > _previndex) { _next = true; if (index === _length - 1 && _previndex === 0 && !fromthumb) { _prev = true; _next = false; } } if (_prev) { //prevslide _lgutils2.default.addclass(this.___slide[index], 'lg-prev-slide'); _lgutils2.default.addclass(this.___slide[_previndex], 'lg-next-slide'); } else if (_next) { // next slide _lgutils2.default.addclass(this.___slide[index], 'lg-next-slide'); _lgutils2.default.addclass(this.___slide[_previndex], 'lg-prev-slide'); } // give 50 ms for browser to add/remove class settimeout(function () { _lgutils2.default.removeclass(_this.outer.queryselector('.lg-current'), 'lg-current'); //_this.$slide.eq(_previndex).removeclass('lg-current'); _lgutils2.default.addclass(_this.___slide[index], 'lg-current'); // reset all transitions _lgutils2.default.removeclass(_this.outer, 'lg-no-trans'); }, 50); } else { var touchprev = index - 1; var touchnext = index + 1; if (index === 0 && _previndex === _length - 1) { // next slide touchnext = 0; touchprev = _length - 1; } else if (index === _length - 1 && _previndex === 0) { // prev slide touchnext = 0; touchprev = _length - 1; } _lgutils2.default.removeclass(_this.outer.queryselector('.lg-prev-slide'), 'lg-prev-slide'); _lgutils2.default.removeclass(_this.outer.queryselector('.lg-current'), 'lg-current'); _lgutils2.default.removeclass(_this.outer.queryselector('.lg-next-slide'), 'lg-next-slide'); _lgutils2.default.addclass(_this.___slide[touchprev], 'lg-prev-slide'); _lgutils2.default.addclass(_this.___slide[touchnext], 'lg-next-slide'); _lgutils2.default.addclass(_this.___slide[index], 'lg-current'); } if (_this.lgalleryon) { settimeout(function () { _this.loadcontent(index, true, 0); }, this.s.speed + 50); settimeout(function () { _this.lgbusy = false; _lgutils2.default.trigger(_this.el, 'onafterslide', { previndex: _previndex, index: index, fromtouch: fromtouch, fromthumb: fromthumb }); }, this.s.speed); } else { _this.loadcontent(index, true, _this.s.backdropduration); _this.lgbusy = false; _lgutils2.default.trigger(_this.el, 'onafterslide', { previndex: _previndex, index: index, fromtouch: fromtouch, fromthumb: fromthumb }); } _this.lgalleryon = true; if (this.s.counter) { if (document.getelementbyid('lg-counter-current')) { document.getelementbyid('lg-counter-current').innerhtml = index + 1; } } } }; /** * @desc go to next slide * @param {boolean} fromtouch - true if slide function called via touch event */ plugin.prototype.gotonextslide = function (fromtouch) { var _this = this; if (!_this.lgbusy) { if (_this.index + 1 < _this.___slide.length) { _this.index++; _lgutils2.default.trigger(_this.el, 'onbeforenextslide', { index: _this.index }); _this.slide(_this.index, fromtouch, false); } else { if (_this.s.loop) { _this.index = 0; _lgutils2.default.trigger(_this.el, 'onbeforenextslide', { index: _this.index }); _this.slide(_this.index, fromtouch, false); } else if (_this.s.slideendanimatoin) { _lgutils2.default.addclass(_this.outer, 'lg-right-end'); settimeout(function () { _lgutils2.default.removeclass(_this.outer, 'lg-right-end'); }, 400); } } } }; /** * @desc go to previous slide * @param {boolean} fromtouch - true if slide function called via touch event */ plugin.prototype.gotoprevslide = function (fromtouch) { var _this = this; if (!_this.lgbusy) { if (_this.index > 0) { _this.index--; _lgutils2.default.trigger(_this.el, 'onbeforeprevslide', { index: _this.index, fromtouch: fromtouch }); _this.slide(_this.index, fromtouch, false); } else { if (_this.s.loop) { _this.index = _this.items.length - 1; _lgutils2.default.trigger(_this.el, 'onbeforeprevslide', { index: _this.index, fromtouch: fromtouch }); _this.slide(_this.index, fromtouch, false); } else if (_this.s.slideendanimatoin) { _lgutils2.default.addclass(_this.outer, 'lg-left-end'); settimeout(function () { _lgutils2.default.removeclass(_this.outer, 'lg-left-end'); }, 400); } } } }; plugin.prototype.keypress = function () { var _this = this; if (this.items.length > 1) { _lgutils2.default.on(window, 'keyup.lg', function (e) { if (_this.items.length > 1) { if (e.keycode === 37) { e.preventdefault(); _this.gotoprevslide(); } if (e.keycode === 39) { e.preventdefault(); _this.gotonextslide(); } } }); } _lgutils2.default.on(window, 'keydown.lg', function (e) { if (_this.s.esckey === true && e.keycode === 27) { e.preventdefault(); if (!_lgutils2.default.hasclass(_this.outer, 'lg-thumb-open')) { _this.destroy(); } else { _lgutils2.default.removeclass(_this.outer, 'lg-thumb-open'); } } }); }; plugin.prototype.arrow = function () { var _this = this; _lgutils2.default.on(this.outer.queryselector('.lg-prev'), 'click.lg', function () { _this.gotoprevslide(); }); _lgutils2.default.on(this.outer.queryselector('.lg-next'), 'click.lg', function () { _this.gotonextslide(); }); }; plugin.prototype.arrowdisable = function (index) { // disable arrows if s.hidecontrolonend is true if (!this.s.loop && this.s.hidecontrolonend) { var next = this.outer.queryselector('.lg-next'); var prev = this.outer.queryselector('.lg-prev'); if (index + 1 < this.___slide.length) { next.removeattribute('disabled'); _lgutils2.default.removeclass(next, 'disabled'); } else { next.setattribute('disabled', 'disabled'); _lgutils2.default.addclass(next, 'disabled'); } if (index > 0) { prev.removeattribute('disabled'); _lgutils2.default.removeclass(prev, 'disabled'); } else { next.setattribute('disabled', 'disabled'); _lgutils2.default.addclass(next, 'disabled'); } } }; plugin.prototype.settranslate = function (el, xvalue, yvalue) { // jquery supports automatic css prefixing since jquery 1.8.0 if (this.s.useleft) { el.style.left = xvalue; } else { _lgutils2.default.setvendor(el, 'transform', 'translate3d(' + xvalue + 'px, ' + yvalue + 'px, 0px)'); } }; plugin.prototype.touchmove = function (startcoords, endcoords) { var distance = endcoords - startcoords; if (math.abs(distance) > 15) { // reset opacity and transition duration _lgutils2.default.addclass(this.outer, 'lg-dragging'); // move current slide this.settranslate(this.___slide[this.index], distance, 0); // move next and prev slide with current slide this.settranslate(document.queryselector('.lg-prev-slide'), -this.___slide[this.index].clientwidth + distance, 0); this.settranslate(document.queryselector('.lg-next-slide'), this.___slide[this.index].clientwidth + distance, 0); } }; plugin.prototype.touchend = function (distance) { var _this = this; // keep slide animation for any mode while dragg/swipe if (_this.s.mode !== 'lg-slide') { _lgutils2.default.addclass(_this.outer, 'lg-slide'); } for (var i = 0; i < this.___slide.length; i++) { if (!_lgutils2.default.hasclass(this.___slide[i], 'lg-current') && !_lgutils2.default.hasclass(this.___slide[i], 'lg-prev-slide') && !_lgutils2.default.hasclass(this.___slide[i], 'lg-next-slide')) { this.___slide[i].style.opacity = '0'; } } // set transition duration settimeout(function () { _lgutils2.default.removeclass(_this.outer, 'lg-dragging'); if (distance < 0 && math.abs(distance) > _this.s.swipethreshold) { _this.gotonextslide(true); } else if (distance > 0 && math.abs(distance) > _this.s.swipethreshold) { _this.gotoprevslide(true); } else if (math.abs(distance) < 5) { // trigger click if distance is less than 5 pix _lgutils2.default.trigger(_this.el, 'onslideclick'); } for (var i = 0; i < _this.___slide.length; i++) { _this.___slide[i].removeattribute('style'); } }); // remove slide class once drag/swipe is completed if mode is not slide settimeout(function () { if (!_lgutils2.default.hasclass(_this.outer, 'lg-dragging') && _this.s.mode !== 'lg-slide') { _lgutils2.default.removeclass(_this.outer, 'lg-slide'); } }, _this.s.speed + 100); }; plugin.prototype.enableswipe = function () { var _this = this; var startcoords = 0; var endcoords = 0; var ismoved = false; if (_this.s.enableswipe && _this.istouch && _this.docss()) { for (var i = 0; i < _this.___slide.length; i++) { /*jshint loopfunc: true */ _lgutils2.default.on(_this.___slide[i], 'touchstart.lg', function (e) { if (!_lgutils2.default.hasclass(_this.outer, 'lg-zoomed') && !_this.lgbusy) { e.preventdefault(); _this.manageswipeclass(); startcoords = e.originalevent.targettouches[0].pagex; } }); } for (var j = 0; j < _this.___slide.length; j++) { /*jshint loopfunc: true */ _lgutils2.default.on(_this.___slide[j], 'touchmove.lg', function (e) { if (!_lgutils2.default.hasclass(_this.outer, 'lg-zoomed')) { e.preventdefault(); endcoords = e.originalevent.targettouches[0].pagex; _this.touchmove(startcoords, endcoords); ismoved = true; } }); } for (var k = 0; k < _this.___slide.length; k++) { /*jshint loopfunc: true */ _lgutils2.default.on(_this.___slide[k], 'touchend.lg', function () { if (!_lgutils2.default.hasclass(_this.outer, 'lg-zoomed')) { if (ismoved) { ismoved = false; _this.touchend(endcoords - startcoords); } else { _lgutils2.default.trigger(_this.el, 'onslideclick'); } } }); } } }; plugin.prototype.enabledrag = function () { var _this = this; var startcoords = 0; var endcoords = 0; var isdraging = false; var ismoved = false; if (_this.s.enabledrag && !_this.istouch && _this.docss()) { for (var i = 0; i < _this.___slide.length; i++) { /*jshint loopfunc: true */ _lgutils2.default.on(_this.___slide[i], 'mousedown.lg', function (e) { // execute only on .lg-object if (!_lgutils2.default.hasclass(_this.outer, 'lg-zoomed')) { if (_lgutils2.default.hasclass(e.target, 'lg-object') || _lgutils2.default.hasclass(e.target, 'lg-video-play')) { e.preventdefault(); if (!_this.lgbusy) { _this.manageswipeclass(); startcoords = e.pagex; isdraging = true; // ** fix for webkit cursor issue https://code.google.com/p/chromium/issues/detail?id=26723 _this.outer.scrollleft += 1; _this.outer.scrollleft -= 1; // * _lgutils2.default.removeclass(_this.outer, 'lg-grab'); _lgutils2.default.addclass(_this.outer, 'lg-grabbing'); _lgutils2.default.trigger(_this.el, 'ondragstart'); } } } }); } _lgutils2.default.on(window, 'mousemove.lg', function (e) { if (isdraging) { ismoved = true; endcoords = e.pagex; _this.touchmove(startcoords, endcoords); _lgutils2.default.trigger(_this.el, 'ondragmove'); } }); _lgutils2.default.on(window, 'mouseup.lg', function (e) { if (ismoved) { ismoved = false; _this.touchend(endcoords - startcoords); _lgutils2.default.trigger(_this.el, 'ondragend'); } else if (_lgutils2.default.hasclass(e.target, 'lg-object') || _lgutils2.default.hasclass(e.target, 'lg-video-play')) { _lgutils2.default.trigger(_this.el, 'onslideclick'); } // prevent execution on click if (isdraging) { isdraging = false; _lgutils2.default.removeclass(_this.outer, 'lg-grabbing'); _lgutils2.default.addclass(_this.outer, 'lg-grab'); } }); } }; plugin.prototype.manageswipeclass = function () { var touchnext = this.index + 1; var touchprev = this.index - 1; var length = this.___slide.length; if (this.s.loop) { if (this.index === 0) { touchprev = length - 1; } else if (this.index === length - 1) { touchnext = 0; } } for (var i = 0; i < this.___slide.length; i++) { _lgutils2.default.removeclass(this.___slide[i], 'lg-next-slide'); _lgutils2.default.removeclass(this.___slide[i], 'lg-prev-slide'); } if (touchprev > -1) { _lgutils2.default.addclass(this.___slide[touchprev], 'lg-prev-slide'); } _lgutils2.default.addclass(this.___slide[touchnext], 'lg-next-slide'); }; plugin.prototype.mousewheel = function () { var _this = this; _lgutils2.default.on(_this.outer, 'mousewheel.lg', function (e) { if (!e.deltay) { return; } if (e.deltay > 0) { _this.gotoprevslide(); } else { _this.gotonextslide(); } e.preventdefault(); }); }; plugin.prototype.closegallery = function () { var _this = this; var mousedown = false; _lgutils2.default.on(this.outer.queryselector('.ppo1'), 'click.lg', function () { _this.destroy(); }); _lgutils2.default.on(this.outer.queryselector('.ppo2'), 'click.lg', function () { _this.destroy(); }); // $('.lg-outer .lg-img-wrap').click(function(){ // _this.destroy(); // $('.lg-close').click(); // console.log(2); // }) if (_this.s.closable) { // if you drag the slide and release outside gallery gets close on chrome // for preventing this check mousedown and mouseup happened on .lg-item or lg-outer _lgutils2.default.on(_this.outer, 'mousedown.lg', function (e) { if (_lgutils2.default.hasclass(e.target, 'lg-outer') || _lgutils2.default.hasclass(e.target, 'lg-item') || _lgutils2.default.hasclass(e.target, 'lg-img-wrap')) { mousedown = true; } else { mousedown = false; } }); _lgutils2.default.on(_this.outer, 'mouseup.lg', function (e) { if (_lgutils2.default.hasclass(e.target, 'lg-outer') || _lgutils2.default.hasclass(e.target, 'lg-item') || _lgutils2.default.hasclass(e.target, 'lg-img-wrap') && mousedown) { if (!_lgutils2.default.hasclass(_this.outer, 'lg-dragging')) { _this.destroy(); } } }); } }; plugin.prototype.destroy = function (d) { var _this = this; if (!d) { _lgutils2.default.trigger(_this.el, 'onbeforeclose'); } document.body.scrolltop = _this.prevscrolltop; /** * if d is false or undefined destroy will only close the gallery * plugins instance remains with the element * * if d is true destroy will completely remove the plugin */ if (d) { if (!_this.s.dynamic) { // only when not using dynamic mode is $items a jquery collection for (var i = 0; i < this.items.length; i++) { _lgutils2.default.off(this.items[i], '.lg'); _lgutils2.default.off(this.items[i], '.lgcustom'); } } var lguid = _this.el.getattribute('lg-uid'); delete window.lgdata[lguid]; _this.el.removeattribute('lg-uid'); } // unbind all events added by lightgallery _lgutils2.default.off(this.el, '.lgtm'); // distroy all lightgallery modules for (var key in window.lgmodules) { if (_this.modules[key]) { _this.modules[key].destroy(); } } this.lgalleryon = false; cleartimeout(_this.hidebartimeout); this.hidebartimeout = false; _lgutils2.default.off(window, '.lg'); _lgutils2.default.removeclass(document.body, 'lg-on'); _lgutils2.default.removeclass(document.body, 'lg-from-hash'); if (_this.outer) { _lgutils2.default.removeclass(_this.outer, 'lg-visible'); } _lgutils2.default.removeclass(document.queryselector('.lg-backdrop'), 'in'); settimeout(function () { try { if (_this.outer) { _this.outer.parentnode.removechild(_this.outer); } if (document.queryselector('.lg-backdrop')) { document.queryselector('.lg-backdrop').parentnode.removechild(document.queryselector('.lg-backdrop')); } if (!d) { _lgutils2.default.trigger(_this.el, 'oncloseafter'); } } catch (err) {} }, _this.s.backdropduration + 50); }; window.lightgallery = function (el, options) { if (!el) { return; } try { if (!el.getattribute('lg-uid')) { var uid = 'lg' + window.lgdata.uid++; window.lgdata[uid] = new plugin(el, options); el.setattribute('lg-uid', uid); } else { try { window.lgdata[el.getattribute('lg-uid')].init(); } catch (err) { console.error('lightgallery has not initiated properly'); } } } catch (err) { console.error('lightgallery has not initiated properly'); } }; }); },{"./lg-utils":1}]},{},[2])(2) });