(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("