glightbox.js 107 KB

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