From a9c4d4c497b4052a6798e5ab63576e7bb6e003e1 Mon Sep 17 00:00:00 2001 From: Felix Ranesberger Date: Thu, 15 Jun 2023 09:45:39 +0200 Subject: [PATCH 1/2] [BUGFIX] Fix height calculation if description + height are set by the user --- src/js/glightbox.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/js/glightbox.js b/src/js/glightbox.js index 4e6ab78..410928f 100644 --- a/src/js/glightbox.js +++ b/src/js/glightbox.js @@ -1085,7 +1085,12 @@ class GlightboxInit { let descHeight = description.offsetHeight; let imgNode = image.querySelector('img'); - imgNode.setAttribute('style', `max-height: calc(100vh - ${descHeight}px)`); + // if a slide height is set via data-height, we want to use that + // if not, we fall back to 100vh + const slideTriggerNode = this.elements[this.index].node; + const maxHeightValue = slideTriggerNode.getAttribute('data-height') ?? '100vh'; + + imgNode.setAttribute('style', `max-height: calc(${maxHeightValue} - ${descHeight}px)`); description.setAttribute('style', `max-width: ${imgNode.offsetWidth}px;`); } } From e2047ae84136a1ea5d09a5d52796a8c331fd78bb Mon Sep 17 00:00:00 2001 From: Felix Ranesberger Date: Thu, 13 Jul 2023 15:12:32 +0200 Subject: [PATCH 2/2] [TASK] Build distribution files --- dist/js/glightbox.js | 675 ++++----------------------------------- dist/js/glightbox.min.js | 2 +- 2 files changed, 60 insertions(+), 617 deletions(-) diff --git a/dist/js/glightbox.js b/dist/js/glightbox.js index 1761dc6..0903f61 100644 --- a/dist/js/glightbox.js +++ b/dist/js/glightbox.js @@ -7,40 +7,48 @@ 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); + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }, _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); + Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } - function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); return Constructor; } + function _toPrimitive(input, hint) { + if (typeof input !== "object" || input === null) return input; + var prim = input[Symbol.toPrimitive]; + if (prim !== undefined) { + var res = prim.call(input, hint || "default"); + if (typeof res !== "object") return res; + throw new TypeError("@@toPrimitive must return a primitive value."); + } + return (hint === "string" ? String : Number)(input); + } + function _toPropertyKey(arg) { + var key = _toPrimitive(arg, "string"); + return typeof key === "symbol" ? key : String(key); + } var uid = Date.now(); function extend() { @@ -48,12 +56,10 @@ 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)) { @@ -65,31 +71,25 @@ } } }; - 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; - + i = 0; for (; i < l; i++) { if (callback.call(collection[i], collection[i], i, collection) === false) { break; @@ -114,7 +114,6 @@ evt: null, found: null }; - if (name && fn && size(cache) > 0) { each(cache, function (cl, i) { if (cl.eventName == name && cl.fn.toString() == fn.toString()) { @@ -124,54 +123,44 @@ } }); } - 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; - + 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({ @@ -198,13 +187,10 @@ 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; } @@ -213,19 +199,15 @@ 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) { @@ -239,7 +221,6 @@ each(animationNames, function (name) { removeClass(target, 'g' + name); }); - if (isFunction(callback)) { callback(); } @@ -248,7 +229,6 @@ } function cssTransform(node) { var translate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; - if (translate === '') { node.style.webkitTransform = ''; node.style.MozTransform = ''; @@ -257,7 +237,6 @@ node.style.transform = ''; return false; } - node.style.webkitTransform = translate; node.style.MozTransform = translate; node.style.msTransform = translate; @@ -272,13 +251,11 @@ } function createHTML(htmlStr) { var frag = document.createDocumentFragment(), - temp = document.createElement('div'); + temp = document.createElement('div'); temp.innerHTML = htmlStr; - while (temp.firstChild) { frag.appendChild(temp.firstChild); } - return frag; } function windowSize() { @@ -289,14 +266,13 @@ } function whichAnimationEvent() { var t, - el = document.createElement('fakeelement'); + 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]; @@ -305,14 +281,13 @@ } function whichTransitionEvent() { var t, - el = document.createElement('fakeelement'); + 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]; @@ -321,32 +296,27 @@ } function createIframe(config) { var url = config.url, - allow = config.allow, - callback = config.callback, - appendTo = config.appendTo; + 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 () { iframe.onload = null; addClass(iframe, 'node-ready'); - if (isFunction(callback)) { callback(); } }; - if (appendTo) { appendTo.appendChild(iframe); } - return iframe; } function waitUntil(check, onComplete, delay, timeout) { @@ -354,26 +324,20 @@ 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); @@ -385,33 +349,25 @@ 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'); @@ -419,22 +375,17 @@ 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)) { @@ -445,17 +396,13 @@ }); 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)) { @@ -466,11 +413,9 @@ }); return false; } - callback(); } }; - document.body.appendChild(script); } function isMobile() { @@ -496,7 +441,6 @@ } function isObject(o) { var type = _typeof(o); - return type === 'object' && o != null && !isFunction(o) && !isArray(o); } function isNil(o) { @@ -510,15 +454,12 @@ 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; @@ -531,19 +472,15 @@ 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 orders = []; each(btns, function (btn) { orders.push(btn.getAttribute('data-taborder')); @@ -552,76 +489,59 @@ return parseInt(order); })); var newIndex = current < 0 ? 1 : current + 1; - if (newIndex > highestOrder) { newIndex = '1'; } - 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(); } @@ -632,49 +552,36 @@ 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) { @@ -686,7 +593,6 @@ if (!handler) { this.handlers = []; } - for (var i = this.handlers.length; i >= 0; i--) { if (this.handlers[i] === handler) { this.handlers.splice(i, 1); @@ -698,27 +604,22 @@ 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); @@ -735,9 +636,7 @@ 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); @@ -769,46 +668,36 @@ 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; - + 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 @@ -818,7 +707,6 @@ this.pinchStartLen = getLen(preV); this.multipointStart.dispatch(evt, this.element); } - this._preventTap = false; this.longTapTimeout = setTimeout(function () { this.longTap.dispatch(evt, this.element); @@ -831,34 +719,28 @@ if (!evt.touches) { return; } - var preV = this.preV, - len = evt.touches.length, - currentX = evt.touches[0].pageX, - currentY = evt.touches[0].pageY; + 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; + 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; @@ -866,7 +748,6 @@ evt.deltaX = 0; evt.deltaY = 0; } - this.twoFingerPressMove.dispatch(evt, this.element); this.sx2 = sCurrentX; this.sy2 = sCurrentY; @@ -875,8 +756,7 @@ 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); - + movedY = Math.abs(this.y1 - this.y2); if (movedX > 10 || movedY > 10) { this._preventTap = true; } @@ -884,17 +764,12 @@ 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(); } @@ -905,16 +780,12 @@ 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 () { @@ -925,20 +796,17 @@ 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; @@ -996,19 +864,15 @@ 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); @@ -1033,7 +897,6 @@ return null; } }]); - return TouchEvents; }(); @@ -1043,11 +906,9 @@ 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, { @@ -1058,17 +919,14 @@ } }); 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; @@ -1102,15 +960,12 @@ 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; @@ -1121,23 +976,17 @@ 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(); } }, @@ -1145,27 +994,21 @@ 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; @@ -1173,58 +1016,46 @@ 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; @@ -1244,12 +1075,10 @@ 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; @@ -1260,11 +1089,9 @@ mediaImage.setAttribute('style', ''); return; } - if (scale > maxScale) { scale = maxScale; } - mediaImage.style.transform = "scale3d(".concat(scale, ", ").concat(scale, ", 1)"); currentScale = scale; }, @@ -1272,23 +1099,18 @@ 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); } }, @@ -1296,25 +1118,20 @@ 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(); } } @@ -1325,19 +1142,14 @@ 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; @@ -1359,40 +1171,32 @@ 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; } @@ -1409,7 +1213,6 @@ this.initialY = null; this.xOffset = 0; this.yOffset = 0; - if (this.onclose && typeof this.onclose == 'function') { this.onclose(); } @@ -1418,12 +1221,10 @@ 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; @@ -1431,7 +1232,6 @@ 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'); @@ -1441,7 +1241,6 @@ key: "dragEnd", value: function dragEnd(e) { var _this2 = this; - e.preventDefault(); this.initialX = this.currentX; this.initialY = this.currentY; @@ -1449,7 +1248,6 @@ setTimeout(function () { _this2.dragging = false; _this2.img.isDragging = false; - _this2.img.classList.remove('dragging'); }, 100); } @@ -1458,7 +1256,6 @@ 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; @@ -1466,7 +1263,6 @@ this.currentX = e.clientX - this.initialX; this.currentY = e.clientY - this.initialY; } - this.xOffset = this.currentX; this.yOffset = this.currentY; this.img.isDragging = true; @@ -1480,7 +1276,6 @@ 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); @@ -1496,27 +1291,23 @@ 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; + _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; @@ -1544,7 +1335,6 @@ return _this.drag(e); }, false); } - _createClass(DragSlides, [{ key: "dragStart", value: function dragStart(e) { @@ -1552,7 +1342,6 @@ this.active = false; return; } - if (e.type === 'touchstart') { this.initialX = e.touches[0].clientX - this.xOffset; this.initialY = e.touches[0].clientY - this.yOffset; @@ -1560,17 +1349,13 @@ 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'); @@ -1581,7 +1366,6 @@ key: "dragEnd", value: function dragEnd(e) { var _this2 = this; - e && e.preventDefault(); this.initialX = 0; this.initialY = 0; @@ -1592,32 +1376,25 @@ 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); @@ -1628,7 +1405,6 @@ 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; @@ -1636,7 +1412,6 @@ this.currentX = e.clientX - this.initialX; this.currentY = e.clientY - this.initialY; } - this.xOffset = this.currentX; this.yOffset = this.currentY; this.el.isDragging = true; @@ -1645,17 +1420,14 @@ 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; @@ -1667,21 +1439,17 @@ 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; } } @@ -1691,15 +1459,12 @@ 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; } }, { @@ -1707,28 +1472,23 @@ 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; }(); @@ -1743,41 +1503,32 @@ } }, false); img.src = data.href; - if (data.sizes != '' && data.srcset != '') { img.sizes = data.sizes; img.srcset = data.srcset; } - 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'); @@ -1794,11 +1545,9 @@ if (!provider && url.match(/vimeo\.com\/([0-9]*)/)) { provider = 'vimeo'; } - if (!provider && (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\-_]+)/))) { provider = 'youtube'; } - if (provider === 'local' || !provider) { provider = 'local'; var html = '