Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

glightbox.js 107KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (global = global || self, global.GLightbox = factory());
  5. }(this, (function () { 'use strict';
  6. function _toPrimitive(t, r) {
  7. if ("object" != typeof t || !t) return t;
  8. var e = t[Symbol.toPrimitive];
  9. if (void 0 !== e) {
  10. var i = e.call(t, r || "default");
  11. if ("object" != typeof i) return i;
  12. throw new TypeError("@@toPrimitive must return a primitive value.");
  13. }
  14. return ("string" === r ? String : Number)(t);
  15. }
  16. function _toPropertyKey(t) {
  17. var i = _toPrimitive(t, "string");
  18. return "symbol" == typeof i ? i : i + "";
  19. }
  20. function _typeof(o) {
  21. "@babel/helpers - typeof";
  22. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  23. return typeof o;
  24. } : function (o) {
  25. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  26. }, _typeof(o);
  27. }
  28. function _classCallCheck(instance, Constructor) {
  29. if (!(instance instanceof Constructor)) {
  30. throw new TypeError("Cannot call a class as a function");
  31. }
  32. }
  33. function _defineProperties(target, props) {
  34. for (var i = 0; i < props.length; i++) {
  35. var descriptor = props[i];
  36. descriptor.enumerable = descriptor.enumerable || false;
  37. descriptor.configurable = true;
  38. if ("value" in descriptor) descriptor.writable = true;
  39. Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
  40. }
  41. }
  42. function _createClass(Constructor, protoProps, staticProps) {
  43. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  44. if (staticProps) _defineProperties(Constructor, staticProps);
  45. Object.defineProperty(Constructor, "prototype", {
  46. writable: false
  47. });
  48. return Constructor;
  49. }
  50. var uid = Date.now();
  51. function extend() {
  52. var extended = {};
  53. var deep = true;
  54. var i = 0;
  55. var length = arguments.length;
  56. if (Object.prototype.toString.call(arguments[0]) === '[object Boolean]') {
  57. deep = arguments[0];
  58. i++;
  59. }
  60. var merge = function merge(obj) {
  61. for (var prop in obj) {
  62. if (Object.prototype.hasOwnProperty.call(obj, prop)) {
  63. if (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {
  64. extended[prop] = extend(true, extended[prop], obj[prop]);
  65. } else {
  66. extended[prop] = obj[prop];
  67. }
  68. }
  69. }
  70. };
  71. for (; i < length; i++) {
  72. var obj = arguments[i];
  73. merge(obj);
  74. }
  75. return extended;
  76. }
  77. function each(collection, callback) {
  78. if (isNode(collection) || collection === window || collection === document) {
  79. collection = [collection];
  80. }
  81. if (!isArrayLike(collection) && !isObject(collection)) {
  82. collection = [collection];
  83. }
  84. if (size(collection) == 0) {
  85. return;
  86. }
  87. if (isArrayLike(collection) && !isObject(collection)) {
  88. var l = collection.length,
  89. i = 0;
  90. for (; i < l; i++) {
  91. if (callback.call(collection[i], collection[i], i, collection) === false) {
  92. break;
  93. }
  94. }
  95. } else if (isObject(collection)) {
  96. for (var key in collection) {
  97. if (has(collection, key)) {
  98. if (callback.call(collection[key], collection[key], key, collection) === false) {
  99. break;
  100. }
  101. }
  102. }
  103. }
  104. }
  105. function getNodeEvents(node) {
  106. var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  107. var fn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  108. var cache = node[uid] = node[uid] || [];
  109. var data = {
  110. all: cache,
  111. evt: null,
  112. found: null
  113. };
  114. if (name && fn && size(cache) > 0) {
  115. each(cache, function (cl, i) {
  116. if (cl.eventName == name && cl.fn.toString() == fn.toString()) {
  117. data.found = true;
  118. data.evt = i;
  119. return false;
  120. }
  121. });
  122. }
  123. return data;
  124. }
  125. function addEvent(eventName) {
  126. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  127. onElement = _ref.onElement,
  128. withCallback = _ref.withCallback,
  129. _ref$avoidDuplicate = _ref.avoidDuplicate,
  130. avoidDuplicate = _ref$avoidDuplicate === void 0 ? true : _ref$avoidDuplicate,
  131. _ref$once = _ref.once,
  132. once = _ref$once === void 0 ? false : _ref$once,
  133. _ref$useCapture = _ref.useCapture,
  134. useCapture = _ref$useCapture === void 0 ? false : _ref$useCapture;
  135. var thisArg = arguments.length > 2 ? arguments[2] : undefined;
  136. var element = onElement || [];
  137. if (isString(element)) {
  138. element = document.querySelectorAll(element);
  139. }
  140. function handler(event) {
  141. if (isFunction(withCallback)) {
  142. withCallback.call(thisArg, event, this);
  143. }
  144. if (once) {
  145. handler.destroy();
  146. }
  147. }
  148. handler.destroy = function () {
  149. each(element, function (el) {
  150. var events = getNodeEvents(el, eventName, handler);
  151. if (events.found) {
  152. events.all.splice(events.evt, 1);
  153. }
  154. if (el.removeEventListener) {
  155. el.removeEventListener(eventName, handler, useCapture);
  156. }
  157. });
  158. };
  159. each(element, function (el) {
  160. var events = getNodeEvents(el, eventName, handler);
  161. if (el.addEventListener && avoidDuplicate && !events.found || !avoidDuplicate) {
  162. el.addEventListener(eventName, handler, useCapture);
  163. events.all.push({
  164. eventName: eventName,
  165. fn: handler
  166. });
  167. }
  168. });
  169. return handler;
  170. }
  171. function addClass(node, name) {
  172. each(name.split(' '), function (cl) {
  173. return node.classList.add(cl);
  174. });
  175. }
  176. function removeClass(node, name) {
  177. each(name.split(' '), function (cl) {
  178. return node.classList.remove(cl);
  179. });
  180. }
  181. function hasClass(node, name) {
  182. return node.classList.contains(name);
  183. }
  184. function closest(elem, selector) {
  185. while (elem !== document.body) {
  186. elem = elem.parentElement;
  187. if (!elem) {
  188. return false;
  189. }
  190. var matches = typeof elem.matches == 'function' ? elem.matches(selector) : elem.msMatchesSelector(selector);
  191. if (matches) {
  192. return elem;
  193. }
  194. }
  195. }
  196. function animateElement(element) {
  197. var animation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  198. var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  199. if (!element || animation === '') {
  200. return false;
  201. }
  202. if (animation === 'none') {
  203. if (isFunction(callback)) {
  204. callback();
  205. }
  206. return false;
  207. }
  208. var animationEnd = whichAnimationEvent();
  209. var animationNames = animation.split(' ');
  210. each(animationNames, function (name) {
  211. addClass(element, 'g' + name);
  212. });
  213. addEvent(animationEnd, {
  214. onElement: element,
  215. avoidDuplicate: false,
  216. once: true,
  217. withCallback: function withCallback(event, target) {
  218. each(animationNames, function (name) {
  219. removeClass(target, 'g' + name);
  220. });
  221. if (isFunction(callback)) {
  222. callback();
  223. }
  224. }
  225. });
  226. }
  227. function cssTransform(node) {
  228. var translate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  229. if (translate === '') {
  230. node.style.webkitTransform = '';
  231. node.style.MozTransform = '';
  232. node.style.msTransform = '';
  233. node.style.OTransform = '';
  234. node.style.transform = '';
  235. return false;
  236. }
  237. node.style.webkitTransform = translate;
  238. node.style.MozTransform = translate;
  239. node.style.msTransform = translate;
  240. node.style.OTransform = translate;
  241. node.style.transform = translate;
  242. }
  243. function show(element) {
  244. element.style.display = 'block';
  245. }
  246. function hide(element) {
  247. element.style.display = 'none';
  248. }
  249. function createHTML(htmlStr) {
  250. var frag = document.createDocumentFragment(),
  251. temp = document.createElement('div');
  252. temp.innerHTML = htmlStr;
  253. while (temp.firstChild) {
  254. frag.appendChild(temp.firstChild);
  255. }
  256. return frag;
  257. }
  258. function windowSize() {
  259. return {
  260. width: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
  261. height: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
  262. };
  263. }
  264. function whichAnimationEvent() {
  265. var t,
  266. el = document.createElement('fakeelement');
  267. var animations = {
  268. animation: 'animationend',
  269. OAnimation: 'oAnimationEnd',
  270. MozAnimation: 'animationend',
  271. WebkitAnimation: 'webkitAnimationEnd'
  272. };
  273. for (t in animations) {
  274. if (el.style[t] !== undefined) {
  275. return animations[t];
  276. }
  277. }
  278. }
  279. function whichTransitionEvent() {
  280. var t,
  281. el = document.createElement('fakeelement');
  282. var transitions = {
  283. transition: 'transitionend',
  284. OTransition: 'oTransitionEnd',
  285. MozTransition: 'transitionend',
  286. WebkitTransition: 'webkitTransitionEnd'
  287. };
  288. for (t in transitions) {
  289. if (el.style[t] !== undefined) {
  290. return transitions[t];
  291. }
  292. }
  293. }
  294. function createIframe(config) {
  295. var url = config.url,
  296. allow = config.allow,
  297. callback = config.callback,
  298. appendTo = config.appendTo;
  299. var iframe = document.createElement('iframe');
  300. iframe.className = 'vimeo-video gvideo';
  301. iframe.src = url;
  302. iframe.style.width = '100%';
  303. iframe.style.height = '100%';
  304. if (allow) {
  305. iframe.setAttribute('allow', allow);
  306. }
  307. iframe.onload = function () {
  308. iframe.onload = null;
  309. addClass(iframe, 'node-ready');
  310. if (isFunction(callback)) {
  311. callback();
  312. }
  313. };
  314. if (appendTo) {
  315. appendTo.appendChild(iframe);
  316. }
  317. return iframe;
  318. }
  319. function waitUntil(check, onComplete, delay, timeout) {
  320. if (check()) {
  321. onComplete();
  322. return;
  323. }
  324. if (!delay) {
  325. delay = 100;
  326. }
  327. var timeoutPointer;
  328. var intervalPointer = setInterval(function () {
  329. if (!check()) {
  330. return;
  331. }
  332. clearInterval(intervalPointer);
  333. if (timeoutPointer) {
  334. clearTimeout(timeoutPointer);
  335. }
  336. onComplete();
  337. }, delay);
  338. if (timeout) {
  339. timeoutPointer = setTimeout(function () {
  340. clearInterval(intervalPointer);
  341. }, timeout);
  342. }
  343. }
  344. function injectAssets(url, waitFor, callback) {
  345. if (isNil(url)) {
  346. console.error('Inject assets error');
  347. return;
  348. }
  349. if (isFunction(waitFor)) {
  350. callback = waitFor;
  351. waitFor = false;
  352. }
  353. if (isString(waitFor) && waitFor in window) {
  354. if (isFunction(callback)) {
  355. callback();
  356. }
  357. return;
  358. }
  359. var found;
  360. if (url.indexOf('.css') !== -1) {
  361. found = document.querySelectorAll('link[href="' + url + '"]');
  362. if (found && found.length > 0) {
  363. if (isFunction(callback)) {
  364. callback();
  365. }
  366. return;
  367. }
  368. var head = document.getElementsByTagName('head')[0];
  369. var headStyles = head.querySelectorAll('link[rel="stylesheet"]');
  370. var link = document.createElement('link');
  371. link.rel = 'stylesheet';
  372. link.type = 'text/css';
  373. link.href = url;
  374. link.media = 'all';
  375. if (headStyles) {
  376. head.insertBefore(link, headStyles[0]);
  377. } else {
  378. head.appendChild(link);
  379. }
  380. if (isFunction(callback)) {
  381. callback();
  382. }
  383. return;
  384. }
  385. found = document.querySelectorAll('script[src="' + url + '"]');
  386. if (found && found.length > 0) {
  387. if (isFunction(callback)) {
  388. if (isString(waitFor)) {
  389. waitUntil(function () {
  390. return typeof window[waitFor] !== 'undefined';
  391. }, function () {
  392. callback();
  393. });
  394. return false;
  395. }
  396. callback();
  397. }
  398. return;
  399. }
  400. var script = document.createElement('script');
  401. script.type = 'text/javascript';
  402. script.src = url;
  403. script.onload = function () {
  404. if (isFunction(callback)) {
  405. if (isString(waitFor)) {
  406. waitUntil(function () {
  407. return typeof window[waitFor] !== 'undefined';
  408. }, function () {
  409. callback();
  410. });
  411. return false;
  412. }
  413. callback();
  414. }
  415. };
  416. document.body.appendChild(script);
  417. }
  418. function isMobile() {
  419. return 'navigator' in window && window.navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(Android)|(PlayBook)|(BB10)|(BlackBerry)|(Opera Mini)|(IEMobile)|(webOS)|(MeeGo)/i);
  420. }
  421. function isTouch() {
  422. return isMobile() !== null || document.createTouch !== undefined || 'ontouchstart' in window || 'onmsgesturechange' in window || navigator.msMaxTouchPoints;
  423. }
  424. function isFunction(f) {
  425. return typeof f === 'function';
  426. }
  427. function isString(s) {
  428. return typeof s === 'string';
  429. }
  430. function isNode(el) {
  431. return !!(el && el.nodeType && el.nodeType == 1);
  432. }
  433. function isArray(ar) {
  434. return Array.isArray(ar);
  435. }
  436. function isArrayLike(ar) {
  437. return ar && ar.length && isFinite(ar.length);
  438. }
  439. function isObject(o) {
  440. var type = _typeof(o);
  441. return type === 'object' && o != null && !isFunction(o) && !isArray(o);
  442. }
  443. function isNil(o) {
  444. return o == null;
  445. }
  446. function has(obj, key) {
  447. return obj !== null && hasOwnProperty.call(obj, key);
  448. }
  449. function size(o) {
  450. if (isObject(o)) {
  451. if (o.keys) {
  452. return o.keys().length;
  453. }
  454. var l = 0;
  455. for (var k in o) {
  456. if (has(o, k)) {
  457. l++;
  458. }
  459. }
  460. return l;
  461. } else {
  462. return o.length;
  463. }
  464. }
  465. function isNumber(n) {
  466. return !isNaN(parseFloat(n)) && isFinite(n);
  467. }
  468. function getNextFocusElement() {
  469. var current = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
  470. var btns = document.querySelectorAll('.gbtn[data-taborder]:not(.disabled)');
  471. if (!btns.length) {
  472. return false;
  473. }
  474. if (btns.length == 1) {
  475. return btns[0];
  476. }
  477. if (typeof current == 'string') {
  478. current = parseInt(current);
  479. }
  480. var orders = [];
  481. each(btns, function (btn) {
  482. orders.push(btn.getAttribute('data-taborder'));
  483. });
  484. var highestOrder = Math.max.apply(Math, orders.map(function (order) {
  485. return parseInt(order);
  486. }));
  487. var newIndex = current < 0 ? 1 : current + 1;
  488. if (newIndex > highestOrder) {
  489. newIndex = '1';
  490. }
  491. var nextOrders = orders.filter(function (el) {
  492. return el >= parseInt(newIndex);
  493. });
  494. var nextFocus = nextOrders.sort()[0];
  495. return document.querySelector(".gbtn[data-taborder=\"".concat(nextFocus, "\"]"));
  496. }
  497. function keyboardNavigation(instance) {
  498. if (instance.events.hasOwnProperty('keyboard')) {
  499. return false;
  500. }
  501. instance.events['keyboard'] = addEvent('keydown', {
  502. onElement: window,
  503. withCallback: function withCallback(event, target) {
  504. event = event || window.event;
  505. var key = event.keyCode;
  506. if (key == 9) {
  507. var focusedButton = document.querySelector('.gbtn.focused');
  508. if (!focusedButton) {
  509. var activeElement = document.activeElement && document.activeElement.nodeName ? document.activeElement.nodeName.toLocaleLowerCase() : false;
  510. if (activeElement == 'input' || activeElement == 'textarea' || activeElement == 'button') {
  511. return;
  512. }
  513. }
  514. event.preventDefault();
  515. var btns = document.querySelectorAll('.gbtn[data-taborder]');
  516. if (!btns || btns.length <= 0) {
  517. return;
  518. }
  519. if (!focusedButton) {
  520. var first = getNextFocusElement();
  521. if (first) {
  522. first.focus();
  523. addClass(first, 'focused');
  524. }
  525. return;
  526. }
  527. var currentFocusOrder = focusedButton.getAttribute('data-taborder');
  528. var nextFocus = getNextFocusElement(currentFocusOrder);
  529. removeClass(focusedButton, 'focused');
  530. if (nextFocus) {
  531. nextFocus.focus();
  532. addClass(nextFocus, 'focused');
  533. }
  534. }
  535. if (key == 39) {
  536. instance.nextSlide();
  537. }
  538. if (key == 37) {
  539. instance.prevSlide();
  540. }
  541. if (key == 27) {
  542. instance.close();
  543. }
  544. }
  545. });
  546. }
  547. var ZoomImages = function () {
  548. function ZoomImages(el, slide) {
  549. var _this = this;
  550. var onclose = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  551. _classCallCheck(this, ZoomImages);
  552. this.img = el;
  553. this.slide = slide;
  554. this.onclose = onclose;
  555. if (this.img.setZoomEvents) {
  556. return false;
  557. }
  558. this.active = false;
  559. this.zoomedIn = false;
  560. this.dragging = false;
  561. this.currentX = null;
  562. this.currentY = null;
  563. this.initialX = null;
  564. this.initialY = null;
  565. this.xOffset = 0;
  566. this.yOffset = 0;
  567. this.img.addEventListener('mousedown', function (e) {
  568. return _this.dragStart(e);
  569. }, false);
  570. this.img.addEventListener('mouseup', function (e) {
  571. return _this.dragEnd(e);
  572. }, false);
  573. this.img.addEventListener('mousemove', function (e) {
  574. return _this.drag(e);
  575. }, false);
  576. this.img.addEventListener('click', function (e) {
  577. if (_this.slide.classList.contains('dragging-nav')) {
  578. _this.zoomOut();
  579. return false;
  580. }
  581. if (!_this.zoomedIn) {
  582. return _this.zoomIn();
  583. }
  584. if (_this.zoomedIn && !_this.dragging) {
  585. _this.zoomOut();
  586. }
  587. }, false);
  588. this.img.setZoomEvents = true;
  589. }
  590. return _createClass(ZoomImages, [{
  591. key: "zoomIn",
  592. value: function zoomIn() {
  593. var winWidth = this.widowWidth();
  594. if (this.zoomedIn || winWidth <= 768) {
  595. return;
  596. }
  597. var img = this.img;
  598. img.setAttribute('data-style', img.getAttribute('style'));
  599. img.style.maxWidth = img.naturalWidth + 'px';
  600. img.style.maxHeight = img.naturalHeight + 'px';
  601. if (img.naturalWidth > winWidth) {
  602. var centerX = winWidth / 2 - img.naturalWidth / 2;
  603. this.setTranslate(this.img.parentNode, centerX, 0);
  604. }
  605. this.slide.classList.add('zoomed');
  606. this.zoomedIn = true;
  607. }
  608. }, {
  609. key: "zoomOut",
  610. value: function zoomOut() {
  611. this.img.parentNode.setAttribute('style', '');
  612. this.img.setAttribute('style', this.img.getAttribute('data-style'));
  613. this.slide.classList.remove('zoomed');
  614. this.zoomedIn = false;
  615. this.currentX = null;
  616. this.currentY = null;
  617. this.initialX = null;
  618. this.initialY = null;
  619. this.xOffset = 0;
  620. this.yOffset = 0;
  621. if (this.onclose && typeof this.onclose == 'function') {
  622. this.onclose();
  623. }
  624. }
  625. }, {
  626. key: "dragStart",
  627. value: function dragStart(e) {
  628. e.preventDefault();
  629. if (!this.zoomedIn) {
  630. this.active = false;
  631. return;
  632. }
  633. if (e.type === 'touchstart') {
  634. this.initialX = e.touches[0].clientX - this.xOffset;
  635. this.initialY = e.touches[0].clientY - this.yOffset;
  636. } else {
  637. this.initialX = e.clientX - this.xOffset;
  638. this.initialY = e.clientY - this.yOffset;
  639. }
  640. if (e.target === this.img) {
  641. this.active = true;
  642. this.img.classList.add('dragging');
  643. }
  644. }
  645. }, {
  646. key: "dragEnd",
  647. value: function dragEnd(e) {
  648. var _this2 = this;
  649. e.preventDefault();
  650. this.initialX = this.currentX;
  651. this.initialY = this.currentY;
  652. this.active = false;
  653. setTimeout(function () {
  654. _this2.dragging = false;
  655. _this2.img.isDragging = false;
  656. _this2.img.classList.remove('dragging');
  657. }, 100);
  658. }
  659. }, {
  660. key: "drag",
  661. value: function drag(e) {
  662. if (this.active) {
  663. e.preventDefault();
  664. if (e.type === 'touchmove') {
  665. this.currentX = e.touches[0].clientX - this.initialX;
  666. this.currentY = e.touches[0].clientY - this.initialY;
  667. } else {
  668. this.currentX = e.clientX - this.initialX;
  669. this.currentY = e.clientY - this.initialY;
  670. }
  671. this.xOffset = this.currentX;
  672. this.yOffset = this.currentY;
  673. this.img.isDragging = true;
  674. this.dragging = true;
  675. this.setTranslate(this.img, this.currentX, this.currentY);
  676. }
  677. }
  678. }, {
  679. key: "onMove",
  680. value: function onMove(e) {
  681. if (!this.zoomedIn) {
  682. return;
  683. }
  684. var xOffset = e.clientX - this.img.naturalWidth / 2;
  685. var yOffset = e.clientY - this.img.naturalHeight / 2;
  686. this.setTranslate(this.img, xOffset, yOffset);
  687. }
  688. }, {
  689. key: "setTranslate",
  690. value: function setTranslate(node, xPos, yPos) {
  691. node.style.transform = 'translate3d(' + xPos + 'px, ' + yPos + 'px, 0)';
  692. }
  693. }, {
  694. key: "widowWidth",
  695. value: function widowWidth() {
  696. return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  697. }
  698. }]);
  699. }();
  700. var DragSlides = function () {
  701. function DragSlides() {
  702. var _this = this;
  703. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  704. _classCallCheck(this, DragSlides);
  705. var dragEl = config.dragEl,
  706. _config$toleranceX = config.toleranceX,
  707. toleranceX = _config$toleranceX === void 0 ? 40 : _config$toleranceX,
  708. _config$toleranceY = config.toleranceY,
  709. toleranceY = _config$toleranceY === void 0 ? 65 : _config$toleranceY,
  710. _config$slide = config.slide,
  711. slide = _config$slide === void 0 ? null : _config$slide,
  712. _config$instance = config.instance,
  713. instance = _config$instance === void 0 ? null : _config$instance;
  714. this.el = dragEl;
  715. this.active = false;
  716. this.dragging = false;
  717. this.currentX = null;
  718. this.currentY = null;
  719. this.initialX = null;
  720. this.initialY = null;
  721. this.xOffset = 0;
  722. this.yOffset = 0;
  723. this.direction = null;
  724. this.lastDirection = null;
  725. this.toleranceX = toleranceX;
  726. this.toleranceY = toleranceY;
  727. this.toleranceReached = false;
  728. this.dragContainer = this.el;
  729. this.slide = slide;
  730. this.instance = instance;
  731. this.el.addEventListener('mousedown', function (e) {
  732. return _this.dragStart(e);
  733. }, false);
  734. this.el.addEventListener('mouseup', function (e) {
  735. return _this.dragEnd(e);
  736. }, false);
  737. this.el.addEventListener('mousemove', function (e) {
  738. return _this.drag(e);
  739. }, false);
  740. }
  741. return _createClass(DragSlides, [{
  742. key: "dragStart",
  743. value: function dragStart(e) {
  744. if (this.slide.classList.contains('zoomed')) {
  745. this.active = false;
  746. return;
  747. }
  748. if (e.type === 'touchstart') {
  749. this.initialX = e.touches[0].clientX - this.xOffset;
  750. this.initialY = e.touches[0].clientY - this.yOffset;
  751. } else {
  752. this.initialX = e.clientX - this.xOffset;
  753. this.initialY = e.clientY - this.yOffset;
  754. }
  755. var clicked = e.target.nodeName.toLowerCase();
  756. var exludeClicks = ['input', 'select', 'textarea', 'button', 'a'];
  757. if (e.target.classList.contains('nodrag') || closest(e.target, '.nodrag') || exludeClicks.indexOf(clicked) !== -1) {
  758. this.active = false;
  759. return;
  760. }
  761. e.preventDefault();
  762. if (e.target === this.el || clicked !== 'img' && closest(e.target, '.gslide-inline')) {
  763. this.active = true;
  764. this.el.classList.add('dragging');
  765. this.dragContainer = closest(e.target, '.ginner-container');
  766. }
  767. }
  768. }, {
  769. key: "dragEnd",
  770. value: function dragEnd(e) {
  771. var _this2 = this;
  772. e && e.preventDefault();
  773. this.initialX = 0;
  774. this.initialY = 0;
  775. this.currentX = null;
  776. this.currentY = null;
  777. this.initialX = null;
  778. this.initialY = null;
  779. this.xOffset = 0;
  780. this.yOffset = 0;
  781. this.active = false;
  782. if (this.doSlideChange) {
  783. this.instance.preventOutsideClick = true;
  784. this.doSlideChange == 'right' && this.instance.prevSlide();
  785. this.doSlideChange == 'left' && this.instance.nextSlide();
  786. }
  787. if (this.doSlideClose) {
  788. this.instance.close();
  789. }
  790. if (!this.toleranceReached) {
  791. this.setTranslate(this.dragContainer, 0, 0, true);
  792. }
  793. setTimeout(function () {
  794. _this2.instance.preventOutsideClick = false;
  795. _this2.toleranceReached = false;
  796. _this2.lastDirection = null;
  797. _this2.dragging = false;
  798. _this2.el.isDragging = false;
  799. _this2.el.classList.remove('dragging');
  800. _this2.slide.classList.remove('dragging-nav');
  801. _this2.dragContainer.style.transform = '';
  802. _this2.dragContainer.style.transition = '';
  803. }, 100);
  804. }
  805. }, {
  806. key: "drag",
  807. value: function drag(e) {
  808. if (this.active) {
  809. e.preventDefault();
  810. this.slide.classList.add('dragging-nav');
  811. if (e.type === 'touchmove') {
  812. this.currentX = e.touches[0].clientX - this.initialX;
  813. this.currentY = e.touches[0].clientY - this.initialY;
  814. } else {
  815. this.currentX = e.clientX - this.initialX;
  816. this.currentY = e.clientY - this.initialY;
  817. }
  818. this.xOffset = this.currentX;
  819. this.yOffset = this.currentY;
  820. this.el.isDragging = true;
  821. this.dragging = true;
  822. this.doSlideChange = false;
  823. this.doSlideClose = false;
  824. var currentXInt = Math.abs(this.currentX);
  825. var currentYInt = Math.abs(this.currentY);
  826. if (currentXInt > 0 && currentXInt >= Math.abs(this.currentY) && (!this.lastDirection || this.lastDirection == 'x')) {
  827. this.yOffset = 0;
  828. this.lastDirection = 'x';
  829. this.setTranslate(this.dragContainer, this.currentX, 0);
  830. var doChange = this.shouldChange();
  831. if (!this.instance.settings.dragAutoSnap && doChange) {
  832. this.doSlideChange = doChange;
  833. }
  834. if (this.instance.settings.dragAutoSnap && doChange) {
  835. this.instance.preventOutsideClick = true;
  836. this.toleranceReached = true;
  837. this.active = false;
  838. this.instance.preventOutsideClick = true;
  839. this.dragEnd(null);
  840. doChange == 'right' && this.instance.prevSlide();
  841. doChange == 'left' && this.instance.nextSlide();
  842. return;
  843. }
  844. }
  845. if (this.toleranceY > 0 && currentYInt > 0 && currentYInt >= currentXInt && (!this.lastDirection || this.lastDirection == 'y')) {
  846. this.xOffset = 0;
  847. this.lastDirection = 'y';
  848. this.setTranslate(this.dragContainer, 0, this.currentY);
  849. var doClose = this.shouldClose();
  850. if (!this.instance.settings.dragAutoSnap && doClose) {
  851. this.doSlideClose = true;
  852. }
  853. if (this.instance.settings.dragAutoSnap && doClose) {
  854. this.instance.close();
  855. }
  856. return;
  857. }
  858. }
  859. }
  860. }, {
  861. key: "shouldChange",
  862. value: function shouldChange() {
  863. var doChange = false;
  864. var currentXInt = Math.abs(this.currentX);
  865. if (currentXInt >= this.toleranceX) {
  866. var dragDir = this.currentX > 0 ? 'right' : 'left';
  867. if (dragDir == 'left' && this.slide !== this.slide.parentNode.lastChild || dragDir == 'right' && this.slide !== this.slide.parentNode.firstChild) {
  868. doChange = dragDir;
  869. }
  870. }
  871. return doChange;
  872. }
  873. }, {
  874. key: "shouldClose",
  875. value: function shouldClose() {
  876. var doClose = false;
  877. var currentYInt = Math.abs(this.currentY);
  878. if (currentYInt >= this.toleranceY) {
  879. doClose = true;
  880. }
  881. return doClose;
  882. }
  883. }, {
  884. key: "setTranslate",
  885. value: function setTranslate(node, xPos, yPos) {
  886. var animated = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  887. if (animated) {
  888. node.style.transition = 'all .2s ease';
  889. } else {
  890. node.style.transition = '';
  891. }
  892. node.style.transform = "translate3d(".concat(xPos, "px, ").concat(yPos, "px, 0)");
  893. }
  894. }]);
  895. }();
  896. function slideImage(slide, data, index, callback) {
  897. var slideMedia = slide.querySelector('.gslide-media');
  898. var img = new Image();
  899. var titleID = 'gSlideTitle_' + index;
  900. var textID = 'gSlideDesc_' + index;
  901. img.addEventListener('load', function () {
  902. if (isFunction(callback)) {
  903. callback();
  904. }
  905. }, false);
  906. img.src = data.href;
  907. if (data.sizes != '' && data.srcset != '') {
  908. img.sizes = data.sizes;
  909. img.srcset = data.srcset;
  910. }
  911. img.alt = '';
  912. if (!isNil(data.alt) && data.alt !== '') {
  913. img.alt = data.alt;
  914. }
  915. if (data.title !== '') {
  916. img.setAttribute('aria-labelledby', titleID);
  917. }
  918. if (data.description !== '') {
  919. img.setAttribute('aria-describedby', textID);
  920. }
  921. if (data.hasOwnProperty('_hasCustomWidth') && data._hasCustomWidth) {
  922. img.style.width = data.width;
  923. }
  924. if (data.hasOwnProperty('_hasCustomHeight') && data._hasCustomHeight) {
  925. img.style.height = data.height;
  926. }
  927. slideMedia.insertBefore(img, slideMedia.firstChild);
  928. return;
  929. }
  930. function slideVideo(slide, data, index, callback) {
  931. var _this = this;
  932. var slideContainer = slide.querySelector('.ginner-container');
  933. var videoID = 'gvideo' + index;
  934. var slideMedia = slide.querySelector('.gslide-media');
  935. var videoPlayers = this.getAllPlayers();
  936. addClass(slideContainer, 'gvideo-container');
  937. slideMedia.insertBefore(createHTML('<div class="gvideo-wrapper"></div>'), slideMedia.firstChild);
  938. var videoWrapper = slide.querySelector('.gvideo-wrapper');
  939. injectAssets(this.settings.plyr.css, 'Plyr');
  940. var url = data.href;
  941. var provider = data === null || data === void 0 ? void 0 : data.videoProvider;
  942. var customPlaceholder = false;
  943. slideMedia.style.maxWidth = data.width;
  944. injectAssets(this.settings.plyr.js, 'Plyr', function () {
  945. if (!provider && url.match(/vimeo\.com\/([0-9]*)/)) {
  946. provider = 'vimeo';
  947. }
  948. 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\-_]+)/) || url.match(/(youtube\.com|youtube-nocookie\.com)\/shorts\/([a-zA-Z0-9\-_]+)/))) {
  949. provider = 'youtube';
  950. }
  951. if (provider === 'local' || !provider) {
  952. provider = 'local';
  953. var html = '<video id="' + videoID + '" ';
  954. html += "style=\"background:#000; max-width: ".concat(data.width, ";\" ");
  955. html += 'preload="metadata" ';
  956. html += 'x-webkit-airplay="allow" ';
  957. html += 'playsinline ';
  958. html += 'controls ';
  959. html += 'class="gvideo-local">';
  960. html += "<source src=\"".concat(url, "\">");
  961. html += '</video>';
  962. customPlaceholder = createHTML(html);
  963. }
  964. var placeholder = customPlaceholder ? customPlaceholder : createHTML("<div id=\"".concat(videoID, "\" data-plyr-provider=\"").concat(provider, "\" data-plyr-embed-id=\"").concat(url, "\"></div>"));
  965. addClass(videoWrapper, "".concat(provider, "-video gvideo"));
  966. videoWrapper.appendChild(placeholder);
  967. videoWrapper.setAttribute('data-id', videoID);
  968. videoWrapper.setAttribute('data-index', index);
  969. var playerConfig = has(_this.settings.plyr, 'config') ? _this.settings.plyr.config : {};
  970. var player = new Plyr('#' + videoID, playerConfig);
  971. player.on('ready', function (event) {
  972. videoPlayers[videoID] = event.detail.plyr;
  973. if (isFunction(callback)) {
  974. callback();
  975. }
  976. });
  977. waitUntil(function () {
  978. return slide.querySelector('iframe') && slide.querySelector('iframe').dataset.ready == 'true';
  979. }, function () {
  980. _this.resize(slide);
  981. });
  982. player.on('enterfullscreen', handleMediaFullScreen);
  983. player.on('exitfullscreen', handleMediaFullScreen);
  984. });
  985. }
  986. function handleMediaFullScreen(event) {
  987. var media = closest(event.target, '.gslide-media');
  988. if (event.type === 'enterfullscreen') {
  989. addClass(media, 'fullscreen');
  990. }
  991. if (event.type === 'exitfullscreen') {
  992. removeClass(media, 'fullscreen');
  993. }
  994. }
  995. function slideInline(slide, data, index, callback) {
  996. var _this = this;
  997. var slideMedia = slide.querySelector('.gslide-media');
  998. var hash = has(data, 'href') && data.href ? data.href.split('#').pop().trim() : false;
  999. var content = has(data, 'content') && data.content ? data.content : false;
  1000. var innerContent;
  1001. if (content) {
  1002. if (isString(content)) {
  1003. innerContent = createHTML("<div class=\"ginlined-content\">".concat(content, "</div>"));
  1004. }
  1005. if (isNode(content)) {
  1006. if (content.style.display == 'none') {
  1007. content.style.display = 'block';
  1008. }
  1009. var container = document.createElement('div');
  1010. container.className = 'ginlined-content';
  1011. container.appendChild(content);
  1012. innerContent = container;
  1013. }
  1014. }
  1015. if (hash) {
  1016. var div = document.getElementById(hash);
  1017. if (!div) {
  1018. return false;
  1019. }
  1020. var cloned = div.cloneNode(true);
  1021. cloned.style.height = data.height;
  1022. cloned.style.maxWidth = data.width;
  1023. addClass(cloned, 'ginlined-content');
  1024. innerContent = cloned;
  1025. }
  1026. if (!innerContent) {
  1027. console.error('Unable to append inline slide content', data);
  1028. return false;
  1029. }
  1030. slideMedia.style.height = data.height;
  1031. slideMedia.style.width = data.width;
  1032. slideMedia.appendChild(innerContent);
  1033. this.events['inlineclose' + hash] = addEvent('click', {
  1034. onElement: slideMedia.querySelectorAll('.gtrigger-close'),
  1035. withCallback: function withCallback(e) {
  1036. e.preventDefault();
  1037. _this.close();
  1038. }
  1039. });
  1040. if (isFunction(callback)) {
  1041. callback();
  1042. }
  1043. return;
  1044. }
  1045. function slideIframe(slide, data, index, callback) {
  1046. var slideMedia = slide.querySelector('.gslide-media');
  1047. var iframe = createIframe({
  1048. url: data.href,
  1049. callback: callback
  1050. });
  1051. slideMedia.parentNode.style.maxWidth = data.width;
  1052. slideMedia.parentNode.style.height = data.height;
  1053. slideMedia.appendChild(iframe);
  1054. return;
  1055. }
  1056. var SlideConfigParser = function () {
  1057. function SlideConfigParser() {
  1058. var slideParamas = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1059. _classCallCheck(this, SlideConfigParser);
  1060. this.defaults = {
  1061. href: '',
  1062. sizes: '',
  1063. srcset: '',
  1064. title: '',
  1065. type: '',
  1066. videoProvider: '',
  1067. description: '',
  1068. alt: '',
  1069. descPosition: 'bottom',
  1070. effect: '',
  1071. width: '',
  1072. height: '',
  1073. content: false,
  1074. zoomable: true,
  1075. draggable: true
  1076. };
  1077. if (isObject(slideParamas)) {
  1078. this.defaults = extend(this.defaults, slideParamas);
  1079. }
  1080. }
  1081. return _createClass(SlideConfigParser, [{
  1082. key: "sourceType",
  1083. value: function sourceType(url) {
  1084. var origin = url;
  1085. url = url.toLowerCase();
  1086. if (url.match(/\.(jpeg|jpg|jpe|gif|png|apn|webp|avif|svg)/) !== null) {
  1087. return 'image';
  1088. }
  1089. 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\-_]+)/) || url.match(/(youtube\.com|youtube-nocookie\.com)\/shorts\/([a-zA-Z0-9\-_]+)/)) {
  1090. return 'video';
  1091. }
  1092. if (url.match(/vimeo\.com\/([0-9]*)/)) {
  1093. return 'video';
  1094. }
  1095. if (url.match(/\.(mp4|ogg|webm|mov)/) !== null) {
  1096. return 'video';
  1097. }
  1098. if (url.match(/\.(mp3|wav|wma|aac|ogg)/) !== null) {
  1099. return 'audio';
  1100. }
  1101. if (url.indexOf('#') > -1) {
  1102. var hash = origin.split('#').pop();
  1103. if (hash.trim() !== '') {
  1104. return 'inline';
  1105. }
  1106. }
  1107. if (url.indexOf('goajax=true') > -1) {
  1108. return 'ajax';
  1109. }
  1110. return 'external';
  1111. }
  1112. }, {
  1113. key: "parseConfig",
  1114. value: function parseConfig(element, settings) {
  1115. var _this = this;
  1116. var data = extend({
  1117. descPosition: settings.descPosition
  1118. }, this.defaults);
  1119. if (isObject(element) && !isNode(element)) {
  1120. if (!has(element, 'type')) {
  1121. if (has(element, 'content') && element.content) {
  1122. element.type = 'inline';
  1123. } else if (has(element, 'href')) {
  1124. element.type = this.sourceType(element.href);
  1125. }
  1126. }
  1127. var objectData = extend(data, element);
  1128. this.setSize(objectData, settings);
  1129. return objectData;
  1130. }
  1131. var url = '';
  1132. var config = element.getAttribute('data-glightbox');
  1133. var nodeType = element.nodeName.toLowerCase();
  1134. if (nodeType === 'a') {
  1135. url = element.href;
  1136. }
  1137. if (nodeType === 'img') {
  1138. url = element.src;
  1139. data.alt = element.alt;
  1140. }
  1141. data.href = url;
  1142. each(data, function (val, key) {
  1143. if (has(settings, key) && key !== 'width') {
  1144. data[key] = settings[key];
  1145. }
  1146. var nodeData = element.dataset[key];
  1147. if (!isNil(nodeData)) {
  1148. data[key] = _this.sanitizeValue(nodeData);
  1149. }
  1150. });
  1151. if (data.content) {
  1152. data.type = 'inline';
  1153. }
  1154. if (!data.type && url) {
  1155. data.type = this.sourceType(url);
  1156. }
  1157. if (!isNil(config)) {
  1158. var cleanKeys = [];
  1159. each(data, function (v, k) {
  1160. cleanKeys.push(';\\s?' + k);
  1161. });
  1162. cleanKeys = cleanKeys.join('\\s?:|');
  1163. if (config.trim() !== '') {
  1164. each(data, function (val, key) {
  1165. var str = config;
  1166. var match = 's?' + key + 's?:s?(.*?)(' + cleanKeys + 's?:|$)';
  1167. var regex = new RegExp(match);
  1168. var matches = str.match(regex);
  1169. if (matches && matches.length && matches[1]) {
  1170. var value = matches[1].trim().replace(/;\s*$/, '');
  1171. data[key] = _this.sanitizeValue(value);
  1172. }
  1173. });
  1174. }
  1175. } else {
  1176. if (!data.title && nodeType == 'a') {
  1177. var title = element.title;
  1178. if (!isNil(title) && title !== '') {
  1179. data.title = title;
  1180. }
  1181. }
  1182. if (!data.title && nodeType == 'img') {
  1183. var alt = element.alt;
  1184. if (!isNil(alt) && alt !== '') {
  1185. data.title = alt;
  1186. }
  1187. }
  1188. }
  1189. if (data.description && data.description.substring(0, 1) === '.') {
  1190. var description;
  1191. try {
  1192. description = document.querySelector(data.description).innerHTML;
  1193. } catch (error) {
  1194. if (!(error instanceof DOMException)) {
  1195. throw error;
  1196. }
  1197. }
  1198. if (description) {
  1199. data.description = description;
  1200. }
  1201. }
  1202. if (!data.description) {
  1203. var nodeDesc = element.querySelector('.glightbox-desc');
  1204. if (nodeDesc) {
  1205. data.description = nodeDesc.innerHTML;
  1206. }
  1207. }
  1208. this.setSize(data, settings, element);
  1209. this.slideConfig = data;
  1210. return data;
  1211. }
  1212. }, {
  1213. key: "setSize",
  1214. value: function setSize(data, settings) {
  1215. var element = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  1216. var defaultWith = data.type == 'video' ? this.checkSize(settings.videosWidth) : this.checkSize(settings.width);
  1217. var defaultHeight = this.checkSize(settings.height);
  1218. data.width = has(data, 'width') && data.width !== '' ? this.checkSize(data.width) : defaultWith;
  1219. data.height = has(data, 'height') && data.height !== '' ? this.checkSize(data.height) : defaultHeight;
  1220. if (element && data.type == 'image') {
  1221. data._hasCustomWidth = element.dataset.width ? true : false;
  1222. data._hasCustomHeight = element.dataset.height ? true : false;
  1223. }
  1224. return data;
  1225. }
  1226. }, {
  1227. key: "checkSize",
  1228. value: function checkSize(size) {
  1229. return isNumber(size) ? "".concat(size, "px") : size;
  1230. }
  1231. }, {
  1232. key: "sanitizeValue",
  1233. value: function sanitizeValue(val) {
  1234. if (val !== 'true' && val !== 'false') {
  1235. return val;
  1236. }
  1237. return val === 'true';
  1238. }
  1239. }]);
  1240. }();
  1241. var Slide = function () {
  1242. function Slide(el, instance, index) {
  1243. _classCallCheck(this, Slide);
  1244. this.element = el;
  1245. this.instance = instance;
  1246. this.index = index;
  1247. }
  1248. return _createClass(Slide, [{
  1249. key: "setContent",
  1250. value: function setContent() {
  1251. var _this = this;
  1252. var slide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  1253. var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1254. if (hasClass(slide, 'loaded')) {
  1255. return false;
  1256. }
  1257. var settings = this.instance.settings;
  1258. var slideConfig = this.slideConfig;
  1259. var isMobileDevice = isMobile();
  1260. if (isFunction(settings.beforeSlideLoad)) {
  1261. settings.beforeSlideLoad({
  1262. index: this.index,
  1263. slide: slide,
  1264. player: false
  1265. });
  1266. }
  1267. var type = slideConfig.type;
  1268. var position = slideConfig.descPosition;
  1269. var slideMedia = slide.querySelector('.gslide-media');
  1270. var slideTitle = slide.querySelector('.gslide-title');
  1271. var slideText = slide.querySelector('.gslide-desc');
  1272. var slideDesc = slide.querySelector('.gdesc-inner');
  1273. var finalCallback = callback;
  1274. var titleID = 'gSlideTitle_' + this.index;
  1275. var textID = 'gSlideDesc_' + this.index;
  1276. if (isFunction(settings.afterSlideLoad)) {
  1277. finalCallback = function finalCallback() {
  1278. if (isFunction(callback)) {
  1279. callback();
  1280. }
  1281. settings.afterSlideLoad({
  1282. index: _this.index,
  1283. slide: slide,
  1284. player: _this.instance.getSlidePlayerInstance(_this.index)
  1285. });
  1286. };
  1287. }
  1288. if (slideConfig.title == '' && slideConfig.description == '') {
  1289. if (slideDesc) {
  1290. slideDesc.parentNode.parentNode.removeChild(slideDesc.parentNode);
  1291. }
  1292. } else {
  1293. if (slideTitle && slideConfig.title !== '') {
  1294. slideTitle.id = titleID;
  1295. slideTitle.innerHTML = slideConfig.title;
  1296. } else {
  1297. slideTitle.parentNode.removeChild(slideTitle);
  1298. }
  1299. if (slideText && slideConfig.description !== '') {
  1300. slideText.id = textID;
  1301. if (isMobileDevice && settings.moreLength > 0) {
  1302. slideConfig.smallDescription = this.slideShortDesc(slideConfig.description, settings.moreLength, settings.moreText);
  1303. slideText.innerHTML = slideConfig.smallDescription;
  1304. this.descriptionEvents(slideText, slideConfig);
  1305. } else {
  1306. slideText.innerHTML = slideConfig.description;
  1307. }
  1308. } else {
  1309. slideText.parentNode.removeChild(slideText);
  1310. }
  1311. addClass(slideMedia.parentNode, "desc-".concat(position));
  1312. addClass(slideDesc.parentNode, "description-".concat(position));
  1313. }
  1314. addClass(slideMedia, "gslide-".concat(type));
  1315. addClass(slide, 'loaded');
  1316. if (type === 'video') {
  1317. slideVideo.apply(this.instance, [slide, slideConfig, this.index, finalCallback]);
  1318. return;
  1319. }
  1320. if (type === 'external') {
  1321. slideIframe.apply(this, [slide, slideConfig, this.index, finalCallback]);
  1322. return;
  1323. }
  1324. if (type === 'inline') {
  1325. slideInline.apply(this.instance, [slide, slideConfig, this.index, finalCallback]);
  1326. if (slideConfig.draggable) {
  1327. new DragSlides({
  1328. dragEl: slide.querySelector('.gslide-inline'),
  1329. toleranceX: settings.dragToleranceX,
  1330. toleranceY: settings.dragToleranceY,
  1331. slide: slide,
  1332. instance: this.instance
  1333. });
  1334. }
  1335. return;
  1336. }
  1337. if (type === 'image') {
  1338. slideImage(slide, slideConfig, this.index, function () {
  1339. var img = slide.querySelector('img');
  1340. if (slideConfig.draggable) {
  1341. new DragSlides({
  1342. dragEl: img,
  1343. toleranceX: settings.dragToleranceX,
  1344. toleranceY: settings.dragToleranceY,
  1345. slide: slide,
  1346. instance: _this.instance
  1347. });
  1348. }
  1349. if (slideConfig.zoomable && img.naturalWidth > img.offsetWidth) {
  1350. addClass(img, 'zoomable');
  1351. new ZoomImages(img, slide, function () {
  1352. _this.instance.resize();
  1353. });
  1354. }
  1355. if (isFunction(finalCallback)) {
  1356. finalCallback();
  1357. }
  1358. });
  1359. return;
  1360. }
  1361. if (isFunction(finalCallback)) {
  1362. finalCallback();
  1363. }
  1364. }
  1365. }, {
  1366. key: "slideShortDesc",
  1367. value: function slideShortDesc(string) {
  1368. var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
  1369. var wordBoundary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  1370. var div = document.createElement('div');
  1371. div.innerHTML = string;
  1372. var cleanedString = div.innerText;
  1373. var useWordBoundary = wordBoundary;
  1374. string = cleanedString.trim();
  1375. if (string.length <= n) {
  1376. return string;
  1377. }
  1378. var subString = string.substr(0, n - 1);
  1379. if (!useWordBoundary) {
  1380. return subString;
  1381. }
  1382. div = null;
  1383. return subString + '... <a href="#" class="desc-more">' + wordBoundary + '</a>';
  1384. }
  1385. }, {
  1386. key: "descriptionEvents",
  1387. value: function descriptionEvents(desc, data) {
  1388. var _this2 = this;
  1389. var moreLink = desc.querySelector('.desc-more');
  1390. if (!moreLink) {
  1391. return false;
  1392. }
  1393. addEvent('click', {
  1394. onElement: moreLink,
  1395. withCallback: function withCallback(event, target) {
  1396. event.preventDefault();
  1397. var body = document.body;
  1398. var desc = closest(target, '.gslide-desc');
  1399. if (!desc) {
  1400. return false;
  1401. }
  1402. desc.innerHTML = data.description;
  1403. addClass(body, 'gdesc-open');
  1404. var shortEvent = addEvent('click', {
  1405. onElement: [body, closest(desc, '.gslide-description')],
  1406. withCallback: function withCallback(event, target) {
  1407. if (event.target.nodeName.toLowerCase() !== 'a') {
  1408. removeClass(body, 'gdesc-open');
  1409. addClass(body, 'gdesc-closed');
  1410. desc.innerHTML = data.smallDescription;
  1411. _this2.descriptionEvents(desc, data);
  1412. setTimeout(function () {
  1413. removeClass(body, 'gdesc-closed');
  1414. }, 400);
  1415. shortEvent.destroy();
  1416. }
  1417. }
  1418. });
  1419. }
  1420. });
  1421. }
  1422. }, {
  1423. key: "create",
  1424. value: function create() {
  1425. return createHTML(this.instance.settings.slideHTML);
  1426. }
  1427. }, {
  1428. key: "getConfig",
  1429. value: function getConfig() {
  1430. if (!isNode(this.element) && !this.element.hasOwnProperty('draggable')) {
  1431. this.element.draggable = this.instance.settings.draggable;
  1432. }
  1433. var parser = new SlideConfigParser(this.instance.settings.slideExtraAttributes);
  1434. this.slideConfig = parser.parseConfig(this.element, this.instance.settings);
  1435. return this.slideConfig;
  1436. }
  1437. }]);
  1438. }();
  1439. function getLen(v) {
  1440. return Math.sqrt(v.x * v.x + v.y * v.y);
  1441. }
  1442. function dot(v1, v2) {
  1443. return v1.x * v2.x + v1.y * v2.y;
  1444. }
  1445. function getAngle(v1, v2) {
  1446. var mr = getLen(v1) * getLen(v2);
  1447. if (mr === 0) {
  1448. return 0;
  1449. }
  1450. var r = dot(v1, v2) / mr;
  1451. if (r > 1) {
  1452. r = 1;
  1453. }
  1454. return Math.acos(r);
  1455. }
  1456. function cross(v1, v2) {
  1457. return v1.x * v2.y - v2.x * v1.y;
  1458. }
  1459. function getRotateAngle(v1, v2) {
  1460. var angle = getAngle(v1, v2);
  1461. if (cross(v1, v2) > 0) {
  1462. angle *= -1;
  1463. }
  1464. return angle * 180 / Math.PI;
  1465. }
  1466. var EventsHandlerAdmin = function () {
  1467. function EventsHandlerAdmin(el) {
  1468. _classCallCheck(this, EventsHandlerAdmin);
  1469. this.handlers = [];
  1470. this.el = el;
  1471. }
  1472. return _createClass(EventsHandlerAdmin, [{
  1473. key: "add",
  1474. value: function add(handler) {
  1475. this.handlers.push(handler);
  1476. }
  1477. }, {
  1478. key: "del",
  1479. value: function del(handler) {
  1480. if (!handler) {
  1481. this.handlers = [];
  1482. }
  1483. for (var i = this.handlers.length; i >= 0; i--) {
  1484. if (this.handlers[i] === handler) {
  1485. this.handlers.splice(i, 1);
  1486. }
  1487. }
  1488. }
  1489. }, {
  1490. key: "dispatch",
  1491. value: function dispatch() {
  1492. for (var i = 0, len = this.handlers.length; i < len; i++) {
  1493. var handler = this.handlers[i];
  1494. if (typeof handler === 'function') {
  1495. handler.apply(this.el, arguments);
  1496. }
  1497. }
  1498. }
  1499. }]);
  1500. }();
  1501. function wrapFunc(el, handler) {
  1502. var EventshandlerAdmin = new EventsHandlerAdmin(el);
  1503. EventshandlerAdmin.add(handler);
  1504. return EventshandlerAdmin;
  1505. }
  1506. var TouchEvents = function () {
  1507. function TouchEvents(el, option) {
  1508. _classCallCheck(this, TouchEvents);
  1509. this.element = typeof el == 'string' ? document.querySelector(el) : el;
  1510. this.start = this.start.bind(this);
  1511. this.move = this.move.bind(this);
  1512. this.end = this.end.bind(this);
  1513. this.cancel = this.cancel.bind(this);
  1514. this.element.addEventListener('touchstart', this.start, false);
  1515. this.element.addEventListener('touchmove', this.move, false);
  1516. this.element.addEventListener('touchend', this.end, false);
  1517. this.element.addEventListener('touchcancel', this.cancel, false);
  1518. this.preV = {
  1519. x: null,
  1520. y: null
  1521. };
  1522. this.pinchStartLen = null;
  1523. this.zoom = 1;
  1524. this.isDoubleTap = false;
  1525. var noop = function noop() {};
  1526. this.rotate = wrapFunc(this.element, option.rotate || noop);
  1527. this.touchStart = wrapFunc(this.element, option.touchStart || noop);
  1528. this.multipointStart = wrapFunc(this.element, option.multipointStart || noop);
  1529. this.multipointEnd = wrapFunc(this.element, option.multipointEnd || noop);
  1530. this.pinch = wrapFunc(this.element, option.pinch || noop);
  1531. this.swipe = wrapFunc(this.element, option.swipe || noop);
  1532. this.tap = wrapFunc(this.element, option.tap || noop);
  1533. this.doubleTap = wrapFunc(this.element, option.doubleTap || noop);
  1534. this.longTap = wrapFunc(this.element, option.longTap || noop);
  1535. this.singleTap = wrapFunc(this.element, option.singleTap || noop);
  1536. this.pressMove = wrapFunc(this.element, option.pressMove || noop);
  1537. this.twoFingerPressMove = wrapFunc(this.element, option.twoFingerPressMove || noop);
  1538. this.touchMove = wrapFunc(this.element, option.touchMove || noop);
  1539. this.touchEnd = wrapFunc(this.element, option.touchEnd || noop);
  1540. this.touchCancel = wrapFunc(this.element, option.touchCancel || noop);
  1541. this.translateContainer = this.element;
  1542. this._cancelAllHandler = this.cancelAll.bind(this);
  1543. window.addEventListener('scroll', this._cancelAllHandler);
  1544. this.delta = null;
  1545. this.last = null;
  1546. this.now = null;
  1547. this.tapTimeout = null;
  1548. this.singleTapTimeout = null;
  1549. this.longTapTimeout = null;
  1550. this.swipeTimeout = null;
  1551. this.x1 = this.x2 = this.y1 = this.y2 = null;
  1552. this.preTapPosition = {
  1553. x: null,
  1554. y: null
  1555. };
  1556. }
  1557. return _createClass(TouchEvents, [{
  1558. key: "start",
  1559. value: function start(evt) {
  1560. if (!evt.touches) {
  1561. return;
  1562. }
  1563. var ignoreDragFor = ['a', 'button', 'input'];
  1564. if (evt.target && evt.target.nodeName && ignoreDragFor.indexOf(evt.target.nodeName.toLowerCase()) >= 0) {
  1565. console.log('ignore drag for this touched element', evt.target.nodeName.toLowerCase());
  1566. return;
  1567. }
  1568. this.now = Date.now();
  1569. this.x1 = evt.touches[0].pageX;
  1570. this.y1 = evt.touches[0].pageY;
  1571. this.delta = this.now - (this.last || this.now);
  1572. this.touchStart.dispatch(evt, this.element);
  1573. if (this.preTapPosition.x !== null) {
  1574. this.isDoubleTap = this.delta > 0 && this.delta <= 250 && Math.abs(this.preTapPosition.x - this.x1) < 30 && Math.abs(this.preTapPosition.y - this.y1) < 30;
  1575. if (this.isDoubleTap) {
  1576. clearTimeout(this.singleTapTimeout);
  1577. }
  1578. }
  1579. this.preTapPosition.x = this.x1;
  1580. this.preTapPosition.y = this.y1;
  1581. this.last = this.now;
  1582. var preV = this.preV,
  1583. len = evt.touches.length;
  1584. if (len > 1) {
  1585. this._cancelLongTap();
  1586. this._cancelSingleTap();
  1587. var v = {
  1588. x: evt.touches[1].pageX - this.x1,
  1589. y: evt.touches[1].pageY - this.y1
  1590. };
  1591. preV.x = v.x;
  1592. preV.y = v.y;
  1593. this.pinchStartLen = getLen(preV);
  1594. this.multipointStart.dispatch(evt, this.element);
  1595. }
  1596. this._preventTap = false;
  1597. this.longTapTimeout = setTimeout(function () {
  1598. this.longTap.dispatch(evt, this.element);
  1599. this._preventTap = true;
  1600. }.bind(this), 750);
  1601. }
  1602. }, {
  1603. key: "move",
  1604. value: function move(evt) {
  1605. if (!evt.touches) {
  1606. return;
  1607. }
  1608. var preV = this.preV,
  1609. len = evt.touches.length,
  1610. currentX = evt.touches[0].pageX,
  1611. currentY = evt.touches[0].pageY;
  1612. this.isDoubleTap = false;
  1613. if (len > 1) {
  1614. var sCurrentX = evt.touches[1].pageX,
  1615. sCurrentY = evt.touches[1].pageY;
  1616. var v = {
  1617. x: evt.touches[1].pageX - currentX,
  1618. y: evt.touches[1].pageY - currentY
  1619. };
  1620. if (preV.x !== null) {
  1621. if (this.pinchStartLen > 0) {
  1622. evt.zoom = getLen(v) / this.pinchStartLen;
  1623. this.pinch.dispatch(evt, this.element);
  1624. }
  1625. evt.angle = getRotateAngle(v, preV);
  1626. this.rotate.dispatch(evt, this.element);
  1627. }
  1628. preV.x = v.x;
  1629. preV.y = v.y;
  1630. if (this.x2 !== null && this.sx2 !== null) {
  1631. evt.deltaX = (currentX - this.x2 + sCurrentX - this.sx2) / 2;
  1632. evt.deltaY = (currentY - this.y2 + sCurrentY - this.sy2) / 2;
  1633. } else {
  1634. evt.deltaX = 0;
  1635. evt.deltaY = 0;
  1636. }
  1637. this.twoFingerPressMove.dispatch(evt, this.element);
  1638. this.sx2 = sCurrentX;
  1639. this.sy2 = sCurrentY;
  1640. } else {
  1641. if (this.x2 !== null) {
  1642. evt.deltaX = currentX - this.x2;
  1643. evt.deltaY = currentY - this.y2;
  1644. var movedX = Math.abs(this.x1 - this.x2),
  1645. movedY = Math.abs(this.y1 - this.y2);
  1646. if (movedX > 10 || movedY > 10) {
  1647. this._preventTap = true;
  1648. }
  1649. } else {
  1650. evt.deltaX = 0;
  1651. evt.deltaY = 0;
  1652. }
  1653. this.pressMove.dispatch(evt, this.element);
  1654. }
  1655. this.touchMove.dispatch(evt, this.element);
  1656. this._cancelLongTap();
  1657. this.x2 = currentX;
  1658. this.y2 = currentY;
  1659. if (len > 1) {
  1660. evt.preventDefault();
  1661. }
  1662. }
  1663. }, {
  1664. key: "end",
  1665. value: function end(evt) {
  1666. if (!evt.changedTouches) {
  1667. return;
  1668. }
  1669. this._cancelLongTap();
  1670. var self = this;
  1671. if (evt.touches.length < 2) {
  1672. this.multipointEnd.dispatch(evt, this.element);
  1673. this.sx2 = this.sy2 = null;
  1674. }
  1675. if (this.x2 && Math.abs(this.x1 - this.x2) > 30 || this.y2 && Math.abs(this.y1 - this.y2) > 30) {
  1676. evt.direction = this._swipeDirection(this.x1, this.x2, this.y1, this.y2);
  1677. this.swipeTimeout = setTimeout(function () {
  1678. self.swipe.dispatch(evt, self.element);
  1679. }, 0);
  1680. } else {
  1681. this.tapTimeout = setTimeout(function () {
  1682. if (!self._preventTap) {
  1683. self.tap.dispatch(evt, self.element);
  1684. }
  1685. if (self.isDoubleTap) {
  1686. self.doubleTap.dispatch(evt, self.element);
  1687. self.isDoubleTap = false;
  1688. }
  1689. }, 0);
  1690. if (!self.isDoubleTap) {
  1691. self.singleTapTimeout = setTimeout(function () {
  1692. self.singleTap.dispatch(evt, self.element);
  1693. }, 250);
  1694. }
  1695. }
  1696. this.touchEnd.dispatch(evt, this.element);
  1697. this.preV.x = 0;
  1698. this.preV.y = 0;
  1699. this.zoom = 1;
  1700. this.pinchStartLen = null;
  1701. this.x1 = this.x2 = this.y1 = this.y2 = null;
  1702. }
  1703. }, {
  1704. key: "cancelAll",
  1705. value: function cancelAll() {
  1706. this._preventTap = true;
  1707. clearTimeout(this.singleTapTimeout);
  1708. clearTimeout(this.tapTimeout);
  1709. clearTimeout(this.longTapTimeout);
  1710. clearTimeout(this.swipeTimeout);
  1711. }
  1712. }, {
  1713. key: "cancel",
  1714. value: function cancel(evt) {
  1715. this.cancelAll();
  1716. this.touchCancel.dispatch(evt, this.element);
  1717. }
  1718. }, {
  1719. key: "_cancelLongTap",
  1720. value: function _cancelLongTap() {
  1721. clearTimeout(this.longTapTimeout);
  1722. }
  1723. }, {
  1724. key: "_cancelSingleTap",
  1725. value: function _cancelSingleTap() {
  1726. clearTimeout(this.singleTapTimeout);
  1727. }
  1728. }, {
  1729. key: "_swipeDirection",
  1730. value: function _swipeDirection(x1, x2, y1, y2) {
  1731. return Math.abs(x1 - x2) >= Math.abs(y1 - y2) ? x1 - x2 > 0 ? 'Left' : 'Right' : y1 - y2 > 0 ? 'Up' : 'Down';
  1732. }
  1733. }, {
  1734. key: "on",
  1735. value: function on(evt, handler) {
  1736. if (this[evt]) {
  1737. this[evt].add(handler);
  1738. }
  1739. }
  1740. }, {
  1741. key: "off",
  1742. value: function off(evt, handler) {
  1743. if (this[evt]) {
  1744. this[evt].del(handler);
  1745. }
  1746. }
  1747. }, {
  1748. key: "destroy",
  1749. value: function destroy() {
  1750. if (this.singleTapTimeout) {
  1751. clearTimeout(this.singleTapTimeout);
  1752. }
  1753. if (this.tapTimeout) {
  1754. clearTimeout(this.tapTimeout);
  1755. }
  1756. if (this.longTapTimeout) {
  1757. clearTimeout(this.longTapTimeout);
  1758. }
  1759. if (this.swipeTimeout) {
  1760. clearTimeout(this.swipeTimeout);
  1761. }
  1762. this.element.removeEventListener('touchstart', this.start);
  1763. this.element.removeEventListener('touchmove', this.move);
  1764. this.element.removeEventListener('touchend', this.end);
  1765. this.element.removeEventListener('touchcancel', this.cancel);
  1766. this.rotate.del();
  1767. this.touchStart.del();
  1768. this.multipointStart.del();
  1769. this.multipointEnd.del();
  1770. this.pinch.del();
  1771. this.swipe.del();
  1772. this.tap.del();
  1773. this.doubleTap.del();
  1774. this.longTap.del();
  1775. this.singleTap.del();
  1776. this.pressMove.del();
  1777. this.twoFingerPressMove.del();
  1778. this.touchMove.del();
  1779. this.touchEnd.del();
  1780. this.touchCancel.del();
  1781. 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;
  1782. window.removeEventListener('scroll', this._cancelAllHandler);
  1783. return null;
  1784. }
  1785. }]);
  1786. }();
  1787. function resetSlideMove(slide) {
  1788. var transitionEnd = whichTransitionEvent();
  1789. var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  1790. var media = hasClass(slide, 'gslide-media') ? slide : slide.querySelector('.gslide-media');
  1791. var container = closest(media, '.ginner-container');
  1792. var desc = slide.querySelector('.gslide-description');
  1793. if (windowWidth > 769) {
  1794. media = container;
  1795. }
  1796. addClass(media, 'greset');
  1797. cssTransform(media, 'translate3d(0, 0, 0)');
  1798. addEvent(transitionEnd, {
  1799. onElement: media,
  1800. once: true,
  1801. withCallback: function withCallback(event, target) {
  1802. removeClass(media, 'greset');
  1803. }
  1804. });
  1805. media.style.opacity = '';
  1806. if (desc) {
  1807. desc.style.opacity = '';
  1808. }
  1809. }
  1810. function touchNavigation(instance) {
  1811. if (instance.events.hasOwnProperty('touch')) {
  1812. return false;
  1813. }
  1814. var winSize = windowSize();
  1815. var winWidth = winSize.width;
  1816. var winHeight = winSize.height;
  1817. var process = false;
  1818. var currentSlide = null;
  1819. var media = null;
  1820. var mediaImage = null;
  1821. var doingMove = false;
  1822. var initScale = 1;
  1823. var maxScale = 4.5;
  1824. var currentScale = 1;
  1825. var doingZoom = false;
  1826. var imageZoomed = false;
  1827. var zoomedPosX = null;
  1828. var zoomedPosY = null;
  1829. var lastZoomedPosX = null;
  1830. var lastZoomedPosY = null;
  1831. var hDistance;
  1832. var vDistance;
  1833. var hDistancePercent = 0;
  1834. var vDistancePercent = 0;
  1835. var vSwipe = false;
  1836. var hSwipe = false;
  1837. var startCoords = {};
  1838. var endCoords = {};
  1839. var xDown = 0;
  1840. var yDown = 0;
  1841. var isInlined;
  1842. var sliderWrapper = document.getElementById('glightbox-slider');
  1843. var overlay = document.querySelector('.goverlay');
  1844. var touchInstance = new TouchEvents(sliderWrapper, {
  1845. touchStart: function touchStart(e) {
  1846. process = true;
  1847. if (hasClass(e.targetTouches[0].target, 'ginner-container') || closest(e.targetTouches[0].target, '.gslide-desc') || e.targetTouches[0].target.nodeName.toLowerCase() == 'a') {
  1848. process = false;
  1849. }
  1850. if (closest(e.targetTouches[0].target, '.gslide-inline') && !hasClass(e.targetTouches[0].target.parentNode, 'gslide-inline')) {
  1851. process = false;
  1852. }
  1853. if (process) {
  1854. endCoords = e.targetTouches[0];
  1855. startCoords.pageX = e.targetTouches[0].pageX;
  1856. startCoords.pageY = e.targetTouches[0].pageY;
  1857. xDown = e.targetTouches[0].clientX;
  1858. yDown = e.targetTouches[0].clientY;
  1859. currentSlide = instance.activeSlide;
  1860. media = currentSlide.querySelector('.gslide-media');
  1861. isInlined = currentSlide.querySelector('.gslide-inline');
  1862. mediaImage = null;
  1863. if (hasClass(media, 'gslide-image')) {
  1864. mediaImage = media.querySelector('img');
  1865. }
  1866. var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  1867. if (windowWidth > 769) {
  1868. media = currentSlide.querySelector('.ginner-container');
  1869. }
  1870. removeClass(overlay, 'greset');
  1871. if (e.pageX > 20 && e.pageX < window.innerWidth - 20) {
  1872. return;
  1873. }
  1874. e.preventDefault();
  1875. }
  1876. },
  1877. touchMove: function touchMove(e) {
  1878. if (!process) {
  1879. return;
  1880. }
  1881. endCoords = e.targetTouches[0];
  1882. if (doingZoom || imageZoomed) {
  1883. return;
  1884. }
  1885. if (isInlined && isInlined.offsetHeight > winHeight) {
  1886. var moved = startCoords.pageX - endCoords.pageX;
  1887. if (Math.abs(moved) <= 13) {
  1888. return false;
  1889. }
  1890. }
  1891. doingMove = true;
  1892. var xUp = e.targetTouches[0].clientX;
  1893. var yUp = e.targetTouches[0].clientY;
  1894. var xDiff = xDown - xUp;
  1895. var yDiff = yDown - yUp;
  1896. if (Math.abs(xDiff) > Math.abs(yDiff)) {
  1897. vSwipe = false;
  1898. hSwipe = true;
  1899. } else {
  1900. hSwipe = false;
  1901. vSwipe = true;
  1902. }
  1903. hDistance = endCoords.pageX - startCoords.pageX;
  1904. hDistancePercent = hDistance * 100 / winWidth;
  1905. vDistance = endCoords.pageY - startCoords.pageY;
  1906. vDistancePercent = vDistance * 100 / winHeight;
  1907. var opacity;
  1908. if (vSwipe && mediaImage) {
  1909. opacity = 1 - Math.abs(vDistance) / winHeight;
  1910. overlay.style.opacity = opacity;
  1911. if (instance.settings.touchFollowAxis) {
  1912. hDistancePercent = 0;
  1913. }
  1914. }
  1915. if (hSwipe) {
  1916. opacity = 1 - Math.abs(hDistance) / winWidth;
  1917. media.style.opacity = opacity;
  1918. if (instance.settings.touchFollowAxis) {
  1919. vDistancePercent = 0;
  1920. }
  1921. }
  1922. if (!mediaImage) {
  1923. return cssTransform(media, "translate3d(".concat(hDistancePercent, "%, 0, 0)"));
  1924. }
  1925. cssTransform(media, "translate3d(".concat(hDistancePercent, "%, ").concat(vDistancePercent, "%, 0)"));
  1926. },
  1927. touchEnd: function touchEnd() {
  1928. if (!process) {
  1929. return;
  1930. }
  1931. doingMove = false;
  1932. if (imageZoomed || doingZoom) {
  1933. lastZoomedPosX = zoomedPosX;
  1934. lastZoomedPosY = zoomedPosY;
  1935. return;
  1936. }
  1937. var v = Math.abs(parseInt(vDistancePercent));
  1938. var h = Math.abs(parseInt(hDistancePercent));
  1939. if (v > 29 && mediaImage) {
  1940. instance.close();
  1941. return;
  1942. }
  1943. if (v < 29 && h < 25) {
  1944. addClass(overlay, 'greset');
  1945. overlay.style.opacity = 1;
  1946. return resetSlideMove(media);
  1947. }
  1948. },
  1949. multipointEnd: function multipointEnd() {
  1950. setTimeout(function () {
  1951. doingZoom = false;
  1952. }, 50);
  1953. },
  1954. multipointStart: function multipointStart() {
  1955. doingZoom = true;
  1956. initScale = currentScale ? currentScale : 1;
  1957. },
  1958. pinch: function pinch(evt) {
  1959. if (!mediaImage || doingMove) {
  1960. return false;
  1961. }
  1962. doingZoom = true;
  1963. mediaImage.scaleX = mediaImage.scaleY = initScale * evt.zoom;
  1964. var scale = initScale * evt.zoom;
  1965. imageZoomed = true;
  1966. if (scale <= 1) {
  1967. imageZoomed = false;
  1968. scale = 1;
  1969. lastZoomedPosY = null;
  1970. lastZoomedPosX = null;
  1971. zoomedPosX = null;
  1972. zoomedPosY = null;
  1973. mediaImage.setAttribute('style', '');
  1974. return;
  1975. }
  1976. if (scale > maxScale) {
  1977. scale = maxScale;
  1978. }
  1979. mediaImage.style.transform = "scale3d(".concat(scale, ", ").concat(scale, ", 1)");
  1980. currentScale = scale;
  1981. },
  1982. pressMove: function pressMove(e) {
  1983. if (imageZoomed && !doingZoom) {
  1984. var mhDistance = endCoords.pageX - startCoords.pageX;
  1985. var mvDistance = endCoords.pageY - startCoords.pageY;
  1986. if (lastZoomedPosX) {
  1987. mhDistance = mhDistance + lastZoomedPosX;
  1988. }
  1989. if (lastZoomedPosY) {
  1990. mvDistance = mvDistance + lastZoomedPosY;
  1991. }
  1992. zoomedPosX = mhDistance;
  1993. zoomedPosY = mvDistance;
  1994. var style = "translate3d(".concat(mhDistance, "px, ").concat(mvDistance, "px, 0)");
  1995. if (currentScale) {
  1996. style += " scale3d(".concat(currentScale, ", ").concat(currentScale, ", 1)");
  1997. }
  1998. cssTransform(mediaImage, style);
  1999. }
  2000. },
  2001. swipe: function swipe(evt) {
  2002. if (imageZoomed) {
  2003. return;
  2004. }
  2005. if (doingZoom) {
  2006. doingZoom = false;
  2007. return;
  2008. }
  2009. if (evt.direction == 'Left') {
  2010. if (instance.index == instance.elements.length - 1) {
  2011. return resetSlideMove(media);
  2012. }
  2013. instance.nextSlide();
  2014. }
  2015. if (evt.direction == 'Right') {
  2016. if (instance.index == 0) {
  2017. return resetSlideMove(media);
  2018. }
  2019. instance.prevSlide();
  2020. }
  2021. }
  2022. });
  2023. instance.events['touch'] = touchInstance;
  2024. }
  2025. var _version = '3.3.0';
  2026. var isMobile$1 = isMobile();
  2027. var isTouch$1 = isTouch();
  2028. var html = document.getElementsByTagName('html')[0];
  2029. var defaults = {
  2030. selector: '.glightbox',
  2031. elements: null,
  2032. skin: 'clean',
  2033. theme: 'clean',
  2034. closeButton: true,
  2035. startAt: null,
  2036. autoplayVideos: true,
  2037. autofocusVideos: true,
  2038. descPosition: 'bottom',
  2039. width: '900px',
  2040. height: '506px',
  2041. videosWidth: '960px',
  2042. beforeSlideChange: null,
  2043. afterSlideChange: null,
  2044. beforeSlideLoad: null,
  2045. afterSlideLoad: null,
  2046. slideInserted: null,
  2047. slideRemoved: null,
  2048. slideExtraAttributes: null,
  2049. onOpen: null,
  2050. onClose: null,
  2051. loop: false,
  2052. zoomable: true,
  2053. draggable: true,
  2054. dragAutoSnap: false,
  2055. dragToleranceX: 40,
  2056. dragToleranceY: 65,
  2057. preload: true,
  2058. oneSlidePerOpen: false,
  2059. touchNavigation: true,
  2060. touchFollowAxis: true,
  2061. keyboardNavigation: true,
  2062. closeOnOutsideClick: true,
  2063. plugins: false,
  2064. plyr: {
  2065. css: 'https://cdn.plyr.io/3.6.12/plyr.css',
  2066. js: 'https://cdn.plyr.io/3.6.12/plyr.js',
  2067. config: {
  2068. ratio: '16:9',
  2069. fullscreen: {
  2070. enabled: true,
  2071. iosNative: true
  2072. },
  2073. youtube: {
  2074. noCookie: true,
  2075. rel: 0,
  2076. showinfo: 0,
  2077. iv_load_policy: 3
  2078. },
  2079. vimeo: {
  2080. byline: false,
  2081. portrait: false,
  2082. title: false,
  2083. transparent: false
  2084. }
  2085. }
  2086. },
  2087. openEffect: 'zoom',
  2088. closeEffect: 'zoom',
  2089. slideEffect: 'slide',
  2090. moreText: 'See more',
  2091. moreLength: 60,
  2092. cssEfects: {
  2093. fade: {
  2094. "in": 'fadeIn',
  2095. out: 'fadeOut'
  2096. },
  2097. zoom: {
  2098. "in": 'zoomIn',
  2099. out: 'zoomOut'
  2100. },
  2101. slide: {
  2102. "in": 'slideInRight',
  2103. out: 'slideOutLeft'
  2104. },
  2105. slideBack: {
  2106. "in": 'slideInLeft',
  2107. out: 'slideOutRight'
  2108. },
  2109. none: {
  2110. "in": 'none',
  2111. out: 'none'
  2112. }
  2113. },
  2114. svg: {
  2115. close: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve"><g><g><path d="M505.943,6.058c-8.077-8.077-21.172-8.077-29.249,0L6.058,476.693c-8.077,8.077-8.077,21.172,0,29.249C10.096,509.982,15.39,512,20.683,512c5.293,0,10.586-2.019,14.625-6.059L505.943,35.306C514.019,27.23,514.019,14.135,505.943,6.058z"/></g></g><g><g><path d="M505.942,476.694L35.306,6.059c-8.076-8.077-21.172-8.077-29.248,0c-8.077,8.076-8.077,21.171,0,29.248l470.636,470.636c4.038,4.039,9.332,6.058,14.625,6.058c5.293,0,10.587-2.019,14.624-6.057C514.018,497.866,514.018,484.771,505.942,476.694z"/></g></g></svg>',
  2116. next: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 477.175 477.175" xml:space="preserve"> <g><path d="M360.731,229.075l-225.1-225.1c-5.3-5.3-13.8-5.3-19.1,0s-5.3,13.8,0,19.1l215.5,215.5l-215.5,215.5c-5.3,5.3-5.3,13.8,0,19.1c2.6,2.6,6.1,4,9.5,4c3.4,0,6.9-1.3,9.5-4l225.1-225.1C365.931,242.875,365.931,234.275,360.731,229.075z"/></g></svg>',
  2117. prev: '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 477.175 477.175" xml:space="preserve"><g><path d="M145.188,238.575l215.5-215.5c5.3-5.3,5.3-13.8,0-19.1s-13.8-5.3-19.1,0l-225.1,225.1c-5.3,5.3-5.3,13.8,0,19.1l225.1,225c2.6,2.6,6.1,4,9.5,4s6.9-1.3,9.5-4c5.3-5.3,5.3-13.8,0-19.1L145.188,238.575z"/></g></svg>'
  2118. }
  2119. };
  2120. defaults.slideHTML = "<div class=\"gslide\">\n <div class=\"gslide-inner-content\">\n <div class=\"ginner-container\">\n <div class=\"gslide-media\">\n </div>\n <div class=\"gslide-description\">\n <div class=\"gdesc-inner\">\n <h4 class=\"gslide-title\"></h4>\n <div class=\"gslide-desc\"></div>\n </div>\n </div>\n </div>\n </div>\n</div>";
  2121. defaults.lightboxHTML = "<div id=\"glightbox-body\" class=\"glightbox-container\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"false\">\n <div class=\"gloader visible\"></div>\n <div class=\"goverlay\"></div>\n <div class=\"gcontainer\">\n <div id=\"glightbox-slider\" class=\"gslider\"></div>\n <button class=\"gclose gbtn\" aria-label=\"Close\" data-taborder=\"3\">{closeSVG}</button>\n <button class=\"gprev gbtn\" aria-label=\"Previous\" data-taborder=\"2\">{prevSVG}</button>\n <button class=\"gnext gbtn\" aria-label=\"Next\" data-taborder=\"1\">{nextSVG}</button>\n</div>\n</div>";
  2122. var GlightboxInit = function () {
  2123. function GlightboxInit() {
  2124. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  2125. _classCallCheck(this, GlightboxInit);
  2126. this.customOptions = options;
  2127. this.settings = extend(defaults, options);
  2128. this.effectsClasses = this.getAnimationClasses();
  2129. this.videoPlayers = {};
  2130. this.apiEvents = [];
  2131. this.fullElementsList = false;
  2132. }
  2133. return _createClass(GlightboxInit, [{
  2134. key: "init",
  2135. value: function init() {
  2136. var _this = this;
  2137. var selector = this.getSelector();
  2138. if (selector) {
  2139. this.baseEvents = addEvent('click', {
  2140. onElement: selector,
  2141. withCallback: function withCallback(e, target) {
  2142. e.preventDefault();
  2143. _this.open(target);
  2144. }
  2145. });
  2146. }
  2147. this.elements = this.getElements();
  2148. }
  2149. }, {
  2150. key: "open",
  2151. value: function open() {
  2152. var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  2153. var startAt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  2154. if (this.elements.length === 0) {
  2155. return false;
  2156. }
  2157. this.activeSlide = null;
  2158. this.prevActiveSlideIndex = null;
  2159. this.prevActiveSlide = null;
  2160. var index = isNumber(startAt) ? startAt : this.settings.startAt;
  2161. if (isNode(element)) {
  2162. var gallery = element.getAttribute('data-gallery');
  2163. if (gallery) {
  2164. this.fullElementsList = this.elements;
  2165. this.elements = this.getGalleryElements(this.elements, gallery);
  2166. }
  2167. if (isNil(index)) {
  2168. index = this.getElementIndex(element);
  2169. if (index < 0) {
  2170. index = 0;
  2171. }
  2172. }
  2173. }
  2174. if (!isNumber(index)) {
  2175. index = 0;
  2176. }
  2177. this.build();
  2178. animateElement(this.overlay, this.settings.openEffect === 'none' ? 'none' : this.settings.cssEfects.fade["in"]);
  2179. var body = document.body;
  2180. var scrollBar = window.innerWidth - document.documentElement.clientWidth;
  2181. if (scrollBar > 0) {
  2182. var styleSheet = document.createElement('style');
  2183. styleSheet.type = 'text/css';
  2184. styleSheet.className = 'gcss-styles';
  2185. styleSheet.innerText = ".gscrollbar-fixer {margin-right: ".concat(scrollBar, "px}");
  2186. document.head.appendChild(styleSheet);
  2187. addClass(body, 'gscrollbar-fixer');
  2188. }
  2189. addClass(body, 'glightbox-open');
  2190. addClass(html, 'glightbox-open');
  2191. if (isMobile$1) {
  2192. addClass(document.body, 'glightbox-mobile');
  2193. this.settings.slideEffect = 'slide';
  2194. }
  2195. this.showSlide(index, true);
  2196. if (this.elements.length === 1) {
  2197. addClass(this.prevButton, 'glightbox-button-hidden');
  2198. addClass(this.nextButton, 'glightbox-button-hidden');
  2199. } else {
  2200. removeClass(this.prevButton, 'glightbox-button-hidden');
  2201. removeClass(this.nextButton, 'glightbox-button-hidden');
  2202. }
  2203. this.lightboxOpen = true;
  2204. this.trigger('open');
  2205. if (isFunction(this.settings.onOpen)) {
  2206. this.settings.onOpen();
  2207. }
  2208. if (isTouch$1 && this.settings.touchNavigation) {
  2209. touchNavigation(this);
  2210. }
  2211. if (this.settings.keyboardNavigation) {
  2212. keyboardNavigation(this);
  2213. }
  2214. }
  2215. }, {
  2216. key: "openAt",
  2217. value: function openAt() {
  2218. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  2219. this.open(null, index);
  2220. }
  2221. }, {
  2222. key: "showSlide",
  2223. value: function showSlide() {
  2224. var _this2 = this;
  2225. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  2226. var first = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2227. show(this.loader);
  2228. this.index = parseInt(index);
  2229. var current = this.slidesContainer.querySelector('.current');
  2230. if (current) {
  2231. removeClass(current, 'current');
  2232. }
  2233. this.slideAnimateOut();
  2234. var slideNode = this.slidesContainer.querySelectorAll('.gslide')[index];
  2235. if (hasClass(slideNode, 'loaded')) {
  2236. this.slideAnimateIn(slideNode, first);
  2237. hide(this.loader);
  2238. } else {
  2239. show(this.loader);
  2240. var slide = this.elements[index];
  2241. var slideData = {
  2242. index: this.index,
  2243. slide: slideNode,
  2244. slideNode: slideNode,
  2245. slideConfig: slide.slideConfig,
  2246. slideIndex: this.index,
  2247. trigger: slide.node,
  2248. player: null
  2249. };
  2250. this.trigger('slide_before_load', slideData);
  2251. slide.instance.setContent(slideNode, function () {
  2252. hide(_this2.loader);
  2253. _this2.resize();
  2254. _this2.slideAnimateIn(slideNode, first);
  2255. _this2.trigger('slide_after_load', slideData);
  2256. });
  2257. }
  2258. this.slideDescription = slideNode.querySelector('.gslide-description');
  2259. this.slideDescriptionContained = this.slideDescription && hasClass(this.slideDescription.parentNode, 'gslide-media');
  2260. if (this.settings.preload) {
  2261. this.preloadSlide(index + 1);
  2262. this.preloadSlide(index - 1);
  2263. }
  2264. this.updateNavigationClasses();
  2265. this.activeSlide = slideNode;
  2266. }
  2267. }, {
  2268. key: "preloadSlide",
  2269. value: function preloadSlide(index) {
  2270. var _this3 = this;
  2271. if (index < 0 || index > this.elements.length - 1) {
  2272. return false;
  2273. }
  2274. if (isNil(this.elements[index])) {
  2275. return false;
  2276. }
  2277. var slideNode = this.slidesContainer.querySelectorAll('.gslide')[index];
  2278. if (hasClass(slideNode, 'loaded')) {
  2279. return false;
  2280. }
  2281. var slide = this.elements[index];
  2282. var type = slide.type;
  2283. var slideData = {
  2284. index: index,
  2285. slide: slideNode,
  2286. slideNode: slideNode,
  2287. slideConfig: slide.slideConfig,
  2288. slideIndex: index,
  2289. trigger: slide.node,
  2290. player: null
  2291. };
  2292. this.trigger('slide_before_load', slideData);
  2293. if (type === 'video' || type === 'external') {
  2294. setTimeout(function () {
  2295. slide.instance.setContent(slideNode, function () {
  2296. _this3.trigger('slide_after_load', slideData);
  2297. });
  2298. }, 200);
  2299. } else {
  2300. slide.instance.setContent(slideNode, function () {
  2301. _this3.trigger('slide_after_load', slideData);
  2302. });
  2303. }
  2304. }
  2305. }, {
  2306. key: "prevSlide",
  2307. value: function prevSlide() {
  2308. this.goToSlide(this.index - 1);
  2309. }
  2310. }, {
  2311. key: "nextSlide",
  2312. value: function nextSlide() {
  2313. this.goToSlide(this.index + 1);
  2314. }
  2315. }, {
  2316. key: "goToSlide",
  2317. value: function goToSlide() {
  2318. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  2319. this.prevActiveSlide = this.activeSlide;
  2320. this.prevActiveSlideIndex = this.index;
  2321. if (!this.loop() && (index < 0 || index > this.elements.length - 1)) {
  2322. return false;
  2323. }
  2324. if (index < 0) {
  2325. index = this.elements.length - 1;
  2326. } else if (index >= this.elements.length) {
  2327. index = 0;
  2328. }
  2329. this.showSlide(index);
  2330. }
  2331. }, {
  2332. key: "insertSlide",
  2333. value: function insertSlide() {
  2334. var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  2335. var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
  2336. if (index < 0) {
  2337. index = this.elements.length;
  2338. }
  2339. var slide = new Slide(config, this, index);
  2340. var data = slide.getConfig();
  2341. var slideInfo = extend({}, data);
  2342. var newSlide = slide.create();
  2343. var totalSlides = this.elements.length - 1;
  2344. slideInfo.index = index;
  2345. slideInfo.node = false;
  2346. slideInfo.instance = slide;
  2347. slideInfo.slideConfig = data;
  2348. this.elements.splice(index, 0, slideInfo);
  2349. var addedSlideNode = null;
  2350. var addedSlidePlayer = null;
  2351. if (this.slidesContainer) {
  2352. if (index > totalSlides) {
  2353. this.slidesContainer.appendChild(newSlide);
  2354. } else {
  2355. var existingSlide = this.slidesContainer.querySelectorAll('.gslide')[index];
  2356. this.slidesContainer.insertBefore(newSlide, existingSlide);
  2357. }
  2358. if (this.settings.preload && this.index == 0 && index == 0 || this.index - 1 == index || this.index + 1 == index) {
  2359. this.preloadSlide(index);
  2360. }
  2361. if (this.index === 0 && index === 0) {
  2362. this.index = 1;
  2363. }
  2364. this.updateNavigationClasses();
  2365. addedSlideNode = this.slidesContainer.querySelectorAll('.gslide')[index];
  2366. addedSlidePlayer = this.getSlidePlayerInstance(index);
  2367. slideInfo.slideNode = addedSlideNode;
  2368. }
  2369. this.trigger('slide_inserted', {
  2370. index: index,
  2371. slide: addedSlideNode,
  2372. slideNode: addedSlideNode,
  2373. slideConfig: data,
  2374. slideIndex: index,
  2375. trigger: null,
  2376. player: addedSlidePlayer
  2377. });
  2378. if (isFunction(this.settings.slideInserted)) {
  2379. this.settings.slideInserted({
  2380. index: index,
  2381. slide: addedSlideNode,
  2382. player: addedSlidePlayer
  2383. });
  2384. }
  2385. }
  2386. }, {
  2387. key: "removeSlide",
  2388. value: function removeSlide() {
  2389. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
  2390. if (index < 0 || index > this.elements.length - 1) {
  2391. return false;
  2392. }
  2393. var slide = this.slidesContainer && this.slidesContainer.querySelectorAll('.gslide')[index];
  2394. if (slide) {
  2395. if (this.getActiveSlideIndex() == index) {
  2396. if (index == this.elements.length - 1) {
  2397. this.prevSlide();
  2398. } else {
  2399. this.nextSlide();
  2400. }
  2401. }
  2402. slide.parentNode.removeChild(slide);
  2403. }
  2404. this.elements.splice(index, 1);
  2405. this.trigger('slide_removed', index);
  2406. if (isFunction(this.settings.slideRemoved)) {
  2407. this.settings.slideRemoved(index);
  2408. }
  2409. }
  2410. }, {
  2411. key: "slideAnimateIn",
  2412. value: function slideAnimateIn(slide, first) {
  2413. var _this4 = this;
  2414. var slideMedia = slide.querySelector('.gslide-media');
  2415. var slideDesc = slide.querySelector('.gslide-description');
  2416. var prevData = {
  2417. index: this.prevActiveSlideIndex,
  2418. slide: this.prevActiveSlide,
  2419. slideNode: this.prevActiveSlide,
  2420. slideIndex: this.prevActiveSlide,
  2421. slideConfig: isNil(this.prevActiveSlideIndex) ? null : this.elements[this.prevActiveSlideIndex].slideConfig,
  2422. trigger: isNil(this.prevActiveSlideIndex) ? null : this.elements[this.prevActiveSlideIndex].node,
  2423. player: this.getSlidePlayerInstance(this.prevActiveSlideIndex)
  2424. };
  2425. var nextData = {
  2426. index: this.index,
  2427. slide: this.activeSlide,
  2428. slideNode: this.activeSlide,
  2429. slideConfig: this.elements[this.index].slideConfig,
  2430. slideIndex: this.index,
  2431. trigger: this.elements[this.index].node,
  2432. player: this.getSlidePlayerInstance(this.index)
  2433. };
  2434. if (slideMedia.offsetWidth > 0 && slideDesc) {
  2435. hide(slideDesc);
  2436. slideDesc.style.display = '';
  2437. }
  2438. removeClass(slide, this.effectsClasses);
  2439. if (first) {
  2440. animateElement(slide, this.settings.cssEfects[this.settings.openEffect]["in"], function () {
  2441. if (_this4.settings.autoplayVideos) {
  2442. _this4.slidePlayerPlay(slide);
  2443. }
  2444. _this4.trigger('slide_changed', {
  2445. prev: prevData,
  2446. current: nextData
  2447. });
  2448. if (isFunction(_this4.settings.afterSlideChange)) {
  2449. _this4.settings.afterSlideChange.apply(_this4, [prevData, nextData]);
  2450. }
  2451. });
  2452. } else {
  2453. var effectName = this.settings.slideEffect;
  2454. var animIn = effectName !== 'none' ? this.settings.cssEfects[effectName]["in"] : effectName;
  2455. if (this.prevActiveSlideIndex > this.index) {
  2456. if (this.settings.slideEffect == 'slide') {
  2457. animIn = this.settings.cssEfects.slideBack["in"];
  2458. }
  2459. }
  2460. animateElement(slide, animIn, function () {
  2461. if (_this4.settings.autoplayVideos) {
  2462. _this4.slidePlayerPlay(slide);
  2463. }
  2464. _this4.trigger('slide_changed', {
  2465. prev: prevData,
  2466. current: nextData
  2467. });
  2468. if (isFunction(_this4.settings.afterSlideChange)) {
  2469. _this4.settings.afterSlideChange.apply(_this4, [prevData, nextData]);
  2470. }
  2471. });
  2472. }
  2473. setTimeout(function () {
  2474. _this4.resize(slide);
  2475. }, 100);
  2476. addClass(slide, 'current');
  2477. }
  2478. }, {
  2479. key: "slideAnimateOut",
  2480. value: function slideAnimateOut() {
  2481. if (!this.prevActiveSlide) {
  2482. return false;
  2483. }
  2484. var prevSlide = this.prevActiveSlide;
  2485. removeClass(prevSlide, this.effectsClasses);
  2486. addClass(prevSlide, 'prev');
  2487. var animation = this.settings.slideEffect;
  2488. var animOut = animation !== 'none' ? this.settings.cssEfects[animation].out : animation;
  2489. this.slidePlayerPause(prevSlide);
  2490. this.trigger('slide_before_change', {
  2491. prev: {
  2492. index: this.prevActiveSlideIndex,
  2493. slide: this.prevActiveSlide,
  2494. slideNode: this.prevActiveSlide,
  2495. slideIndex: this.prevActiveSlideIndex,
  2496. slideConfig: isNil(this.prevActiveSlideIndex) ? null : this.elements[this.prevActiveSlideIndex].slideConfig,
  2497. trigger: isNil(this.prevActiveSlideIndex) ? null : this.elements[this.prevActiveSlideIndex].node,
  2498. player: this.getSlidePlayerInstance(this.prevActiveSlideIndex)
  2499. },
  2500. current: {
  2501. index: this.index,
  2502. slide: this.activeSlide,
  2503. slideNode: this.activeSlide,
  2504. slideIndex: this.index,
  2505. slideConfig: this.elements[this.index].slideConfig,
  2506. trigger: this.elements[this.index].node,
  2507. player: this.getSlidePlayerInstance(this.index)
  2508. }
  2509. });
  2510. if (isFunction(this.settings.beforeSlideChange)) {
  2511. this.settings.beforeSlideChange.apply(this, [{
  2512. index: this.prevActiveSlideIndex,
  2513. slide: this.prevActiveSlide,
  2514. player: this.getSlidePlayerInstance(this.prevActiveSlideIndex)
  2515. }, {
  2516. index: this.index,
  2517. slide: this.activeSlide,
  2518. player: this.getSlidePlayerInstance(this.index)
  2519. }]);
  2520. }
  2521. if (this.prevActiveSlideIndex > this.index && this.settings.slideEffect == 'slide') {
  2522. animOut = this.settings.cssEfects.slideBack.out;
  2523. }
  2524. animateElement(prevSlide, animOut, function () {
  2525. var container = prevSlide.querySelector('.ginner-container');
  2526. var media = prevSlide.querySelector('.gslide-media');
  2527. var desc = prevSlide.querySelector('.gslide-description');
  2528. container.style.transform = '';
  2529. media.style.transform = '';
  2530. removeClass(media, 'greset');
  2531. media.style.opacity = '';
  2532. if (desc) {
  2533. desc.style.opacity = '';
  2534. }
  2535. removeClass(prevSlide, 'prev');
  2536. });
  2537. }
  2538. }, {
  2539. key: "getAllPlayers",
  2540. value: function getAllPlayers() {
  2541. return this.videoPlayers;
  2542. }
  2543. }, {
  2544. key: "getSlidePlayerInstance",
  2545. value: function getSlidePlayerInstance(index) {
  2546. var id = 'gvideo' + index;
  2547. var videoPlayers = this.getAllPlayers();
  2548. if (has(videoPlayers, id) && videoPlayers[id]) {
  2549. return videoPlayers[id];
  2550. }
  2551. return false;
  2552. }
  2553. }, {
  2554. key: "stopSlideVideo",
  2555. value: function stopSlideVideo(slide) {
  2556. if (isNode(slide)) {
  2557. var node = slide.querySelector('.gvideo-wrapper');
  2558. if (node) {
  2559. slide = node.getAttribute('data-index');
  2560. }
  2561. }
  2562. console.log('stopSlideVideo is deprecated, use slidePlayerPause');
  2563. var player = this.getSlidePlayerInstance(slide);
  2564. if (player && player.playing) {
  2565. player.pause();
  2566. }
  2567. }
  2568. }, {
  2569. key: "slidePlayerPause",
  2570. value: function slidePlayerPause(slide) {
  2571. if (isNode(slide)) {
  2572. var node = slide.querySelector('.gvideo-wrapper');
  2573. if (node) {
  2574. slide = node.getAttribute('data-index');
  2575. }
  2576. }
  2577. var player = this.getSlidePlayerInstance(slide);
  2578. if (player && player.playing) {
  2579. player.pause();
  2580. }
  2581. }
  2582. }, {
  2583. key: "playSlideVideo",
  2584. value: function playSlideVideo(slide) {
  2585. if (isNode(slide)) {
  2586. var node = slide.querySelector('.gvideo-wrapper');
  2587. if (node) {
  2588. slide = node.getAttribute('data-index');
  2589. }
  2590. }
  2591. console.log('playSlideVideo is deprecated, use slidePlayerPlay');
  2592. var player = this.getSlidePlayerInstance(slide);
  2593. if (player && !player.playing) {
  2594. player.play();
  2595. }
  2596. }
  2597. }, {
  2598. key: "slidePlayerPlay",
  2599. value: function slidePlayerPlay(slide) {
  2600. var _this$settings$plyr$c;
  2601. if (isMobile$1 && !((_this$settings$plyr$c = this.settings.plyr.config) !== null && _this$settings$plyr$c !== void 0 && _this$settings$plyr$c.muted)) {
  2602. return;
  2603. }
  2604. if (isNode(slide)) {
  2605. var node = slide.querySelector('.gvideo-wrapper');
  2606. if (node) {
  2607. slide = node.getAttribute('data-index');
  2608. }
  2609. }
  2610. var player = this.getSlidePlayerInstance(slide);
  2611. if (player && !player.playing) {
  2612. player.play();
  2613. if (this.settings.autofocusVideos) {
  2614. player.elements.container.focus();
  2615. }
  2616. }
  2617. }
  2618. }, {
  2619. key: "setElements",
  2620. value: function setElements(elements) {
  2621. var _this5 = this;
  2622. this.settings.elements = false;
  2623. var newElements = [];
  2624. if (elements && elements.length) {
  2625. each(elements, function (el, i) {
  2626. var slide = new Slide(el, _this5, i);
  2627. var data = slide.getConfig();
  2628. var slideInfo = extend({}, data);
  2629. slideInfo.slideConfig = data;
  2630. slideInfo.instance = slide;
  2631. slideInfo.index = i;
  2632. newElements.push(slideInfo);
  2633. });
  2634. }
  2635. this.elements = newElements;
  2636. if (this.lightboxOpen) {
  2637. this.slidesContainer.innerHTML = '';
  2638. if (this.elements.length) {
  2639. each(this.elements, function () {
  2640. var slide = createHTML(_this5.settings.slideHTML);
  2641. _this5.slidesContainer.appendChild(slide);
  2642. });
  2643. this.showSlide(0, true);
  2644. }
  2645. }
  2646. }
  2647. }, {
  2648. key: "getElementIndex",
  2649. value: function getElementIndex(node) {
  2650. var index = false;
  2651. each(this.elements, function (el, i) {
  2652. if (has(el, 'node') && el.node == node) {
  2653. index = i;
  2654. return true;
  2655. }
  2656. });
  2657. return index;
  2658. }
  2659. }, {
  2660. key: "getElements",
  2661. value: function getElements() {
  2662. var _this6 = this;
  2663. var list = [];
  2664. this.elements = this.elements ? this.elements : [];
  2665. if (!isNil(this.settings.elements) && isArray(this.settings.elements) && this.settings.elements.length) {
  2666. each(this.settings.elements, function (el, i) {
  2667. var slide = new Slide(el, _this6, i);
  2668. var elData = slide.getConfig();
  2669. var slideInfo = extend({}, elData);
  2670. slideInfo.node = false;
  2671. slideInfo.index = i;
  2672. slideInfo.instance = slide;
  2673. slideInfo.slideConfig = elData;
  2674. list.push(slideInfo);
  2675. });
  2676. }
  2677. var nodes = false;
  2678. var selector = this.getSelector();
  2679. if (selector) {
  2680. nodes = document.querySelectorAll(this.getSelector());
  2681. }
  2682. if (!nodes) {
  2683. return list;
  2684. }
  2685. each(nodes, function (el, i) {
  2686. var slide = new Slide(el, _this6, i);
  2687. var elData = slide.getConfig();
  2688. var slideInfo = extend({}, elData);
  2689. slideInfo.node = el;
  2690. slideInfo.index = i;
  2691. slideInfo.instance = slide;
  2692. slideInfo.slideConfig = elData;
  2693. slideInfo.gallery = el.getAttribute('data-gallery');
  2694. list.push(slideInfo);
  2695. });
  2696. return list;
  2697. }
  2698. }, {
  2699. key: "getGalleryElements",
  2700. value: function getGalleryElements(list, gallery) {
  2701. return list.filter(function (el) {
  2702. return el.gallery == gallery;
  2703. });
  2704. }
  2705. }, {
  2706. key: "getSelector",
  2707. value: function getSelector() {
  2708. if (this.settings.elements) {
  2709. return false;
  2710. }
  2711. if (this.settings.selector && this.settings.selector.substring(0, 5) == 'data-') {
  2712. return "*[".concat(this.settings.selector, "]");
  2713. }
  2714. return this.settings.selector;
  2715. }
  2716. }, {
  2717. key: "getActiveSlide",
  2718. value: function getActiveSlide() {
  2719. return this.slidesContainer.querySelectorAll('.gslide')[this.index];
  2720. }
  2721. }, {
  2722. key: "getActiveSlideIndex",
  2723. value: function getActiveSlideIndex() {
  2724. return this.index;
  2725. }
  2726. }, {
  2727. key: "getAnimationClasses",
  2728. value: function getAnimationClasses() {
  2729. var effects = [];
  2730. for (var key in this.settings.cssEfects) {
  2731. if (this.settings.cssEfects.hasOwnProperty(key)) {
  2732. var effect = this.settings.cssEfects[key];
  2733. effects.push("g".concat(effect["in"]));
  2734. effects.push("g".concat(effect.out));
  2735. }
  2736. }
  2737. return effects.join(' ');
  2738. }
  2739. }, {
  2740. key: "build",
  2741. value: function build() {
  2742. var _this7 = this;
  2743. if (this.built) {
  2744. return false;
  2745. }
  2746. var children = document.body.childNodes;
  2747. var bodyChildElms = [];
  2748. each(children, function (el) {
  2749. if (el.parentNode == document.body && el.nodeName.charAt(0) !== '#' && el.hasAttribute && !el.hasAttribute('aria-hidden')) {
  2750. bodyChildElms.push(el);
  2751. el.setAttribute('aria-hidden', 'true');
  2752. }
  2753. });
  2754. var nextSVG = has(this.settings.svg, 'next') ? this.settings.svg.next : '';
  2755. var prevSVG = has(this.settings.svg, 'prev') ? this.settings.svg.prev : '';
  2756. var closeSVG = has(this.settings.svg, 'close') ? this.settings.svg.close : '';
  2757. var lightboxHTML = this.settings.lightboxHTML;
  2758. lightboxHTML = lightboxHTML.replace(/{nextSVG}/g, nextSVG);
  2759. lightboxHTML = lightboxHTML.replace(/{prevSVG}/g, prevSVG);
  2760. lightboxHTML = lightboxHTML.replace(/{closeSVG}/g, closeSVG);
  2761. lightboxHTML = createHTML(lightboxHTML);
  2762. document.body.appendChild(lightboxHTML);
  2763. var modal = document.getElementById('glightbox-body');
  2764. this.modal = modal;
  2765. var closeButton = modal.querySelector('.gclose');
  2766. this.prevButton = modal.querySelector('.gprev');
  2767. this.nextButton = modal.querySelector('.gnext');
  2768. this.overlay = modal.querySelector('.goverlay');
  2769. this.loader = modal.querySelector('.gloader');
  2770. this.slidesContainer = document.getElementById('glightbox-slider');
  2771. this.bodyHiddenChildElms = bodyChildElms;
  2772. this.events = {};
  2773. addClass(this.modal, 'glightbox-' + this.settings.skin);
  2774. if (this.settings.closeButton && closeButton) {
  2775. this.events['close'] = addEvent('click', {
  2776. onElement: closeButton,
  2777. withCallback: function withCallback(e, target) {
  2778. e.preventDefault();
  2779. _this7.close();
  2780. }
  2781. });
  2782. }
  2783. if (closeButton && !this.settings.closeButton) {
  2784. closeButton.parentNode.removeChild(closeButton);
  2785. }
  2786. if (this.nextButton) {
  2787. this.events['next'] = addEvent('click', {
  2788. onElement: this.nextButton,
  2789. withCallback: function withCallback(e, target) {
  2790. e.preventDefault();
  2791. _this7.nextSlide();
  2792. }
  2793. });
  2794. }
  2795. if (this.prevButton) {
  2796. this.events['prev'] = addEvent('click', {
  2797. onElement: this.prevButton,
  2798. withCallback: function withCallback(e, target) {
  2799. e.preventDefault();
  2800. _this7.prevSlide();
  2801. }
  2802. });
  2803. }
  2804. if (this.settings.closeOnOutsideClick) {
  2805. this.events['outClose'] = addEvent('click', {
  2806. onElement: modal,
  2807. withCallback: function withCallback(e, target) {
  2808. if (!_this7.preventOutsideClick && !hasClass(document.body, 'glightbox-mobile') && !closest(e.target, '.ginner-container')) {
  2809. if (!closest(e.target, '.gbtn') && !hasClass(e.target, 'gnext') && !hasClass(e.target, 'gprev')) {
  2810. _this7.close();
  2811. }
  2812. }
  2813. }
  2814. });
  2815. }
  2816. each(this.elements, function (slide, i) {
  2817. _this7.slidesContainer.appendChild(slide.instance.create());
  2818. slide.slideNode = _this7.slidesContainer.querySelectorAll('.gslide')[i];
  2819. });
  2820. if (isTouch$1) {
  2821. addClass(document.body, 'glightbox-touch');
  2822. }
  2823. this.events['resize'] = addEvent('resize', {
  2824. onElement: window,
  2825. withCallback: function withCallback() {
  2826. _this7.resize();
  2827. }
  2828. });
  2829. this.built = true;
  2830. }
  2831. }, {
  2832. key: "resize",
  2833. value: function resize() {
  2834. var slide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  2835. slide = !slide ? this.activeSlide : slide;
  2836. if (!slide || hasClass(slide, 'zoomed')) {
  2837. return;
  2838. }
  2839. var winSize = windowSize();
  2840. var video = slide.querySelector('.gvideo-wrapper');
  2841. var image = slide.querySelector('.gslide-image');
  2842. var description = this.slideDescription;
  2843. var winWidth = winSize.width;
  2844. var winHeight = winSize.height;
  2845. if (winWidth <= 768) {
  2846. addClass(document.body, 'glightbox-mobile');
  2847. } else {
  2848. removeClass(document.body, 'glightbox-mobile');
  2849. }
  2850. if (!video && !image) {
  2851. return;
  2852. }
  2853. var descriptionResize = false;
  2854. if (description && (hasClass(description, 'description-bottom') || hasClass(description, 'description-top')) && !hasClass(description, 'gabsolute')) {
  2855. descriptionResize = true;
  2856. }
  2857. if (image) {
  2858. if (winWidth <= 768) {
  2859. var imgNode = image.querySelector('img');
  2860. } else if (descriptionResize) {
  2861. var _slideTriggerNode$get;
  2862. var descHeight = description.offsetHeight;
  2863. var _imgNode = image.querySelector('img');
  2864. var slideTriggerNode = this.elements[this.index].node;
  2865. var maxHeightValue = (_slideTriggerNode$get = slideTriggerNode.getAttribute('data-height')) !== null && _slideTriggerNode$get !== void 0 ? _slideTriggerNode$get : '100vh';
  2866. _imgNode.setAttribute('style', "max-height: calc(".concat(maxHeightValue, " - ").concat(descHeight, "px)"));
  2867. description.setAttribute('style', "max-width: ".concat(_imgNode.offsetWidth, "px;"));
  2868. }
  2869. }
  2870. if (video) {
  2871. var ratio = has(this.settings.plyr.config, 'ratio') ? this.settings.plyr.config.ratio : '';
  2872. if (!ratio) {
  2873. var containerWidth = video.clientWidth;
  2874. var containerHeight = video.clientHeight;
  2875. var divisor = containerWidth / containerHeight;
  2876. ratio = "".concat(containerWidth / divisor, ":").concat(containerHeight / divisor);
  2877. }
  2878. var videoRatio = ratio.split(':');
  2879. var videoWidth = this.settings.videosWidth;
  2880. var maxWidth = this.settings.videosWidth;
  2881. if (isNumber(videoWidth) || videoWidth.indexOf('px') !== -1) {
  2882. maxWidth = parseInt(videoWidth);
  2883. } else {
  2884. if (videoWidth.indexOf('vw') !== -1) {
  2885. maxWidth = winWidth * parseInt(videoWidth) / 100;
  2886. } else if (videoWidth.indexOf('vh') !== -1) {
  2887. maxWidth = winHeight * parseInt(videoWidth) / 100;
  2888. } else if (videoWidth.indexOf('%') !== -1) {
  2889. maxWidth = winWidth * parseInt(videoWidth) / 100;
  2890. } else {
  2891. maxWidth = parseInt(video.clientWidth);
  2892. }
  2893. }
  2894. var maxHeight = maxWidth / (parseInt(videoRatio[0]) / parseInt(videoRatio[1]));
  2895. maxHeight = Math.floor(maxHeight);
  2896. if (descriptionResize) {
  2897. winHeight = winHeight - description.offsetHeight;
  2898. }
  2899. if (maxWidth > winWidth || maxHeight > winHeight || winHeight < maxHeight && winWidth > maxWidth) {
  2900. var vwidth = video.offsetWidth;
  2901. var vheight = video.offsetHeight;
  2902. var _ratio = winHeight / vheight;
  2903. var vsize = {
  2904. width: vwidth * _ratio,
  2905. height: vheight * _ratio
  2906. };
  2907. video.parentNode.setAttribute('style', "max-width: ".concat(vsize.width, "px"));
  2908. if (descriptionResize) {
  2909. description.setAttribute('style', "max-width: ".concat(vsize.width, "px;"));
  2910. }
  2911. } else {
  2912. video.parentNode.style.maxWidth = "".concat(videoWidth);
  2913. if (descriptionResize) {
  2914. description.setAttribute('style', "max-width: ".concat(videoWidth, ";"));
  2915. }
  2916. }
  2917. }
  2918. }
  2919. }, {
  2920. key: "reload",
  2921. value: function reload() {
  2922. this.init();
  2923. }
  2924. }, {
  2925. key: "updateNavigationClasses",
  2926. value: function updateNavigationClasses() {
  2927. var loop = this.loop();
  2928. removeClass(this.nextButton, 'disabled');
  2929. removeClass(this.prevButton, 'disabled');
  2930. if (this.index == 0 && this.elements.length - 1 == 0) {
  2931. addClass(this.prevButton, 'disabled');
  2932. addClass(this.nextButton, 'disabled');
  2933. } else if (this.index === 0 && !loop) {
  2934. addClass(this.prevButton, 'disabled');
  2935. } else if (this.index === this.elements.length - 1 && !loop) {
  2936. addClass(this.nextButton, 'disabled');
  2937. }
  2938. }
  2939. }, {
  2940. key: "loop",
  2941. value: function loop() {
  2942. var loop = has(this.settings, 'loopAtEnd') ? this.settings.loopAtEnd : null;
  2943. loop = has(this.settings, 'loop') ? this.settings.loop : loop;
  2944. return loop;
  2945. }
  2946. }, {
  2947. key: "close",
  2948. value: function close() {
  2949. var _this8 = this;
  2950. if (!this.lightboxOpen) {
  2951. if (this.events) {
  2952. for (var key in this.events) {
  2953. if (this.events.hasOwnProperty(key)) {
  2954. this.events[key].destroy();
  2955. }
  2956. }
  2957. this.events = null;
  2958. }
  2959. return false;
  2960. }
  2961. if (this.closing) {
  2962. return false;
  2963. }
  2964. this.closing = true;
  2965. this.slidePlayerPause(this.activeSlide);
  2966. if (this.fullElementsList) {
  2967. this.elements = this.fullElementsList;
  2968. }
  2969. if (this.bodyHiddenChildElms.length) {
  2970. each(this.bodyHiddenChildElms, function (el) {
  2971. el.removeAttribute('aria-hidden');
  2972. });
  2973. }
  2974. addClass(this.modal, 'glightbox-closing');
  2975. animateElement(this.overlay, this.settings.openEffect == 'none' ? 'none' : this.settings.cssEfects.fade.out);
  2976. animateElement(this.activeSlide, this.settings.cssEfects[this.settings.closeEffect].out, function () {
  2977. _this8.activeSlide = null;
  2978. _this8.prevActiveSlideIndex = null;
  2979. _this8.prevActiveSlide = null;
  2980. _this8.built = false;
  2981. if (_this8.events) {
  2982. for (var _key in _this8.events) {
  2983. if (_this8.events.hasOwnProperty(_key)) {
  2984. _this8.events[_key].destroy();
  2985. }
  2986. }
  2987. _this8.events = null;
  2988. }
  2989. var body = document.body;
  2990. removeClass(html, 'glightbox-open');
  2991. removeClass(body, 'glightbox-open touching gdesc-open glightbox-touch glightbox-mobile gscrollbar-fixer');
  2992. _this8.modal.parentNode.removeChild(_this8.modal);
  2993. _this8.trigger('close');
  2994. if (isFunction(_this8.settings.onClose)) {
  2995. _this8.settings.onClose();
  2996. }
  2997. var styles = document.querySelector('.gcss-styles');
  2998. if (styles) {
  2999. styles.parentNode.removeChild(styles);
  3000. }
  3001. _this8.lightboxOpen = false;
  3002. _this8.closing = null;
  3003. });
  3004. }
  3005. }, {
  3006. key: "destroy",
  3007. value: function destroy() {
  3008. this.close();
  3009. this.clearAllEvents();
  3010. if (this.baseEvents) {
  3011. this.baseEvents.destroy();
  3012. }
  3013. }
  3014. }, {
  3015. key: "on",
  3016. value: function on(evt, callback) {
  3017. var once = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  3018. if (!evt || !isFunction(callback)) {
  3019. throw new TypeError('Event name and callback must be defined');
  3020. }
  3021. this.apiEvents.push({
  3022. evt: evt,
  3023. once: once,
  3024. callback: callback
  3025. });
  3026. }
  3027. }, {
  3028. key: "once",
  3029. value: function once(evt, callback) {
  3030. this.on(evt, callback, true);
  3031. }
  3032. }, {
  3033. key: "trigger",
  3034. value: function trigger(eventName) {
  3035. var _this9 = this;
  3036. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  3037. var onceTriggered = [];
  3038. each(this.apiEvents, function (event, i) {
  3039. var evt = event.evt,
  3040. once = event.once,
  3041. callback = event.callback;
  3042. if (evt == eventName) {
  3043. callback(data);
  3044. if (once) {
  3045. onceTriggered.push(i);
  3046. }
  3047. }
  3048. });
  3049. if (onceTriggered.length) {
  3050. each(onceTriggered, function (i) {
  3051. return _this9.apiEvents.splice(i, 1);
  3052. });
  3053. }
  3054. }
  3055. }, {
  3056. key: "clearAllEvents",
  3057. value: function clearAllEvents() {
  3058. this.apiEvents.splice(0, this.apiEvents.length);
  3059. }
  3060. }, {
  3061. key: "version",
  3062. value: function version() {
  3063. return _version;
  3064. }
  3065. }]);
  3066. }();
  3067. function glightbox () {
  3068. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  3069. var instance = new GlightboxInit(options);
  3070. instance.init();
  3071. return instance;
  3072. }
  3073. return glightbox;
  3074. })));