viewer.js 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601
  1. /*!
  2. * Viewer.js v1.10.2
  3. * https://fengyuanchen.github.io/viewerjs
  4. *
  5. * Copyright 2015-present Chen Fengyuan
  6. * Released under the MIT license
  7. *
  8. * Date: 2021-10-22T13:59:51.046Z
  9. */
  10. (function (global, factory) {
  11. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  12. typeof define === 'function' && define.amd ? define(factory) :
  13. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Viewer = factory());
  14. })(this, (function () {
  15. 'use strict';
  16. function ownKeys(object, enumerableOnly) {
  17. var keys = Object.keys(object);
  18. if (Object.getOwnPropertySymbols) {
  19. var symbols = Object.getOwnPropertySymbols(object);
  20. if (enumerableOnly) {
  21. symbols = symbols.filter(function (sym) {
  22. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  23. });
  24. }
  25. keys.push.apply(keys, symbols);
  26. }
  27. return keys;
  28. }
  29. function _objectSpread2(target) {
  30. for (var i = 1; i < arguments.length; i++) {
  31. var source = arguments[i] != null ? arguments[i] : {};
  32. if (i % 2) {
  33. ownKeys(Object(source), true).forEach(function (key) {
  34. _defineProperty(target, key, source[key]);
  35. });
  36. } else if (Object.getOwnPropertyDescriptors) {
  37. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  38. } else {
  39. ownKeys(Object(source)).forEach(function (key) {
  40. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  41. });
  42. }
  43. }
  44. return target;
  45. }
  46. function _typeof(obj) {
  47. "@babel/helpers - typeof";
  48. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  49. _typeof = function (obj) {
  50. return typeof obj;
  51. };
  52. } else {
  53. _typeof = function (obj) {
  54. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  55. };
  56. }
  57. return _typeof(obj);
  58. }
  59. function _classCallCheck(instance, Constructor) {
  60. if (!(instance instanceof Constructor)) {
  61. throw new TypeError("Cannot call a class as a function");
  62. }
  63. }
  64. function _defineProperties(target, props) {
  65. for (var i = 0; i < props.length; i++) {
  66. var descriptor = props[i];
  67. descriptor.enumerable = descriptor.enumerable || false;
  68. descriptor.configurable = true;
  69. if ("value" in descriptor) descriptor.writable = true;
  70. Object.defineProperty(target, descriptor.key, descriptor);
  71. }
  72. }
  73. function _createClass(Constructor, protoProps, staticProps) {
  74. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  75. if (staticProps) _defineProperties(Constructor, staticProps);
  76. return Constructor;
  77. }
  78. function _defineProperty(obj, key, value) {
  79. if (key in obj) {
  80. Object.defineProperty(obj, key, {
  81. value: value,
  82. enumerable: true,
  83. configurable: true,
  84. writable: true
  85. });
  86. } else {
  87. obj[key] = value;
  88. }
  89. return obj;
  90. }
  91. var DEFAULTS = {
  92. /**
  93. * Enable a modal backdrop, specify `static` for a backdrop
  94. * which doesn't close the modal on click.
  95. * @type {boolean}
  96. */
  97. backdrop: true,
  98. /**
  99. * Show the button on the top-right of the viewer.
  100. * @type {boolean}
  101. */
  102. button: true,
  103. /**
  104. * Show the navbar.
  105. * @type {boolean | number}
  106. */
  107. navbar: true,
  108. /**
  109. * Specify the visibility and the content of the title.
  110. * @type {boolean | number | Function | Array}
  111. */
  112. title: true,
  113. /**
  114. * Show the toolbar.
  115. * @type {boolean | number | Object}
  116. */
  117. toolbar: true,
  118. /**
  119. * Custom class name(s) to add to the viewer's root element.
  120. * @type {string}
  121. */
  122. className: '',
  123. /**
  124. * Define where to put the viewer in modal mode.
  125. * @type {string | Element}
  126. */
  127. container: 'body',
  128. /**
  129. * Filter the images for viewing. Return true if the image is viewable.
  130. * @type {Function}
  131. */
  132. filter: null,
  133. /**
  134. * Enable to request fullscreen when play.
  135. * {@link https://developer.mozilla.org/en-US/docs/Web/API/FullscreenOptions}
  136. * @type {boolean|FullscreenOptions}
  137. */
  138. fullscreen: true,
  139. /**
  140. * Define the extra attributes to inherit from the original image.
  141. * @type {Array}
  142. */
  143. inheritedAttributes: ['crossOrigin', 'decoding', 'isMap', 'loading', 'referrerPolicy', 'sizes', 'srcset', 'useMap'],
  144. /**
  145. * Define the initial index of image for viewing.
  146. * @type {number}
  147. */
  148. initialViewIndex: 0,
  149. /**
  150. * Enable inline mode.
  151. * @type {boolean}
  152. */
  153. inline: false,
  154. /**
  155. * The amount of time to delay between automatically cycling an image when playing.
  156. * @type {number}
  157. */
  158. interval: 5000,
  159. /**
  160. * Enable keyboard support.
  161. * @type {boolean}
  162. */
  163. keyboard: true,
  164. /**
  165. * Focus the viewer when initialized.
  166. * @type {boolean}
  167. */
  168. focus: true,
  169. /**
  170. * Indicate if show a loading spinner when load image or not.
  171. * @type {boolean}
  172. */
  173. loading: true,
  174. /**
  175. * Indicate if enable loop viewing or not.
  176. * @type {boolean}
  177. */
  178. loop: true,
  179. /**
  180. * Min width of the viewer in inline mode.
  181. * @type {number}
  182. */
  183. minWidth: 200,
  184. /**
  185. * Min height of the viewer in inline mode.
  186. * @type {number}
  187. */
  188. minHeight: 100,
  189. /**
  190. * Enable to move the image.
  191. * @type {boolean}
  192. */
  193. movable: true,
  194. /**
  195. * Enable to rotate the image.
  196. * @type {boolean}
  197. */
  198. rotatable: true,
  199. /**
  200. * Enable to scale the image.
  201. * @type {boolean}
  202. */
  203. scalable: true,
  204. /**
  205. * Enable to zoom the image.
  206. * @type {boolean}
  207. */
  208. zoomable: true,
  209. /**
  210. * Enable to zoom the current image by dragging on the touch screen.
  211. * @type {boolean}
  212. */
  213. zoomOnTouch: true,
  214. /**
  215. * Enable to zoom the image by wheeling mouse.
  216. * @type {boolean}
  217. */
  218. zoomOnWheel: true,
  219. /**
  220. * Enable to slide to the next or previous image by swiping on the touch screen.
  221. * @type {boolean}
  222. */
  223. slideOnTouch: true,
  224. /**
  225. * Indicate if toggle the image size between its natural size
  226. * and initial size when double click on the image or not.
  227. * @type {boolean}
  228. */
  229. toggleOnDblclick: true,
  230. /**
  231. * Show the tooltip with image ratio (percentage) when zoom in or zoom out.
  232. * @type {boolean}
  233. */
  234. tooltip: true,
  235. /**
  236. * Enable CSS3 Transition for some special elements.
  237. * @type {boolean}
  238. */
  239. transition: true,
  240. /**
  241. * Define the CSS `z-index` value of viewer in modal mode.
  242. * @type {number}
  243. */
  244. zIndex: 2015,
  245. /**
  246. * Define the CSS `z-index` value of viewer in inline mode.
  247. * @type {number}
  248. */
  249. zIndexInline: 0,
  250. /**
  251. * Define the ratio when zoom the image by wheeling mouse.
  252. * @type {number}
  253. */
  254. zoomRatio: 0.1,
  255. /**
  256. * Define the min ratio of the image when zoom out.
  257. * @type {number}
  258. */
  259. minZoomRatio: 0.01,
  260. /**
  261. * Define the max ratio of the image when zoom in.
  262. * @type {number}
  263. */
  264. maxZoomRatio: 100,
  265. /**
  266. * Define where to get the original image URL for viewing.
  267. * @type {string | Function}
  268. */
  269. url: 'src',
  270. /**
  271. * Event shortcuts.
  272. * @type {Function}
  273. */
  274. ready: null,
  275. show: null,
  276. shown: null,
  277. hide: null,
  278. hidden: null,
  279. view: null,
  280. viewed: null,
  281. move: null,
  282. moved: null,
  283. rotate: null,
  284. rotated: null,
  285. scale: null,
  286. scaled: null,
  287. zoom: null,
  288. zoomed: null,
  289. play: null,
  290. stop: null
  291. };
  292. var TEMPLATE = '<div class="viewer-container" tabindex="-1" touch-action="none">' + '<div class="viewer-canvas"></div>' + '<div class="viewer-footer">' + '<div class="viewer-title"></div>' + '<div class="viewer-toolbar"></div>' + '<div class="viewer-navbar">' + '<ul class="viewer-list" role="navigation"></ul>' + '</div>' + '</div>' + '<div class="viewer-tooltip" role="alert" aria-hidden="true"></div>' + '<div class="viewer-button" data-viewer-action="mix" role="button"></div>' + '<div class="viewer-player"></div>' + '</div>';
  293. var IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
  294. var WINDOW = IS_BROWSER ? window : {};
  295. var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW.document.documentElement ? 'ontouchstart' in WINDOW.document.documentElement : false;
  296. var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false;
  297. var NAMESPACE = 'viewer'; // Actions
  298. var ACTION_MOVE = 'move';
  299. var ACTION_SWITCH = 'switch';
  300. var ACTION_ZOOM = 'zoom'; // Classes
  301. var CLASS_ACTIVE = "".concat(NAMESPACE, "-active");
  302. var CLASS_CLOSE = "".concat(NAMESPACE, "-close");
  303. var CLASS_FADE = "".concat(NAMESPACE, "-fade");
  304. var CLASS_FIXED = "".concat(NAMESPACE, "-fixed");
  305. var CLASS_FULLSCREEN = "".concat(NAMESPACE, "-fullscreen");
  306. var CLASS_FULLSCREEN_EXIT = "".concat(NAMESPACE, "-fullscreen-exit");
  307. var CLASS_HIDE = "".concat(NAMESPACE, "-hide");
  308. var CLASS_HIDE_MD_DOWN = "".concat(NAMESPACE, "-hide-md-down");
  309. var CLASS_HIDE_SM_DOWN = "".concat(NAMESPACE, "-hide-sm-down");
  310. var CLASS_HIDE_XS_DOWN = "".concat(NAMESPACE, "-hide-xs-down");
  311. var CLASS_IN = "".concat(NAMESPACE, "-in");
  312. var CLASS_INVISIBLE = "".concat(NAMESPACE, "-invisible");
  313. var CLASS_LOADING = "".concat(NAMESPACE, "-loading");
  314. var CLASS_MOVE = "".concat(NAMESPACE, "-move");
  315. var CLASS_OPEN = "".concat(NAMESPACE, "-open");
  316. var CLASS_SHOW = "".concat(NAMESPACE, "-show");
  317. var CLASS_TRANSITION = "".concat(NAMESPACE, "-transition"); // Native events
  318. var EVENT_CLICK = 'click';
  319. var EVENT_DBLCLICK = 'dblclick';
  320. var EVENT_DRAG_START = 'dragstart';
  321. var EVENT_FOCUSIN = 'focusin';
  322. var EVENT_KEY_DOWN = 'keydown';
  323. var EVENT_LOAD = 'load';
  324. var EVENT_ERROR = 'error';
  325. var EVENT_TOUCH_END = IS_TOUCH_DEVICE ? 'touchend touchcancel' : 'mouseup';
  326. var EVENT_TOUCH_MOVE = IS_TOUCH_DEVICE ? 'touchmove' : 'mousemove';
  327. var EVENT_TOUCH_START = IS_TOUCH_DEVICE ? 'touchstart' : 'mousedown';
  328. var EVENT_POINTER_DOWN = HAS_POINTER_EVENT ? 'pointerdown' : EVENT_TOUCH_START;
  329. var EVENT_POINTER_MOVE = HAS_POINTER_EVENT ? 'pointermove' : EVENT_TOUCH_MOVE;
  330. var EVENT_POINTER_UP = HAS_POINTER_EVENT ? 'pointerup pointercancel' : EVENT_TOUCH_END;
  331. var EVENT_RESIZE = 'resize';
  332. var EVENT_TRANSITION_END = 'transitionend';
  333. var EVENT_WHEEL = 'wheel'; // Custom events
  334. var EVENT_READY = 'ready';
  335. var EVENT_SHOW = 'show';
  336. var EVENT_SHOWN = 'shown';
  337. var EVENT_HIDE = 'hide';
  338. var EVENT_HIDDEN = 'hidden';
  339. var EVENT_VIEW = 'view';
  340. var EVENT_VIEWED = 'viewed';
  341. var EVENT_MOVE = 'move';
  342. var EVENT_MOVED = 'moved';
  343. var EVENT_ROTATE = 'rotate';
  344. var EVENT_ROTATED = 'rotated';
  345. var EVENT_SCALE = 'scale';
  346. var EVENT_SCALED = 'scaled';
  347. var EVENT_ZOOM = 'zoom';
  348. var EVENT_ZOOMED = 'zoomed';
  349. var EVENT_PLAY = 'play';
  350. var EVENT_STOP = 'stop'; // Data keys
  351. var DATA_ACTION = "".concat(NAMESPACE, "Action"); // RegExps
  352. var REGEXP_SPACES = /\s\s*/; // Misc
  353. var BUTTONS = ['zoom-in', 'zoom-out', 'one-to-one', 'reset', 'prev', 'play', 'next', 'rotate-left', 'rotate-right', 'flip-horizontal', 'flip-vertical'];
  354. /**
  355. * Check if the given value is a string.
  356. * @param {*} value - The value to check.
  357. * @returns {boolean} Returns `true` if the given value is a string, else `false`.
  358. */
  359. function isString(value) {
  360. return typeof value === 'string';
  361. }
  362. /**
  363. * Check if the given value is not a number.
  364. */
  365. var isNaN = Number.isNaN || WINDOW.isNaN;
  366. /**
  367. * Check if the given value is a number.
  368. * @param {*} value - The value to check.
  369. * @returns {boolean} Returns `true` if the given value is a number, else `false`.
  370. */
  371. function isNumber(value) {
  372. return typeof value === 'number' && !isNaN(value);
  373. }
  374. /**
  375. * Check if the given value is undefined.
  376. * @param {*} value - The value to check.
  377. * @returns {boolean} Returns `true` if the given value is undefined, else `false`.
  378. */
  379. function isUndefined(value) {
  380. return typeof value === 'undefined';
  381. }
  382. /**
  383. * Check if the given value is an object.
  384. * @param {*} value - The value to check.
  385. * @returns {boolean} Returns `true` if the given value is an object, else `false`.
  386. */
  387. function isObject(value) {
  388. return _typeof(value) === 'object' && value !== null;
  389. }
  390. var hasOwnProperty = Object.prototype.hasOwnProperty;
  391. /**
  392. * Check if the given value is a plain object.
  393. * @param {*} value - The value to check.
  394. * @returns {boolean} Returns `true` if the given value is a plain object, else `false`.
  395. */
  396. function isPlainObject(value) {
  397. if (!isObject(value)) {
  398. return false;
  399. }
  400. try {
  401. var _constructor = value.constructor;
  402. var prototype = _constructor.prototype;
  403. return _constructor && prototype && hasOwnProperty.call(prototype, 'isPrototypeOf');
  404. } catch (error) {
  405. return false;
  406. }
  407. }
  408. /**
  409. * Check if the given value is a function.
  410. * @param {*} value - The value to check.
  411. * @returns {boolean} Returns `true` if the given value is a function, else `false`.
  412. */
  413. function isFunction(value) {
  414. return typeof value === 'function';
  415. }
  416. /**
  417. * Iterate the given data.
  418. * @param {*} data - The data to iterate.
  419. * @param {Function} callback - The process function for each element.
  420. * @returns {*} The original data.
  421. */
  422. function forEach(data, callback) {
  423. if (data && isFunction(callback)) {
  424. if (Array.isArray(data) || isNumber(data.length)
  425. /* array-like */
  426. ) {
  427. var length = data.length;
  428. var i;
  429. for (i = 0; i < length; i += 1) {
  430. if (callback.call(data, data[i], i, data) === false) {
  431. break;
  432. }
  433. }
  434. } else if (isObject(data)) {
  435. Object.keys(data).forEach(function (key) {
  436. callback.call(data, data[key], key, data);
  437. });
  438. }
  439. }
  440. return data;
  441. }
  442. /**
  443. * Extend the given object.
  444. * @param {*} obj - The object to be extended.
  445. * @param {*} args - The rest objects which will be merged to the first object.
  446. * @returns {Object} The extended object.
  447. */
  448. var assign = Object.assign || function assign(obj) {
  449. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  450. args[_key - 1] = arguments[_key];
  451. }
  452. if (isObject(obj) && args.length > 0) {
  453. args.forEach(function (arg) {
  454. if (isObject(arg)) {
  455. Object.keys(arg).forEach(function (key) {
  456. obj[key] = arg[key];
  457. });
  458. }
  459. });
  460. }
  461. return obj;
  462. };
  463. var REGEXP_SUFFIX = /^(?:width|height|left|top|marginLeft|marginTop)$/;
  464. /**
  465. * Apply styles to the given element.
  466. * @param {Element} element - The target element.
  467. * @param {Object} styles - The styles for applying.
  468. */
  469. function setStyle(element, styles) {
  470. var style = element.style;
  471. forEach(styles, function (value, property) {
  472. if (REGEXP_SUFFIX.test(property) && isNumber(value)) {
  473. value += 'px';
  474. }
  475. style[property] = value;
  476. });
  477. }
  478. /**
  479. * Escape a string for using in HTML.
  480. * @param {String} value - The string to escape.
  481. * @returns {String} Returns the escaped string.
  482. */
  483. function escapeHTMLEntities(value) {
  484. return isString(value) ? value.replace(/&(?!amp;|quot;|#39;|lt;|gt;)/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;') : value;
  485. }
  486. /**
  487. * Check if the given element has a special class.
  488. * @param {Element} element - The element to check.
  489. * @param {string} value - The class to search.
  490. * @returns {boolean} Returns `true` if the special class was found.
  491. */
  492. function hasClass(element, value) {
  493. if (!element || !value) {
  494. return false;
  495. }
  496. return element.classList ? element.classList.contains(value) : element.className.indexOf(value) > -1;
  497. }
  498. /**
  499. * Add classes to the given element.
  500. * @param {Element} element - The target element.
  501. * @param {string} value - The classes to be added.
  502. */
  503. function addClass(element, value) {
  504. if (!element || !value) {
  505. return;
  506. }
  507. if (isNumber(element.length)) {
  508. forEach(element, function (elem) {
  509. addClass(elem, value);
  510. });
  511. return;
  512. }
  513. if (element.classList) {
  514. element.classList.add(value);
  515. return;
  516. }
  517. var className = element.className.trim();
  518. if (!className) {
  519. element.className = value;
  520. } else if (className.indexOf(value) < 0) {
  521. element.className = "".concat(className, " ").concat(value);
  522. }
  523. }
  524. /**
  525. * Remove classes from the given element.
  526. * @param {Element} element - The target element.
  527. * @param {string} value - The classes to be removed.
  528. */
  529. function removeClass(element, value) {
  530. if (!element || !value) {
  531. return;
  532. }
  533. if (isNumber(element.length)) {
  534. forEach(element, function (elem) {
  535. removeClass(elem, value);
  536. });
  537. return;
  538. }
  539. if (element.classList) {
  540. element.classList.remove(value);
  541. return;
  542. }
  543. if (element.className.indexOf(value) >= 0) {
  544. element.className = element.className.replace(value, '');
  545. }
  546. }
  547. /**
  548. * Add or remove classes from the given element.
  549. * @param {Element} element - The target element.
  550. * @param {string} value - The classes to be toggled.
  551. * @param {boolean} added - Add only.
  552. */
  553. function toggleClass(element, value, added) {
  554. if (!value) {
  555. return;
  556. }
  557. if (isNumber(element.length)) {
  558. forEach(element, function (elem) {
  559. toggleClass(elem, value, added);
  560. });
  561. return;
  562. } // IE10-11 doesn't support the second parameter of `classList.toggle`
  563. if (added) {
  564. addClass(element, value);
  565. } else {
  566. removeClass(element, value);
  567. }
  568. }
  569. var REGEXP_HYPHENATE = /([a-z\d])([A-Z])/g;
  570. /**
  571. * Transform the given string from camelCase to kebab-case
  572. * @param {string} value - The value to transform.
  573. * @returns {string} The transformed value.
  574. */
  575. function hyphenate(value) {
  576. return value.replace(REGEXP_HYPHENATE, '$1-$2').toLowerCase();
  577. }
  578. /**
  579. * Get data from the given element.
  580. * @param {Element} element - The target element.
  581. * @param {string} name - The data key to get.
  582. * @returns {string} The data value.
  583. */
  584. function getData(element, name) {
  585. if (isObject(element[name])) {
  586. return element[name];
  587. }
  588. if (element.dataset) {
  589. return element.dataset[name];
  590. }
  591. return element.getAttribute("data-".concat(hyphenate(name)));
  592. }
  593. /**
  594. * Set data to the given element.
  595. * @param {Element} element - The target element.
  596. * @param {string} name - The data key to set.
  597. * @param {string} data - The data value.
  598. */
  599. function setData(element, name, data) {
  600. if (isObject(data)) {
  601. element[name] = data;
  602. } else if (element.dataset) {
  603. element.dataset[name] = data;
  604. } else {
  605. element.setAttribute("data-".concat(hyphenate(name)), data);
  606. }
  607. }
  608. var onceSupported = function () {
  609. var supported = false;
  610. if (IS_BROWSER) {
  611. var once = false;
  612. var listener = function listener() {
  613. };
  614. var options = Object.defineProperty({}, 'once', {
  615. get: function get() {
  616. supported = true;
  617. return once;
  618. },
  619. /**
  620. * This setter can fix a `TypeError` in strict mode
  621. * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only}
  622. * @param {boolean} value - The value to set
  623. */
  624. set: function set(value) {
  625. once = value;
  626. }
  627. });
  628. WINDOW.addEventListener('test', listener, options);
  629. WINDOW.removeEventListener('test', listener, options);
  630. }
  631. return supported;
  632. }();
  633. /**
  634. * Remove event listener from the target element.
  635. * @param {Element} element - The event target.
  636. * @param {string} type - The event type(s).
  637. * @param {Function} listener - The event listener.
  638. * @param {Object} options - The event options.
  639. */
  640. function removeListener(element, type, listener) {
  641. var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  642. var handler = listener;
  643. type.trim().split(REGEXP_SPACES).forEach(function (event) {
  644. if (!onceSupported) {
  645. var listeners = element.listeners;
  646. if (listeners && listeners[event] && listeners[event][listener]) {
  647. handler = listeners[event][listener];
  648. delete listeners[event][listener];
  649. if (Object.keys(listeners[event]).length === 0) {
  650. delete listeners[event];
  651. }
  652. if (Object.keys(listeners).length === 0) {
  653. delete element.listeners;
  654. }
  655. }
  656. }
  657. element.removeEventListener(event, handler, options);
  658. });
  659. }
  660. /**
  661. * Add event listener to the target element.
  662. * @param {Element} element - The event target.
  663. * @param {string} type - The event type(s).
  664. * @param {Function} listener - The event listener.
  665. * @param {Object} options - The event options.
  666. */
  667. function addListener(element, type, listener) {
  668. var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
  669. var _handler = listener;
  670. type.trim().split(REGEXP_SPACES).forEach(function (event) {
  671. if (options.once && !onceSupported) {
  672. var _element$listeners = element.listeners,
  673. listeners = _element$listeners === void 0 ? {} : _element$listeners;
  674. _handler = function handler() {
  675. delete listeners[event][listener];
  676. element.removeEventListener(event, _handler, options);
  677. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  678. args[_key2] = arguments[_key2];
  679. }
  680. listener.apply(element, args);
  681. };
  682. if (!listeners[event]) {
  683. listeners[event] = {};
  684. }
  685. if (listeners[event][listener]) {
  686. element.removeEventListener(event, listeners[event][listener], options);
  687. }
  688. listeners[event][listener] = _handler;
  689. element.listeners = listeners;
  690. }
  691. element.addEventListener(event, _handler, options);
  692. });
  693. }
  694. /**
  695. * Dispatch event on the target element.
  696. * @param {Element} element - The event target.
  697. * @param {string} type - The event type(s).
  698. * @param {Object} data - The additional event data.
  699. * @param {Object} options - The additional event options.
  700. * @returns {boolean} Indicate if the event is default prevented or not.
  701. */
  702. function dispatchEvent(element, type, data, options) {
  703. var event; // Event and CustomEvent on IE9-11 are global objects, not constructors
  704. if (isFunction(Event) && isFunction(CustomEvent)) {
  705. event = new CustomEvent(type, _objectSpread2({
  706. bubbles: true,
  707. cancelable: true,
  708. detail: data
  709. }, options));
  710. } else {
  711. event = document.createEvent('CustomEvent');
  712. event.initCustomEvent(type, true, true, data);
  713. }
  714. return element.dispatchEvent(event);
  715. }
  716. /**
  717. * Get the offset base on the document.
  718. * @param {Element} element - The target element.
  719. * @returns {Object} The offset data.
  720. */
  721. function getOffset(element) {
  722. var box = element.getBoundingClientRect();
  723. return {
  724. left: box.left + (window.pageXOffset - document.documentElement.clientLeft),
  725. top: box.top + (window.pageYOffset - document.documentElement.clientTop)
  726. };
  727. }
  728. /**
  729. * Get transforms base on the given object.
  730. * @param {Object} obj - The target object.
  731. * @returns {string} A string contains transform values.
  732. */
  733. function getTransforms(_ref) {
  734. var rotate = _ref.rotate,
  735. scaleX = _ref.scaleX,
  736. scaleY = _ref.scaleY,
  737. translateX = _ref.translateX,
  738. translateY = _ref.translateY;
  739. var values = [];
  740. if (isNumber(translateX) && translateX !== 0) {
  741. values.push("translateX(".concat(translateX, "px)"));
  742. }
  743. if (isNumber(translateY) && translateY !== 0) {
  744. values.push("translateY(".concat(translateY, "px)"));
  745. } // Rotate should come first before scale to match orientation transform
  746. if (isNumber(rotate) && rotate !== 0) {
  747. values.push("rotate(".concat(rotate, "deg)"));
  748. }
  749. if (isNumber(scaleX) && scaleX !== 1) {
  750. values.push("scaleX(".concat(scaleX, ")"));
  751. }
  752. if (isNumber(scaleY) && scaleY !== 1) {
  753. values.push("scaleY(".concat(scaleY, ")"));
  754. }
  755. var transform = values.length ? values.join(' ') : 'none';
  756. return {
  757. WebkitTransform: transform,
  758. msTransform: transform,
  759. transform: transform
  760. };
  761. }
  762. /**
  763. * Get an image name from an image url.
  764. * @param {string} url - The target url.
  765. * @example
  766. * // picture.jpg
  767. * getImageNameFromURL('https://domain.com/path/to/picture.jpg?size=1280×960')
  768. * @returns {string} A string contains the image name.
  769. */
  770. function getImageNameFromURL(url) {
  771. return isString(url) ? decodeURIComponent(url.replace(/^.*\//, '').replace(/[?&#].*$/, '')) : '';
  772. }
  773. var IS_SAFARI = WINDOW.navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(WINDOW.navigator.userAgent);
  774. /**
  775. * Get an image's natural sizes.
  776. * @param {string} image - The target image.
  777. * @param {Object} options - The viewer options.
  778. * @param {Function} callback - The callback function.
  779. * @returns {HTMLImageElement} The new image.
  780. */
  781. function getImageNaturalSizes(image, options, callback) {
  782. var newImage = document.createElement('img'); // Modern browsers (except Safari)
  783. if (image.naturalWidth && !IS_SAFARI) {
  784. callback(image.naturalWidth, image.naturalHeight);
  785. return newImage;
  786. }
  787. var body = document.body || document.documentElement;
  788. newImage.onload = function () {
  789. callback(newImage.width, newImage.height);
  790. if (!IS_SAFARI) {
  791. body.removeChild(newImage);
  792. }
  793. };
  794. forEach(options.inheritedAttributes, function (name) {
  795. var value = image.getAttribute(name);
  796. if (value !== null) {
  797. newImage.setAttribute(name, value);
  798. }
  799. });
  800. newImage.src = image.src; // iOS Safari will convert the image automatically
  801. // with its orientation once append it into DOM
  802. if (!IS_SAFARI) {
  803. newImage.style.cssText = 'left:0;' + 'max-height:none!important;' + 'max-width:none!important;' + 'min-height:0!important;' + 'min-width:0!important;' + 'opacity:0;' + 'position:absolute;' + 'top:0;' + 'z-index:-1;';
  804. body.appendChild(newImage);
  805. }
  806. return newImage;
  807. }
  808. /**
  809. * Get the related class name of a responsive type number.
  810. * @param {string} type - The responsive type.
  811. * @returns {string} The related class name.
  812. */
  813. function getResponsiveClass(type) {
  814. switch (type) {
  815. case 2:
  816. return CLASS_HIDE_XS_DOWN;
  817. case 3:
  818. return CLASS_HIDE_SM_DOWN;
  819. case 4:
  820. return CLASS_HIDE_MD_DOWN;
  821. default:
  822. return '';
  823. }
  824. }
  825. /**
  826. * Get the max ratio of a group of pointers.
  827. * @param {string} pointers - The target pointers.
  828. * @returns {number} The result ratio.
  829. */
  830. function getMaxZoomRatio(pointers) {
  831. var pointers2 = _objectSpread2({}, pointers);
  832. var ratios = [];
  833. forEach(pointers, function (pointer, pointerId) {
  834. delete pointers2[pointerId];
  835. forEach(pointers2, function (pointer2) {
  836. var x1 = Math.abs(pointer.startX - pointer2.startX);
  837. var y1 = Math.abs(pointer.startY - pointer2.startY);
  838. var x2 = Math.abs(pointer.endX - pointer2.endX);
  839. var y2 = Math.abs(pointer.endY - pointer2.endY);
  840. var z1 = Math.sqrt(x1 * x1 + y1 * y1);
  841. var z2 = Math.sqrt(x2 * x2 + y2 * y2);
  842. var ratio = (z2 - z1) / z1;
  843. ratios.push(ratio);
  844. });
  845. });
  846. ratios.sort(function (a, b) {
  847. return Math.abs(a) < Math.abs(b);
  848. });
  849. return ratios[0];
  850. }
  851. /**
  852. * Get a pointer from an event object.
  853. * @param {Object} event - The target event object.
  854. * @param {boolean} endOnly - Indicates if only returns the end point coordinate or not.
  855. * @returns {Object} The result pointer contains start and/or end point coordinates.
  856. */
  857. function getPointer(_ref2, endOnly) {
  858. var pageX = _ref2.pageX,
  859. pageY = _ref2.pageY;
  860. var end = {
  861. endX: pageX,
  862. endY: pageY
  863. };
  864. return endOnly ? end : _objectSpread2({
  865. timeStamp: Date.now(),
  866. startX: pageX,
  867. startY: pageY
  868. }, end);
  869. }
  870. /**
  871. * Get the center point coordinate of a group of pointers.
  872. * @param {Object} pointers - The target pointers.
  873. * @returns {Object} The center point coordinate.
  874. */
  875. function getPointersCenter(pointers) {
  876. var pageX = 0;
  877. var pageY = 0;
  878. var count = 0;
  879. forEach(pointers, function (_ref3) {
  880. var startX = _ref3.startX,
  881. startY = _ref3.startY;
  882. pageX += startX;
  883. pageY += startY;
  884. count += 1;
  885. });
  886. pageX /= count;
  887. pageY /= count;
  888. return {
  889. pageX: pageX,
  890. pageY: pageY
  891. };
  892. }
  893. var render = {
  894. render: function render() {
  895. this.initContainer();
  896. this.initViewer();
  897. this.initList();
  898. this.renderViewer();
  899. },
  900. initBody: function initBody() {
  901. var ownerDocument = this.element.ownerDocument;
  902. var body = ownerDocument.body || ownerDocument.documentElement;
  903. this.body = body;
  904. this.scrollbarWidth = window.innerWidth - ownerDocument.documentElement.clientWidth;
  905. this.initialBodyPaddingRight = body.style.paddingRight;
  906. this.initialBodyComputedPaddingRight = window.getComputedStyle(body).paddingRight;
  907. },
  908. initContainer: function initContainer() {
  909. this.containerData = {
  910. width: window.innerWidth,
  911. height: window.innerHeight
  912. };
  913. },
  914. initViewer: function initViewer() {
  915. var options = this.options,
  916. parent = this.parent;
  917. var viewerData;
  918. if (options.inline) {
  919. viewerData = {
  920. width: Math.max(parent.offsetWidth, options.minWidth),
  921. height: Math.max(parent.offsetHeight, options.minHeight)
  922. };
  923. this.parentData = viewerData;
  924. }
  925. if (this.fulled || !viewerData) {
  926. viewerData = this.containerData;
  927. }
  928. this.viewerData = assign({}, viewerData);
  929. },
  930. renderViewer: function renderViewer() {
  931. if (this.options.inline && !this.fulled) {
  932. setStyle(this.viewer, this.viewerData);
  933. }
  934. },
  935. initList: function initList() {
  936. var _this = this;
  937. var element = this.element,
  938. options = this.options,
  939. list = this.list;
  940. var items = []; // initList may be called in this.update, so should keep idempotent
  941. list.innerHTML = '';
  942. forEach(this.images, function (image, index) {
  943. var src = image.src;
  944. var alt = image.alt || getImageNameFromURL(src);
  945. var url = _this.getImageURL(image);
  946. if (src || url) {
  947. var item = document.createElement('li');
  948. var img = document.createElement('img');
  949. forEach(options.inheritedAttributes, function (name) {
  950. var value = image.getAttribute(name);
  951. if (value !== null) {
  952. img.setAttribute(name, value);
  953. }
  954. });
  955. img.src = src || url;
  956. img.alt = alt;
  957. img.setAttribute('data-original-url', url || src);
  958. item.setAttribute('data-index', index);
  959. item.setAttribute('data-viewer-action', 'view');
  960. item.setAttribute('role', 'button');
  961. if (options.keyboard) {
  962. item.setAttribute('tabindex', 0);
  963. }
  964. item.appendChild(img);
  965. list.appendChild(item);
  966. items.push(item);
  967. }
  968. });
  969. this.items = items;
  970. forEach(items, function (item) {
  971. var image = item.firstElementChild;
  972. var onLoad;
  973. var onError;
  974. setData(image, 'filled', true);
  975. if (options.loading) {
  976. addClass(item, CLASS_LOADING);
  977. }
  978. addListener(image, EVENT_LOAD, onLoad = function onLoad(event) {
  979. removeListener(image, EVENT_ERROR, onError);
  980. if (options.loading) {
  981. removeClass(item, CLASS_LOADING);
  982. }
  983. _this.loadImage(event);
  984. }, {
  985. once: true
  986. });
  987. addListener(image, EVENT_ERROR, onError = function onError() {
  988. removeListener(image, EVENT_LOAD, onLoad);
  989. if (options.loading) {
  990. removeClass(item, CLASS_LOADING);
  991. }
  992. }, {
  993. once: true
  994. });
  995. });
  996. if (options.transition) {
  997. addListener(element, EVENT_VIEWED, function () {
  998. addClass(list, CLASS_TRANSITION);
  999. }, {
  1000. once: true
  1001. });
  1002. }
  1003. },
  1004. renderList: function renderList() {
  1005. var index = this.index;
  1006. var item = this.items[index];
  1007. if (!item) {
  1008. return;
  1009. }
  1010. var next = item.nextElementSibling;
  1011. var gutter = parseInt(window.getComputedStyle(next || item).marginLeft, 10);
  1012. var offsetWidth = item.offsetWidth;
  1013. var outerWidth = offsetWidth + gutter; // Place the active item in the center of the screen
  1014. setStyle(this.list, assign({
  1015. width: outerWidth * this.length - gutter
  1016. }, getTransforms({
  1017. translateX: (this.viewerData.width - offsetWidth) / 2 - outerWidth * index
  1018. })));
  1019. },
  1020. resetList: function resetList() {
  1021. var list = this.list;
  1022. list.innerHTML = '';
  1023. removeClass(list, CLASS_TRANSITION);
  1024. setStyle(list, getTransforms({
  1025. translateX: 0
  1026. }));
  1027. },
  1028. initImage: function initImage(done) {
  1029. var _this2 = this;
  1030. var options = this.options,
  1031. image = this.image,
  1032. viewerData = this.viewerData;
  1033. var footerHeight = this.footer.offsetHeight;
  1034. var viewerWidth = viewerData.width;
  1035. var viewerHeight = Math.max(viewerData.height - footerHeight, footerHeight);
  1036. var oldImageData = this.imageData || {};
  1037. var sizingImage;
  1038. this.imageInitializing = {
  1039. abort: function abort() {
  1040. sizingImage.onload = null;
  1041. }
  1042. };
  1043. sizingImage = getImageNaturalSizes(image, options, function (naturalWidth, naturalHeight) {
  1044. var aspectRatio = naturalWidth / naturalHeight;
  1045. var width = viewerWidth;
  1046. var height = viewerHeight;
  1047. _this2.imageInitializing = false;
  1048. if (viewerHeight * aspectRatio > viewerWidth) {
  1049. height = viewerWidth / aspectRatio;
  1050. } else {
  1051. width = viewerHeight * aspectRatio;
  1052. }
  1053. width = Math.min(width * 0.9, naturalWidth);
  1054. height = Math.min(height * 0.9, naturalHeight);
  1055. var left = (viewerWidth - width) / 2;
  1056. var top = (viewerHeight - height) / 2;
  1057. var imageData = {
  1058. left: left,
  1059. top: top,
  1060. x: left,
  1061. y: top,
  1062. width: width,
  1063. height: height,
  1064. oldRatio: 1,
  1065. ratio: width / naturalWidth,
  1066. aspectRatio: aspectRatio,
  1067. naturalWidth: naturalWidth,
  1068. naturalHeight: naturalHeight
  1069. };
  1070. var initialImageData = assign({}, imageData);
  1071. if (options.rotatable) {
  1072. imageData.rotate = oldImageData.rotate || 0;
  1073. initialImageData.rotate = 0;
  1074. }
  1075. if (options.scalable) {
  1076. imageData.scaleX = oldImageData.scaleX || 1;
  1077. imageData.scaleY = oldImageData.scaleY || 1;
  1078. initialImageData.scaleX = 1;
  1079. initialImageData.scaleY = 1;
  1080. }
  1081. _this2.imageData = imageData;
  1082. _this2.initialImageData = initialImageData;
  1083. if (done) {
  1084. done();
  1085. }
  1086. });
  1087. },
  1088. renderImage: function renderImage(done) {
  1089. var _this3 = this;
  1090. var image = this.image,
  1091. imageData = this.imageData;
  1092. setStyle(image, assign({
  1093. width: imageData.width,
  1094. height: imageData.height,
  1095. // XXX: Not to use translateX/Y to avoid image shaking when zooming
  1096. marginLeft: imageData.x,
  1097. marginTop: imageData.y
  1098. }, getTransforms(imageData)));
  1099. if (done) {
  1100. if ((this.viewing || this.moving || this.rotating || this.scaling || this.zooming) && this.options.transition && hasClass(image, CLASS_TRANSITION)) {
  1101. var onTransitionEnd = function onTransitionEnd() {
  1102. _this3.imageRendering = false;
  1103. done();
  1104. };
  1105. this.imageRendering = {
  1106. abort: function abort() {
  1107. removeListener(image, EVENT_TRANSITION_END, onTransitionEnd);
  1108. }
  1109. };
  1110. addListener(image, EVENT_TRANSITION_END, onTransitionEnd, {
  1111. once: true
  1112. });
  1113. } else {
  1114. done();
  1115. }
  1116. }
  1117. },
  1118. resetImage: function resetImage() {
  1119. // this.image only defined after viewed
  1120. if (this.viewing || this.viewed) {
  1121. var image = this.image;
  1122. if (this.viewing) {
  1123. this.viewing.abort();
  1124. }
  1125. image.parentNode.removeChild(image);
  1126. this.image = null;
  1127. }
  1128. }
  1129. };
  1130. var events = {
  1131. bind: function bind() {
  1132. var options = this.options,
  1133. viewer = this.viewer,
  1134. canvas = this.canvas;
  1135. var document = this.element.ownerDocument;
  1136. addListener(viewer, EVENT_CLICK, this.onClick = this.click.bind(this));
  1137. addListener(viewer, EVENT_DRAG_START, this.onDragStart = this.dragstart.bind(this));
  1138. addListener(canvas, EVENT_POINTER_DOWN, this.onPointerDown = this.pointerdown.bind(this));
  1139. addListener(document, EVENT_POINTER_MOVE, this.onPointerMove = this.pointermove.bind(this));
  1140. addListener(document, EVENT_POINTER_UP, this.onPointerUp = this.pointerup.bind(this));
  1141. addListener(document, EVENT_KEY_DOWN, this.onKeyDown = this.keydown.bind(this));
  1142. addListener(window, EVENT_RESIZE, this.onResize = this.resize.bind(this));
  1143. if (options.zoomable && options.zoomOnWheel) {
  1144. addListener(viewer, EVENT_WHEEL, this.onWheel = this.wheel.bind(this), {
  1145. passive: false,
  1146. capture: true
  1147. });
  1148. }
  1149. if (options.toggleOnDblclick) {
  1150. addListener(canvas, EVENT_DBLCLICK, this.onDblclick = this.dblclick.bind(this));
  1151. }
  1152. },
  1153. unbind: function unbind() {
  1154. var options = this.options,
  1155. viewer = this.viewer,
  1156. canvas = this.canvas;
  1157. var document = this.element.ownerDocument;
  1158. removeListener(viewer, EVENT_CLICK, this.onClick);
  1159. removeListener(viewer, EVENT_DRAG_START, this.onDragStart);
  1160. removeListener(canvas, EVENT_POINTER_DOWN, this.onPointerDown);
  1161. removeListener(document, EVENT_POINTER_MOVE, this.onPointerMove);
  1162. removeListener(document, EVENT_POINTER_UP, this.onPointerUp);
  1163. removeListener(document, EVENT_KEY_DOWN, this.onKeyDown);
  1164. removeListener(window, EVENT_RESIZE, this.onResize);
  1165. if (options.zoomable && options.zoomOnWheel) {
  1166. removeListener(viewer, EVENT_WHEEL, this.onWheel, {
  1167. passive: false,
  1168. capture: true
  1169. });
  1170. }
  1171. if (options.toggleOnDblclick) {
  1172. removeListener(canvas, EVENT_DBLCLICK, this.onDblclick);
  1173. }
  1174. }
  1175. };
  1176. var handlers = {
  1177. click: function click(event) {
  1178. var options = this.options,
  1179. imageData = this.imageData;
  1180. var target = event.target;
  1181. var action = getData(target, DATA_ACTION);
  1182. if (!action && target.localName === 'img' && target.parentElement.localName === 'li') {
  1183. target = target.parentElement;
  1184. action = getData(target, DATA_ACTION);
  1185. } // Cancel the emulated click when the native click event was triggered.
  1186. if (IS_TOUCH_DEVICE && event.isTrusted && target === this.canvas) {
  1187. clearTimeout(this.clickCanvasTimeout);
  1188. }
  1189. switch (action) {
  1190. case 'mix':
  1191. if (this.played) {
  1192. this.stop();
  1193. } else if (options.inline) {
  1194. if (this.fulled) {
  1195. this.exit();
  1196. } else {
  1197. this.full();
  1198. }
  1199. } else {
  1200. this.hide();
  1201. }
  1202. break;
  1203. case 'hide':
  1204. this.hide();
  1205. break;
  1206. case 'view':
  1207. this.view(getData(target, 'index'));
  1208. break;
  1209. case 'zoom-in':
  1210. this.zoom(0.1, true);
  1211. break;
  1212. case 'zoom-out':
  1213. this.zoom(-0.1, true);
  1214. break;
  1215. case 'one-to-one':
  1216. this.toggle();
  1217. break;
  1218. case 'reset':
  1219. this.reset();
  1220. break;
  1221. case 'prev':
  1222. this.prev(options.loop);
  1223. break;
  1224. case 'play':
  1225. this.play(options.fullscreen);
  1226. break;
  1227. case 'next':
  1228. this.next(options.loop);
  1229. break;
  1230. case 'rotate-left':
  1231. this.rotate(-90);
  1232. break;
  1233. case 'rotate-right':
  1234. this.rotate(90);
  1235. break;
  1236. case 'flip-horizontal':
  1237. this.scaleX(-imageData.scaleX || -1);
  1238. break;
  1239. case 'flip-vertical':
  1240. this.scaleY(-imageData.scaleY || -1);
  1241. break;
  1242. default:
  1243. if (this.played) {
  1244. this.stop();
  1245. }
  1246. }
  1247. },
  1248. dblclick: function dblclick(event) {
  1249. event.preventDefault();
  1250. if (this.viewed && event.target === this.image) {
  1251. // Cancel the emulated double click when the native dblclick event was triggered.
  1252. if (IS_TOUCH_DEVICE && event.isTrusted) {
  1253. clearTimeout(this.doubleClickImageTimeout);
  1254. }
  1255. this.toggle(event);
  1256. }
  1257. },
  1258. load: function load() {
  1259. var _this = this;
  1260. if (this.timeout) {
  1261. clearTimeout(this.timeout);
  1262. this.timeout = false;
  1263. }
  1264. var element = this.element,
  1265. options = this.options,
  1266. image = this.image,
  1267. index = this.index,
  1268. viewerData = this.viewerData;
  1269. removeClass(image, CLASS_INVISIBLE);
  1270. if (options.loading) {
  1271. removeClass(this.canvas, CLASS_LOADING);
  1272. }
  1273. image.style.cssText = 'height:0;' + "margin-left:".concat(viewerData.width / 2, "px;") + "margin-top:".concat(viewerData.height / 2, "px;") + 'max-width:none!important;' + 'position:relative;' + 'width:0;';
  1274. this.initImage(function () {
  1275. toggleClass(image, CLASS_MOVE, options.movable);
  1276. toggleClass(image, CLASS_TRANSITION, options.transition);
  1277. _this.renderImage(function () {
  1278. _this.viewed = true;
  1279. _this.viewing = false;
  1280. if (isFunction(options.viewed)) {
  1281. addListener(element, EVENT_VIEWED, options.viewed, {
  1282. once: true
  1283. });
  1284. }
  1285. dispatchEvent(element, EVENT_VIEWED, {
  1286. originalImage: _this.images[index],
  1287. index: index,
  1288. image: image
  1289. }, {
  1290. cancelable: false
  1291. });
  1292. });
  1293. });
  1294. },
  1295. loadImage: function loadImage(event) {
  1296. var image = event.target;
  1297. var parent = image.parentNode;
  1298. var parentWidth = parent.offsetWidth || 30;
  1299. var parentHeight = parent.offsetHeight || 50;
  1300. var filled = !!getData(image, 'filled');
  1301. getImageNaturalSizes(image, this.options, function (naturalWidth, naturalHeight) {
  1302. var aspectRatio = naturalWidth / naturalHeight;
  1303. var width = parentWidth;
  1304. var height = parentHeight;
  1305. if (parentHeight * aspectRatio > parentWidth) {
  1306. if (filled) {
  1307. width = parentHeight * aspectRatio;
  1308. } else {
  1309. height = parentWidth / aspectRatio;
  1310. }
  1311. } else if (filled) {
  1312. height = parentWidth / aspectRatio;
  1313. } else {
  1314. width = parentHeight * aspectRatio;
  1315. }
  1316. setStyle(image, assign({
  1317. width: width,
  1318. height: height
  1319. }, getTransforms({
  1320. translateX: (parentWidth - width) / 2,
  1321. translateY: (parentHeight - height) / 2
  1322. })));
  1323. });
  1324. },
  1325. keydown: function keydown(event) {
  1326. var options = this.options;
  1327. if (!options.keyboard) {
  1328. return;
  1329. }
  1330. var keyCode = event.keyCode || event.which || event.charCode;
  1331. switch (keyCode) {
  1332. // Enter
  1333. case 13:
  1334. if (this.viewer.contains(event.target)) {
  1335. this.click(event);
  1336. }
  1337. break;
  1338. }
  1339. if (!this.fulled) {
  1340. return;
  1341. }
  1342. switch (keyCode) {
  1343. // Escape
  1344. case 27:
  1345. if (this.played) {
  1346. this.stop();
  1347. } else if (options.inline) {
  1348. if (this.fulled) {
  1349. this.exit();
  1350. }
  1351. } else {
  1352. this.hide();
  1353. }
  1354. break;
  1355. // Space
  1356. case 32:
  1357. if (this.played) {
  1358. this.stop();
  1359. }
  1360. break;
  1361. // ArrowLeft
  1362. case 37:
  1363. this.prev(options.loop);
  1364. break;
  1365. // ArrowUp
  1366. case 38:
  1367. // Prevent scroll on Firefox
  1368. event.preventDefault(); // Zoom in
  1369. this.zoom(options.zoomRatio, true);
  1370. break;
  1371. // ArrowRight
  1372. case 39:
  1373. this.next(options.loop);
  1374. break;
  1375. // ArrowDown
  1376. case 40:
  1377. // Prevent scroll on Firefox
  1378. event.preventDefault(); // Zoom out
  1379. this.zoom(-options.zoomRatio, true);
  1380. break;
  1381. // Ctrl + 0
  1382. case 48: // Fall through
  1383. // Ctrl + 1
  1384. // eslint-disable-next-line no-fallthrough
  1385. case 49:
  1386. if (event.ctrlKey) {
  1387. event.preventDefault();
  1388. this.toggle();
  1389. }
  1390. break;
  1391. }
  1392. },
  1393. dragstart: function dragstart(event) {
  1394. if (event.target.localName === 'img') {
  1395. event.preventDefault();
  1396. }
  1397. },
  1398. pointerdown: function pointerdown(event) {
  1399. var options = this.options,
  1400. pointers = this.pointers;
  1401. var buttons = event.buttons,
  1402. button = event.button;
  1403. if (!this.viewed || this.showing || this.viewing || this.hiding // Handle mouse event and pointer event and ignore touch event
  1404. || (event.type === 'mousedown' || event.type === 'pointerdown' && event.pointerType === 'mouse') && ( // No primary button (Usually the left button)
  1405. isNumber(buttons) && buttons !== 1 || isNumber(button) && button !== 0 // Open context menu
  1406. || event.ctrlKey)) {
  1407. return;
  1408. } // Prevent default behaviours as page zooming in touch devices.
  1409. event.preventDefault();
  1410. if (event.changedTouches) {
  1411. forEach(event.changedTouches, function (touch) {
  1412. pointers[touch.identifier] = getPointer(touch);
  1413. });
  1414. } else {
  1415. pointers[event.pointerId || 0] = getPointer(event);
  1416. }
  1417. var action = options.movable ? ACTION_MOVE : false;
  1418. if (options.zoomOnTouch && options.zoomable && Object.keys(pointers).length > 1) {
  1419. action = ACTION_ZOOM;
  1420. } else if (options.slideOnTouch && (event.pointerType === 'touch' || event.type === 'touchstart') && this.isSwitchable()) {
  1421. action = ACTION_SWITCH;
  1422. }
  1423. if (options.transition && (action === ACTION_MOVE || action === ACTION_ZOOM)) {
  1424. removeClass(this.image, CLASS_TRANSITION);
  1425. }
  1426. this.action = action;
  1427. },
  1428. pointermove: function pointermove(event) {
  1429. var pointers = this.pointers,
  1430. action = this.action;
  1431. if (!this.viewed || !action) {
  1432. return;
  1433. }
  1434. event.preventDefault();
  1435. if (event.changedTouches) {
  1436. forEach(event.changedTouches, function (touch) {
  1437. assign(pointers[touch.identifier] || {}, getPointer(touch, true));
  1438. });
  1439. } else {
  1440. assign(pointers[event.pointerId || 0] || {}, getPointer(event, true));
  1441. }
  1442. this.change(event);
  1443. },
  1444. pointerup: function pointerup(event) {
  1445. var _this2 = this;
  1446. var options = this.options,
  1447. action = this.action,
  1448. pointers = this.pointers;
  1449. var pointer;
  1450. if (event.changedTouches) {
  1451. forEach(event.changedTouches, function (touch) {
  1452. pointer = pointers[touch.identifier];
  1453. delete pointers[touch.identifier];
  1454. });
  1455. } else {
  1456. pointer = pointers[event.pointerId || 0];
  1457. delete pointers[event.pointerId || 0];
  1458. }
  1459. if (!action) {
  1460. return;
  1461. }
  1462. event.preventDefault();
  1463. if (options.transition && (action === ACTION_MOVE || action === ACTION_ZOOM)) {
  1464. addClass(this.image, CLASS_TRANSITION);
  1465. }
  1466. this.action = false; // Emulate click and double click in touch devices to support backdrop and image zooming (#210).
  1467. if (IS_TOUCH_DEVICE && action !== ACTION_ZOOM && pointer && Date.now() - pointer.timeStamp < 500) {
  1468. clearTimeout(this.clickCanvasTimeout);
  1469. clearTimeout(this.doubleClickImageTimeout);
  1470. if (options.toggleOnDblclick && this.viewed && event.target === this.image) {
  1471. if (this.imageClicked) {
  1472. this.imageClicked = false; // This timeout will be cleared later when a native dblclick event is triggering
  1473. this.doubleClickImageTimeout = setTimeout(function () {
  1474. dispatchEvent(_this2.image, EVENT_DBLCLICK);
  1475. }, 50);
  1476. } else {
  1477. this.imageClicked = true; // The default timing of a double click in Windows is 500 ms
  1478. this.doubleClickImageTimeout = setTimeout(function () {
  1479. _this2.imageClicked = false;
  1480. }, 500);
  1481. }
  1482. } else {
  1483. this.imageClicked = false;
  1484. if (options.backdrop && options.backdrop !== 'static' && event.target === this.canvas) {
  1485. // This timeout will be cleared later when a native click event is triggering
  1486. this.clickCanvasTimeout = setTimeout(function () {
  1487. dispatchEvent(_this2.canvas, EVENT_CLICK);
  1488. }, 50);
  1489. }
  1490. }
  1491. }
  1492. },
  1493. resize: function resize() {
  1494. var _this3 = this;
  1495. if (!this.isShown || this.hiding) {
  1496. return;
  1497. }
  1498. if (this.fulled) {
  1499. this.close();
  1500. this.initBody();
  1501. this.open();
  1502. }
  1503. this.initContainer();
  1504. this.initViewer();
  1505. this.renderViewer();
  1506. this.renderList();
  1507. if (this.viewed) {
  1508. this.initImage(function () {
  1509. _this3.renderImage();
  1510. });
  1511. }
  1512. if (this.played) {
  1513. if (this.options.fullscreen && this.fulled && !(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) {
  1514. this.stop();
  1515. return;
  1516. }
  1517. forEach(this.player.getElementsByTagName('img'), function (image) {
  1518. addListener(image, EVENT_LOAD, _this3.loadImage.bind(_this3), {
  1519. once: true
  1520. });
  1521. dispatchEvent(image, EVENT_LOAD);
  1522. });
  1523. }
  1524. },
  1525. wheel: function wheel(event) {
  1526. var _this4 = this;
  1527. if (!this.viewed) {
  1528. return;
  1529. }
  1530. event.preventDefault(); // Limit wheel speed to prevent zoom too fast
  1531. if (this.wheeling) {
  1532. return;
  1533. }
  1534. this.wheeling = true;
  1535. setTimeout(function () {
  1536. _this4.wheeling = false;
  1537. }, 50);
  1538. var ratio = Number(this.options.zoomRatio) || 0.1;
  1539. var delta = 1;
  1540. if (event.deltaY) {
  1541. delta = event.deltaY > 0 ? 1 : -1;
  1542. } else if (event.wheelDelta) {
  1543. delta = -event.wheelDelta / 120;
  1544. } else if (event.detail) {
  1545. delta = event.detail > 0 ? 1 : -1;
  1546. }
  1547. this.zoom(-delta * ratio, true, event);
  1548. }
  1549. };
  1550. var methods = {
  1551. /** Show the viewer (only available in modal mode)
  1552. * @param {boolean} [immediate=false] - Indicates if show the viewer immediately or not.
  1553. * @returns {Viewer} this
  1554. */
  1555. show: function show() {
  1556. var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1557. var element = this.element,
  1558. options = this.options;
  1559. if (options.inline || this.showing || this.isShown || this.showing) {
  1560. return this;
  1561. }
  1562. if (!this.ready) {
  1563. this.build();
  1564. if (this.ready) {
  1565. this.show(immediate);
  1566. }
  1567. return this;
  1568. }
  1569. if (isFunction(options.show)) {
  1570. addListener(element, EVENT_SHOW, options.show, {
  1571. once: true
  1572. });
  1573. }
  1574. if (dispatchEvent(element, EVENT_SHOW) === false || !this.ready) {
  1575. return this;
  1576. }
  1577. if (this.hiding) {
  1578. this.transitioning.abort();
  1579. }
  1580. this.showing = true;
  1581. this.open();
  1582. var viewer = this.viewer;
  1583. removeClass(viewer, CLASS_HIDE);
  1584. viewer.setAttribute('role', 'dialog');
  1585. viewer.setAttribute('aria-labelledby', this.title.id);
  1586. viewer.setAttribute('aria-modal', true);
  1587. viewer.removeAttribute('aria-hidden');
  1588. if (options.transition && !immediate) {
  1589. var shown = this.shown.bind(this);
  1590. this.transitioning = {
  1591. abort: function abort() {
  1592. removeListener(viewer, EVENT_TRANSITION_END, shown);
  1593. removeClass(viewer, CLASS_IN);
  1594. }
  1595. };
  1596. addClass(viewer, CLASS_TRANSITION); // Force reflow to enable CSS3 transition
  1597. viewer.initialOffsetWidth = viewer.offsetWidth;
  1598. addListener(viewer, EVENT_TRANSITION_END, shown, {
  1599. once: true
  1600. });
  1601. addClass(viewer, CLASS_IN);
  1602. } else {
  1603. addClass(viewer, CLASS_IN);
  1604. this.shown();
  1605. }
  1606. return this;
  1607. },
  1608. /**
  1609. * Hide the viewer (only available in modal mode)
  1610. * @param {boolean} [immediate=false] - Indicates if hide the viewer immediately or not.
  1611. * @returns {Viewer} this
  1612. */
  1613. hide: function hide() {
  1614. var _this = this;
  1615. var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1616. var element = this.element,
  1617. options = this.options;
  1618. if (options.inline || this.hiding || !(this.isShown || this.showing)) {
  1619. return this;
  1620. }
  1621. if (isFunction(options.hide)) {
  1622. addListener(element, EVENT_HIDE, options.hide, {
  1623. once: true
  1624. });
  1625. }
  1626. if (dispatchEvent(element, EVENT_HIDE) === false) {
  1627. return this;
  1628. }
  1629. if (this.showing) {
  1630. this.transitioning.abort();
  1631. }
  1632. this.hiding = true;
  1633. if (this.played) {
  1634. this.stop();
  1635. } else if (this.viewing) {
  1636. this.viewing.abort();
  1637. }
  1638. var viewer = this.viewer,
  1639. image = this.image;
  1640. var hideImmediately = function hideImmediately() {
  1641. removeClass(viewer, CLASS_IN);
  1642. _this.hidden();
  1643. };
  1644. if (options.transition && !immediate) {
  1645. var onViewerTransitionEnd = function onViewerTransitionEnd(event) {
  1646. // Ignore all propagating `transitionend` events (#275).
  1647. if (event && event.target === viewer) {
  1648. removeListener(viewer, EVENT_TRANSITION_END, onViewerTransitionEnd);
  1649. _this.hidden();
  1650. }
  1651. };
  1652. var onImageTransitionEnd = function onImageTransitionEnd() {
  1653. // In case of show the viewer by `viewer.show(true)` previously (#407).
  1654. if (hasClass(viewer, CLASS_TRANSITION)) {
  1655. addListener(viewer, EVENT_TRANSITION_END, onViewerTransitionEnd);
  1656. removeClass(viewer, CLASS_IN);
  1657. } else {
  1658. hideImmediately();
  1659. }
  1660. };
  1661. this.transitioning = {
  1662. abort: function abort() {
  1663. if (_this.viewed && hasClass(image, CLASS_TRANSITION)) {
  1664. removeListener(image, EVENT_TRANSITION_END, onImageTransitionEnd);
  1665. } else if (hasClass(viewer, CLASS_TRANSITION)) {
  1666. removeListener(viewer, EVENT_TRANSITION_END, onViewerTransitionEnd);
  1667. }
  1668. }
  1669. }; // In case of hiding the viewer when holding on the image (#255),
  1670. // note that the `CLASS_TRANSITION` class will be removed on pointer down.
  1671. if (this.viewed && hasClass(image, CLASS_TRANSITION)) {
  1672. addListener(image, EVENT_TRANSITION_END, onImageTransitionEnd, {
  1673. once: true
  1674. });
  1675. this.zoomTo(0, false, null, true);
  1676. } else {
  1677. onImageTransitionEnd();
  1678. }
  1679. } else {
  1680. hideImmediately();
  1681. }
  1682. return this;
  1683. },
  1684. /**
  1685. * View one of the images with image's index
  1686. * @param {number} index - The index of the image to view.
  1687. * @returns {Viewer} this
  1688. */
  1689. view: function view() {
  1690. var _this2 = this;
  1691. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.initialViewIndex;
  1692. index = Number(index) || 0;
  1693. if (this.hiding || this.played || index < 0 || index >= this.length || this.viewed && index === this.index) {
  1694. return this;
  1695. }
  1696. if (!this.isShown) {
  1697. this.index = index;
  1698. return this.show();
  1699. }
  1700. if (this.viewing) {
  1701. this.viewing.abort();
  1702. }
  1703. var element = this.element,
  1704. options = this.options,
  1705. title = this.title,
  1706. canvas = this.canvas;
  1707. var item = this.items[index];
  1708. var img = item.querySelector('img');
  1709. var url = getData(img, 'originalUrl');
  1710. var alt = img.getAttribute('alt');
  1711. var image = document.createElement('img');
  1712. forEach(options.inheritedAttributes, function (name) {
  1713. var value = img.getAttribute(name);
  1714. if (value !== null) {
  1715. image.setAttribute(name, value);
  1716. }
  1717. });
  1718. image.src = url;
  1719. image.alt = alt;
  1720. if (isFunction(options.view)) {
  1721. addListener(element, EVENT_VIEW, options.view, {
  1722. once: true
  1723. });
  1724. }
  1725. if (dispatchEvent(element, EVENT_VIEW, {
  1726. originalImage: this.images[index],
  1727. index: index,
  1728. image: image
  1729. }) === false || !this.isShown || this.hiding || this.played) {
  1730. return this;
  1731. }
  1732. var activeItem = this.items[this.index];
  1733. if (activeItem) {
  1734. removeClass(activeItem, CLASS_ACTIVE);
  1735. activeItem.removeAttribute('aria-selected');
  1736. }
  1737. addClass(item, CLASS_ACTIVE);
  1738. item.setAttribute('aria-selected', true);
  1739. if (options.focus) {
  1740. item.focus();
  1741. }
  1742. this.image = image;
  1743. this.viewed = false;
  1744. this.index = index;
  1745. this.imageData = {};
  1746. addClass(image, CLASS_INVISIBLE);
  1747. if (options.loading) {
  1748. addClass(canvas, CLASS_LOADING);
  1749. }
  1750. canvas.innerHTML = '';
  1751. canvas.appendChild(image); // Center current item
  1752. this.renderList(); // Clear title
  1753. title.innerHTML = ''; // Generate title after viewed
  1754. var onViewed = function onViewed() {
  1755. var imageData = _this2.imageData;
  1756. var render = Array.isArray(options.title) ? options.title[1] : options.title;
  1757. title.innerHTML = escapeHTMLEntities(isFunction(render) ? render.call(_this2, image, imageData) : "".concat(alt, " (").concat(imageData.naturalWidth, " \xD7 ").concat(imageData.naturalHeight, ")"));
  1758. };
  1759. var onLoad;
  1760. var onError;
  1761. addListener(element, EVENT_VIEWED, onViewed, {
  1762. once: true
  1763. });
  1764. this.viewing = {
  1765. abort: function abort() {
  1766. removeListener(element, EVENT_VIEWED, onViewed);
  1767. if (image.complete) {
  1768. if (_this2.imageRendering) {
  1769. _this2.imageRendering.abort();
  1770. } else if (_this2.imageInitializing) {
  1771. _this2.imageInitializing.abort();
  1772. }
  1773. } else {
  1774. // Cancel download to save bandwidth.
  1775. image.src = '';
  1776. removeListener(image, EVENT_LOAD, onLoad);
  1777. if (_this2.timeout) {
  1778. clearTimeout(_this2.timeout);
  1779. }
  1780. }
  1781. }
  1782. };
  1783. if (image.complete) {
  1784. this.load();
  1785. } else {
  1786. addListener(image, EVENT_LOAD, onLoad = function onLoad() {
  1787. removeListener(image, EVENT_ERROR, onError);
  1788. _this2.load();
  1789. }, {
  1790. once: true
  1791. });
  1792. addListener(image, EVENT_ERROR, onError = function onError() {
  1793. removeListener(image, EVENT_LOAD, onLoad);
  1794. if (_this2.timeout) {
  1795. clearTimeout(_this2.timeout);
  1796. _this2.timeout = false;
  1797. }
  1798. removeClass(image, CLASS_INVISIBLE);
  1799. if (options.loading) {
  1800. removeClass(_this2.canvas, CLASS_LOADING);
  1801. }
  1802. }, {
  1803. once: true
  1804. });
  1805. if (this.timeout) {
  1806. clearTimeout(this.timeout);
  1807. } // Make the image visible if it fails to load within 1s
  1808. this.timeout = setTimeout(function () {
  1809. removeClass(image, CLASS_INVISIBLE);
  1810. _this2.timeout = false;
  1811. }, 1000);
  1812. }
  1813. return this;
  1814. },
  1815. /**
  1816. * View the previous image
  1817. * @param {boolean} [loop=false] - Indicate if view the last one
  1818. * when it is the first one at present.
  1819. * @returns {Viewer} this
  1820. */
  1821. prev: function prev() {
  1822. var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1823. var index = this.index - 1;
  1824. if (index < 0) {
  1825. index = loop ? this.length - 1 : 0;
  1826. }
  1827. this.view(index);
  1828. return this;
  1829. },
  1830. /**
  1831. * View the next image
  1832. * @param {boolean} [loop=false] - Indicate if view the first one
  1833. * when it is the last one at present.
  1834. * @returns {Viewer} this
  1835. */
  1836. next: function next() {
  1837. var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1838. var maxIndex = this.length - 1;
  1839. var index = this.index + 1;
  1840. if (index > maxIndex) {
  1841. index = loop ? 0 : maxIndex;
  1842. }
  1843. this.view(index);
  1844. return this;
  1845. },
  1846. /**
  1847. * Move the image with relative offsets.
  1848. * @param {number} x - The moving distance in the horizontal direction.
  1849. * @param {number} [y=x] The moving distance in the vertical direction.
  1850. * @returns {Viewer} this
  1851. */
  1852. move: function move(x) {
  1853. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;
  1854. var imageData = this.imageData;
  1855. this.moveTo(isUndefined(x) ? x : imageData.x + Number(x), isUndefined(y) ? y : imageData.y + Number(y));
  1856. return this;
  1857. },
  1858. /**
  1859. * Move the image to an absolute point.
  1860. * @param {number} x - The new position in the horizontal direction.
  1861. * @param {number} [y=x] - The new position in the vertical direction.
  1862. * @param {Event} [_originalEvent=null] - The original event if any.
  1863. * @returns {Viewer} this
  1864. */
  1865. moveTo: function moveTo(x) {
  1866. var _this3 = this;
  1867. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;
  1868. var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  1869. var element = this.element,
  1870. options = this.options,
  1871. imageData = this.imageData;
  1872. x = Number(x);
  1873. y = Number(y);
  1874. if (this.viewed && !this.played && options.movable) {
  1875. var oldX = imageData.x;
  1876. var oldY = imageData.y;
  1877. var changed = false;
  1878. if (isNumber(x)) {
  1879. changed = true;
  1880. } else {
  1881. x = oldX;
  1882. }
  1883. if (isNumber(y)) {
  1884. changed = true;
  1885. } else {
  1886. y = oldY;
  1887. }
  1888. if (changed) {
  1889. if (isFunction(options.move)) {
  1890. addListener(element, EVENT_MOVE, options.move, {
  1891. once: true
  1892. });
  1893. }
  1894. if (dispatchEvent(element, EVENT_MOVE, {
  1895. x: x,
  1896. y: y,
  1897. oldX: oldX,
  1898. oldY: oldY,
  1899. originalEvent: _originalEvent
  1900. }) === false) {
  1901. return this;
  1902. }
  1903. imageData.x = x;
  1904. imageData.y = y;
  1905. imageData.left = x;
  1906. imageData.top = y;
  1907. this.moving = true;
  1908. this.renderImage(function () {
  1909. _this3.moving = false;
  1910. if (isFunction(options.moved)) {
  1911. addListener(element, EVENT_MOVED, options.moved, {
  1912. once: true
  1913. });
  1914. }
  1915. dispatchEvent(element, EVENT_MOVED, {
  1916. x: x,
  1917. y: y,
  1918. oldX: oldX,
  1919. oldY: oldY,
  1920. originalEvent: _originalEvent
  1921. }, {
  1922. cancelable: false
  1923. });
  1924. });
  1925. }
  1926. }
  1927. return this;
  1928. },
  1929. /**
  1930. * Rotate the image with a relative degree.
  1931. * @param {number} degree - The rotate degree.
  1932. * @returns {Viewer} this
  1933. */
  1934. rotate: function rotate(degree) {
  1935. this.rotateTo((this.imageData.rotate || 0) + Number(degree));
  1936. return this;
  1937. },
  1938. /**
  1939. * Rotate the image to an absolute degree.
  1940. * @param {number} degree - The rotate degree.
  1941. * @returns {Viewer} this
  1942. */
  1943. rotateTo: function rotateTo(degree) {
  1944. var _this4 = this;
  1945. var element = this.element,
  1946. options = this.options,
  1947. imageData = this.imageData;
  1948. degree = Number(degree);
  1949. if (isNumber(degree) && this.viewed && !this.played && options.rotatable) {
  1950. var oldDegree = imageData.rotate;
  1951. if (isFunction(options.rotate)) {
  1952. addListener(element, EVENT_ROTATE, options.rotate, {
  1953. once: true
  1954. });
  1955. }
  1956. if (dispatchEvent(element, EVENT_ROTATE, {
  1957. degree: degree,
  1958. oldDegree: oldDegree
  1959. }) === false) {
  1960. return this;
  1961. }
  1962. imageData.rotate = degree;
  1963. this.rotating = true;
  1964. this.renderImage(function () {
  1965. _this4.rotating = false;
  1966. if (isFunction(options.rotated)) {
  1967. addListener(element, EVENT_ROTATED, options.rotated, {
  1968. once: true
  1969. });
  1970. }
  1971. dispatchEvent(element, EVENT_ROTATED, {
  1972. degree: degree,
  1973. oldDegree: oldDegree
  1974. }, {
  1975. cancelable: false
  1976. });
  1977. });
  1978. }
  1979. return this;
  1980. },
  1981. /**
  1982. * Scale the image on the x-axis.
  1983. * @param {number} scaleX - The scale ratio on the x-axis.
  1984. * @returns {Viewer} this
  1985. */
  1986. scaleX: function scaleX(_scaleX) {
  1987. this.scale(_scaleX, this.imageData.scaleY);
  1988. return this;
  1989. },
  1990. /**
  1991. * Scale the image on the y-axis.
  1992. * @param {number} scaleY - The scale ratio on the y-axis.
  1993. * @returns {Viewer} this
  1994. */
  1995. scaleY: function scaleY(_scaleY) {
  1996. this.scale(this.imageData.scaleX, _scaleY);
  1997. return this;
  1998. },
  1999. /**
  2000. * Scale the image.
  2001. * @param {number} scaleX - The scale ratio on the x-axis.
  2002. * @param {number} [scaleY=scaleX] - The scale ratio on the y-axis.
  2003. * @returns {Viewer} this
  2004. */
  2005. scale: function scale(scaleX) {
  2006. var _this5 = this;
  2007. var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX;
  2008. var element = this.element,
  2009. options = this.options,
  2010. imageData = this.imageData;
  2011. scaleX = Number(scaleX);
  2012. scaleY = Number(scaleY);
  2013. if (this.viewed && !this.played && options.scalable) {
  2014. var oldScaleX = imageData.scaleX;
  2015. var oldScaleY = imageData.scaleY;
  2016. var changed = false;
  2017. if (isNumber(scaleX)) {
  2018. changed = true;
  2019. } else {
  2020. scaleX = oldScaleX;
  2021. }
  2022. if (isNumber(scaleY)) {
  2023. changed = true;
  2024. } else {
  2025. scaleY = oldScaleY;
  2026. }
  2027. if (changed) {
  2028. if (isFunction(options.scale)) {
  2029. addListener(element, EVENT_SCALE, options.scale, {
  2030. once: true
  2031. });
  2032. }
  2033. if (dispatchEvent(element, EVENT_SCALE, {
  2034. scaleX: scaleX,
  2035. scaleY: scaleY,
  2036. oldScaleX: oldScaleX,
  2037. oldScaleY: oldScaleY
  2038. }) === false) {
  2039. return this;
  2040. }
  2041. imageData.scaleX = scaleX;
  2042. imageData.scaleY = scaleY;
  2043. this.scaling = true;
  2044. this.renderImage(function () {
  2045. _this5.scaling = false;
  2046. if (isFunction(options.scaled)) {
  2047. addListener(element, EVENT_SCALED, options.scaled, {
  2048. once: true
  2049. });
  2050. }
  2051. dispatchEvent(element, EVENT_SCALED, {
  2052. scaleX: scaleX,
  2053. scaleY: scaleY,
  2054. oldScaleX: oldScaleX,
  2055. oldScaleY: oldScaleY
  2056. }, {
  2057. cancelable: false
  2058. });
  2059. });
  2060. }
  2061. }
  2062. return this;
  2063. },
  2064. /**
  2065. * Zoom the image with a relative ratio.
  2066. * @param {number} ratio - The target ratio.
  2067. * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
  2068. * @param {Event} [_originalEvent=null] - The original event if any.
  2069. * @returns {Viewer} this
  2070. */
  2071. zoom: function zoom(ratio) {
  2072. var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2073. var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  2074. var imageData = this.imageData;
  2075. ratio = Number(ratio);
  2076. if (ratio < 0) {
  2077. ratio = 1 / (1 - ratio);
  2078. } else {
  2079. ratio = 1 + ratio;
  2080. }
  2081. this.zoomTo(imageData.width * ratio / imageData.naturalWidth, hasTooltip, _originalEvent);
  2082. return this;
  2083. },
  2084. /**
  2085. * Zoom the image to an absolute ratio.
  2086. * @param {number} ratio - The target ratio.
  2087. * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
  2088. * @param {Event} [_originalEvent=null] - The original event if any.
  2089. * @param {Event} [_zoomable=false] - Indicates if the current zoom is available or not.
  2090. * @returns {Viewer} this
  2091. */
  2092. zoomTo: function zoomTo(ratio) {
  2093. var _this6 = this;
  2094. var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  2095. var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  2096. var _zoomable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  2097. var element = this.element,
  2098. options = this.options,
  2099. pointers = this.pointers,
  2100. imageData = this.imageData;
  2101. var x = imageData.x,
  2102. y = imageData.y,
  2103. width = imageData.width,
  2104. height = imageData.height,
  2105. naturalWidth = imageData.naturalWidth,
  2106. naturalHeight = imageData.naturalHeight;
  2107. ratio = Math.max(0, ratio);
  2108. if (isNumber(ratio) && this.viewed && !this.played && (_zoomable || options.zoomable)) {
  2109. if (!_zoomable) {
  2110. var minZoomRatio = Math.max(0.01, options.minZoomRatio);
  2111. var maxZoomRatio = Math.min(100, options.maxZoomRatio);
  2112. ratio = Math.min(Math.max(ratio, minZoomRatio), maxZoomRatio);
  2113. }
  2114. if (_originalEvent && options.zoomRatio >= 0.055 && ratio > 0.95 && ratio < 1.05) {
  2115. ratio = 1;
  2116. }
  2117. var newWidth = naturalWidth * ratio;
  2118. var newHeight = naturalHeight * ratio;
  2119. var offsetWidth = newWidth - width;
  2120. var offsetHeight = newHeight - height;
  2121. var oldRatio = imageData.ratio;
  2122. if (isFunction(options.zoom)) {
  2123. addListener(element, EVENT_ZOOM, options.zoom, {
  2124. once: true
  2125. });
  2126. }
  2127. if (dispatchEvent(element, EVENT_ZOOM, {
  2128. ratio: ratio,
  2129. oldRatio: oldRatio,
  2130. originalEvent: _originalEvent
  2131. }) === false) {
  2132. return this;
  2133. }
  2134. this.zooming = true;
  2135. if (_originalEvent) {
  2136. var offset = getOffset(this.viewer);
  2137. var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : {
  2138. pageX: _originalEvent.pageX,
  2139. pageY: _originalEvent.pageY
  2140. }; // Zoom from the triggering point of the event
  2141. imageData.x -= offsetWidth * ((center.pageX - offset.left - x) / width);
  2142. imageData.y -= offsetHeight * ((center.pageY - offset.top - y) / height);
  2143. } else {
  2144. // Zoom from the center of the image
  2145. imageData.x -= offsetWidth / 2;
  2146. imageData.y -= offsetHeight / 2;
  2147. }
  2148. imageData.left = imageData.x;
  2149. imageData.top = imageData.y;
  2150. imageData.width = newWidth;
  2151. imageData.height = newHeight;
  2152. imageData.oldRatio = oldRatio;
  2153. imageData.ratio = ratio;
  2154. this.renderImage(function () {
  2155. _this6.zooming = false;
  2156. if (isFunction(options.zoomed)) {
  2157. addListener(element, EVENT_ZOOMED, options.zoomed, {
  2158. once: true
  2159. });
  2160. }
  2161. dispatchEvent(element, EVENT_ZOOMED, {
  2162. ratio: ratio,
  2163. oldRatio: oldRatio,
  2164. originalEvent: _originalEvent
  2165. }, {
  2166. cancelable: false
  2167. });
  2168. });
  2169. if (hasTooltip) {
  2170. this.tooltip();
  2171. }
  2172. }
  2173. return this;
  2174. },
  2175. /**
  2176. * Play the images
  2177. * @param {boolean|FullscreenOptions} [fullscreen=false] - Indicate if request fullscreen or not.
  2178. * @returns {Viewer} this
  2179. */
  2180. play: function play() {
  2181. var _this7 = this;
  2182. var fullscreen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  2183. if (!this.isShown || this.played) {
  2184. return this;
  2185. }
  2186. var element = this.element,
  2187. options = this.options;
  2188. if (isFunction(options.play)) {
  2189. addListener(element, EVENT_PLAY, options.play, {
  2190. once: true
  2191. });
  2192. }
  2193. if (dispatchEvent(element, EVENT_PLAY) === false) {
  2194. return this;
  2195. }
  2196. var player = this.player;
  2197. var onLoad = this.loadImage.bind(this);
  2198. var list = [];
  2199. var total = 0;
  2200. var index = 0;
  2201. this.played = true;
  2202. this.onLoadWhenPlay = onLoad;
  2203. if (fullscreen) {
  2204. this.requestFullscreen(fullscreen);
  2205. }
  2206. addClass(player, CLASS_SHOW);
  2207. forEach(this.items, function (item, i) {
  2208. var img = item.querySelector('img');
  2209. var image = document.createElement('img');
  2210. image.src = getData(img, 'originalUrl');
  2211. image.alt = img.getAttribute('alt');
  2212. image.referrerPolicy = img.referrerPolicy;
  2213. total += 1;
  2214. addClass(image, CLASS_FADE);
  2215. toggleClass(image, CLASS_TRANSITION, options.transition);
  2216. if (hasClass(item, CLASS_ACTIVE)) {
  2217. addClass(image, CLASS_IN);
  2218. index = i;
  2219. }
  2220. list.push(image);
  2221. addListener(image, EVENT_LOAD, onLoad, {
  2222. once: true
  2223. });
  2224. player.appendChild(image);
  2225. });
  2226. if (isNumber(options.interval) && options.interval > 0) {
  2227. var play = function play() {
  2228. _this7.playing = setTimeout(function () {
  2229. removeClass(list[index], CLASS_IN);
  2230. index += 1;
  2231. index = index < total ? index : 0;
  2232. addClass(list[index], CLASS_IN);
  2233. play();
  2234. }, options.interval);
  2235. };
  2236. if (total > 1) {
  2237. play();
  2238. }
  2239. }
  2240. return this;
  2241. },
  2242. // Stop play
  2243. stop: function stop() {
  2244. var _this8 = this;
  2245. if (!this.played) {
  2246. return this;
  2247. }
  2248. var element = this.element,
  2249. options = this.options;
  2250. if (isFunction(options.stop)) {
  2251. addListener(element, EVENT_STOP, options.stop, {
  2252. once: true
  2253. });
  2254. }
  2255. if (dispatchEvent(element, EVENT_STOP) === false) {
  2256. return this;
  2257. }
  2258. var player = this.player;
  2259. this.played = false;
  2260. clearTimeout(this.playing);
  2261. forEach(player.getElementsByTagName('img'), function (image) {
  2262. removeListener(image, EVENT_LOAD, _this8.onLoadWhenPlay);
  2263. });
  2264. removeClass(player, CLASS_SHOW);
  2265. player.innerHTML = '';
  2266. this.exitFullscreen();
  2267. return this;
  2268. },
  2269. // Enter modal mode (only available in inline mode)
  2270. full: function full() {
  2271. var _this9 = this;
  2272. var options = this.options,
  2273. viewer = this.viewer,
  2274. image = this.image,
  2275. list = this.list;
  2276. if (!this.isShown || this.played || this.fulled || !options.inline) {
  2277. return this;
  2278. }
  2279. this.fulled = true;
  2280. this.open();
  2281. addClass(this.button, CLASS_FULLSCREEN_EXIT);
  2282. if (options.transition) {
  2283. removeClass(list, CLASS_TRANSITION);
  2284. if (this.viewed) {
  2285. removeClass(image, CLASS_TRANSITION);
  2286. }
  2287. }
  2288. addClass(viewer, CLASS_FIXED);
  2289. viewer.setAttribute('role', 'dialog');
  2290. viewer.setAttribute('aria-labelledby', this.title.id);
  2291. viewer.setAttribute('aria-modal', true);
  2292. viewer.removeAttribute('style');
  2293. setStyle(viewer, {
  2294. zIndex: options.zIndex
  2295. });
  2296. if (options.focus) {
  2297. this.enforceFocus();
  2298. }
  2299. this.initContainer();
  2300. this.viewerData = assign({}, this.containerData);
  2301. this.renderList();
  2302. if (this.viewed) {
  2303. this.initImage(function () {
  2304. _this9.renderImage(function () {
  2305. if (options.transition) {
  2306. setTimeout(function () {
  2307. addClass(image, CLASS_TRANSITION);
  2308. addClass(list, CLASS_TRANSITION);
  2309. }, 0);
  2310. }
  2311. });
  2312. });
  2313. }
  2314. return this;
  2315. },
  2316. // Exit modal mode (only available in inline mode)
  2317. exit: function exit() {
  2318. var _this10 = this;
  2319. var options = this.options,
  2320. viewer = this.viewer,
  2321. image = this.image,
  2322. list = this.list;
  2323. if (!this.isShown || this.played || !this.fulled || !options.inline) {
  2324. return this;
  2325. }
  2326. this.fulled = false;
  2327. this.close();
  2328. removeClass(this.button, CLASS_FULLSCREEN_EXIT);
  2329. if (options.transition) {
  2330. removeClass(list, CLASS_TRANSITION);
  2331. if (this.viewed) {
  2332. removeClass(image, CLASS_TRANSITION);
  2333. }
  2334. }
  2335. if (options.focus) {
  2336. this.clearEnforceFocus();
  2337. }
  2338. viewer.removeAttribute('role');
  2339. viewer.removeAttribute('aria-labelledby');
  2340. viewer.removeAttribute('aria-modal');
  2341. removeClass(viewer, CLASS_FIXED);
  2342. setStyle(viewer, {
  2343. zIndex: options.zIndexInline
  2344. });
  2345. this.viewerData = assign({}, this.parentData);
  2346. this.renderViewer();
  2347. this.renderList();
  2348. if (this.viewed) {
  2349. this.initImage(function () {
  2350. _this10.renderImage(function () {
  2351. if (options.transition) {
  2352. setTimeout(function () {
  2353. addClass(image, CLASS_TRANSITION);
  2354. addClass(list, CLASS_TRANSITION);
  2355. }, 0);
  2356. }
  2357. });
  2358. });
  2359. }
  2360. return this;
  2361. },
  2362. // Show the current ratio of the image with percentage
  2363. tooltip: function tooltip() {
  2364. var _this11 = this;
  2365. var options = this.options,
  2366. tooltipBox = this.tooltipBox,
  2367. imageData = this.imageData;
  2368. if (!this.viewed || this.played || !options.tooltip) {
  2369. return this;
  2370. }
  2371. tooltipBox.textContent = "".concat(Math.round(imageData.ratio * 100), "%");
  2372. if (!this.tooltipping) {
  2373. if (options.transition) {
  2374. if (this.fading) {
  2375. dispatchEvent(tooltipBox, EVENT_TRANSITION_END);
  2376. }
  2377. addClass(tooltipBox, CLASS_SHOW);
  2378. addClass(tooltipBox, CLASS_FADE);
  2379. addClass(tooltipBox, CLASS_TRANSITION);
  2380. tooltipBox.removeAttribute('aria-hidden'); // Force reflow to enable CSS3 transition
  2381. tooltipBox.initialOffsetWidth = tooltipBox.offsetWidth;
  2382. addClass(tooltipBox, CLASS_IN);
  2383. } else {
  2384. addClass(tooltipBox, CLASS_SHOW);
  2385. tooltipBox.removeAttribute('aria-hidden');
  2386. }
  2387. } else {
  2388. clearTimeout(this.tooltipping);
  2389. }
  2390. this.tooltipping = setTimeout(function () {
  2391. if (options.transition) {
  2392. addListener(tooltipBox, EVENT_TRANSITION_END, function () {
  2393. removeClass(tooltipBox, CLASS_SHOW);
  2394. removeClass(tooltipBox, CLASS_FADE);
  2395. removeClass(tooltipBox, CLASS_TRANSITION);
  2396. tooltipBox.setAttribute('aria-hidden', true);
  2397. _this11.fading = false;
  2398. }, {
  2399. once: true
  2400. });
  2401. removeClass(tooltipBox, CLASS_IN);
  2402. _this11.fading = true;
  2403. } else {
  2404. removeClass(tooltipBox, CLASS_SHOW);
  2405. tooltipBox.setAttribute('aria-hidden', true);
  2406. }
  2407. _this11.tooltipping = false;
  2408. }, 1000);
  2409. return this;
  2410. },
  2411. /**
  2412. * Toggle the image size between its current size and natural size
  2413. * @param {Event} [_originalEvent=null] - The original event if any.
  2414. * @returns {Viewer} this
  2415. */
  2416. toggle: function toggle() {
  2417. var _originalEvent = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  2418. if (this.imageData.ratio === 1) {
  2419. this.zoomTo(this.imageData.oldRatio, true, _originalEvent);
  2420. } else {
  2421. this.zoomTo(1, true, _originalEvent);
  2422. }
  2423. return this;
  2424. },
  2425. // Reset the image to its initial state
  2426. reset: function reset() {
  2427. if (this.viewed && !this.played) {
  2428. this.imageData = assign({}, this.initialImageData);
  2429. this.renderImage();
  2430. }
  2431. return this;
  2432. },
  2433. // Update viewer when images changed
  2434. update: function update() {
  2435. var _this12 = this;
  2436. var element = this.element,
  2437. options = this.options,
  2438. isImg = this.isImg; // Destroy viewer if the target image was deleted
  2439. if (isImg && !element.parentNode) {
  2440. return this.destroy();
  2441. }
  2442. var images = [];
  2443. forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
  2444. if (isFunction(options.filter)) {
  2445. if (options.filter.call(_this12, image)) {
  2446. images.push(image);
  2447. }
  2448. } else if (_this12.getImageURL(image)) {
  2449. images.push(image);
  2450. }
  2451. });
  2452. if (!images.length) {
  2453. return this;
  2454. }
  2455. this.images = images;
  2456. this.length = images.length;
  2457. if (this.ready) {
  2458. var changedIndexes = [];
  2459. forEach(this.items, function (item, i) {
  2460. var img = item.querySelector('img');
  2461. var image = images[i];
  2462. if (image && img) {
  2463. if (image.src !== img.src // Title changed (#408)
  2464. || image.alt !== img.alt) {
  2465. changedIndexes.push(i);
  2466. }
  2467. } else {
  2468. changedIndexes.push(i);
  2469. }
  2470. });
  2471. setStyle(this.list, {
  2472. width: 'auto'
  2473. });
  2474. this.initList();
  2475. if (this.isShown) {
  2476. if (this.length) {
  2477. if (this.viewed) {
  2478. var changedIndex = changedIndexes.indexOf(this.index);
  2479. if (changedIndex >= 0) {
  2480. this.viewed = false;
  2481. this.view(Math.max(Math.min(this.index - changedIndex, this.length - 1), 0));
  2482. } else {
  2483. var activeItem = this.items[this.index]; // Reactivate the current viewing item after reset the list.
  2484. addClass(activeItem, CLASS_ACTIVE);
  2485. activeItem.setAttribute('aria-selected', true);
  2486. }
  2487. }
  2488. } else {
  2489. this.image = null;
  2490. this.viewed = false;
  2491. this.index = 0;
  2492. this.imageData = {};
  2493. this.canvas.innerHTML = '';
  2494. this.title.innerHTML = '';
  2495. }
  2496. }
  2497. } else {
  2498. this.build();
  2499. }
  2500. return this;
  2501. },
  2502. // Destroy the viewer
  2503. destroy: function destroy() {
  2504. var element = this.element,
  2505. options = this.options;
  2506. if (!element[NAMESPACE]) {
  2507. return this;
  2508. }
  2509. this.destroyed = true;
  2510. if (this.ready) {
  2511. if (this.played) {
  2512. this.stop();
  2513. }
  2514. if (options.inline) {
  2515. if (this.fulled) {
  2516. this.exit();
  2517. }
  2518. this.unbind();
  2519. } else if (this.isShown) {
  2520. if (this.viewing) {
  2521. if (this.imageRendering) {
  2522. this.imageRendering.abort();
  2523. } else if (this.imageInitializing) {
  2524. this.imageInitializing.abort();
  2525. }
  2526. }
  2527. if (this.hiding) {
  2528. this.transitioning.abort();
  2529. }
  2530. this.hidden();
  2531. } else if (this.showing) {
  2532. this.transitioning.abort();
  2533. this.hidden();
  2534. }
  2535. this.ready = false;
  2536. this.viewer.parentNode.removeChild(this.viewer);
  2537. } else if (options.inline) {
  2538. if (this.delaying) {
  2539. this.delaying.abort();
  2540. } else if (this.initializing) {
  2541. this.initializing.abort();
  2542. }
  2543. }
  2544. if (!options.inline) {
  2545. removeListener(element, EVENT_CLICK, this.onStart);
  2546. }
  2547. element[NAMESPACE] = undefined;
  2548. return this;
  2549. }
  2550. };
  2551. var others = {
  2552. getImageURL: function getImageURL(image) {
  2553. var url = this.options.url;
  2554. if (isString(url)) {
  2555. url = image.getAttribute(url);
  2556. } else if (isFunction(url)) {
  2557. url = url.call(this, image);
  2558. } else {
  2559. url = '';
  2560. }
  2561. return url;
  2562. },
  2563. enforceFocus: function enforceFocus() {
  2564. var _this = this;
  2565. this.clearEnforceFocus();
  2566. addListener(document, EVENT_FOCUSIN, this.onFocusin = function (event) {
  2567. var viewer = _this.viewer;
  2568. var target = event.target;
  2569. if (target !== document && target !== viewer && !viewer.contains(target) // Avoid conflicts with other modals (#474)
  2570. && (target.getAttribute('tabindex') === null || target.getAttribute('aria-modal') !== 'true')) {
  2571. viewer.focus();
  2572. }
  2573. });
  2574. },
  2575. clearEnforceFocus: function clearEnforceFocus() {
  2576. if (this.onFocusin) {
  2577. removeListener(document, EVENT_FOCUSIN, this.onFocusin);
  2578. this.onFocusin = null;
  2579. }
  2580. },
  2581. open: function open() {
  2582. var body = this.body;
  2583. addClass(body, CLASS_OPEN);
  2584. body.style.paddingRight = "".concat(this.scrollbarWidth + (parseFloat(this.initialBodyComputedPaddingRight) || 0), "px");
  2585. },
  2586. close: function close() {
  2587. var body = this.body;
  2588. removeClass(body, CLASS_OPEN);
  2589. body.style.paddingRight = this.initialBodyPaddingRight;
  2590. },
  2591. shown: function shown() {
  2592. var element = this.element,
  2593. options = this.options,
  2594. viewer = this.viewer;
  2595. this.fulled = true;
  2596. this.isShown = true;
  2597. this.render();
  2598. this.bind();
  2599. this.showing = false;
  2600. if (options.focus) {
  2601. viewer.focus();
  2602. this.enforceFocus();
  2603. }
  2604. if (isFunction(options.shown)) {
  2605. addListener(element, EVENT_SHOWN, options.shown, {
  2606. once: true
  2607. });
  2608. }
  2609. if (dispatchEvent(element, EVENT_SHOWN) === false) {
  2610. return;
  2611. }
  2612. if (this.ready && this.isShown && !this.hiding) {
  2613. this.view(this.index);
  2614. }
  2615. },
  2616. hidden: function hidden() {
  2617. var element = this.element,
  2618. options = this.options,
  2619. viewer = this.viewer;
  2620. if (options.fucus) {
  2621. this.clearEnforceFocus();
  2622. }
  2623. this.fulled = false;
  2624. this.viewed = false;
  2625. this.isShown = false;
  2626. this.close();
  2627. this.unbind();
  2628. addClass(viewer, CLASS_HIDE);
  2629. viewer.removeAttribute('role');
  2630. viewer.removeAttribute('aria-labelledby');
  2631. viewer.removeAttribute('aria-modal');
  2632. viewer.setAttribute('aria-hidden', true);
  2633. this.resetList();
  2634. this.resetImage();
  2635. this.hiding = false;
  2636. if (!this.destroyed) {
  2637. if (isFunction(options.hidden)) {
  2638. addListener(element, EVENT_HIDDEN, options.hidden, {
  2639. once: true
  2640. });
  2641. }
  2642. dispatchEvent(element, EVENT_HIDDEN, null, {
  2643. cancelable: false
  2644. });
  2645. }
  2646. },
  2647. requestFullscreen: function requestFullscreen(options) {
  2648. var document = this.element.ownerDocument;
  2649. if (this.fulled && !(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) {
  2650. var documentElement = document.documentElement; // Element.requestFullscreen()
  2651. if (documentElement.requestFullscreen) {
  2652. // Avoid TypeError when convert `options` to dictionary
  2653. if (isPlainObject(options)) {
  2654. documentElement.requestFullscreen(options);
  2655. } else {
  2656. documentElement.requestFullscreen();
  2657. }
  2658. } else if (documentElement.webkitRequestFullscreen) {
  2659. documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  2660. } else if (documentElement.mozRequestFullScreen) {
  2661. documentElement.mozRequestFullScreen();
  2662. } else if (documentElement.msRequestFullscreen) {
  2663. documentElement.msRequestFullscreen();
  2664. }
  2665. }
  2666. },
  2667. exitFullscreen: function exitFullscreen() {
  2668. var document = this.element.ownerDocument;
  2669. if (this.fulled && (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) {
  2670. // Document.exitFullscreen()
  2671. if (document.exitFullscreen) {
  2672. document.exitFullscreen();
  2673. } else if (document.webkitExitFullscreen) {
  2674. document.webkitExitFullscreen();
  2675. } else if (document.mozCancelFullScreen) {
  2676. document.mozCancelFullScreen();
  2677. } else if (document.msExitFullscreen) {
  2678. document.msExitFullscreen();
  2679. }
  2680. }
  2681. },
  2682. change: function change(event) {
  2683. var options = this.options,
  2684. pointers = this.pointers;
  2685. var pointer = pointers[Object.keys(pointers)[0]]; // In the case of the `pointers` object is empty (#421)
  2686. if (!pointer) {
  2687. return;
  2688. }
  2689. var offsetX = pointer.endX - pointer.startX;
  2690. var offsetY = pointer.endY - pointer.startY;
  2691. switch (this.action) {
  2692. // Move the current image
  2693. case ACTION_MOVE:
  2694. this.move(offsetX, offsetY, event);
  2695. break;
  2696. // Zoom the current image
  2697. case ACTION_ZOOM:
  2698. this.zoom(getMaxZoomRatio(pointers), false, event);
  2699. break;
  2700. case ACTION_SWITCH: {
  2701. this.action = 'switched';
  2702. var absoluteOffsetX = Math.abs(offsetX);
  2703. if (absoluteOffsetX > 1 && absoluteOffsetX > Math.abs(offsetY)) {
  2704. // Empty `pointers` as `touchend` event will not be fired after swiped in iOS browsers.
  2705. this.pointers = {};
  2706. if (offsetX > 1) {
  2707. this.prev(options.loop);
  2708. } else if (offsetX < -1) {
  2709. this.next(options.loop);
  2710. }
  2711. }
  2712. break;
  2713. }
  2714. } // Override
  2715. forEach(pointers, function (p) {
  2716. p.startX = p.endX;
  2717. p.startY = p.endY;
  2718. });
  2719. },
  2720. isSwitchable: function isSwitchable() {
  2721. var imageData = this.imageData,
  2722. viewerData = this.viewerData;
  2723. return this.length > 1 && imageData.x >= 0 && imageData.y >= 0 && imageData.width <= viewerData.width && imageData.height <= viewerData.height;
  2724. }
  2725. };
  2726. var AnotherViewer = WINDOW.Viewer;
  2727. var getUniqueID = function (id) {
  2728. return function () {
  2729. id += 1;
  2730. return id;
  2731. };
  2732. }(-1);
  2733. var Viewer = /*#__PURE__*/function () {
  2734. /**
  2735. * Create a new Viewer.
  2736. * @param {Element} element - The target element for viewing.
  2737. * @param {Object} [options={}] - The configuration options.
  2738. */
  2739. function Viewer(element) {
  2740. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2741. _classCallCheck(this, Viewer);
  2742. if (!element || element.nodeType !== 1) {
  2743. throw new Error('The first argument is required and must be an element.');
  2744. }
  2745. this.element = element;
  2746. this.options = assign({}, DEFAULTS, isPlainObject(options) && options);
  2747. this.action = false;
  2748. this.fading = false;
  2749. this.fulled = false;
  2750. this.hiding = false;
  2751. this.imageClicked = false;
  2752. this.imageData = {};
  2753. this.index = this.options.initialViewIndex;
  2754. this.isImg = false;
  2755. this.isShown = false;
  2756. this.length = 0;
  2757. this.moving = false;
  2758. this.played = false;
  2759. this.playing = false;
  2760. this.pointers = {};
  2761. this.ready = false;
  2762. this.rotating = false;
  2763. this.scaling = false;
  2764. this.showing = false;
  2765. this.timeout = false;
  2766. this.tooltipping = false;
  2767. this.viewed = false;
  2768. this.viewing = false;
  2769. this.wheeling = false;
  2770. this.zooming = false;
  2771. this.id = getUniqueID();
  2772. this.init();
  2773. }
  2774. _createClass(Viewer, [{
  2775. key: "init",
  2776. value: function init() {
  2777. var _this = this;
  2778. var element = this.element,
  2779. options = this.options;
  2780. if (element[NAMESPACE]) {
  2781. return;
  2782. }
  2783. element[NAMESPACE] = this; // The `focus` option requires the `keyboard` option set to `true`.
  2784. if (options.focus && !options.keyboard) {
  2785. options.focus = false;
  2786. }
  2787. var isImg = element.localName === 'img';
  2788. var images = [];
  2789. forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
  2790. if (isFunction(options.filter)) {
  2791. if (options.filter.call(_this, image)) {
  2792. images.push(image);
  2793. }
  2794. } else if (_this.getImageURL(image)) {
  2795. images.push(image);
  2796. }
  2797. });
  2798. this.isImg = isImg;
  2799. this.length = images.length;
  2800. this.images = images;
  2801. this.initBody(); // Override `transition` option if it is not supported
  2802. if (isUndefined(document.createElement(NAMESPACE).style.transition)) {
  2803. options.transition = false;
  2804. }
  2805. if (options.inline) {
  2806. var count = 0;
  2807. var progress = function progress() {
  2808. count += 1;
  2809. if (count === _this.length) {
  2810. var timeout;
  2811. _this.initializing = false;
  2812. _this.delaying = {
  2813. abort: function abort() {
  2814. clearTimeout(timeout);
  2815. }
  2816. }; // build asynchronously to keep `this.viewer` is accessible in `ready` event handler.
  2817. timeout = setTimeout(function () {
  2818. _this.delaying = false;
  2819. _this.build();
  2820. }, 0);
  2821. }
  2822. };
  2823. this.initializing = {
  2824. abort: function abort() {
  2825. forEach(images, function (image) {
  2826. if (!image.complete) {
  2827. removeListener(image, EVENT_LOAD, progress);
  2828. }
  2829. });
  2830. }
  2831. };
  2832. forEach(images, function (image) {
  2833. if (image.complete) {
  2834. progress();
  2835. } else {
  2836. addListener(image, EVENT_LOAD, progress, {
  2837. once: true
  2838. });
  2839. }
  2840. });
  2841. } else {
  2842. addListener(element, EVENT_CLICK, this.onStart = function (_ref) {
  2843. var target = _ref.target;
  2844. if (target.localName === 'img' && (!isFunction(options.filter) || options.filter.call(_this, target))) {
  2845. _this.view(_this.images.indexOf(target));
  2846. }
  2847. });
  2848. }
  2849. }
  2850. }, {
  2851. key: "build",
  2852. value: function build() {
  2853. if (this.ready) {
  2854. return;
  2855. }
  2856. var element = this.element,
  2857. options = this.options;
  2858. var parent = element.parentNode;
  2859. var template = document.createElement('div');
  2860. template.innerHTML = TEMPLATE;
  2861. var viewer = template.querySelector(".".concat(NAMESPACE, "-container"));
  2862. var title = viewer.querySelector(".".concat(NAMESPACE, "-title"));
  2863. var toolbar = viewer.querySelector(".".concat(NAMESPACE, "-toolbar"));
  2864. var navbar = viewer.querySelector(".".concat(NAMESPACE, "-navbar"));
  2865. var button = viewer.querySelector(".".concat(NAMESPACE, "-button"));
  2866. var canvas = viewer.querySelector(".".concat(NAMESPACE, "-canvas"));
  2867. this.parent = parent;
  2868. this.viewer = viewer;
  2869. this.title = title;
  2870. this.toolbar = toolbar;
  2871. this.navbar = navbar;
  2872. this.button = button;
  2873. this.canvas = canvas;
  2874. this.footer = viewer.querySelector(".".concat(NAMESPACE, "-footer"));
  2875. this.tooltipBox = viewer.querySelector(".".concat(NAMESPACE, "-tooltip"));
  2876. this.player = viewer.querySelector(".".concat(NAMESPACE, "-player"));
  2877. this.list = viewer.querySelector(".".concat(NAMESPACE, "-list"));
  2878. viewer.id = "".concat(NAMESPACE).concat(this.id);
  2879. title.id = "".concat(NAMESPACE, "Title").concat(this.id);
  2880. addClass(title, !options.title ? CLASS_HIDE : getResponsiveClass(Array.isArray(options.title) ? options.title[0] : options.title));
  2881. addClass(navbar, !options.navbar ? CLASS_HIDE : getResponsiveClass(options.navbar));
  2882. toggleClass(button, CLASS_HIDE, !options.button);
  2883. if (options.keyboard) {
  2884. button.setAttribute('tabindex', 0);
  2885. }
  2886. if (options.backdrop) {
  2887. addClass(viewer, "".concat(NAMESPACE, "-backdrop"));
  2888. if (!options.inline && options.backdrop !== 'static') {
  2889. setData(canvas, DATA_ACTION, 'hide');
  2890. }
  2891. }
  2892. if (isString(options.className) && options.className) {
  2893. // In case there are multiple class names
  2894. options.className.split(REGEXP_SPACES).forEach(function (className) {
  2895. addClass(viewer, className);
  2896. });
  2897. }
  2898. if (options.toolbar) {
  2899. var list = document.createElement('ul');
  2900. var custom = isPlainObject(options.toolbar);
  2901. var zoomButtons = BUTTONS.slice(0, 3);
  2902. var rotateButtons = BUTTONS.slice(7, 9);
  2903. var scaleButtons = BUTTONS.slice(9);
  2904. if (!custom) {
  2905. addClass(toolbar, getResponsiveClass(options.toolbar));
  2906. }
  2907. forEach(custom ? options.toolbar : BUTTONS, function (value, index) {
  2908. var deep = custom && isPlainObject(value);
  2909. var name = custom ? hyphenate(index) : value;
  2910. var show = deep && !isUndefined(value.show) ? value.show : value;
  2911. if (!show || !options.zoomable && zoomButtons.indexOf(name) !== -1 || !options.rotatable && rotateButtons.indexOf(name) !== -1 || !options.scalable && scaleButtons.indexOf(name) !== -1) {
  2912. return;
  2913. }
  2914. var size = deep && !isUndefined(value.size) ? value.size : value;
  2915. var click = deep && !isUndefined(value.click) ? value.click : value;
  2916. var item = document.createElement('li');
  2917. if (options.keyboard) {
  2918. item.setAttribute('tabindex', 0);
  2919. }
  2920. item.setAttribute('role', 'button');
  2921. addClass(item, "".concat(NAMESPACE, "-").concat(name));
  2922. if (!isFunction(click)) {
  2923. setData(item, DATA_ACTION, name);
  2924. }
  2925. if (isNumber(show)) {
  2926. addClass(item, getResponsiveClass(show));
  2927. }
  2928. if (['small', 'large'].indexOf(size) !== -1) {
  2929. addClass(item, "".concat(NAMESPACE, "-").concat(size));
  2930. } else if (name === 'play') {
  2931. addClass(item, "".concat(NAMESPACE, "-large"));
  2932. }
  2933. if (isFunction(click)) {
  2934. addListener(item, EVENT_CLICK, click);
  2935. }
  2936. list.appendChild(item);
  2937. });
  2938. toolbar.appendChild(list);
  2939. } else {
  2940. addClass(toolbar, CLASS_HIDE);
  2941. }
  2942. if (!options.rotatable) {
  2943. var rotates = toolbar.querySelectorAll('li[class*="rotate"]');
  2944. addClass(rotates, CLASS_INVISIBLE);
  2945. forEach(rotates, function (rotate) {
  2946. toolbar.appendChild(rotate);
  2947. });
  2948. }
  2949. if (options.inline) {
  2950. addClass(button, CLASS_FULLSCREEN);
  2951. setStyle(viewer, {
  2952. zIndex: options.zIndexInline
  2953. });
  2954. if (window.getComputedStyle(parent).position === 'static') {
  2955. setStyle(parent, {
  2956. position: 'relative'
  2957. });
  2958. }
  2959. parent.insertBefore(viewer, element.nextSibling);
  2960. } else {
  2961. addClass(button, CLASS_CLOSE);
  2962. addClass(viewer, CLASS_FIXED);
  2963. addClass(viewer, CLASS_FADE);
  2964. addClass(viewer, CLASS_HIDE);
  2965. setStyle(viewer, {
  2966. zIndex: options.zIndex
  2967. });
  2968. var container = options.container;
  2969. if (isString(container)) {
  2970. container = element.ownerDocument.querySelector(container);
  2971. }
  2972. if (!container) {
  2973. container = this.body;
  2974. }
  2975. container.appendChild(viewer);
  2976. }
  2977. if (options.inline) {
  2978. this.render();
  2979. this.bind();
  2980. this.isShown = true;
  2981. }
  2982. this.ready = true;
  2983. if (isFunction(options.ready)) {
  2984. addListener(element, EVENT_READY, options.ready, {
  2985. once: true
  2986. });
  2987. }
  2988. if (dispatchEvent(element, EVENT_READY) === false) {
  2989. this.ready = false;
  2990. return;
  2991. }
  2992. if (this.ready && options.inline) {
  2993. this.view(this.index);
  2994. }
  2995. }
  2996. /**
  2997. * Get the no conflict viewer class.
  2998. * @returns {Viewer} The viewer class.
  2999. */
  3000. }], [{
  3001. key: "noConflict",
  3002. value: function noConflict() {
  3003. window.Viewer = AnotherViewer;
  3004. return Viewer;
  3005. }
  3006. /**
  3007. * Change the default options.
  3008. * @param {Object} options - The new default options.
  3009. */
  3010. }, {
  3011. key: "setDefaults",
  3012. value: function setDefaults(options) {
  3013. assign(DEFAULTS, isPlainObject(options) && options);
  3014. }
  3015. }]);
  3016. return Viewer;
  3017. }();
  3018. assign(Viewer.prototype, render, events, handlers, methods, others);
  3019. return Viewer;
  3020. }));