| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598 |
- /**!
- * lightgallery.js | 0.0.2 | August 4th 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<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
- (function (global, factory) {
- if (typeof define === "function" && define.amd) {
- define(['exports'], factory);
- } else if (typeof exports !== "undefined") {
- factory(exports);
- } else {
- var mod = {
- exports: {}
- };
- factory(mod.exports);
- global.lgUtils = mod.exports;
- }
- })(this, function (exports) {
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- /*
- *@todo remove function from window and document. Update on and off functions
- */
- window.getAttribute = function (label) {
- return window[label];
- };
- window.setAttribute = function (label, value) {
- window[label] = value;
- };
- document.getAttribute = function (label) {
- return document[label];
- };
- document.setAttribute = function (label, value) {
- document[label] = value;
- };
- var utils = {
- wrap: function wrap(el, className) {
- if (!el) {
- return;
- }
- var wrapper = document.createElement('div');
- wrapper.className = className;
- el.parentNode.insertBefore(wrapper, el);
- el.parentNode.removeChild(el);
- wrapper.appendChild(el);
- },
- addClass: function addClass(el, className) {
- if (!el) {
- return;
- }
- if (el.classList) {
- el.classList.add(className);
- } else {
- el.className += ' ' + className;
- }
- },
- removeClass: function removeClass(el, className) {
- if (!el) {
- return;
- }
- if (el.classList) {
- el.classList.remove(className);
- } else {
- el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
- }
- },
- hasClass: function hasClass(el, className) {
- if (el.classList) {
- return el.classList.contains(className);
- } else {
- return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className);
- }
- return false;
- },
- // ex Transform
- // ex TransitionTimingFunction
- setVendor: function setVendor(el, property, value) {
- if (!el) {
- return;
- }
- el.style[property.charAt(0).toLowerCase() + property.slice(1)] = value;
- el.style['webkit' + property] = value;
- el.style['moz' + property] = value;
- el.style['ms' + property] = value;
- el.style['o' + property] = value;
- },
- trigger: function trigger(el, event) {
- var detail = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
- if (!el) {
- return;
- }
- var customEvent = new CustomEvent(event, {
- detail: detail
- });
- el.dispatchEvent(customEvent);
- },
- Listener: {
- uid: 0
- },
- on: function on(el, events, fn) {
- if (!el) {
- return;
- }
- events.split(' ').forEach(function (event) {
- var _id = el.getAttribute('lg-event-uid') || '';
- utils.Listener.uid++;
- _id += '&' + utils.Listener.uid;
- el.setAttribute('lg-event-uid', _id);
- utils.Listener[event + utils.Listener.uid] = fn;
- el.addEventListener(event.split('.')[0], fn, false);
- });
- },
- off: function off(el, event) {
- if (!el) {
- return;
- }
- var _id = el.getAttribute('lg-event-uid');
- if (_id) {
- _id = _id.split('&');
- for (var i = 0; i < _id.length; i++) {
- if (_id[i]) {
- var _event = event + _id[i];
- if (_event.substring(0, 1) === '.') {
- for (var key in utils.Listener) {
- if (utils.Listener.hasOwnProperty(key)) {
- if (key.split('.').indexOf(_event.split('.')[1]) > -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', '<div class="lg-backdrop"></div>');
- _lgUtils2.default.setVendor(document.querySelector('.lg-backdrop'), 'TransitionDuration', this.s.backdropDuration + 'ms');
- // Create gallery items
- for (i = 0; i < this.items.length; i++) {
- list += '<div class="lg-item"></div>';
- }
- // Create controlls
- if (this.s.controls && this.items.length > 1) {
- controls = '<div class="lg-actions">' + '<div class="lg-prev lg-icon">' + this.s.prevHtml + '</div>' + '<div class="lg-next lg-icon">' + this.s.nextHtml + '</div>' + '</div>';
- }
- if (this.s.appendSubHtmlTo === '.lg-sub-html') {
- subHtmlCont = '<div class="lg-sub-html"></div>';
- }
- template = '<div class="lg-outer ' + this.s.addClass + ' ' + this.s.startClass + '">' + '<div class="lg" style="width:' + this.s.width + '; height:' + this.s.height + '">' + '<div class="lg-inner">' + list + '</div>' + '<div class="lg-toolbar group">' + '<span class="lg-close lg-icon"></span>' + '</div>' + controls + subHtmlCont + '</div>' + '</div>';
- 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', '<a id="lg-download" target="_blank" download class="lg-download lg-icon"></a>');
- }
- // Store the current scroll top value to scroll back after closing the gallery..
- this.prevScrollTop = document.documentElement.scrollTop || 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', '<div id="lg-counter"><span id="lg-counter-current">' + (parseInt(this.index, 10) + 1) + '</span> / <span id="lg-counter-all">' + this.items.length + '</span></div>');
- }
- };
- /**
- * @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', '<div class="lg-video-cont" style="max-width:' + _this.s.iframeMaxWidth + '"><div class="lg-video"><iframe class="lg-object" frameborder="0" src="' + _src + '" allowfullscreen="true"></iframe></div></div>');
- } 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', '<div class="lg-video-cont ' + videoClass + ' "><div class="lg-video"><span class="lg-video-play"></span><img class="lg-object lg-has-poster" src="' + _poster + '" /></div></div>');
- } else if (_isVideo) {
- _this.___slide[index].insertAdjacentHTML('beforeend', '<div class="lg-video-cont "><div class="lg-video"></div></div>');
- _lgUtils2.default.trigger(_this.el, 'hasVideo', {
- index: index,
- src: _src,
- html: _html
- });
- } else {
- _this.___slide[index].insertAdjacentHTML('beforeend', '<div class="lg-img-wrap"><img class="lg-object lg-image" src="' + _src + '" /></div>');
- }
- _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);
- });
- } else {
- _this.preload(index);
- }
- }
- //}
- };
- /**
- * @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.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.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('.lg-close'), 'click.lg', function () {
- _this.destroy();
- });
- 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;
- document.documentElement.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)
- });
|