(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; } var uid = date.now(); 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; } function each(collection, callback) { if (isnode(collection) || collection === window || collection === document) { collection = [collection]; } if (!isarraylike(collection) && !isobject(collection)) { collection = [collection]; } if (size(collection) == 0) { return; } if (isarraylike(collection) && !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 (isobject(collection)) { for (var key in collection) { if (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 && 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 (isstring(element)) { element = document.queryselectorall(element); } function handler(event) { if (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 closest(elem, selector) { while (elem !== document.body) { elem = elem.parentelement; if (!elem) { return false; } var matches = typeof elem.matches == 'function' ? elem.matches(selector) : elem.msmatchesselector(selector); if (matches) { return elem; } } } 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 (isfunction(callback)) { callback(); } return false; } var animationend = whichanimationevent(); 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 (isfunction(callback)) { callback(); } } }); } function csstransform(node) { var translate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; if (translate == '') { node.style.webkittransform = ''; node.style.moztransform = ''; node.style.mstransform = ''; node.style.otransform = ''; node.style.transform = ''; return false; } node.style.webkittransform = translate; node.style.moztransform = translate; node.style.mstransform = translate; node.style.otransform = translate; node.style.transform = translate; } function show(element) { element.style.display = 'block'; } function hide(element) { element.style.display = 'none'; } function createhtml(htmlstr) { var frag = document.createdocumentfragment(), temp = document.createelement('div'); temp.innerhtml = htmlstr; while (temp.firstchild) { frag.appendchild(temp.firstchild); } return frag; } function windowsize() { return { width: window.innerwidth || document.documentelement.clientwidth || document.body.clientwidth, height: window.innerheight || document.documentelement.clientheight || document.body.clientheight }; } 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 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 (isfunction(callback)) { callback(); } }; if (appendto) { appendto.appendchild(iframe); } return iframe; } 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 injectassets(url, waitfor, callback) { if (isnil(url)) { console.error('inject assets error'); return; } if (isfunction(waitfor)) { callback = waitfor; waitfor = false; } if (isstring(waitfor) && waitfor in window) { if (isfunction(callback)) { callback(); } return; } var found; if (url.indexof('.css') !== -1) { found = document.queryselectorall('link[href="' + url + '"]'); if (found && found.length > 0) { if (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 (isfunction(callback)) { callback(); } return; } found = document.queryselectorall('script[src="' + url + '"]'); if (found && found.length > 0) { if (isfunction(callback)) { if (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 (isfunction(callback)) { if (isstring(waitfor)) { waituntil(function () { return typeof window[waitfor] !== 'undefined'; }, function () { callback(); }); return false; } callback(); } }; document.body.appendchild(script); return; } function ismobile() { return 'navigator' in window && window.navigator.useragent.match(/(ipad)|(iphone)|(ipod)|(android)|(playbook)|(bb10)|(blackberry)|(opera mini)|(iemobile)|(webos)|(meego)/i); } function istouch() { return ismobile() !== null || document.createtouch !== undefined || 'ontouchstart' in window || 'onmsgesturechange' in window || navigator.msmaxtouchpoints; } function isfunction(f) { return typeof f === 'function'; } function isstring(s) { return typeof s === 'string'; } function isnode(el) { return !!(el && el.nodetype && el.nodetype == 1); } function isarray(ar) { return array.isarray(ar); } function isarraylike(ar) { return ar && ar.length && isfinite(ar.length); } function isobject(o) { var type = _typeof(o); return type === 'object' && o != null && !isfunction(o) && !isarray(o); } function isnil(o) { return o == null; } function has(obj, key) { return obj !== null && hasownproperty.call(obj, key); } function size(o) { if (isobject(o)) { if (o.keys) { return o.keys().length; } var l = 0; for (var k in o) { if (has(o, k)) { l++; } } return l; } else { return o.length; } } function isnumber(n) { return !isnan(parsefloat(n)) && isfinite(n); } function getnextfocuselement() { var current = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; var btns = document.queryselectorall('.gbtn[data-taborder]:not(.disabled)'); if (!btns.length) { return false; } if (btns.length == 1) { return btns[0]; } if (typeof current == 'string') { current = parseint(current); } var newindex = current < 0 ? 1 : current + 1; if (newindex > btns.length) { newindex = '1'; } var orders = []; each(btns, function (btn) { orders.push(btn.getattribute('data-taborder')); }); var nextorders = orders.filter(function (el) { return el >= parseint(newindex); }); var nextfocus = nextorders.sort()[0]; return document.queryselector(".gbtn[data-taborder=\"".concat(nextfocus, "\"]")); } function keyboardnavigation(instance) { if (instance.events.hasownproperty('keyboard')) { return false; } instance.events['keyboard'] = addevent('keydown', { onelement: window, withcallback: function withcallback(event, target) { event = event || window.event; var key = event.keycode; if (key == 9) { var focusedbutton = document.queryselector('.gbtn.focused'); if (!focusedbutton) { 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[data-taborder]'); if (!btns || btns.length <= 0) { return; } if (!focusedbutton) { var first = getnextfocuselement(); if (first) { first.focus(); addclass(first, 'focused'); } return; } var currentfocusorder = focusedbutton.getattribute('data-taborder'); var nextfocus = getnextfocuselement(currentfocusorder); removeclass(focusedbutton, 'focused'); if (nextfocus) { nextfocus.focus(); addclass(nextfocus, 'focused'); } } if (key == 39) { instance.nextslide(); } if (key == 37) { instance.prevslide(); } if (key == 27) { instance.close(); } } }); } 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.translatecontainer = this.element; 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; } var ignoredragfor = ['a', 'button', 'input']; if (evt.target && evt.target.nodename && ignoredragfor.indexof(evt.target.nodename.tolowercase()) >= 0) { console.log('ignore drag for this touched element', evt.target.nodename.tolowercase()); 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; }(); function resetslidemove(slide) { var transitionend = whichtransitionevent(); var windowwidth = window.innerwidth || document.documentelement.clientwidth || document.body.clientwidth; var media = hasclass(slide, 'gslide-media') ? slide : slide.queryselector('.gslide-media'); var container = closest(media, '.ginner-container'); var desc = slide.queryselector('.gslide-description'); if (windowwidth > 769) { media = container; } addclass(media, 'greset'); csstransform(media, 'translate3d(0, 0, 0)'); addevent(transitionend, { onelement: media, once: true, withcallback: function withcallback(event, target) { removeclass(media, 'greset'); } }); media.style.opacity = ''; if (desc) { desc.style.opacity = ''; } } function touchnavigation(instance) { if (instance.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 sliderwrapper = document.getelementbyid('glightbox-slider'); var overlay = document.queryselector('.goverlay'); var touchinstance = new touchevents(sliderwrapper, { touchstart: function touchstart(e) { process = true; if (hasclass(e.targettouches[0].target, 'ginner-container') || closest(e.targettouches[0].target, '.gslide-desc') || e.targettouches[0].target.nodename.tolowercase() == 'a') { process = false; } if (closest(e.targettouches[0].target, '.gslide-inline') && !hasclass(e.targettouches[0].target.parentnode, 'gslide-inline')) { process = false; } if (process) { 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'); } var windowwidth = window.innerwidth || document.documentelement.clientwidth || document.body.clientwidth; if (windowwidth > 769) { media = currentslide.queryselector('.ginner-container'); } removeclass(overlay, 'greset'); if (e.pagex > 20 && e.pagex < window.innerwidth - 20) { return; } e.preventdefault(); } }, 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 (instance.settings.touchfollowaxis) { hdistancepercent = 0; } } if (hswipe) { opacity = 1 - math.abs(hdistance) / winwidth; media.style.opacity = opacity; if (instance.settings.touchfollowaxis) { vdistancepercent = 0; } } if (!mediaimage) { return csstransform(media, "translate3d(".concat(hdistancepercent, "%, 0, 0)")); } csstransform(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) { instance.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)"); } csstransform(mediaimage, style); } }, swipe: function swipe(evt) { if (imagezoomed) { return; } if (doingzoom) { doingzoom = false; return; } if (evt.direction == 'left') { if (instance.index == instance.elements.length - 1) { return resetslidemove(media); } instance.nextslide(); } if (evt.direction == 'right') { if (instance.index == 0) { return resetslidemove(media); } instance.prevslide(); } } }); instance.events['touch'] = touchinstance; } 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.slide.classlist.contains('dragging-nav')) { _this.zoomout(); return false; } 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 dragslides = function () { function dragslides() { var _this = this; var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classcallcheck(this, dragslides); var dragel = config.dragel, _config$tolerancex = config.tolerancex, tolerancex = _config$tolerancex === void 0 ? 40 : _config$tolerancex, _config$tolerancey = config.tolerancey, tolerancey = _config$tolerancey === void 0 ? 65 : _config$tolerancey, _config$slide = config.slide, slide = _config$slide === void 0 ? null : _config$slide, _config$instance = config.instance, instance = _config$instance === void 0 ? null : _config$instance; this.el = dragel; this.active = false; this.dragging = false; this.currentx = null; this.currenty = null; this.initialx = null; this.initialy = null; this.xoffset = 0; this.yoffset = 0; this.direction = null; this.lastdirection = null; this.tolerancex = tolerancex; this.tolerancey = tolerancey; this.tolerancereached = false; this.dragcontainer = this.el; this.slide = slide; this.instance = instance; this.el.addeventlistener('mousedown', function (e) { return _this.dragstart(e); }, false); this.el.addeventlistener('mouseup', function (e) { return _this.dragend(e); }, false); this.el.addeventlistener('mousemove', function (e) { return _this.drag(e); }, false); } _createclass(dragslides, [{ key: "dragstart", value: function dragstart(e) { if (this.slide.classlist.contains('zoomed')) { 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; } var clicked = e.target.nodename.tolowercase(); var exludeclicks = ['input', 'select', 'textarea', 'button', 'a']; if (e.target.classlist.contains('nodrag') || closest(e.target, '.nodrag') || exludeclicks.indexof(clicked) !== -1) { this.active = false; return; } e.preventdefault(); if (e.target === this.el || clicked !== 'img' && closest(e.target, '.gslide-inline')) { this.active = true; this.el.classlist.add('dragging'); this.dragcontainer = closest(e.target, '.ginner-container'); } } }, { key: "dragend", value: function dragend(e) { var _this2 = this; e && e.preventdefault(); this.initialx = 0; this.initialy = 0; this.currentx = null; this.currenty = null; this.initialx = null; this.initialy = null; this.xoffset = 0; this.yoffset = 0; this.active = false; if (this.doslidechange) { this.instance.preventoutsideclick = true; this.doslidechange == 'right' && this.instance.prevslide(); this.doslidechange == 'left' && this.instance.nextslide(); } if (this.doslideclose) { this.instance.close(); } if (!this.tolerancereached) { this.settranslate(this.dragcontainer, 0, 0, true); } settimeout(function () { _this2.instance.preventoutsideclick = false; _this2.tolerancereached = false; _this2.lastdirection = null; _this2.dragging = false; _this2.el.isdragging = false; _this2.el.classlist.remove('dragging'); _this2.slide.classlist.remove('dragging-nav'); _this2.dragcontainer.style.transform = ''; _this2.dragcontainer.style.transition = ''; }, 100); } }, { key: "drag", value: function drag(e) { if (this.active) { e.preventdefault(); this.slide.classlist.add('dragging-nav'); 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.el.isdragging = true; this.dragging = true; this.doslidechange = false; this.doslideclose = false; var currentxint = math.abs(this.currentx); var currentyint = math.abs(this.currenty); if (currentxint > 0 && currentxint >= math.abs(this.currenty) && (!this.lastdirection || this.lastdirection == 'x')) { this.yoffset = 0; this.lastdirection = 'x'; this.settranslate(this.dragcontainer, this.currentx, 0); var dochange = this.shouldchange(); if (!this.instance.settings.dragautosnap && dochange) { this.doslidechange = dochange; } if (this.instance.settings.dragautosnap && dochange) { this.instance.preventoutsideclick = true; this.tolerancereached = true; this.active = false; this.instance.preventoutsideclick = true; this.dragend(null); dochange == 'right' && this.instance.prevslide(); dochange == 'left' && this.instance.nextslide(); return; } } if (this.tolerancey > 0 && currentyint > 0 && currentyint >= currentxint && (!this.lastdirection || this.lastdirection == 'y')) { this.xoffset = 0; this.lastdirection = 'y'; this.settranslate(this.dragcontainer, 0, this.currenty); var doclose = this.shouldclose(); if (!this.instance.settings.dragautosnap && doclose) { this.doslideclose = true; } if (this.instance.settings.dragautosnap && doclose) { this.instance.close(); } return; } } } }, { key: "shouldchange", value: function shouldchange() { var dochange = false; var currentxint = math.abs(this.currentx); if (currentxint >= this.tolerancex) { var dragdir = this.currentx > 0 ? 'right' : 'left'; if (dragdir == 'left' && this.slide !== this.slide.parentnode.lastchild || dragdir == 'right' && this.slide !== this.slide.parentnode.firstchild) { dochange = dragdir; } } return dochange; } }, { key: "shouldclose", value: function shouldclose() { var doclose = false; var currentyint = math.abs(this.currenty); if (currentyint >= this.tolerancey) { doclose = true; } return doclose; } }, { key: "settranslate", value: function settranslate(node, xpos, ypos) { var animated = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; if (animated) { node.style.transition = 'all .2s ease'; } else { node.style.transition = ''; } node.style.transform = "translate3d(".concat(xpos, "px, ").concat(ypos, "px, 0)"); } }]); return dragslides; }(); function slideimage(slide, data, index, callback) { var slidemedia = slide.queryselector('.gslide-media'); var img = new image(); var titleid = 'gslidetitle_' + index; var textid = 'gslidedesc_' + index; img.addeventlistener('load', function () { if (isfunction(callback)) { callback(); } }, false); img.src = data.href; img.alt = ''; if (!isnil(data.alt) && data.alt !== '') { img.alt = data.alt; } if (data.title !== '') { img.setattribute('aria-labelledby', titleid); } if (data.description !== '') { img.setattribute('aria-describedby', textid); } if (data.hasownproperty('_hascustomwidth') && data._hascustomwidth) { img.style.width = data.width; } if (data.hasownproperty('_hascustomheight') && data._hascustomheight) { img.style.height = data.height; } slidemedia.insertbefore(img, slidemedia.firstchild); return; } function slidevideo(slide, data, index, callback) { var _this = this; var slidecontainer = slide.queryselector('.ginner-container'); var videoid = 'gvideo' + index; var slidemedia = slide.queryselector('.gslide-media'); var videoplayers = this.getallplayers(); addclass(slidecontainer, 'gvideo-container'); slidemedia.insertbefore(createhtml('
'), slidemedia.firstchild); var videowrapper = slide.queryselector('.gvideo-wrapper'); injectassets(this.settings.plyr.css, 'plyr'); var url = data.href; var protocol = location.protocol.replace(':', ''); var videosource = ''; var embedid = ''; var customplaceholder = false; if (protocol == 'file') { protocol = 'http'; } slidemedia.style.maxwidth = data.width; injectassets(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(videowrapper, "".concat(videosource, "-video gvideo")); videowrapper.appendchild(placeholder); videowrapper.setattribute('data-id', videoid); videowrapper.setattribute('data-index', index); var playerconfig = has(_this.settings.plyr, 'config') ? _this.settings.plyr.config : {}; var player = new plyr('#' + videoid, playerconfig); player.on('ready', function (event) { var instance = event.detail.plyr; videoplayers[videoid] = instance; if (isfunction(callback)) { callback(); } }); waituntil(function () { return slide.queryselector('iframe') && slide.queryselector('iframe').dataset.ready == 'true'; }, function () { _this.resize(slide); }); player.on('enterfullscreen', handlemediafullscreen); player.on('exitfullscreen', handlemediafullscreen); }); } 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 handlemediafullscreen(event) { var media = closest(event.target, '.gslide-media'); if (event.type == 'enterfullscreen') { addclass(media, 'fullscreen'); } if (event.type == 'exitfullscreen') { removeclass(media, 'fullscreen'); } } function slideinline(slide, data, index, callback) { var _this = this; var slidemedia = slide.queryselector('.gslide-media'); var hash = has(data, 'href') && data.href ? data.href.split('#').pop().trim() : false; var content = has(data, 'content') && data.content ? data.content : false; var innercontent; if (content) { if (isstring(content)) { innercontent = createhtml("
".concat(content, "
")); } if (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(); _this.close(); } }); if (isfunction(callback)) { callback(); } return; } function slideiframe(slide, data, index, callback) { var slidemedia = slide.queryselector('.gslide-media'); var iframe = createiframe({ url: data.href, callback: callback }); slidemedia.parentnode.style.maxwidth = data.width; slidemedia.parentnode.style.height = data.height; slidemedia.appendchild(iframe); return; } var slideconfigparser = function () { function slideconfigparser() { var slideparamas = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classcallcheck(this, slideconfigparser); this.defaults = { href: '', title: '', type: '', description: '', alt: '', descposition: 'bottom', effect: '', width: '', height: '', content: false, zoomable: true, draggable: true }; if (isobject(slideparamas)) { this.defaults = extend(this.defaults, slideparamas); } } _createclass(slideconfigparser, [{ key: "sourcetype", value: function sourcetype(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.match(/\.(mp3|wav|wma|aac|ogg)$/) !== null) { return 'audio'; } if (url.indexof('#') > -1) { var hash = origin.split('#').pop(); if (hash.trim() !== '') { return 'inline'; } } if (url.indexof('goajax=true') > -1) { return 'ajax'; } return 'external'; } }, { key: "parseconfig", value: function parseconfig(element, settings) { var _this = this; var data = extend({ descposition: settings.descposition }, this.defaults); if (isobject(element) && !isnode(element)) { if (!has(element, 'type')) { if (has(element, 'content') && element.content) { element.type = 'inline'; } else if (has(element, 'href')) { element.type = this.sourcetype(element.href); } } var objectdata = extend(data, element); this.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.alt = element.alt; } data.href = url; each(data, function (val, key) { if (has(settings, key) && key !== 'width') { data[key] = settings[key]; } var nodedata = element.dataset[key]; if (!isnil(nodedata)) { data[key] = _this.sanitizevalue(nodedata); } }); if (data.content) { data.type = 'inline'; } if (!data.type && url) { data.type = this.sourcetype(url); } if (!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] = _this.sanitizevalue(value); } }); } } else { if (!data.title && nodetype == 'a') { var title = element.title; if (!isnil(title) && title !== '') { data.title = title; } } if (!data.title && nodetype == 'img') { var alt = element.alt; if (!isnil(alt) && alt !== '') { data.title = alt; } } } if (data.description && data.description.substring(0, 1) === '.') { var description; try { description = document.queryselector(data.description).innerhtml; } catch (error) { if (!(error instanceof domexception)) { throw error; } } if (description) { data.description = description; } } if (!data.description) { var nodedesc = element.queryselector('.glightbox-desc'); if (nodedesc) { data.description = nodedesc.innerhtml; } } this.setsize(data, settings, element); this.slideconfig = data; return data; } }, { key: "setsize", value: function setsize(data, settings) { var element = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var defaultwith = data.type == 'video' ? this.checksize(settings.videoswidth) : this.checksize(settings.width); var defaultheight = this.checksize(settings.height); data.width = has(data, 'width') && data.width !== '' ? this.checksize(data.width) : defaultwith; data.height = has(data, 'height') && data.height !== '' ? this.checksize(data.height) : defaultheight; if (element && data.type == 'image') { data._hascustomwidth = element.dataset.width ? true : false; data._hascustomheight = element.dataset.height ? true : false; } return data; } }, { key: "checksize", value: function checksize(size) { return isnumber(size) ? "".concat(size, "px") : size; } }, { key: "sanitizevalue", value: function sanitizevalue(val) { if (val !== 'true' && val !== 'false') { return val; } return val === 'true'; } }]); return slideconfigparser; }(); var slide = function () { function slide(el, instance, index) { _classcallcheck(this, slide); this.element = el; this.instance = instance; this.index = index; } _createclass(slide, [{ key: "setcontent", value: function setcontent() { var _this = this; var slide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (hasclass(slide, 'loaded')) { return false; } var settings = this.instance.settings; var slideconfig = this.slideconfig; var ismobiledevice = ismobile(); if (isfunction(settings.beforeslideload)) { settings.beforeslideload({ index: this.index, slide: slide, player: false }); } var type = slideconfig.type; var position = slideconfig.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_' + this.index; var textid = 'gslidedesc_' + this.index; if (isfunction(settings.afterslideload)) { finalcallback = function finalcallback() { if (isfunction(callback)) { callback(); } settings.afterslideload({ index: _this.index, slide: slide, player: _this.instance.getslideplayerinstance(_this.index) }); }; } if (slideconfig.title == '' && slideconfig.description == '') { if (slidedesc) { slidedesc.parentnode.parentnode.removechild(slidedesc.parentnode); } } else { if (slidetitle && slideconfig.title !== '') { slidetitle.id = titleid; slidetitle.innerhtml = slideconfig.title; } else { slidetitle.parentnode.removechild(slidetitle); } if (slidetext && slideconfig.description !== '') { slidetext.id = textid; if (ismobiledevice && settings.morelength > 0) { slideconfig.smalldescription = this.slideshortdesc(slideconfig.description, settings.morelength, settings.moretext); slidetext.innerhtml = slideconfig.smalldescription; this.descriptionevents(slidetext, slideconfig); } else { slidetext.innerhtml = slideconfig.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') { slidevideo.apply(this.instance, [slide, slideconfig, this.index, finalcallback]); return; } if (type === 'external') { slideiframe.apply(this, [slide, slideconfig, this.index, finalcallback]); return; } if (type === 'inline') { slideinline.apply(this.instance, [slide, slideconfig, this.index, finalcallback]); if (settings.draggable) { new dragslides({ dragel: slide.queryselector('.gslide-inline'), tolerancex: settings.dragtolerancex, tolerancey: settings.dragtolerancey, slide: slide, instance: this.instance }); } return; } if (type === 'image') { slideimage(slide, slideconfig, this.index, function () { var img = slide.queryselector('img'); if (settings.draggable) { new dragslides({ dragel: img, tolerancex: settings.dragtolerancex, tolerancey: settings.dragtolerancey, slide: slide, instance: _this.instance }); } if (slideconfig.zoomable && img.naturalwidth > img.offsetwidth) { addclass(img, 'zoomable'); new zoomimages(img, slide, function () { _this.instance.resize(); }); } if (isfunction(finalcallback)) { finalcallback(); } }); return; } if (isfunction(finalcallback)) { finalcallback(); } } }, { key: "slideshortdesc", value: 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 div = document.createelement('div'); div.innerhtml = string; var cleanedstring = div.innertext; var usewordboundary = wordboundary; string = cleanedstring.trim(); if (string.length <= n) { return string; } var substring = string.substr(0, n - 1); if (!usewordboundary) { return substring; } div = null; return substring + '... ' + wordboundary + ''; } }, { key: "descriptionevents", value: function descriptionevents(desc, data) { var _this2 = this; 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 = closest(target, '.gslide-desc'); if (!desc) { return false; } desc.innerhtml = data.description; addclass(body, 'gdesc-open'); var shortevent = addevent('click', { onelement: [body, closest(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; _this2.descriptionevents(desc, data); settimeout(function () { removeclass(body, 'gdesc-closed'); }, 400); shortevent.destroy(); } } }); } }); } }, { key: "create", value: function create() { return createhtml(this.instance.settings.slidehtml); } }, { key: "getconfig", value: function getconfig() { var parser = new slideconfigparser(this.instance.settings.slideextraattributes); this.slideconfig = parser.parseconfig(this.element, this.instance.settings); return this.slideconfig; } }]); return slide; }(); var _version = '3.0.9'; var ismobile$1 = ismobile(); var istouch$1 = istouch(); var html = document.getelementsbytagname('html')[0]; var defaults = { selector: '.glightbox', elements: null, skin: 'clean', theme: 'clean', closebutton: true, startat: null, autoplayvideos: true, autofocusvideos: true, descposition: 'bottom', width: '900px', height: '506px', videoswidth: '960px', beforeslidechange: null, afterslidechange: null, beforeslideload: null, afterslideload: null, slideinserted: null, slideremoved: null, slideextraattributes: null, onopen: null, onclose: null, loop: false, zoomable: true, draggable: true, dragautosnap: false, dragtolerancex: 40, dragtolerancey: 65, preload: true, oneslideperopen: false, touchnavigation: true, touchfollowaxis: true, keyboardnavigation: true, closeonoutsideclick: true, plugins: false, plyr: { css: 'https://cdn.plyr.io/3.6.8/plyr.css', js: 'https://cdn.plyr.io/3.6.8/plyr.js', config: { ratio: '16:9', fullscreen: { enabled: true, iosnative: true }, youtube: { nocookie: true, rel: 0, showinfo: 0, iv_load_policy: 3 }, vimeo: { byline: false, portrait: false, title: false, transparent: false } } }, openeffect: 'zoom', closeeffect: 'zoom', slideeffect: 'slide', moretext: 'see more', morelength: 60, cssefects: { fade: { "in": 'fadein', out: 'fadeout' }, zoom: { "in": 'zoomin', out: 'zoomout' }, slide: { "in": 'slideinright', out: 'slideoutleft' }, slideback: { "in": 'slideinleft', out: 'slideoutright' }, none: { "in": 'none', out: 'none' } }, svg: { close: '', next: ' ', prev: '' } }; defaults.slidehtml = "
\n
\n
\n
\n
\n
\n
\n

\n
\n
\n
\n
\n
\n
"; defaults.lightboxhtml = "
\n
\n
\n
\n
\n \n \n \n
\n
"; var glightboxinit = function () { function glightboxinit() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classcallcheck(this, glightboxinit); this.customoptions = options; this.settings = extend(defaults, options); this.effectsclasses = this.getanimationclasses(); this.videoplayers = {}; this.apievents = []; this.fullelementslist = false; } _createclass(glightboxinit, [{ key: "init", value: function init() { var _this = this; var selector = this.getselector(); if (selector) { this.baseevents = addevent('click', { onelement: selector, withcallback: function withcallback(e, target) { e.preventdefault(); _this.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 = isnumber(startat) ? startat : this.settings.startat; if (isnode(element)) { var gallery = element.getattribute('data-gallery'); if (gallery) { this.fullelementslist = this.elements; this.elements = this.getgalleryelements(this.elements, gallery); } if (isnil(index)) { index = this.getelementindex(element); if (index < 0) { index = 0; } } } if (!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$1) { addclass(document.body, 'glightbox-mobile'); this.settings.slideeffect = 'slide'; } this.showslide(index, true); if (this.elements.length == 1) { addclass(this.prevbutton, 'glightbox-button-hidden'); addclass(this.nextbutton, 'glightbox-button-hidden'); } else { removeclass(this.prevbutton, 'glightbox-button-hidden'); removeclass(this.nextbutton, 'glightbox-button-hidden'); } this.lightboxopen = true; this.trigger('open'); if (isfunction(this.settings.onopen)) { this.settings.onopen(); } if (istouch$1 && this.settings.touchnavigation) { touchnavigation(this); } if (this.settings.keyboardnavigation) { keyboardnavigation(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 _this2 = 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 slidenode = this.slidescontainer.queryselectorall('.gslide')[index]; if (hasclass(slidenode, 'loaded')) { this.slideanimatein(slidenode, first); hide(this.loader); } else { show(this.loader); var slide = this.elements[index]; var slidedata = { index: this.index, slide: slidenode, slidenode: slidenode, slideconfig: slide.slideconfig, slideindex: this.index, trigger: slide.node, player: null }; this.trigger('slide_before_load', slidedata); slide.instance.setcontent(slidenode, function () { hide(_this2.loader); _this2.resize(); _this2.slideanimatein(slidenode, first); _this2.trigger('slide_after_load', slidedata); }); } this.slidedescription = slidenode.queryselector('.gslide-description'); this.slidedescriptioncontained = this.slidedescription && hasclass(this.slidedescription.parentnode, 'gslide-media'); if (this.settings.preload) { this.preloadslide(index + 1); this.preloadslide(index - 1); } this.updatenavigationclasses(); this.activeslide = slidenode; } }, { key: "preloadslide", value: function preloadslide(index) { var _this3 = this; if (index < 0 || index > this.elements.length - 1) { return false; } if (isnil(this.elements[index])) { return false; } var slidenode = this.slidescontainer.queryselectorall('.gslide')[index]; if (hasclass(slidenode, 'loaded')) { return false; } var slide = this.elements[index]; var type = slide.type; var slidedata = { index: index, slide: slidenode, slidenode: slidenode, slideconfig: slide.slideconfig, slideindex: index, trigger: slide.node, player: null }; this.trigger('slide_before_load', slidedata); if (type == 'video' || type == 'external') { settimeout(function () { slide.instance.setcontent(slidenode, function () { _this3.trigger('slide_after_load', slidedata); }); }, 200); } else { slide.instance.setcontent(slidenode, function () { _this3.trigger('slide_after_load', 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; if (!this.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 config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; if (index < 0) { index = this.elements.length; } var slide = new slide(config, this, index); var data = slide.getconfig(); var slideinfo = extend({}, data); var newslide = slide.create(); var totalslides = this.elements.length - 1; slideinfo.index = index; slideinfo.node = false; slideinfo.instance = slide; slideinfo.slideconfig = data; this.elements.splice(index, 0, slideinfo); var addedslidenode = null; var addedslideplayer = null; 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.settings.preload && 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(); addedslidenode = this.slidescontainer.queryselectorall('.gslide')[index]; addedslideplayer = this.getslideplayerinstance(index); slideinfo.slidenode = addedslidenode; } this.trigger('slide_inserted', { index: index, slide: addedslidenode, slidenode: addedslidenode, slideconfig: data, slideindex: index, trigger: null, player: addedslideplayer }); if (isfunction(this.settings.slideinserted)) { this.settings.slideinserted({ index: index, slide: addedslidenode, player: addedslideplayer }); } } }, { 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); this.trigger('slide_removed', index); if (isfunction(this.settings.slideremoved)) { this.settings.slideremoved(index); } } }, { key: "slideanimatein", value: function slideanimatein(slide, first) { var _this4 = this; var slidemedia = slide.queryselector('.gslide-media'); var slidedesc = slide.queryselector('.gslide-description'); var prevdata = { index: this.prevactiveslideindex, slide: this.prevactiveslide, slidenode: this.prevactiveslide, slideindex: this.prevactiveslide, slideconfig: isnil(this.prevactiveslideindex) ? null : this.elements[this.prevactiveslideindex].slideconfig, trigger: isnil(this.prevactiveslideindex) ? null : this.elements[this.prevactiveslideindex].node, player: this.getslideplayerinstance(this.prevactiveslideindex) }; var nextdata = { index: this.index, slide: this.activeslide, slidenode: this.activeslide, slideconfig: this.elements[this.index].slideconfig, slideindex: this.index, trigger: this.elements[this.index].node, 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.cssefects[this.settings.openeffect]["in"], function () { if (_this4.settings.autoplayvideos) { _this4.slideplayerplay(slide); } _this4.trigger('slide_changed', { prev: prevdata, current: nextdata }); if (isfunction(_this4.settings.afterslidechange)) { _this4.settings.afterslidechange.apply(_this4, [prevdata, nextdata]); } }); } else { var effectname = this.settings.slideeffect; var animin = effectname !== 'none' ? this.settings.cssefects[effectname]["in"] : effectname; if (this.prevactiveslideindex > this.index) { if (this.settings.slideeffect == 'slide') { animin = this.settings.cssefects.slideback["in"]; } } animateelement(slide, animin, function () { if (_this4.settings.autoplayvideos) { _this4.slideplayerplay(slide); } _this4.trigger('slide_changed', { prev: prevdata, current: nextdata }); if (isfunction(_this4.settings.afterslidechange)) { _this4.settings.afterslidechange.apply(_this4, [prevdata, nextdata]); } }); } settimeout(function () { _this4.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.slideplayerpause(prevslide); this.trigger('slide_before_change', { prev: { index: this.prevactiveslideindex, slide: this.prevactiveslide, slidenode: this.prevactiveslide, slideindex: this.prevactiveslideindex, slideconfig: isnil(this.prevactiveslideindex) ? null : this.elements[this.prevactiveslideindex].slideconfig, trigger: isnil(this.prevactiveslideindex) ? null : this.elements[this.prevactiveslideindex].node, player: this.getslideplayerinstance(this.prevactiveslideindex) }, current: { index: this.index, slide: this.activeslide, slidenode: this.activeslide, slideindex: this.index, slideconfig: this.elements[this.index].slideconfig, trigger: this.elements[this.index].node, player: this.getslideplayerinstance(this.index) } }); if (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.slideback.out; } animateelement(prevslide, animout, function () { var container = prevslide.queryselector('.ginner-container'); var media = prevslide.queryselector('.gslide-media'); var desc = prevslide.queryselector('.gslide-description'); container.style.transform = ''; media.style.transform = ''; removeclass(media, 'greset'); media.style.opacity = ''; if (desc) { desc.style.opacity = ''; } removeclass(prevslide, 'prev'); }); } }, { key: "getallplayers", value: function getallplayers() { return this.videoplayers; } }, { key: "getslideplayerinstance", value: function getslideplayerinstance(index) { var id = 'gvideo' + index; var videoplayers = this.getallplayers(); if (has(videoplayers, id) && videoplayers[id]) { return videoplayers[id]; } return false; } }, { key: "stopslidevideo", value: function stopslidevideo(slide) { if (isnode(slide)) { var node = slide.queryselector('.gvideo-wrapper'); if (node) { slide = node.getattribute('data-index'); } } console.log('stopslidevideo is deprecated, use slideplayerpause'); var player = this.getslideplayerinstance(slide); if (player && player.playing) { player.pause(); } } }, { key: "slideplayerpause", value: function slideplayerpause(slide) { if (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 (isnode(slide)) { var node = slide.queryselector('.gvideo-wrapper'); if (node) { slide = node.getattribute('data-index'); } } console.log('playslidevideo is deprecated, use slideplayerplay'); var player = this.getslideplayerinstance(slide); if (player && !player.playing) { player.play(); } } }, { key: "slideplayerplay", value: function slideplayerplay(slide) { if (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(); if (this.settings.autofocusvideos) { player.elements.container.focus(); } } } }, { key: "setelements", value: function setelements(elements) { var _this5 = this; this.settings.elements = false; var newelements = []; if (elements && elements.length) { each(elements, function (el, i) { var slide = new slide(el, _this5, i); var data = slide.getconfig(); var slideinfo = extend({}, data); slideinfo.slideconfig = data; slideinfo.instance = slide; slideinfo.index = i; newelements.push(slideinfo); }); } this.elements = newelements; if (this.lightboxopen) { this.slidescontainer.innerhtml = ''; if (this.elements.length) { each(this.elements, function () { var slide = createhtml(_this5.settings.slidehtml); _this5.slidescontainer.appendchild(slide); }); this.showslide(0, true); } } } }, { key: "getelementindex", value: function getelementindex(node) { var index = false; each(this.elements, function (el, i) { if (has(el, 'node') && el.node == node) { index = i; return true; } }); return index; } }, { key: "getelements", value: function getelements() { var _this6 = this; var list = []; this.elements = this.elements ? this.elements : []; if (!isnil(this.settings.elements) && isarray(this.settings.elements) && this.settings.elements.length) { each(this.settings.elements, function (el, i) { var slide = new slide(el, _this6, i); var eldata = slide.getconfig(); var slideinfo = extend({}, eldata); slideinfo.node = false; slideinfo.index = i; slideinfo.instance = slide; slideinfo.slideconfig = eldata; list.push(slideinfo); }); } var nodes = false; var selector = this.getselector(); if (selector) { nodes = document.queryselectorall(this.getselector()); } if (!nodes) { return list; } each(nodes, function (el, i) { var slide = new slide(el, _this6, i); var eldata = slide.getconfig(); var slideinfo = extend({}, eldata); slideinfo.node = el; slideinfo.index = i; slideinfo.instance = slide; slideinfo.slideconfig = eldata; slideinfo.gallery = el.getattribute('data-gallery'); list.push(slideinfo); }); return list; } }, { key: "getgalleryelements", value: function getgalleryelements(list, gallery) { return list.filter(function (el) { return el.gallery == gallery; }); } }, { key: "getselector", value: function getselector() { if (this.settings.elements) { return false; } 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 _this7 = this; if (this.built) { return false; } var children = document.body.childnodes; var bodychildelms = []; each(children, function (el) { if (el.parentnode == document.body && el.nodename.charat(0) !== '#' && el.hasattribute && !el.hasattribute('aria-hidden')) { bodychildelms.push(el); el.setattribute('aria-hidden', 'true'); } }); var nextsvg = has(this.settings.svg, 'next') ? this.settings.svg.next : ''; var prevsvg = has(this.settings.svg, 'prev') ? this.settings.svg.prev : ''; var closesvg = 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.bodyhiddenchildelms = bodychildelms; 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(); _this7.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(); _this7.nextslide(); } }); } if (this.prevbutton) { this.events['prev'] = addevent('click', { onelement: this.prevbutton, withcallback: function withcallback(e, target) { e.preventdefault(); _this7.prevslide(); } }); } if (this.settings.closeonoutsideclick) { this.events['outclose'] = addevent('click', { onelement: modal, withcallback: function withcallback(e, target) { if (!_this7.preventoutsideclick && !hasclass(document.body, 'glightbox-mobile') && !closest(e.target, '.ginner-container')) { if (!closest(e.target, '.gbtn') && !hasclass(e.target, 'gnext') && !hasclass(e.target, 'gprev')) { _this7.close(); } } } }); } each(this.elements, function (slide, i) { _this7.slidescontainer.appendchild(slide.instance.create()); slide.slidenode = _this7.slidescontainer.queryselectorall('.gslide')[i]; }); if (istouch$1) { addclass(document.body, 'glightbox-touch'); } this.events['resize'] = addevent('resize', { onelement: window, withcallback: function withcallback() { _this7.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'); } else if (descriptionresize) { var descheight = description.offsetheight; 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 = has(this.settings.plyr.config, 'ratio') ? this.settings.plyr.config.ratio : ''; if (!ratio) { var containerwidth = video.clientwidth; var containerheight = video.clientheight; var divisor = containerwidth / containerheight; ratio = "".concat(containerwidth / divisor, ":").concat(containerheight / divisor); } var videoratio = ratio.split(':'); var videowidth = this.settings.videoswidth; var maxwidth = this.settings.videoswidth; if (isnumber(videowidth) || videowidth.indexof('px') !== -1) { maxwidth = parseint(videowidth); } else { if (videowidth.indexof('vw') !== -1) { maxwidth = winwidth * parseint(videowidth) / 100; } else if (videowidth.indexof('vh') !== -1) { maxwidth = winheight * parseint(videowidth) / 100; } else if (videowidth.indexof('%') !== -1) { maxwidth = winwidth * parseint(videowidth) / 100; } else { maxwidth = parseint(video.clientwidth); } } var maxheight = maxwidth / (parseint(videoratio[0]) / parseint(videoratio[1])); maxheight = math.floor(maxheight); if (descriptionresize) { winheight = winheight - description.offsetheight; } if (maxwidth > winwidth || maxheight > winheight || 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(videowidth); if (descriptionresize) { description.setattribute('style', "max-width: ".concat(videowidth, ";")); } } } } }, { 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 = has(this.settings, 'loopatend') ? this.settings.loopatend : null; loop = has(this.settings, 'loop') ? this.settings.loop : loop; return loop; } }, { key: "close", value: function close() { var _this8 = 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.slideplayerpause(this.activeslide); if (this.fullelementslist) { this.elements = this.fullelementslist; } if (this.bodyhiddenchildelms.length) { each(this.bodyhiddenchildelms, function (el) { el.removeattribute('aria-hidden'); }); } addclass(this.modal, 'glightbox-closing'); animateelement(this.overlay, this.settings.openeffect == 'none' ? 'none' : this.settings.cssefects.fade.out); animateelement(this.activeslide, this.settings.cssefects[this.settings.closeeffect].out, function () { _this8.activeslide = null; _this8.prevactiveslideindex = null; _this8.prevactiveslide = null; _this8.built = false; if (_this8.events) { for (var _key in _this8.events) { if (_this8.events.hasownproperty(_key)) { _this8.events[_key].destroy(); } } _this8.events = null; } var body = document.body; removeclass(html, 'glightbox-open'); removeclass(body, 'glightbox-open touching gdesc-open glightbox-touch glightbox-mobile gscrollbar-fixer'); _this8.modal.parentnode.removechild(_this8.modal); _this8.trigger('close'); if (isfunction(_this8.settings.onclose)) { _this8.settings.onclose(); } var styles = document.queryselector('.gcss-styles'); if (styles) { styles.parentnode.removechild(styles); } _this8.lightboxopen = false; _this8.closing = null; }); } }, { key: "destroy", value: function destroy() { this.close(); this.clearallevents(); if (this.baseevents) { this.baseevents.destroy(); } } }, { key: "on", value: function on(evt, callback) { var once = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (!evt || !isfunction(callback)) { throw new typeerror('event name and callback must be defined'); } this.apievents.push({ evt: evt, once: once, callback: callback }); } }, { key: "once", value: function once(evt, callback) { this.on(evt, callback, true); } }, { key: "trigger", value: function trigger(eventname) { var _this9 = this; var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; var oncetriggered = []; each(this.apievents, function (event, i) { var evt = event.evt, once = event.once, callback = event.callback; if (evt == eventname) { callback(data); if (once) { oncetriggered.push(i); } } }); if (oncetriggered.length) { each(oncetriggered, function (i) { return _this9.apievents.splice(i, 1); }); } } }, { key: "clearallevents", value: function clearallevents() { this.apievents.splice(0, this.apievents.length); } }, { key: "version", value: function version() { return _version; } }]); 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; })));