云致官网

glightbox.js 108KB

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