viewer.js 99 KB

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