(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = global || self, global.glightbox = factory()); }(this, (function () { 'use strict'; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof symbol === "function" && typeof symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; }; } else { _typeof = function (obj) { return obj && typeof symbol === "function" && obj.constructor === symbol && obj !== symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classcallcheck(instance, constructor) { if (!(instance instanceof constructor)) { throw new typeerror("cannot call a class as a function"); } } function _defineproperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; object.defineproperty(target, descriptor.key, descriptor); } } function _createclass(constructor, protoprops, staticprops) { if (protoprops) _defineproperties(constructor.prototype, protoprops); if (staticprops) _defineproperties(constructor, staticprops); return constructor; } function _toconsumablearray(arr) { return _arraywithoutholes(arr) || _iterabletoarray(arr) || _unsupportediterabletoarray(arr) || _noniterablespread(); } function _arraywithoutholes(arr) { if (array.isarray(arr)) return _arrayliketoarray(arr); } function _iterabletoarray(iter) { if (typeof symbol !== "undefined" && symbol.iterator in object(iter)) return array.from(iter); } function _unsupportediterabletoarray(o, minlen) { if (!o) return; if (typeof o === "string") return _arrayliketoarray(o, minlen); var n = object.prototype.tostring.call(o).slice(8, -1); if (n === "object" && o.constructor) n = o.constructor.name; if (n === "map" || n === "set") return array.from(o); if (n === "arguments" || /^(?:ui|i)nt(?:8|16|32)(?:clamped)?array$/.test(n)) return _arrayliketoarray(o, minlen); } function _arrayliketoarray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _noniterablespread() { throw new typeerror("invalid attempt to spread non-iterable instance.\nin order to be iterable, non-array objects must have a [symbol.iterator]() method."); } function getlen(v) { return math.sqrt(v.x * v.x + v.y * v.y); } function dot(v1, v2) { return v1.x * v2.x + v1.y * v2.y; } function getangle(v1, v2) { var mr = getlen(v1) * getlen(v2); if (mr === 0) return 0; var r = dot(v1, v2) / mr; if (r > 1) r = 1; return math.acos(r); } function cross(v1, v2) { return v1.x * v2.y - v2.x * v1.y; } function getrotateangle(v1, v2) { var angle = getangle(v1, v2); if (cross(v1, v2) > 0) { angle *= -1; } return angle * 180 / math.pi; } var eventshandleradmin = function () { function eventshandleradmin(el) { _classcallcheck(this, eventshandleradmin); this.handlers = []; this.el = el; } _createclass(eventshandleradmin, [{ key: "add", value: function add(handler) { this.handlers.push(handler); } }, { key: "del", value: function del(handler) { if (!handler) this.handlers = []; for (var i = this.handlers.length; i >= 0; i--) { if (this.handlers[i] === handler) { this.handlers.splice(i, 1); } } } }, { key: "dispatch", value: function dispatch() { for (var i = 0, len = this.handlers.length; i < len; i++) { var handler = this.handlers[i]; if (typeof handler === 'function') handler.apply(this.el, arguments); } } }]); return eventshandleradmin; }(); function wrapfunc(el, handler) { var eventshandleradmin = new eventshandleradmin(el); eventshandleradmin.add(handler); return eventshandleradmin; } var touchevents = function () { function touchevents(el, option) { _classcallcheck(this, touchevents); this.element = typeof el == 'string' ? document.queryselector(el) : el; this.start = this.start.bind(this); this.move = this.move.bind(this); this.end = this.end.bind(this); this.cancel = this.cancel.bind(this); this.element.addeventlistener("touchstart", this.start, false); this.element.addeventlistener("touchmove", this.move, false); this.element.addeventlistener("touchend", this.end, false); this.element.addeventlistener("touchcancel", this.cancel, false); this.prev = { x: null, y: null }; this.pinchstartlen = null; this.zoom = 1; this.isdoubletap = false; var noop = function noop() {}; this.rotate = wrapfunc(this.element, option.rotate || noop); this.touchstart = wrapfunc(this.element, option.touchstart || noop); this.multipointstart = wrapfunc(this.element, option.multipointstart || noop); this.multipointend = wrapfunc(this.element, option.multipointend || noop); this.pinch = wrapfunc(this.element, option.pinch || noop); this.swipe = wrapfunc(this.element, option.swipe || noop); this.tap = wrapfunc(this.element, option.tap || noop); this.doubletap = wrapfunc(this.element, option.doubletap || noop); this.longtap = wrapfunc(this.element, option.longtap || noop); this.singletap = wrapfunc(this.element, option.singletap || noop); this.pressmove = wrapfunc(this.element, option.pressmove || noop); this.twofingerpressmove = wrapfunc(this.element, option.twofingerpressmove || noop); this.touchmove = wrapfunc(this.element, option.touchmove || noop); this.touchend = wrapfunc(this.element, option.touchend || noop); this.touchcancel = wrapfunc(this.element, option.touchcancel || noop); this._cancelallhandler = this.cancelall.bind(this); window.addeventlistener('scroll', this._cancelallhandler); this.delta = null; this.last = null; this.now = null; this.taptimeout = null; this.singletaptimeout = null; this.longtaptimeout = null; this.swipetimeout = null; this.x1 = this.x2 = this.y1 = this.y2 = null; this.pretapposition = { x: null, y: null }; } _createclass(touchevents, [{ key: "start", value: function start(evt) { if (!evt.touches) return; this.now = date.now(); this.x1 = evt.touches[0].pagex; this.y1 = evt.touches[0].pagey; this.delta = this.now - (this.last || this.now); this.touchstart.dispatch(evt, this.element); if (this.pretapposition.x !== null) { this.isdoubletap = this.delta > 0 && this.delta <= 250 && math.abs(this.pretapposition.x - this.x1) < 30 && math.abs(this.pretapposition.y - this.y1) < 30; if (this.isdoubletap) cleartimeout(this.singletaptimeout); } this.pretapposition.x = this.x1; this.pretapposition.y = this.y1; this.last = this.now; var prev = this.prev, len = evt.touches.length; if (len > 1) { this._cancellongtap(); this._cancelsingletap(); var v = { x: evt.touches[1].pagex - this.x1, y: evt.touches[1].pagey - this.y1 }; prev.x = v.x; prev.y = v.y; this.pinchstartlen = getlen(prev); this.multipointstart.dispatch(evt, this.element); } this._preventtap = false; this.longtaptimeout = settimeout(function () { this.longtap.dispatch(evt, this.element); this._preventtap = true; }.bind(this), 750); } }, { key: "move", value: function move(evt) { if (!evt.touches) return; var prev = this.prev, len = evt.touches.length, currentx = evt.touches[0].pagex, currenty = evt.touches[0].pagey; this.isdoubletap = false; if (len > 1) { var scurrentx = evt.touches[1].pagex, scurrenty = evt.touches[1].pagey; var v = { x: evt.touches[1].pagex - currentx, y: evt.touches[1].pagey - currenty }; if (prev.x !== null) { if (this.pinchstartlen > 0) { evt.zoom = getlen(v) / this.pinchstartlen; this.pinch.dispatch(evt, this.element); } evt.angle = getrotateangle(v, prev); this.rotate.dispatch(evt, this.element); } prev.x = v.x; prev.y = v.y; if (this.x2 !== null && this.sx2 !== null) { evt.deltax = (currentx - this.x2 + scurrentx - this.sx2) / 2; evt.deltay = (currenty - this.y2 + scurrenty - this.sy2) / 2; } else { evt.deltax = 0; evt.deltay = 0; } this.twofingerpressmove.dispatch(evt, this.element); this.sx2 = scurrentx; this.sy2 = scurrenty; } else { if (this.x2 !== null) { evt.deltax = currentx - this.x2; evt.deltay = currenty - this.y2; var movedx = math.abs(this.x1 - this.x2), movedy = math.abs(this.y1 - this.y2); if (movedx > 10 || movedy > 10) { this._preventtap = true; } } else { evt.deltax = 0; evt.deltay = 0; } this.pressmove.dispatch(evt, this.element); } this.touchmove.dispatch(evt, this.element); this._cancellongtap(); this.x2 = currentx; this.y2 = currenty; if (len > 1) { evt.preventdefault(); } } }, { key: "end", value: function end(evt) { if (!evt.changedtouches) return; this._cancellongtap(); var self = this; if (evt.touches.length < 2) { this.multipointend.dispatch(evt, this.element); this.sx2 = this.sy2 = null; } if (this.x2 && math.abs(this.x1 - this.x2) > 30 || this.y2 && math.abs(this.y1 - this.y2) > 30) { evt.direction = this._swipedirection(this.x1, this.x2, this.y1, this.y2); this.swipetimeout = settimeout(function () { self.swipe.dispatch(evt, self.element); }, 0); } else { this.taptimeout = settimeout(function () { if (!self._preventtap) { self.tap.dispatch(evt, self.element); } if (self.isdoubletap) { self.doubletap.dispatch(evt, self.element); self.isdoubletap = false; } }, 0); if (!self.isdoubletap) { self.singletaptimeout = settimeout(function () { self.singletap.dispatch(evt, self.element); }, 250); } } this.touchend.dispatch(evt, this.element); this.prev.x = 0; this.prev.y = 0; this.zoom = 1; this.pinchstartlen = null; this.x1 = this.x2 = this.y1 = this.y2 = null; } }, { key: "cancelall", value: function cancelall() { this._preventtap = true; cleartimeout(this.singletaptimeout); cleartimeout(this.taptimeout); cleartimeout(this.longtaptimeout); cleartimeout(this.swipetimeout); } }, { key: "cancel", value: function cancel(evt) { this.cancelall(); this.touchcancel.dispatch(evt, this.element); } }, { key: "_cancellongtap", value: function _cancellongtap() { cleartimeout(this.longtaptimeout); } }, { key: "_cancelsingletap", value: function _cancelsingletap() { cleartimeout(this.singletaptimeout); } }, { key: "_swipedirection", value: function _swipedirection(x1, x2, y1, y2) { return math.abs(x1 - x2) >= math.abs(y1 - y2) ? x1 - x2 > 0 ? 'left' : 'right' : y1 - y2 > 0 ? 'up' : 'down'; } }, { key: "on", value: function on(evt, handler) { if (this[evt]) { this[evt].add(handler); } } }, { key: "off", value: function off(evt, handler) { if (this[evt]) { this[evt].del(handler); } } }, { key: "destroy", value: function destroy() { if (this.singletaptimeout) cleartimeout(this.singletaptimeout); if (this.taptimeout) cleartimeout(this.taptimeout); if (this.longtaptimeout) cleartimeout(this.longtaptimeout); if (this.swipetimeout) cleartimeout(this.swipetimeout); this.element.removeeventlistener("touchstart", this.start); this.element.removeeventlistener("touchmove", this.move); this.element.removeeventlistener("touchend", this.end); this.element.removeeventlistener("touchcancel", this.cancel); this.rotate.del(); this.touchstart.del(); this.multipointstart.del(); this.multipointend.del(); this.pinch.del(); this.swipe.del(); this.tap.del(); this.doubletap.del(); this.longtap.del(); this.singletap.del(); this.pressmove.del(); this.twofingerpressmove.del(); this.touchmove.del(); this.touchend.del(); this.touchcancel.del(); this.prev = this.pinchstartlen = this.zoom = this.isdoubletap = this.delta = this.last = this.now = this.taptimeout = this.singletaptimeout = this.longtaptimeout = this.swipetimeout = this.x1 = this.x2 = this.y1 = this.y2 = this.pretapposition = this.rotate = this.touchstart = this.multipointstart = this.multipointend = this.pinch = this.swipe = this.tap = this.doubletap = this.longtap = this.singletap = this.pressmove = this.touchmove = this.touchend = this.touchcancel = this.twofingerpressmove = null; window.removeeventlistener('scroll', this._cancelallhandler); return null; } }]); return touchevents; }(); var zoomimages = function () { function zoomimages(el, slide) { var _this = this; var onclose = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; _classcallcheck(this, zoomimages); this.img = el; this.slide = slide; this.onclose = onclose; if (this.img.setzoomevents) { return false; } this.active = false; this.zoomedin = false; this.dragging = false; this.currentx = null; this.currenty = null; this.initialx = null; this.initialy = null; this.xoffset = 0; this.yoffset = 0; this.img.addeventlistener('mousedown', function (e) { return _this.dragstart(e); }, false); this.img.addeventlistener('mouseup', function (e) { return _this.dragend(e); }, false); this.img.addeventlistener('mousemove', function (e) { return _this.drag(e); }, false); this.img.addeventlistener('click', function (e) { if (!_this.zoomedin) { return _this.zoomin(); } if (_this.zoomedin && !_this.dragging) { _this.zoomout(); } }, false); this.img.setzoomevents = true; } _createclass(zoomimages, [{ key: "zoomin", value: function zoomin() { var winwidth = this.widowwidth(); if (this.zoomedin || winwidth <= 768) { return; } var img = this.img; img.setattribute('data-style', img.getattribute('style')); img.style.maxwidth = img.naturalwidth + 'px'; img.style.maxheight = img.naturalheight + 'px'; if (img.naturalwidth > winwidth) { var centerx = winwidth / 2 - img.naturalwidth / 2; this.settranslate(this.img.parentnode, centerx, 0); } this.slide.classlist.add('zoomed'); this.zoomedin = true; } }, { key: "zoomout", value: function zoomout() { this.img.parentnode.setattribute('style', ''); this.img.setattribute('style', this.img.getattribute('data-style')); this.slide.classlist.remove('zoomed'); this.zoomedin = false; this.currentx = null; this.currenty = null; this.initialx = null; this.initialy = null; this.xoffset = 0; this.yoffset = 0; if (this.onclose && typeof this.onclose == 'function') { this.onclose(); } } }, { key: "dragstart", value: function dragstart(e) { e.preventdefault(); if (!this.zoomedin) { this.active = false; return; } if (e.type === "touchstart") { this.initialx = e.touches[0].clientx - this.xoffset; this.initialy = e.touches[0].clienty - this.yoffset; } else { this.initialx = e.clientx - this.xoffset; this.initialy = e.clienty - this.yoffset; } if (e.target === this.img) { this.active = true; this.img.classlist.add('dragging'); } } }, { key: "dragend", value: function dragend(e) { var _this2 = this; e.preventdefault(); this.initialx = this.currentx; this.initialy = this.currenty; this.active = false; settimeout(function () { _this2.dragging = false; _this2.img.isdragging = false; _this2.img.classlist.remove('dragging'); }, 100); } }, { key: "drag", value: function drag(e) { if (this.active) { e.preventdefault(); if (e.type === 'touchmove') { this.currentx = e.touches[0].clientx - this.initialx; this.currenty = e.touches[0].clienty - this.initialy; } else { this.currentx = e.clientx - this.initialx; this.currenty = e.clienty - this.initialy; } this.xoffset = this.currentx; this.yoffset = this.currenty; this.img.isdragging = true; this.dragging = true; this.settranslate(this.img, this.currentx, this.currenty); } } }, { key: "onmove", value: function onmove(e) { if (!this.zoomedin) { return; } var xoffset = e.clientx - this.img.naturalwidth / 2; var yoffset = e.clienty - this.img.naturalheight / 2; this.settranslate(this.img, xoffset, yoffset); } }, { key: "settranslate", value: function settranslate(node, xpos, ypos) { node.style.transform = "translate3d(" + xpos + "px, " + ypos + "px, 0)"; } }, { key: "widowwidth", value: function widowwidth() { return window.innerwidth || document.documentelement.clientwidth || document.body.clientwidth; } }]); return zoomimages; }(); var ismobile = 'navigator' in window && window.navigator.useragent.match(/(ipad)|(iphone)|(ipod)|(android)|(playbook)|(bb10)|(blackberry)|(opera mini)|(iemobile)|(webos)|(meego)/i); var istouch = ismobile !== null || document.createtouch !== undefined || 'ontouchstart' in window || 'onmsgesturechange' in window || navigator.msmaxtouchpoints; var html = document.getelementsbytagname('html')[0]; var transitionend = whichtransitionevent(); var animationend = whichanimationevent(); var uid = date.now(); var videoplayers = {}; var defaults = { selector: '.glightbox', elements: null, skin: 'clean', closebutton: true, startat: null, autoplayvideos: true, descposition: 'bottom', width: '900px', height: '506px', videoswidth: '960px', beforeslidechange: null, afterslidechange: null, beforeslideload: null, afterslideload: null, slideinserted: null, slideremoved: null, onopen: null, onclose: null, loop: false, touchnavigation: true, touchfollowaxis: true, keyboardnavigation: true, closeonoutsideclick: true, plyr: { css: 'https://cdn.plyr.io/3.5.6/plyr.css', js: 'https://cdn.plyr.io/3.5.6/plyr.js', config: { ratio: '16:9', youtube: { nocookie: true, rel: 0, showinfo: 0, iv_load_policy: 3 }, vimeo: { byline: false, portrait: false, title: false, transparent: false } } }, openeffect: 'zoomin', closeeffect: 'zoomout', slideeffect: 'slide', moretext: 'see more', morelength: 60, lightboxhtml: '', cssefects: { fade: { "in": 'fadein', out: 'fadeout' }, zoom: { "in": 'zoomin', out: 'zoomout' }, slide: { "in": 'slideinright', out: 'slideoutleft' }, slide_back: { "in": 'slideinleft', out: 'slideoutright' } }, svg: { close: '', next: ' ', prev: '' } }; var lightboxslidehtml = "
\n
\n
\n
\n
\n
\n
\n

\n
\n
\n
\n
\n
\n
"; defaults.slidehtml = lightboxslidehtml; var lightboxhtml = "
\n
\n
\n
\n
\n \n \n \n
\n
"; defaults.lightboxhtml = lightboxhtml; var singleslidedata = { href: '', title: '', type: '', description: '', descposition: '', effect: '', width: '', height: '', node: false, content: false }; function extend() { var extended = {}; var deep = true; var i = 0; var length = arguments.length; if (object.prototype.tostring.call(arguments[0]) === '[object boolean]') { deep = arguments[0]; i++; } var merge = function merge(obj) { for (var prop in obj) { if (object.prototype.hasownproperty.call(obj, prop)) { if (deep && object.prototype.tostring.call(obj[prop]) === '[object object]') { extended[prop] = extend(true, extended[prop], obj[prop]); } else { extended[prop] = obj[prop]; } } } }; for (; i < length; i++) { var obj = arguments[i]; merge(obj); } return extended; } var utils = { isfunction: function isfunction(f) { return typeof f === 'function'; }, isstring: function isstring(s) { return typeof s === 'string'; }, isnode: function isnode(el) { return !!(el && el.nodetype && el.nodetype == 1); }, isarray: function isarray(ar) { return array.isarray(ar); }, isarraylike: function isarraylike(ar) { return ar && ar.length && isfinite(ar.length); }, isobject: function isobject(o) { var type = _typeof(o); return type === 'object' && o != null && !utils.isfunction(o) && !utils.isarray(o); }, isnil: function isnil(o) { return o == null; }, has: function has(obj, key) { return obj !== null && hasownproperty.call(obj, key); }, size: function size(o) { if (utils.isobject(o)) { if (o.keys) { return o.keys().length; } var l = 0; for (var k in o) { if (utils.has(o, k)) { l++; } } return l; } else { return o.length; } }, isnumber: function isnumber(n) { return !isnan(parsefloat(n)) && isfinite(n); } }; function each(collection, callback) { if (utils.isnode(collection) || collection === window || collection === document) { collection = [collection]; } if (!utils.isarraylike(collection) && !utils.isobject(collection)) { collection = [collection]; } if (utils.size(collection) == 0) { return; } if (utils.isarraylike(collection) && !utils.isobject(collection)) { var l = collection.length, i = 0; for (; i < l; i++) { if (callback.call(collection[i], collection[i], i, collection) === false) { break; } } } else if (utils.isobject(collection)) { for (var key in collection) { if (utils.has(collection, key)) { if (callback.call(collection[key], collection[key], key, collection) === false) { break; } } } } } function getnodeevents(node) { var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var fn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var cache = node[uid] = node[uid] || []; var data = { all: cache, evt: null, found: null }; if (name && fn && utils.size(cache) > 0) { each(cache, function (cl, i) { if (cl.eventname == name && cl.fn.tostring() == fn.tostring()) { data.found = true; data.evt = i; return false; } }); } return data; } function addevent(eventname) { var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, onelement = _ref.onelement, withcallback = _ref.withcallback, _ref$avoidduplicate = _ref.avoidduplicate, avoidduplicate = _ref$avoidduplicate === void 0 ? true : _ref$avoidduplicate, _ref$once = _ref.once, once = _ref$once === void 0 ? false : _ref$once, _ref$usecapture = _ref.usecapture, usecapture = _ref$usecapture === void 0 ? false : _ref$usecapture; var thisarg = arguments.length > 2 ? arguments[2] : undefined; var element = onelement || []; if (utils.isstring(element)) { element = document.queryselectorall(element); } function handler(event) { if (utils.isfunction(withcallback)) { withcallback.call(thisarg, event, this); } if (once) { handler.destroy(); } } handler.destroy = function () { each(element, function (el) { var events = getnodeevents(el, eventname, handler); if (events.found) { events.all.splice(events.evt, 1); } if (el.removeeventlistener) el.removeeventlistener(eventname, handler, usecapture); }); }; each(element, function (el) { var events = getnodeevents(el, eventname, handler); if (el.addeventlistener && avoidduplicate && !events.found || !avoidduplicate) { el.addeventlistener(eventname, handler, usecapture); events.all.push({ eventname: eventname, fn: handler }); } }); return handler; } function addclass(node, name) { each(name.split(' '), function (cl) { return node.classlist.add(cl); }); } function removeclass(node, name) { each(name.split(' '), function (cl) { return node.classlist.remove(cl); }); } function hasclass(node, name) { return node.classlist.contains(name); } function whichanimationevent() { var t, el = document.createelement("fakeelement"); var animations = { animation: "animationend", oanimation: "oanimationend", mozanimation: "animationend", webkitanimation: "webkitanimationend" }; for (t in animations) { if (el.style[t] !== undefined) { return animations[t]; } } } function whichtransitionevent() { var t, el = document.createelement("fakeelement"); var transitions = { transition: "transitionend", otransition: "otransitionend", moztransition: "transitionend", webkittransition: "webkittransitionend" }; for (t in transitions) { if (el.style[t] !== undefined) { return transitions[t]; } } } function animateelement(element) { var animation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (!element || animation === '') { return false; } if (animation == 'none') { if (utils.isfunction(callback)) callback(); return false; } var animationnames = animation.split(' '); each(animationnames, function (name) { addclass(element, 'g' + name); }); addevent(animationend, { onelement: element, avoidduplicate: false, once: true, withcallback: function withcallback(event, target) { each(animationnames, function (name) { removeclass(target, 'g' + name); }); if (utils.isfunction(callback)) callback(); } }); } function createhtml(htmlstr) { var frag = document.createdocumentfragment(), temp = document.createelement('div'); temp.innerhtml = htmlstr; while (temp.firstchild) { frag.appendchild(temp.firstchild); } return frag; } function getclosest(elem, selector) { while (elem !== document.body) { elem = elem.parentelement; var matches = typeof elem.matches == 'function' ? elem.matches(selector) : elem.msmatchesselector(selector); if (matches) return elem; } } function show(element) { element.style.display = 'block'; } function hide(element) { element.style.display = 'none'; } function windowsize() { return { width: window.innerwidth || document.documentelement.clientwidth || document.body.clientwidth, height: window.innerheight || document.documentelement.clientheight || document.body.clientheight }; } function handlemediafullscreen(event) { if (!hasclass(event.target, 'plyr--html5')) { return; } var media = getclosest(event.target, '.gslide-media'); if (event.type == 'enterfullscreen') { addclass(media, 'fullscreen'); } if (event.type == 'exitfullscreen') { removeclass(media, 'fullscreen'); } } function checksize(size) { return utils.isnumber(size) ? "".concat(size, "px") : size; } function setsize(data, settings) { var defaultwith = data.type == 'video' ? checksize(settings.videoswidth) : checksize(settings.width); var defaultheight = checksize(settings.height); data.width = utils.has(data, 'width') && data.width !== '' ? checksize(data.width) : defaultwith; data.height = utils.has(data, 'height') && data.height !== '' ? checksize(data.height) : defaultheight; return data; } var getslidedata = function getslidedata() { var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var settings = arguments.length > 1 ? arguments[1] : undefined; var data = extend({ descposition: settings.descposition }, singleslidedata); if (utils.isobject(element) && !utils.isnode(element)) { if (!utils.has(element, 'type')) { if (utils.has(element, 'content') && element.content) { element.type = 'inline'; } else if (utils.has(element, 'href')) { element.type = getsourcetype(element.href); } } var objectdata = extend(data, element); setsize(objectdata, settings); return objectdata; } var url = ''; var config = element.getattribute('data-glightbox'); var nodetype = element.nodename.tolowercase(); if (nodetype === 'a') url = element.href; if (nodetype === 'img') url = element.src; data.href = url; each(data, function (val, key) { if (utils.has(settings, key) && key !== 'width') { data[key] = settings[key]; } var nodedata = element.dataset[key]; if (!utils.isnil(nodedata)) { data[key] = nodedata; } }); if (data.content) { data.type = 'inline'; } if (!data.type && url) { data.type = getsourcetype(url); } if (!utils.isnil(config)) { var cleankeys = []; each(data, function (v, k) { cleankeys.push(';\\s?' + k); }); cleankeys = cleankeys.join('\\s?:|'); if (config.trim() !== '') { each(data, function (val, key) { var str = config; var match = '\s?' + key + '\s?:\s?(.*?)(' + cleankeys + '\s?:|$)'; var regex = new regexp(match); var matches = str.match(regex); if (matches && matches.length && matches[1]) { var value = matches[1].trim().replace(/;\s*$/, ''); data[key] = value; } }); } } else { if (nodetype == 'a') { var title = element.title; if (!utils.isnil(title) && title !== '') data.title = title; } if (nodetype == 'img') { var alt = element.alt; if (!utils.isnil(alt) && alt !== '') data.title = alt; } var desc = element.getattribute('data-description'); if (!utils.isnil(desc) && desc !== '') data.description = desc; } if (data.description && data.description.substring(0, 1) == '.' && document.queryselector(data.description)) { data.description = document.queryselector(data.description).innerhtml; } else { var nodedesc = element.queryselector('.glightbox-desc'); if (nodedesc) { data.description = nodedesc.innerhtml; } } setsize(data, settings); return data; }; var setslidecontent = function setslidecontent() { var _this = this; var slide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (hasclass(slide, 'loaded')) { return false; } if (utils.isfunction(this.settings.beforeslideload)) { this.settings.beforeslideload({ index: data.index, slide: slide, player: false }); } var type = data.type; var position = data.descposition; var slidemedia = slide.queryselector('.gslide-media'); var slidetitle = slide.queryselector('.gslide-title'); var slidetext = slide.queryselector('.gslide-desc'); var slidedesc = slide.queryselector('.gdesc-inner'); var finalcallback = callback; var titleid = 'gslidetitle_' + data.index; var textid = 'gslidedesc_' + data.index; if (utils.isfunction(this.settings.afterslideload)) { finalcallback = function finalcallback() { if (utils.isfunction(callback)) { callback(); } _this.settings.afterslideload({ index: data.index, slide: slide, player: _this.getslideplayerinstance(data.index) }); }; } if (data.title == '' && data.description == '') { if (slidedesc) { slidedesc.parentnode.parentnode.removechild(slidedesc.parentnode); } } else { if (slidetitle && data.title !== '') { slidetitle.id = titleid; slidetitle.innerhtml = data.title; } else { slidetitle.parentnode.removechild(slidetitle); } if (slidetext && data.description !== '') { slidetext.id = textid; if (ismobile && this.settings.morelength > 0) { data.smalldescription = slideshortdesc(data.description, this.settings.morelength, this.settings.moretext); slidetext.innerhtml = data.smalldescription; slidedescriptionevents.apply(this, [slidetext, data]); } else { slidetext.innerhtml = data.description; } } else { slidetext.parentnode.removechild(slidetext); } addclass(slidemedia.parentnode, "desc-".concat(position)); addclass(slidedesc.parentnode, "description-".concat(position)); } addclass(slidemedia, "gslide-".concat(type)); addclass(slide, 'loaded'); if (type === 'video') { addclass(slidemedia.parentnode, "gvideo-container"); slidemedia.insertbefore(createhtml('
'), slidemedia.firstchild); setslidevideo.apply(this, [slide, data, finalcallback]); return; } if (type === 'external') { var iframe = createiframe({ url: data.href, callback: finalcallback }); slidemedia.parentnode.style.maxwidth = data.width; slidemedia.parentnode.style.height = data.height; slidemedia.appendchild(iframe); return; } if (type === 'inline') { setinlinecontent.apply(this, [slide, data, finalcallback]); return; } if (type === 'image') { var img = new image(); img.addeventlistener('load', function () { if (img.naturalwidth > img.offsetwidth) { addclass(img, 'zoomable'); new zoomimages(img, slide, function () { _this.resize(slide); }); } if (utils.isfunction(finalcallback)) { finalcallback(); } }, false); img.src = data.href; img.alt = ''; if (data.title !== '') { img.setattribute('aria-labelledby', titleid); } if (data.description !== '') { img.setattribute('aria-describedby', textid); } slidemedia.insertbefore(img, slidemedia.firstchild); return; } if (utils.isfunction(finalcallback)) finalcallback(); }; function setslidevideo(slide, data, callback) { var _this2 = this; var videoid = 'gvideo' + data.index; var slidemedia = slide.queryselector('.gvideo-wrapper'); injectvideoapi(this.settings.plyr.css); var url = data.href; var protocol = location.protocol.replace(':', ''); var videosource = ''; var embedid = ''; var customplaceholder = false; if (protocol == 'file') { protocol = 'http'; } slidemedia.parentnode.style.maxwidth = data.width; injectvideoapi(this.settings.plyr.js, 'plyr', function () { if (url.match(/vimeo\.com\/([0-9]*)/)) { var vimeoid = /vimeo.*\/(\d+)/i.exec(url); videosource = 'vimeo'; embedid = vimeoid[1]; } if (url.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-za-z0-9\-_]+)/) || url.match(/youtu\.be\/([a-za-z0-9\-_]+)/) || url.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-za-z0-9\-_]+)/)) { var youtubeid = getyoutubeid(url); videosource = 'youtube'; embedid = youtubeid; } if (url.match(/\.(mp4|ogg|webm|mov)$/) !== null) { videosource = 'local'; var _html = ''; customplaceholder = createhtml(_html); } var placeholder = customplaceholder ? customplaceholder : createhtml("
")); addclass(slidemedia, "".concat(videosource, "-video gvideo")); slidemedia.appendchild(placeholder); slidemedia.setattribute('data-id', videoid); slidemedia.setattribute('data-index', data.index); var playerconfig = utils.has(_this2.settings.plyr, 'config') ? _this2.settings.plyr.config : {}; var player = new plyr('#' + videoid, playerconfig); player.on('ready', function (event) { var instance = event.detail.plyr; videoplayers[videoid] = instance; if (utils.isfunction(callback)) { callback(); } }); player.on('enterfullscreen', handlemediafullscreen); player.on('exitfullscreen', handlemediafullscreen); }); } function createiframe(config) { var url = config.url, allow = config.allow, callback = config.callback, appendto = config.appendto; var iframe = document.createelement('iframe'); iframe.classname = 'vimeo-video gvideo'; iframe.src = url; iframe.style.width = '100%'; iframe.style.height = '100%'; if (allow) { iframe.setattribute('allow', allow); } iframe.onload = function () { addclass(iframe, 'node-ready'); if (utils.isfunction(callback)) { callback(); } }; if (appendto) { appendto.appendchild(iframe); } return iframe; } function getyoutubeid(url) { var videoid = ''; url = url.replace(/(>|<)/gi, '').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/); if (url[2] !== undefined) { videoid = url[2].split(/[^0-9a-z_\-]/i); videoid = videoid[0]; } else { videoid = url; } return videoid; } function injectvideoapi(url, waitfor, callback) { if (utils.isnil(url)) { console.error('inject videos api error'); return; } if (utils.isfunction(waitfor)) { callback = waitfor; waitfor = false; } var found; if (url.indexof('.css') !== -1) { found = document.queryselectorall('link[href="' + url + '"]'); if (found && found.length > 0) { if (utils.isfunction(callback)) callback(); return; } var head = document.getelementsbytagname("head")[0]; var headstyles = head.queryselectorall('link[rel="stylesheet"]'); var link = document.createelement('link'); link.rel = 'stylesheet'; link.type = 'text/css'; link.href = url; link.media = 'all'; if (headstyles) { head.insertbefore(link, headstyles[0]); } else { head.appendchild(link); } if (utils.isfunction(callback)) callback(); return; } found = document.queryselectorall('script[src="' + url + '"]'); if (found && found.length > 0) { if (utils.isfunction(callback)) { if (utils.isstring(waitfor)) { waituntil(function () { return typeof window[waitfor] !== 'undefined'; }, function () { callback(); }); return false; } callback(); } return; } var script = document.createelement('script'); script.type = 'text/javascript'; script.src = url; script.onload = function () { if (utils.isfunction(callback)) { if (utils.isstring(waitfor)) { waituntil(function () { return typeof window[waitfor] !== 'undefined'; }, function () { callback(); }); return false; } callback(); } }; document.body.appendchild(script); return; } function waituntil(check, oncomplete, delay, timeout) { if (check()) { oncomplete(); return; } if (!delay) delay = 100; var timeoutpointer; var intervalpointer = setinterval(function () { if (!check()) return; clearinterval(intervalpointer); if (timeoutpointer) cleartimeout(timeoutpointer); oncomplete(); }, delay); if (timeout) timeoutpointer = settimeout(function () { clearinterval(intervalpointer); }, timeout); } function setinlinecontent(slide, data, callback) { var _this3 = this; var slidemedia = slide.queryselector('.gslide-media'); var hash = utils.has(data, 'href') && data.href ? data.href.split('#').pop().trim() : false; var content = utils.has(data, 'content') && data.content ? data.content : false; var innercontent; if (content) { if (utils.isstring(content)) { innercontent = createhtml("
".concat(content, "
")); } if (utils.isnode(content)) { if (content.style.display == 'none') { content.style.display = 'block'; } var container = document.createelement('div'); container.classname = 'ginlined-content'; container.appendchild(content); innercontent = container; } } if (hash) { var div = document.getelementbyid(hash); if (!div) { return false; } var cloned = div.clonenode(true); cloned.style.height = data.height; cloned.style.maxwidth = data.width; addclass(cloned, 'ginlined-content'); innercontent = cloned; } if (!innercontent) { console.error('unable to append inline slide content', data); return false; } slidemedia.style.height = data.height; slidemedia.style.width = data.width; slidemedia.appendchild(innercontent); this.events['inlineclose' + hash] = addevent('click', { onelement: slidemedia.queryselectorall('.gtrigger-close'), withcallback: function withcallback(e) { e.preventdefault(); _this3.close(); } }); if (utils.isfunction(callback)) { callback(); } return; } var getsourcetype = function getsourcetype(url) { var origin = url; url = url.tolowercase(); if (url.match(/\.(jpeg|jpg|jpe|gif|png|apn|webp|svg)$/) !== null) { return 'image'; } if (url.match(/(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-za-z0-9\-_]+)/) || url.match(/youtu\.be\/([a-za-z0-9\-_]+)/) || url.match(/(youtube\.com|youtube-nocookie\.com)\/embed\/([a-za-z0-9\-_]+)/)) { return 'video'; } if (url.match(/vimeo\.com\/([0-9]*)/)) { return 'video'; } if (url.match(/\.(mp4|ogg|webm|mov)$/) !== null) { return 'video'; } if (url.indexof("#") > -1) { var hash = origin.split('#').pop(); if (hash.trim() !== '') { return 'inline'; } } if (url.includes("gajax=true")) { return 'ajax'; } return 'external'; }; function keyboardnavigation() { var _this4 = this; if (this.events.hasownproperty('keyboard')) { return false; } this.events['keyboard'] = addevent('keydown', { onelement: window, withcallback: function withcallback(event, target) { event = event || window.event; var key = event.keycode; if (key == 9) { var activeelement = document.activeelement && document.activeelement.nodename ? document.activeelement.nodename.tolocalelowercase() : false; if (activeelement == 'input' || activeelement == 'textarea' || activeelement == 'button') { return; } event.preventdefault(); var btns = document.queryselectorall('.gbtn'); if (!btns || btns.length <= 0) { return; } var focused = _toconsumablearray(btns).filter(function (item) { return hasclass(item, 'focused'); }); if (!focused.length) { var first = document.queryselector('.gbtn[tabindex="0"]'); if (first) { first.focus(); addclass(first, 'focused'); } return; } btns.foreach(function (element) { return removeclass(element, 'focused'); }); var tabindex = focused[0].getattribute('tabindex'); tabindex = tabindex ? tabindex : '0'; var newindex = parseint(tabindex) + 1; if (newindex > btns.length - 1) { newindex = '0'; } var next = document.queryselector(".gbtn[tabindex=\"".concat(newindex, "\"]")); if (next) { next.focus(); addclass(next, 'focused'); } } if (key == 39) _this4.nextslide(); if (key == 37) _this4.prevslide(); if (key == 27) _this4.close(); } }); } function touchnavigation() { var _this5 = this; if (this.events.hasownproperty('touch')) { return false; } var winsize = windowsize(); var winwidth = winsize.width; var winheight = winsize.height; var process = false; var currentslide = null; var media = null; var mediaimage = null; var doingmove = false; var initscale = 1; var maxscale = 4.5; var currentscale = 1; var doingzoom = false; var imagezoomed = false; var zoomedposx = null; var zoomedposy = null; var lastzoomedposx = null; var lastzoomedposy = null; var hdistance; var vdistance; var hdistancepercent = 0; var vdistancepercent = 0; var vswipe = false; var hswipe = false; var startcoords = {}; var endcoords = {}; var xdown = 0; var ydown = 0; var isinlined; var instance = this; var sliderwrapper = document.getelementbyid('glightbox-slider'); var overlay = document.queryselector('.goverlay'); var loop = this.loop(); var touchinstance = new touchevents(sliderwrapper, { touchstart: function touchstart(e) { if (hasclass(e.targettouches[0].target, 'ginner-container') || getclosest(e.targettouches[0].target, '.gslide-desc')) { process = false; return false; } process = true; endcoords = e.targettouches[0]; startcoords.pagex = e.targettouches[0].pagex; startcoords.pagey = e.targettouches[0].pagey; xdown = e.targettouches[0].clientx; ydown = e.targettouches[0].clienty; currentslide = instance.activeslide; media = currentslide.queryselector('.gslide-media'); isinlined = currentslide.queryselector('.gslide-inline'); mediaimage = null; if (hasclass(media, 'gslide-image')) { mediaimage = media.queryselector('img'); } removeclass(overlay, 'greset'); }, touchmove: function touchmove(e) { if (!process) { return; } endcoords = e.targettouches[0]; if (doingzoom || imagezoomed) { return; } if (isinlined && isinlined.offsetheight > winheight) { var moved = startcoords.pagex - endcoords.pagex; if (math.abs(moved) <= 13) { return false; } } doingmove = true; var xup = e.targettouches[0].clientx; var yup = e.targettouches[0].clienty; var xdiff = xdown - xup; var ydiff = ydown - yup; if (math.abs(xdiff) > math.abs(ydiff)) { vswipe = false; hswipe = true; } else { hswipe = false; vswipe = true; } hdistance = endcoords.pagex - startcoords.pagex; hdistancepercent = hdistance * 100 / winwidth; vdistance = endcoords.pagey - startcoords.pagey; vdistancepercent = vdistance * 100 / winheight; var opacity; if (vswipe && mediaimage) { opacity = 1 - math.abs(vdistance) / winheight; overlay.style.opacity = opacity; if (_this5.settings.touchfollowaxis) { hdistancepercent = 0; } } if (hswipe) { opacity = 1 - math.abs(hdistance) / winwidth; media.style.opacity = opacity; if (_this5.settings.touchfollowaxis) { vdistancepercent = 0; } } if (!mediaimage) { return slidecsstransform(media, "translate3d(".concat(hdistancepercent, "%, 0, 0)")); } slidecsstransform(media, "translate3d(".concat(hdistancepercent, "%, ").concat(vdistancepercent, "%, 0)")); }, touchend: function touchend() { if (!process) { return; } doingmove = false; if (imagezoomed || doingzoom) { lastzoomedposx = zoomedposx; lastzoomedposy = zoomedposy; return; } var v = math.abs(parseint(vdistancepercent)); var h = math.abs(parseint(hdistancepercent)); if (v > 29 && mediaimage) { _this5.close(); return; } if (v < 29 && h < 25) { addclass(overlay, 'greset'); overlay.style.opacity = 1; return resetslidemove(media); } }, multipointend: function multipointend() { settimeout(function () { doingzoom = false; }, 50); }, multipointstart: function multipointstart() { doingzoom = true; initscale = currentscale ? currentscale : 1; }, pinch: function pinch(evt) { if (!mediaimage || doingmove) { return false; } doingzoom = true; mediaimage.scalex = mediaimage.scaley = initscale * evt.zoom; var scale = initscale * evt.zoom; imagezoomed = true; if (scale <= 1) { imagezoomed = false; scale = 1; lastzoomedposy = null; lastzoomedposx = null; zoomedposx = null; zoomedposy = null; mediaimage.setattribute('style', ''); return; } if (scale > maxscale) { scale = maxscale; } mediaimage.style.transform = "scale3d(".concat(scale, ", ").concat(scale, ", 1)"); currentscale = scale; }, pressmove: function pressmove(e) { if (imagezoomed && !doingzoom) { var mhdistance = endcoords.pagex - startcoords.pagex; var mvdistance = endcoords.pagey - startcoords.pagey; if (lastzoomedposx) { mhdistance = mhdistance + lastzoomedposx; } if (lastzoomedposy) { mvdistance = mvdistance + lastzoomedposy; } zoomedposx = mhdistance; zoomedposy = mvdistance; var style = "translate3d(".concat(mhdistance, "px, ").concat(mvdistance, "px, 0)"); if (currentscale) { style += " scale3d(".concat(currentscale, ", ").concat(currentscale, ", 1)"); } slidecsstransform(mediaimage, style); } }, swipe: function swipe(evt) { if (imagezoomed) { return; } if (doingzoom) { doingzoom = false; return; } if (evt.direction == 'left') { if (_this5.index == _this5.elements.length - 1) { return resetslidemove(media); } _this5.nextslide(); } if (evt.direction == 'right') { if (_this5.index == 0) { return resetslidemove(media); } _this5.prevslide(); } } }); this.events['touch'] = touchinstance; } function slidecsstransform(slide) { var translate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; if (translate == '') { slide.style.webkittransform = ''; slide.style.moztransform = ''; slide.style.mstransform = ''; slide.style.otransform = ''; slide.style.transform = ''; return false; } slide.style.webkittransform = translate; slide.style.moztransform = translate; slide.style.mstransform = translate; slide.style.otransform = translate; slide.style.transform = translate; } function resetslidemove(slide) { var media = hasclass(slide, 'gslide-media') ? slide : slide.queryselector('.gslide-media'); var desc = slide.queryselector('.gslide-description'); addclass(media, 'greset'); slidecsstransform(media, "translate3d(0, 0, 0)"); var animation = addevent(transitionend, { onelement: media, once: true, withcallback: function withcallback(event, target) { removeclass(media, 'greset'); } }); media.style.opacity = ''; if (desc) { desc.style.opacity = ''; } } function slideshortdesc(string) { var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50; var wordboundary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var usewordboundary = wordboundary; string = string.trim(); if (string.length <= n) { return string; } var substring = string.substr(0, n - 1); if (!usewordboundary) { return substring; } return substring + '... ' + wordboundary + ''; } function slidedescriptionevents(desc, data) { var morelink = desc.queryselector('.desc-more'); if (!morelink) { return false; } addevent('click', { onelement: morelink, withcallback: function withcallback(event, target) { event.preventdefault(); var body = document.body; var desc = getclosest(target, '.gslide-desc'); if (!desc) { return false; } desc.innerhtml = data.description; addclass(body, 'gdesc-open'); var shortevent = addevent('click', { onelement: [body, getclosest(desc, '.gslide-description')], withcallback: function withcallback(event, target) { if (event.target.nodename.tolowercase() !== 'a') { removeclass(body, 'gdesc-open'); addclass(body, 'gdesc-closed'); desc.innerhtml = data.smalldescription; slidedescriptionevents(desc, data); settimeout(function () { removeclass(body, 'gdesc-closed'); }, 400); shortevent.destroy(); } } }); } }); } var glightboxinit = function () { function glightboxinit() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classcallcheck(this, glightboxinit); this.settings = extend(defaults, options); this.effectsclasses = this.getanimationclasses(); this.slidesdata = {}; } _createclass(glightboxinit, [{ key: "init", value: function init() { var _this6 = this; var selector = this.getselector(); if (selector) { this.baseevents = addevent('click', { onelement: selector, withcallback: function withcallback(e, target) { e.preventdefault(); _this6.open(target); } }); } this.elements = this.getelements(); } }, { key: "open", value: function open() { var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var startat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; if (this.elements.length == 0) return false; this.activeslide = null; this.prevactiveslideindex = null; this.prevactiveslide = null; var index = utils.isnumber(startat) ? startat : this.settings.startat; if (utils.isnode(element) && utils.isnil(index)) { index = this.getelementindex(element); if (index < 0) { index = 0; } } if (!utils.isnumber(index)) { index = 0; } this.build(); animateelement(this.overlay, this.settings.openeffect == 'none' ? 'none' : this.settings.cssefects.fade["in"]); var body = document.body; var scrollbar = window.innerwidth - document.documentelement.clientwidth; if (scrollbar > 0) { var stylesheet = document.createelement("style"); stylesheet.type = 'text/css'; stylesheet.classname = 'gcss-styles'; stylesheet.innertext = ".gscrollbar-fixer {margin-right: ".concat(scrollbar, "px}"); document.head.appendchild(stylesheet); addclass(body, 'gscrollbar-fixer'); } addclass(body, 'glightbox-open'); addclass(html, 'glightbox-open'); if (ismobile) { addclass(document.body, 'glightbox-mobile'); this.settings.slideeffect = 'slide'; } this.showslide(index, true); if (this.elements.length == 1) { hide(this.prevbutton); hide(this.nextbutton); } else { show(this.prevbutton); show(this.nextbutton); } this.lightboxopen = true; if (utils.isfunction(this.settings.onopen)) { this.settings.onopen(); } if (istouch && this.settings.touchnavigation) { touchnavigation.apply(this); return false; } if (this.settings.keyboardnavigation) { keyboardnavigation.apply(this); } } }, { key: "openat", value: function openat() { var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; this.open(null, index); } }, { key: "showslide", value: function showslide() { var _this7 = this; var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var first = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; show(this.loader); this.index = parseint(index); var current = this.slidescontainer.queryselector('.current'); if (current) { removeclass(current, 'current'); } this.slideanimateout(); var slide = this.slidescontainer.queryselectorall('.gslide')[index]; if (hasclass(slide, 'loaded')) { this.slideanimatein(slide, first); hide(this.loader); } else { show(this.loader); var slidedata = this.elements[index]; slidedata.index = index; this.slidesdata[index] = slidedata; setslidecontent.apply(this, [slide, slidedata, function () { hide(_this7.loader); _this7.resize(); _this7.slideanimatein(slide, first); }]); } this.slidedescription = slide.queryselector('.gslide-description'); this.slidedescriptioncontained = this.slidedescription && hasclass(this.slidedescription.parentnode, 'gslide-media'); this.preloadslide(index + 1); this.preloadslide(index - 1); this.updatenavigationclasses(); this.activeslide = slide; } }, { key: "preloadslide", value: function preloadslide(index) { var _this8 = this; if (index < 0 || index > this.elements.length - 1) return false; if (utils.isnil(this.elements[index])) return false; var slide = this.slidescontainer.queryselectorall('.gslide')[index]; if (hasclass(slide, 'loaded')) { return false; } var slidedata = this.elements[index]; slidedata.index = index; this.slidesdata[index] = slidedata; var type = slidedata.sourcetype; if (type == 'video' || type == 'external') { settimeout(function () { setslidecontent.apply(_this8, [slide, slidedata]); }, 200); } else { setslidecontent.apply(this, [slide, slidedata]); } } }, { key: "prevslide", value: function prevslide() { this.gotoslide(this.index - 1); } }, { key: "nextslide", value: function nextslide() { this.gotoslide(this.index + 1); } }, { key: "gotoslide", value: function gotoslide() { var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; this.prevactiveslide = this.activeslide; this.prevactiveslideindex = this.index; var loop = this.loop(); if (!loop && (index < 0 || index > this.elements.length - 1)) { return false; } if (index < 0) { index = this.elements.length - 1; } else if (index >= this.elements.length) { index = 0; } this.showslide(index); } }, { key: "insertslide", value: function insertslide() { var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; var defaults = extend({ descposition: this.settings.descposition }, singleslidedata); var newslide = createhtml(this.settings.slidehtml); var totalslides = this.elements.length - 1; if (index < 0) { index = this.elements.length; } data = extend(defaults, data); data.index = index; data.node = false; this.elements.splice(index, 0, data); if (this.slidescontainer) { if (index > totalslides) { this.slidescontainer.appendchild(newslide); } else { var existingslide = this.slidescontainer.queryselectorall('.gslide')[index]; this.slidescontainer.insertbefore(newslide, existingslide); } if (this.index == 0 && index == 0 || this.index - 1 == index || this.index + 1 == index) { this.preloadslide(index); } if (this.index == 0 && index == 0) { this.index = 1; } this.updatenavigationclasses(); } if (utils.isfunction(this.settings.slideinserted)) { this.settings.slideinserted({ index: index, slide: this.slidescontainer.queryselectorall('.gslide')[index], player: this.getslideplayerinstance(index) }); } } }, { key: "removeslide", value: function removeslide() { var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; if (index < 0 || index > this.elements.length - 1) { return false; } var slide = this.slidescontainer && this.slidescontainer.queryselectorall('.gslide')[index]; if (slide) { if (this.getactiveslideindex() == index) { if (index == this.elements.length - 1) { this.prevslide(); } else { this.nextslide(); } } slide.parentnode.removechild(slide); } this.elements.splice(index, 1); if (utils.isfunction(this.settings.slideremoved)) { this.settings.slideremoved(index); } } }, { key: "slideanimatein", value: function slideanimatein(slide, first) { var _this9 = this; var slidemedia = slide.queryselector('.gslide-media'); var slidedesc = slide.queryselector('.gslide-description'); var prevdata = { index: this.prevactiveslideindex, slide: this.prevactiveslide, player: this.getslideplayerinstance(this.prevactiveslideindex) }; var nextdata = { index: this.index, slide: this.activeslide, player: this.getslideplayerinstance(this.index) }; if (slidemedia.offsetwidth > 0 && slidedesc) { hide(slidedesc); slidedesc.style.display = ''; } removeclass(slide, this.effectsclasses); if (first) { animateelement(slide, this.settings.openeffect, function () { if (!ismobile && _this9.settings.autoplayvideos) { _this9.playslidevideo(slide); } if (utils.isfunction(_this9.settings.afterslidechange)) { _this9.settings.afterslidechange.apply(_this9, [prevdata, nextdata]); } }); } else { var effect_name = this.settings.slideeffect; var animin = effect_name !== 'none' ? this.settings.cssefects[effect_name]["in"] : effect_name; if (this.prevactiveslideindex > this.index) { if (this.settings.slideeffect == 'slide') { animin = this.settings.cssefects.slide_back["in"]; } } animateelement(slide, animin, function () { if (!ismobile && _this9.settings.autoplayvideos) { _this9.playslidevideo(slide); } if (utils.isfunction(_this9.settings.afterslidechange)) { _this9.settings.afterslidechange.apply(_this9, [prevdata, nextdata]); } }); } settimeout(function () { _this9.resize(slide); }, 100); addclass(slide, 'current'); } }, { key: "slideanimateout", value: function slideanimateout() { if (!this.prevactiveslide) { return false; } var prevslide = this.prevactiveslide; removeclass(prevslide, this.effectsclasses); addclass(prevslide, 'prev'); var animation = this.settings.slideeffect; var animout = animation !== 'none' ? this.settings.cssefects[animation].out : animation; this.stopslidevideo(prevslide); if (utils.isfunction(this.settings.beforeslidechange)) { this.settings.beforeslidechange.apply(this, [{ index: this.prevactiveslideindex, slide: this.prevactiveslide, player: this.getslideplayerinstance(this.prevactiveslideindex) }, { index: this.index, slide: this.activeslide, player: this.getslideplayerinstance(this.index) }]); } if (this.prevactiveslideindex > this.index && this.settings.slideeffect == 'slide') { animout = this.settings.cssefects.slide_back.out; } animateelement(prevslide, animout, function () { var media = prevslide.queryselector('.gslide-media'); var desc = prevslide.queryselector('.gslide-description'); media.style.transform = ''; removeclass(media, 'greset'); media.style.opacity = ''; if (desc) { desc.style.opacity = ''; } removeclass(prevslide, 'prev'); }); } }, { key: "getallplayers", value: function getallplayers() { return videoplayers; } }, { key: "getslideplayerinstance", value: function getslideplayerinstance(index) { var id = 'gvideo' + index; if (utils.has(videoplayers, id) && videoplayers[id]) { return videoplayers[id]; } return false; } }, { key: "stopslidevideo", value: function stopslidevideo(slide) { if (utils.isnode(slide)) { var node = slide.queryselector('.gvideo-wrapper'); if (node) { slide = node.getattribute('data-index'); } } var player = this.getslideplayerinstance(slide); if (player && player.playing) { player.pause(); } } }, { key: "playslidevideo", value: function playslidevideo(slide) { if (utils.isnode(slide)) { var node = slide.queryselector('.gvideo-wrapper'); if (node) { slide = node.getattribute('data-index'); } } var player = this.getslideplayerinstance(slide); if (player && !player.playing) { player.play(); } } }, { key: "setelements", value: function setelements(elements) { var _this10 = this; this.settings.elements = false; var newelements = []; each(elements, function (el) { var data = getslidedata(el, _this10.settings); newelements.push(data); }); this.elements = newelements; if (this.lightboxopen) { this.slidescontainer.innerhtml = ''; each(this.elements, function () { var slide = createhtml(_this10.settings.slidehtml); _this10.slidescontainer.appendchild(slide); }); this.showslide(0, true); } } }, { key: "getelementindex", value: function getelementindex(node) { var index = false; each(this.elements, function (el, i) { if (utils.has(el, 'node') && el.node == node) { index = i; return true; } }); return index; } }, { key: "getelements", value: function getelements() { var _this11 = this; var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var list = []; this.elements = this.elements ? this.elements : []; if (!utils.isnil(this.settings.elements) && utils.isarray(this.settings.elements)) { list = this.settings.elements; } var nodes = false; var selector = this.getselector(); if (element !== null) { var gallery = element.getattribute('data-gallery'); if (gallery && gallery !== '') { nodes = document.queryselectorall("[data-gallery=\"".concat(gallery, "\"]")); } } if (nodes == false && selector) { nodes = document.queryselectorall(this.getselector()); } if (!nodes) { return list; } each(nodes, function (el, i) { var eldata = getslidedata(el, _this11.settings); eldata.node = el; eldata.index = i; list.push(eldata); }); return list; } }, { key: "getselector", value: function getselector() { if (this.settings.selector && this.settings.selector.substring(0, 5) == 'data-') { return "*[".concat(this.settings.selector, "]"); } return this.settings.selector; } }, { key: "getactiveslide", value: function getactiveslide() { return this.slidescontainer.queryselectorall('.gslide')[this.index]; } }, { key: "getactiveslideindex", value: function getactiveslideindex() { return this.index; } }, { key: "getanimationclasses", value: function getanimationclasses() { var effects = []; for (var key in this.settings.cssefects) { if (this.settings.cssefects.hasownproperty(key)) { var effect = this.settings.cssefects[key]; effects.push("g".concat(effect["in"])); effects.push("g".concat(effect.out)); } } return effects.join(' '); } }, { key: "build", value: function build() { var _this12 = this; if (this.built) { return false; } var nextsvg = utils.has(this.settings.svg, 'next') ? this.settings.svg.next : ''; var prevsvg = utils.has(this.settings.svg, 'prev') ? this.settings.svg.prev : ''; var closesvg = utils.has(this.settings.svg, 'close') ? this.settings.svg.close : ''; var lightboxhtml = this.settings.lightboxhtml; lightboxhtml = lightboxhtml.replace(/{nextsvg}/g, nextsvg); lightboxhtml = lightboxhtml.replace(/{prevsvg}/g, prevsvg); lightboxhtml = lightboxhtml.replace(/{closesvg}/g, closesvg); lightboxhtml = createhtml(lightboxhtml); document.body.appendchild(lightboxhtml); var modal = document.getelementbyid('glightbox-body'); this.modal = modal; var closebutton = modal.queryselector('.gclose'); this.prevbutton = modal.queryselector('.gprev'); this.nextbutton = modal.queryselector('.gnext'); this.overlay = modal.queryselector('.goverlay'); this.loader = modal.queryselector('.gloader'); this.slidescontainer = document.getelementbyid('glightbox-slider'); this.events = {}; addclass(this.modal, 'glightbox-' + this.settings.skin); if (this.settings.closebutton && closebutton) { this.events['close'] = addevent('click', { onelement: closebutton, withcallback: function withcallback(e, target) { e.preventdefault(); _this12.close(); } }); } if (closebutton && !this.settings.closebutton) { closebutton.parentnode.removechild(closebutton); } if (this.nextbutton) { this.events['next'] = addevent('click', { onelement: this.nextbutton, withcallback: function withcallback(e, target) { e.preventdefault(); _this12.nextslide(); } }); } if (this.prevbutton) { this.events['prev'] = addevent('click', { onelement: this.prevbutton, withcallback: function withcallback(e, target) { e.preventdefault(); _this12.prevslide(); } }); } if (this.settings.closeonoutsideclick) { this.events['outclose'] = addevent('click', { onelement: modal, withcallback: function withcallback(e, target) { if (!hasclass(document.body, 'glightbox-mobile') && !getclosest(e.target, '.ginner-container')) { if (!getclosest(e.target, '.gbtn') && !hasclass(e.target, 'gnext') && !hasclass(e.target, 'gprev')) { _this12.close(); } } } }); } each(this.elements, function () { var slide = createhtml(_this12.settings.slidehtml); _this12.slidescontainer.appendchild(slide); }); if (istouch) { addclass(document.body, 'glightbox-touch'); } this.events['resize'] = addevent('resize', { onelement: window, withcallback: function withcallback() { _this12.resize(); } }); this.built = true; } }, { key: "resize", value: function resize() { var slide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; slide = !slide ? this.activeslide : slide; if (!slide || hasclass(slide, 'zoomed')) { return; } var winsize = windowsize(); var video = slide.queryselector('.gvideo-wrapper'); var image = slide.queryselector('.gslide-image'); var description = this.slidedescription; var winwidth = winsize.width; var winheight = winsize.height; if (winwidth <= 768) { addclass(document.body, 'glightbox-mobile'); } else { removeclass(document.body, 'glightbox-mobile'); } if (!video && !image) { return; } var descriptionresize = false; if (description && (hasclass(description, 'description-bottom') || hasclass(description, 'description-top')) && !hasclass(description, 'gabsolute')) { descriptionresize = true; } if (image) { if (winwidth <= 768) { var imgnode = image.queryselector('img'); imgnode.setattribute('style', ''); } else if (descriptionresize) { var descheight = description.offsetheight; var maxwidth = this.slidesdata[this.index].width; maxwidth = maxwidth <= winwidth ? maxwidth + 'px' : '100%'; var _imgnode = image.queryselector('img'); _imgnode.setattribute('style', "max-height: calc(100vh - ".concat(descheight, "px)")); description.setattribute('style', "max-width: ".concat(_imgnode.offsetwidth, "px;")); } } if (video) { var ratio = utils.has(this.settings.plyr.config, 'ratio') ? this.settings.plyr.config.ratio : '16:9'; var videoratio = ratio.split(':'); var _maxwidth = this.slidesdata[this.index].width; var maxheight = _maxwidth / (parseint(videoratio[0]) / parseint(videoratio[1])); maxheight = math.floor(maxheight); if (descriptionresize) { winheight = winheight - description.offsetheight; } if (winheight < maxheight && winwidth > _maxwidth) { var vwidth = video.offsetwidth; var vheight = video.offsetheight; var _ratio = winheight / vheight; var vsize = { width: vwidth * _ratio, height: vheight * _ratio }; video.parentnode.setattribute('style', "max-width: ".concat(vsize.width, "px")); if (descriptionresize) { description.setattribute('style', "max-width: ".concat(vsize.width, "px;")); } } else { video.parentnode.style.maxwidth = "".concat(_maxwidth, "px"); if (descriptionresize) { description.setattribute('style', "max-width: ".concat(_maxwidth, "px;")); } } } } }, { key: "reload", value: function reload() { this.init(); } }, { key: "updatenavigationclasses", value: function updatenavigationclasses() { var loop = this.loop(); removeclass(this.nextbutton, 'disabled'); removeclass(this.prevbutton, 'disabled'); if (this.index == 0 && this.elements.length - 1 == 0) { addclass(this.prevbutton, 'disabled'); addclass(this.nextbutton, 'disabled'); } else if (this.index === 0 && !loop) { addclass(this.prevbutton, 'disabled'); } else if (this.index === this.elements.length - 1 && !loop) { addclass(this.nextbutton, 'disabled'); } } }, { key: "loop", value: function loop() { var loop = utils.has(this.settings, 'loopatend') ? this.settings.loopatend : null; loop = utils.has(this.settings, 'loop') ? this.settings.loop : loop; return loop; } }, { key: "close", value: function close() { var _this13 = this; if (!this.lightboxopen) { if (this.events) { for (var key in this.events) { if (this.events.hasownproperty(key)) { this.events[key].destroy(); } } this.events = null; } return false; } if (this.closing) { return false; } this.closing = true; this.stopslidevideo(this.activeslide); addclass(this.modal, 'glightbox-closing'); animateelement(this.overlay, this.settings.openeffect == 'none' ? 'none' : this.settings.cssefects.fade.out); animateelement(this.activeslide, this.settings.closeeffect, function () { _this13.activeslide = null; _this13.prevactiveslideindex = null; _this13.prevactiveslide = null; _this13.built = false; if (_this13.events) { for (var _key in _this13.events) { if (_this13.events.hasownproperty(_key)) { _this13.events[_key].destroy(); } } _this13.events = null; } var body = document.body; removeclass(html, 'glightbox-open'); removeclass(body, 'glightbox-open touching gdesc-open glightbox-touch glightbox-mobile gscrollbar-fixer'); _this13.modal.parentnode.removechild(_this13.modal); if (utils.isfunction(_this13.settings.onclose)) { _this13.settings.onclose(); } var styles = document.queryselector('.gcss-styles'); if (styles) { styles.parentnode.removechild(styles); } _this13.lightboxopen = false; _this13.closing = null; }); } }, { key: "destroy", value: function destroy() { this.close(); this.baseevents.destroy(); } }]); return glightboxinit; }(); function glightbox () { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var instance = new glightboxinit(options); instance.init(); return instance; } return glightbox; })));