viewer.js 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404
  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','one-to-ones2','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. viewerData = this.viewerData,
  880. imageData = this.imageData;
  881. setStyle(image, assign({
  882. width: imageData.width,
  883. height: imageData.height,
  884. marginLeft: imageData.left,
  885. marginTop: imageData.top
  886. }, getTransforms(imageData)));
  887. if (done) {
  888. if (this.viewing && this.options.transition) {
  889. var onTransitionEnd = function onTransitionEnd() {
  890. _this3.imageRendering = false;
  891. done();
  892. };
  893. this.imageRendering = {
  894. abort: function abort() {
  895. removeListener(image, EVENT_TRANSITION_END, onTransitionEnd);
  896. }
  897. };
  898. addListener(image, EVENT_TRANSITION_END, onTransitionEnd, {
  899. once: true
  900. });
  901. } else {
  902. done();
  903. }
  904. }
  905. //pxn
  906. var userAgent = window.navigator.userAgent;
  907. if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i) || userAgent.match(/android/i))
  908. {
  909. var imageLi=image.parentNode;
  910. if (image.width>viewerData.width)
  911. {
  912. imageLi.style.width='auto';
  913. if (imageData.left<0)
  914. {
  915. imageLi.style.paddingLeft =(imageData.left*-1).toString()+'px';
  916. }
  917. }else {
  918. imageLi.style.width=viewerData.width.toString()+'px';
  919. imageLi.style.paddingLeft='0';
  920. }
  921. this.isSwitchable3();
  922. }
  923. },
  924. resetImage: function resetImage() {
  925. // this.image only defined after viewed
  926. if (this.viewing || this.viewed) {
  927. var image = this.image;
  928. if (this.viewing) {
  929. this.viewing.abort();
  930. }
  931. image.parentNode.removeChild(image);
  932. this.image = null;
  933. }
  934. }
  935. };
  936. var events = {
  937. bind: function bind() {
  938. var element = this.element,
  939. viewer = this.viewer;
  940. addListener(viewer, EVENT_CLICK, this.onClick = this.click.bind(this));
  941. addListener(viewer, EVENT_WHEEL, this.onWheel = this.wheel.bind(this));
  942. addListener(viewer, EVENT_DRAG_START, this.onDragStart = this.dragstart.bind(this));
  943. addListener(this.canvas, EVENT_POINTER_DOWN, this.onPointerDown = this.pointerdown.bind(this));
  944. addListener(element.ownerDocument, EVENT_POINTER_MOVE, this.onPointerMove = this.pointermove.bind(this));
  945. addListener(element.ownerDocument, EVENT_POINTER_UP, this.onPointerUp = this.pointerup.bind(this));
  946. addListener(element.ownerDocument, EVENT_KEY_DOWN, this.onKeyDown = this.keydown.bind(this));
  947. addListener(window, EVENT_RESIZE, this.onResize = this.resize.bind(this));
  948. },
  949. unbind: function unbind() {
  950. var element = this.element,
  951. viewer = this.viewer;
  952. removeListener(viewer, EVENT_CLICK, this.onClick);
  953. removeListener(viewer, EVENT_WHEEL, this.onWheel);
  954. removeListener(viewer, EVENT_DRAG_START, this.onDragStart);
  955. removeListener(this.canvas, EVENT_POINTER_DOWN, this.onPointerDown);
  956. removeListener(element.ownerDocument, EVENT_POINTER_MOVE, this.onPointerMove);
  957. removeListener(element.ownerDocument, EVENT_POINTER_UP, this.onPointerUp);
  958. removeListener(element.ownerDocument, EVENT_KEY_DOWN, this.onKeyDown);
  959. removeListener(window, EVENT_RESIZE, this.onResize);
  960. }
  961. };
  962. var handlers = {
  963. click: function click(_ref) {
  964. var target = _ref.target;
  965. var options = this.options,
  966. imageData = this.imageData;
  967. var action = getData(target, 'action');
  968. switch (action) {
  969. case 'mix':
  970. if (this.played) {
  971. this.stop();
  972. } else if (options.inline) {
  973. if (this.fulled) {
  974. this.exit();
  975. } else {
  976. this.full();
  977. }
  978. } else {
  979. this.hide();
  980. }
  981. break;
  982. case 'hide':
  983. this.hide();
  984. break;
  985. case 'view':
  986. this.view(getData(target, 'index'));
  987. break;
  988. case 'zoom-ins':
  989. this.zoom(0.1, true);
  990. break;
  991. case 'zoom-outs':
  992. this.zoom(-0.1, true);
  993. break;
  994. case 'reset':
  995. this.reset();
  996. break;
  997. case 'prevs':
  998. this.prev(options.loop);
  999. break;
  1000. case 'plays':
  1001. this.play(options.fullscreen);
  1002. break;
  1003. case 'nexts':
  1004. this.next(options.loop);
  1005. break;
  1006. case 'one-to-ones':
  1007. case 'one-to-ones2':
  1008. this.normal();
  1009. break;
  1010. //放大
  1011. case 'enlarge':
  1012. this.toggle();
  1013. break;
  1014. case 'toolbar':
  1015. break;
  1016. //case 'rotate-left':
  1017. // this.rotate(-90);
  1018. // break;
  1019. //
  1020. //case 'rotate-right':
  1021. // this.rotate(90);
  1022. // break;
  1023. //
  1024. //case 'flip-horizontal':
  1025. // this.scaleX(-imageData.scaleX || -1);
  1026. // break;
  1027. //
  1028. //case 'flip-vertical':
  1029. // this.scaleY(-imageData.scaleY || -1);
  1030. // break;
  1031. default:
  1032. if (this.played) {
  1033. this.stop();
  1034. return;
  1035. }
  1036. if (target.className ==""
  1037. ||target.className =="viewer-toolbar"
  1038. ||target.className =="viewer-footer"
  1039. ||target.className =="viewer-title")
  1040. {
  1041. return;
  1042. }
  1043. this.hide();
  1044. }
  1045. },
  1046. load: function load() {
  1047. var _this = this;
  1048. if (this.timeout) {
  1049. clearTimeout(this.timeout);
  1050. this.timeout = false;
  1051. }
  1052. var element = this.element,
  1053. options = this.options,
  1054. image = this.image,
  1055. index = this.index,
  1056. viewerData = this.viewerData;
  1057. removeClass(image, CLASS_INVISIBLE);
  1058. if (options.loading) {
  1059. removeClass(this.canvas, CLASS_LOADING);
  1060. }
  1061. 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;';
  1062. this.initImage(function () {
  1063. toggleClass(image, CLASS_MOVE, options.movable);
  1064. toggleClass(image, CLASS_TRANSITION, options.transition);
  1065. _this.renderImage(function () {
  1066. _this.viewed = true;
  1067. _this.viewing = false;
  1068. if (isFunction(options.viewed)) {
  1069. addListener(element, EVENT_VIEWED, options.viewed, {
  1070. once: true
  1071. });
  1072. }
  1073. dispatchEvent(element, EVENT_VIEWED, {
  1074. originalImage: _this.images[index],
  1075. index: index,
  1076. image: image
  1077. });
  1078. });
  1079. });
  1080. },
  1081. loadImage: function loadImage(e) {
  1082. var image = e.target;
  1083. var parent = image.parentNode;
  1084. var parentWidth = parent.offsetWidth || 30;
  1085. var parentHeight = parent.offsetHeight || 50;
  1086. var filled = !!getData(image, 'filled');
  1087. getImageNaturalSizes(image, function (naturalWidth, naturalHeight) {
  1088. var aspectRatio = naturalWidth / naturalHeight;
  1089. var width = parentWidth;
  1090. var height = parentHeight;
  1091. if (parentHeight * aspectRatio > parentWidth) {
  1092. if (filled) {
  1093. width = parentHeight * aspectRatio;
  1094. } else {
  1095. height = parentWidth / aspectRatio;
  1096. }
  1097. } else if (filled) {
  1098. height = parentWidth / aspectRatio;
  1099. } else {
  1100. width = parentHeight * aspectRatio;
  1101. }
  1102. setStyle(image, assign({
  1103. width: width,
  1104. height: height
  1105. }, getTransforms({
  1106. translateX: (parentWidth - width) / 2,
  1107. translateY: (parentHeight - height) / 2
  1108. })));
  1109. });
  1110. },
  1111. keydown: function keydown(e) {
  1112. var options = this.options;
  1113. if (!this.fulled || !options.keyboard) {
  1114. return;
  1115. }
  1116. switch (e.keyCode || e.which || e.charCode) {
  1117. // Escape
  1118. case 27:
  1119. if (this.played) {
  1120. this.stop();
  1121. } else if (options.inline) {
  1122. if (this.fulled) {
  1123. this.exit();
  1124. }
  1125. } else {
  1126. this.hide();
  1127. }
  1128. break;
  1129. // Space
  1130. case 32:
  1131. if (this.played) {
  1132. this.stop();
  1133. }
  1134. break;
  1135. // ArrowLeft
  1136. case 37:
  1137. this.prev(options.loop);
  1138. break;
  1139. // ArrowUp
  1140. case 38:
  1141. // Prevent scroll on Firefox
  1142. e.preventDefault();
  1143. // Zoom in
  1144. this.zoom(options.zoomRatio, true);
  1145. break;
  1146. // ArrowRight
  1147. case 39:
  1148. this.next(options.loop);
  1149. break;
  1150. // ArrowDown
  1151. case 40:
  1152. // Prevent scroll on Firefox
  1153. e.preventDefault();
  1154. // Zoom out
  1155. this.zoom(-options.zoomRatio, true);
  1156. break;
  1157. // Ctrl + 0
  1158. case 48:
  1159. // Fall through
  1160. // Ctrl + 1
  1161. // eslint-disable-next-line no-fallthrough
  1162. case 49:
  1163. if (e.ctrlKey) {
  1164. e.preventDefault();
  1165. this.toggle();
  1166. }
  1167. break;
  1168. default:
  1169. }
  1170. },
  1171. dragstart: function dragstart(e) {
  1172. if (e.target.tagName.toLowerCase() === 'img') {
  1173. e.preventDefault();
  1174. }
  1175. },
  1176. pointerdown: function pointerdown(e) {
  1177. var options = this.options,
  1178. pointers = this.pointers;
  1179. if (!this.viewed || this.showing || this.viewing || this.hiding) {
  1180. return;
  1181. }
  1182. if (this.intervalTime!==undefined)
  1183. {
  1184. clearInterval(this.intervalTime);
  1185. }
  1186. if (e.changedTouches) {
  1187. forEach(e.changedTouches, function (touch) {
  1188. pointers[touch.identifier] = getPointer(touch);
  1189. });
  1190. } else {
  1191. pointers[e.pointerId || 0] = getPointer(e);
  1192. }
  1193. var action = options.movable ? ACTION_MOVE : false;
  1194. if (Object.keys(pointers).length > 1) {
  1195. action = ACTION_ZOOM;
  1196. } else if ((e.pointerType === 'touch' || e.type === 'touchstart')) {
  1197. // action = ACTION_SWITCH;
  1198. var ul=this.canvas.querySelector("ul");
  1199. this.ulLeft= parseInt(ul.style.marginLeft);
  1200. }
  1201. this.action = action;
  1202. },
  1203. pointermove: function pointermove(e) {
  1204. var options = this.options,
  1205. pointers = this.pointers,
  1206. action = this.action,
  1207. image = this.image;
  1208. if (!this.viewed || !action) {
  1209. return;
  1210. }
  1211. e.preventDefault();
  1212. if (e.changedTouches) {
  1213. forEach(e.changedTouches, function (touch) {
  1214. assign(pointers[touch.identifier], getPointer(touch, true));
  1215. });
  1216. } else {
  1217. var pointerTmep=pointers[e.pointerId || 0];
  1218. if (pointerTmep==null||pointerTmep==undefined)
  1219. {
  1220. return;
  1221. }
  1222. assign(pointerTmep, getPointer(e, true));
  1223. }
  1224. if (action === ACTION_MOVE && options.transition && hasClass(image, CLASS_TRANSITION)) {
  1225. removeClass(image, CLASS_TRANSITION);
  1226. }
  1227. if (Object.keys(pointers).length > 1|| action===ACTION_SWITCH) {
  1228. }else if ((e.pointerType === 'touch' || e.type === 'touchmove') && this.isSwitchable2()) {
  1229. this.action = ACTION_SWITCH;
  1230. }
  1231. this.change(e);
  1232. },
  1233. pointerup: function pointerup(e) {
  1234. var action = this.action,
  1235. pointers = this.pointers;
  1236. if (e.changedTouches) {
  1237. forEach(e.changedTouches, function (touch) {
  1238. delete pointers[touch.identifier];
  1239. });
  1240. } else {
  1241. delete pointers[e.pointerId || 0];
  1242. }
  1243. if (!action) {
  1244. return;
  1245. }
  1246. if (action === ACTION_MOVE && this.options.transition) {
  1247. addClass(this.image, CLASS_TRANSITION);
  1248. }
  1249. if (Object.keys(pointers).length<=1&&action===ACTION_MOVE) {
  1250. this.isSwitchable3();
  1251. }
  1252. this.action = false;
  1253. },
  1254. resize: function resize() {
  1255. var _this2 = this;
  1256. if (!this.isShown || this.hiding) {
  1257. return;
  1258. }
  1259. this.initContainer();
  1260. this.initViewer();
  1261. this.renderViewer();
  1262. this.renderList();
  1263. if (this.viewed) {
  1264. this.initImage(function () {
  1265. _this2.renderImage();
  1266. });
  1267. }
  1268. if (this.played) {
  1269. if (this.options.fullscreen && this.fulled && !document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
  1270. this.stop();
  1271. return;
  1272. }
  1273. forEach(this.player.getElementsByTagName('img'), function (image) {
  1274. addListener(image, EVENT_LOAD, _this2.loadImage.bind(_this2), {
  1275. once: true
  1276. });
  1277. dispatchEvent(image, EVENT_LOAD);
  1278. });
  1279. }
  1280. },
  1281. wheel: function wheel(e) {
  1282. var _this3 = this;
  1283. if (!this.viewed) {
  1284. return;
  1285. }
  1286. e.preventDefault();
  1287. // Limit wheel speed to prevent zoom too fast
  1288. if (this.wheeling) {
  1289. return;
  1290. }
  1291. this.wheeling = true;
  1292. setTimeout(function () {
  1293. _this3.wheeling = false;
  1294. }, 50);
  1295. var ratio = Number(this.options.zoomRatio) || 0.1;
  1296. var delta = 1;
  1297. if (e.deltaY) {
  1298. delta = e.deltaY > 0 ? 1 : -1;
  1299. } else if (e.wheelDelta) {
  1300. delta = -e.wheelDelta / 120;
  1301. } else if (e.detail) {
  1302. delta = e.detail > 0 ? 1 : -1;
  1303. }
  1304. this.zoom(-delta * ratio, true, e);
  1305. }
  1306. };
  1307. var methods = {
  1308. /** Show the viewer (only available in modal mode)
  1309. * @param {boolean} [immediate=false] - Indicates if show the viewer immediately or not.
  1310. * @returns {Viewer} this
  1311. */
  1312. show: function show() {
  1313. var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1314. var element = this.element,
  1315. options = this.options;
  1316. if (options.inline || this.showing || this.isShown || this.showing) {
  1317. return this;
  1318. }
  1319. if (!this.ready) {
  1320. this.build();
  1321. if (this.ready) {
  1322. this.show(immediate);
  1323. }
  1324. return this;
  1325. }
  1326. if (isFunction(options.show)) {
  1327. addListener(element, EVENT_SHOW, options.show, {
  1328. once: true
  1329. });
  1330. }
  1331. if (dispatchEvent(element, EVENT_SHOW) === false || !this.ready) {
  1332. return this;
  1333. }
  1334. if (this.hiding) {
  1335. this.transitioning.abort();
  1336. }
  1337. this.showing = true;
  1338. this.open();
  1339. var viewer = this.viewer;
  1340. removeClass(viewer, CLASS_HIDE);
  1341. if (options.transition && !immediate) {
  1342. var shown = this.shown.bind(this);
  1343. this.transitioning = {
  1344. abort: function abort() {
  1345. removeListener(viewer, EVENT_TRANSITION_END, shown);
  1346. removeClass(viewer, CLASS_IN);
  1347. }
  1348. };
  1349. addClass(viewer, CLASS_TRANSITION);
  1350. // Force reflow to enable CSS3 transition
  1351. // eslint-disable-next-line
  1352. viewer.offsetWidth;
  1353. addListener(viewer, EVENT_TRANSITION_END, shown, {
  1354. once: true
  1355. });
  1356. addClass(viewer, CLASS_IN);
  1357. } else {
  1358. addClass(viewer, CLASS_IN);
  1359. this.shown();
  1360. }
  1361. return this;
  1362. },
  1363. /**
  1364. * Hide the viewer (only available in modal mode)
  1365. * @param {boolean} [immediate=false] - Indicates if hide the viewer immediately or not.
  1366. * @returns {Viewer} this
  1367. */
  1368. hide: function hide() {
  1369. var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1370. var element = this.element,
  1371. options = this.options;
  1372. if (options.inline || this.hiding || !(this.isShown || this.showing)) {
  1373. return this;
  1374. }
  1375. if (isFunction(options.hide)) {
  1376. addListener(element, EVENT_HIDE, options.hide, {
  1377. once: true
  1378. });
  1379. }
  1380. if (dispatchEvent(element, EVENT_HIDE) === false) {
  1381. return this;
  1382. }
  1383. if (this.showing) {
  1384. this.transitioning.abort();
  1385. }
  1386. this.hiding = true;
  1387. if (this.played) {
  1388. this.stop();
  1389. } else if (this.viewing) {
  1390. this.viewing.abort();
  1391. }
  1392. var viewer = this.viewer;
  1393. if (options.transition && !immediate) {
  1394. var hidden = this.hidden.bind(this);
  1395. var hide = function hide() {
  1396. addListener(viewer, EVENT_TRANSITION_END, hidden, {
  1397. once: true
  1398. });
  1399. removeClass(viewer, CLASS_IN);
  1400. };
  1401. this.transitioning = {
  1402. abort: function abort() {
  1403. if (this.viewed) {
  1404. removeListener(this.image, EVENT_TRANSITION_END, hide);
  1405. } else {
  1406. removeListener(viewer, EVENT_TRANSITION_END, hidden);
  1407. }
  1408. }
  1409. };
  1410. if (this.viewed) {
  1411. addListener(this.image, EVENT_TRANSITION_END, hide, {
  1412. once: true
  1413. });
  1414. this.zoomTo(0, false, false, true);
  1415. } else {
  1416. hide();
  1417. }
  1418. } else {
  1419. removeClass(viewer, CLASS_IN);
  1420. this.hidden();
  1421. }
  1422. return this;
  1423. },
  1424. /**
  1425. * View one of the images with image's index
  1426. * @param {number} index - The index of the image to view.
  1427. * @returns {Viewer} this
  1428. */
  1429. view: function view() {
  1430. var _this = this;
  1431. var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1432. var mandatory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1433. index = Number(index) || 0;
  1434. if (!this.isShown) {
  1435. this.index = index;
  1436. return this.show();
  1437. }
  1438. if (this.hiding || this.played || index < 0 || index >= this.length) {
  1439. return this;
  1440. }
  1441. if (!mandatory)
  1442. {
  1443. if (this.viewed && index === this.index) {
  1444. return this;
  1445. }
  1446. }
  1447. if (this.viewing) {
  1448. this.viewing.abort();
  1449. }
  1450. var element = this.element,
  1451. options = this.options,
  1452. title = this.title,
  1453. canvas = this.canvas;
  1454. var item = this.items[index];
  1455. var img = item.querySelector('img');
  1456. var url = getData(img, 'originalUrl');
  1457. var alt = img.getAttribute('alt');
  1458. var image = document.createElement('img');
  1459. image.src = url;
  1460. image.alt = alt;
  1461. image.style.display='none';
  1462. if (isFunction(options.view)) {
  1463. addListener(element, EVENT_VIEW, options.view, {
  1464. once: true
  1465. });
  1466. }
  1467. if (dispatchEvent(element, EVENT_VIEW, {
  1468. originalImage: this.images[index],
  1469. index: index,
  1470. image: image
  1471. }) === false || !this.isShown || this.hiding || this.played) {
  1472. return this;
  1473. }
  1474. this.image = image;
  1475. removeClass(this.items[this.index], CLASS_ACTIVE);
  1476. addClass(item, CLASS_ACTIVE);
  1477. this.viewed = false;
  1478. this.index = index;
  1479. this.imageData = {};
  1480. addClass(image, CLASS_INVISIBLE);
  1481. if (options.loading) {
  1482. addClass(canvas, CLASS_LOADING);
  1483. }
  1484. canvas.innerHTML = '';
  1485. var viewerData = _this.viewerData;
  1486. this.intervalTime=null;
  1487. this.ulLeft= this.ulLeftInitial=0;
  1488. var is_sj=false;
  1489. var imageBf=null;
  1490. var imageAf=null;
  1491. var liBf=null;
  1492. var liAf=null;
  1493. var ul=null;
  1494. var userAgent = window.navigator.userAgent;
  1495. if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i) || userAgent.match(/android/i))
  1496. {
  1497. is_sj=true;
  1498. }
  1499. if (is_sj)
  1500. {
  1501. ul = document.createElement('ul');
  1502. if (index-1>=0)
  1503. {
  1504. var itemBf = this.items[index-1];
  1505. var imgBf = itemBf.querySelector('img');
  1506. var urlBf = getData(imgBf, 'originalUrl');
  1507. var altBf = imgBf.getAttribute('alt');
  1508. imageBf = document.createElement('img');
  1509. imageBf.src = urlBf;
  1510. imageBf.alt = altBf;
  1511. imageBf.style.display='none';
  1512. imageBf.style.width='100%';
  1513. liBf = document.createElement('li');
  1514. liBf.appendChild(imageBf);
  1515. liBf.style.width=viewerData.width.toString()+'px';
  1516. ul.appendChild(liBf);
  1517. }
  1518. var li = document.createElement('li');
  1519. li.appendChild(image);
  1520. li.style.width=viewerData.width.toString()+'px';
  1521. ul.appendChild(li);
  1522. if (index+1<this.length)
  1523. {
  1524. var itemAf = this.items[index+1];
  1525. var imgAf = itemAf.querySelector('img');
  1526. var urlAf = getData(imgAf, 'originalUrl');
  1527. var altAf = imgAf.getAttribute('alt');
  1528. imageAf = document.createElement('img');
  1529. imageAf.src = urlAf;
  1530. imageAf.alt = altAf;
  1531. imageAf.style.display='none';
  1532. imageAf.style.width='100%';
  1533. liAf = document.createElement('li');
  1534. liAf.appendChild(imageAf);
  1535. liAf.style.width=viewerData.width.toString()+'px';
  1536. ul.appendChild(liAf);
  1537. }
  1538. canvas.appendChild(ul);
  1539. }else {
  1540. canvas.appendChild(image);
  1541. }
  1542. // Center current item
  1543. this.renderList();
  1544. // Clear title
  1545. // title.innerHTML = '';
  1546. title.textContent = (_this.index+1)+'/'+options.totalCount;
  1547. if (this.dealOriginal.indexOf(url)>-1)
  1548. {
  1549. this.toolbar.querySelector(".viewer-one-to-ones2").style.display='block';
  1550. this.toolbar.querySelector(".viewer-one-to-ones").style.display='none';
  1551. }else {
  1552. this.toolbar.querySelector(".viewer-one-to-ones").style.display='block';
  1553. this.toolbar.querySelector(".viewer-one-to-ones2").style.display='none';
  1554. }
  1555. // Generate title after viewed
  1556. var onViewed = function onViewed() {
  1557. // var imageData = _this.imageData;
  1558. image.style.display='block';
  1559. if (is_sj)
  1560. {
  1561. if (imageBf!=null)
  1562. {
  1563. _this.ulLeft= _this.ulLeftInitial=-viewerData.width;
  1564. }
  1565. ul.style.marginLeft=_this.ulLeft.toString()+'px';
  1566. if (imageBf!=null)
  1567. {
  1568. imageBf.style.height=image.style.height;
  1569. imageBf.style.marginTop=image.style.marginTop;
  1570. imageBf.style.display='block';
  1571. }
  1572. if (imageAf!=null) {
  1573. imageAf.style.height=image.style.height;
  1574. imageAf.style.marginTop=image.style.marginTop;
  1575. imageAf.style.display='block';
  1576. }
  1577. }
  1578. // title.textContent = alt + ' (' + imageData.naturalWidth + ' \xD7 ' + imageData.naturalHeight + ')';
  1579. };
  1580. var onLoad = void 0;
  1581. addListener(element, EVENT_VIEWED, onViewed, {
  1582. once: true
  1583. });
  1584. this.viewing = {
  1585. abort: function abort() {
  1586. removeListener(element, EVENT_VIEWED, onViewed);
  1587. if (image.complete) {
  1588. if (this.imageRendering) {
  1589. this.imageRendering.abort();
  1590. } else if (this.imageInitializing) {
  1591. this.imageInitializing.abort();
  1592. }
  1593. } else {
  1594. removeListener(image, EVENT_LOAD, onLoad);
  1595. if (this.timeout) {
  1596. clearTimeout(this.timeout);
  1597. }
  1598. }
  1599. }
  1600. };
  1601. if (image.complete) {
  1602. this.load();
  1603. } else {
  1604. addListener(image, EVENT_LOAD, onLoad = this.load.bind(this), {
  1605. once: true
  1606. });
  1607. if (this.timeout) {
  1608. clearTimeout(this.timeout);
  1609. }
  1610. // Make the image visible if it fails to load within 1s
  1611. this.timeout = setTimeout(function () {
  1612. removeClass(image, CLASS_INVISIBLE);
  1613. _this.timeout = false;
  1614. }, 1000);
  1615. }
  1616. return this;
  1617. },
  1618. /**
  1619. * View the previous image
  1620. * @param {boolean} [loop=false] - Indicate if view the last one
  1621. * when it is the first one at present.
  1622. * @returns {Viewer} this
  1623. */
  1624. prev: function prev() {
  1625. var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1626. var index = this.index - 1;
  1627. if (index < 0) {
  1628. index = loop ? this.length - 1 : 0;
  1629. swal("当前是第一个", {
  1630. buttons: false,
  1631. timer: 3000,
  1632. });
  1633. }
  1634. this.view(index);
  1635. return this;
  1636. },
  1637. /**
  1638. * View the next image
  1639. * @param {boolean} [loop=false] - Indicate if view the first one
  1640. * when it is the last one at present.
  1641. * @returns {Viewer} this
  1642. */
  1643. next: function next() {
  1644. var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1645. var options = this.options;
  1646. var maxIndex =options.totalCount-1; //this.length - 1;
  1647. var index = this.index + 1;
  1648. if (index > maxIndex) {
  1649. swal("当前是最后一个", {
  1650. buttons: false,
  1651. timer: 3000,
  1652. });
  1653. index = loop ? 0 : maxIndex;
  1654. }else {
  1655. if (index>=this.length - 1)
  1656. {
  1657. var element = this.element;
  1658. if (isFunction(options.next)) {
  1659. addListener(element, EVENT_NEXT, options.next, {
  1660. once: true
  1661. });
  1662. }
  1663. if (dispatchEvent(element, EVENT_NEXT) === false) {
  1664. return;
  1665. }
  1666. this.update();
  1667. }
  1668. }
  1669. this.view(index);
  1670. return this;
  1671. },
  1672. normal: function normal() {
  1673. var index = this.index;
  1674. var item = this.items[index];
  1675. var img = item.querySelector('img');
  1676. var dealUrl = getData(img, 'dealUrl');
  1677. if (this.dealOriginal.indexOf(dealUrl)>-1)
  1678. {
  1679. return this;
  1680. }
  1681. this.dealOriginal.push(dealUrl);
  1682. setData(img,'originalUrl',dealUrl);
  1683. this.view(index,true);
  1684. return this;
  1685. },
  1686. /**
  1687. * Move the image with relative offsets.
  1688. * @param {number} offsetX - The relative offset distance on the x-axis.
  1689. * @param {number} offsetY - The relative offset distance on the y-axis.
  1690. * @returns {Viewer} this
  1691. */
  1692. move: function move(offsetX, offsetY) {
  1693. var imageData = this.imageData;
  1694. this.moveTo(isUndefined(offsetX) ? offsetX : imageData.left + Number(offsetX), isUndefined(offsetY) ? offsetY : imageData.top + Number(offsetY));
  1695. return this;
  1696. },
  1697. moveSj: function move(offsetX, offsetY) {
  1698. var ul=this.canvas.querySelector("ul");
  1699. this.ulLeft=this.ulLeft+offsetX;
  1700. ul.style.marginLeft = this.ulLeft+ 'px';
  1701. if (this.isSwitchable2())
  1702. {
  1703. var than=this,
  1704. image = this.image,
  1705. viewerData = this.viewerData;
  1706. if (offsetX > 0) {
  1707. this.action=false;
  1708. var index = this.index - 1;
  1709. if (index < 0) {
  1710. this.springMove(this.ulLeftInitial);
  1711. }
  1712. // this.springMove(this.ulLeftInitial+viewerData.width);
  1713. than.prev(false);
  1714. } else if (offsetX < 0) {
  1715. this.action=false;
  1716. var imageLi=image.parentNode;
  1717. var maxIndex =this.options.totalCount-1; //this.length - 1;
  1718. var index = this.index + 1;
  1719. if (index > maxIndex) {
  1720. var gjLeft2 = parseInt(this.ulLeftInitial);
  1721. var diff = parseInt(parseInt(image.style.width) - parseInt(viewerData.width));
  1722. if (diff > 0) {
  1723. gjLeft2 = gjLeft2 - diff;
  1724. }
  1725. this.springMove(gjLeft2);
  1726. }
  1727. // this.springMove(this.ulLeftInitial+parseInt(imageLi.style.paddingLeft)-image.width);
  1728. than.next(false);
  1729. }
  1730. }
  1731. },
  1732. testPromise:function testPromise() {
  1733. var than=this;
  1734. var promise1 = new Promise(function(resolve, reject) {
  1735. setTimeout(function() {
  1736. resolve('foo');
  1737. }, 1000);
  1738. });
  1739. var rush=false;
  1740. promise1.then(function(value) {
  1741. than.next(false);
  1742. rush=true;
  1743. });
  1744. return rush;
  1745. },
  1746. /**
  1747. * Move the image to an absolute point.
  1748. * @param {number} x - The x-axis coordinate.
  1749. * @param {number} [y=x] - The y-axis coordinate.
  1750. * @returns {Viewer} this
  1751. */
  1752. moveTo: function moveTo(x) {
  1753. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;
  1754. var imageData = this.imageData;
  1755. x = Number(x);
  1756. y = Number(y);
  1757. if (this.viewed && !this.played && this.options.movable) {
  1758. var changed = false;
  1759. if (isNumber(x)) {
  1760. imageData.left = x;
  1761. changed = true;
  1762. }
  1763. if (isNumber(y)) {
  1764. imageData.top = y;
  1765. changed = true;
  1766. }
  1767. if (changed) {
  1768. this.renderImage();
  1769. }
  1770. }
  1771. return this;
  1772. },
  1773. /**
  1774. * Zoom the image with a relative ratio.
  1775. * @param {number} ratio - The target ratio.
  1776. * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
  1777. * @param {Event} [_originalEvent=null] - The original event if any.
  1778. * @returns {Viewer} this
  1779. */
  1780. zoom: function zoom(ratio) {
  1781. var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1782. var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  1783. var imageData = this.imageData;
  1784. ratio = Number(ratio);
  1785. if (ratio < 0) {
  1786. ratio = 1 / (1 - ratio);
  1787. } else {
  1788. ratio = 1 + ratio;
  1789. }
  1790. this.zoomTo(imageData.width * ratio / imageData.naturalWidth, hasTooltip, _originalEvent);
  1791. return this;
  1792. },
  1793. /**
  1794. * Zoom the image to an absolute ratio.
  1795. * @param {number} ratio - The target ratio.
  1796. * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
  1797. * @param {Event} [_originalEvent=null] - The original event if any.
  1798. * @param {Event} [_zoomable=false] - Indicates if the current zoom is available or not.
  1799. * @returns {Viewer} this
  1800. */
  1801. zoomTo: function zoomTo(ratio) {
  1802. var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1803. var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  1804. var _zoomable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  1805. var options = this.options,
  1806. pointers = this.pointers,
  1807. imageData = this.imageData;
  1808. ratio = Math.max(0, ratio);
  1809. if (isNumber(ratio) && this.viewed && !this.played && (_zoomable || options.zoomable)) {
  1810. if (!_zoomable) {
  1811. var minZoomRatio = Math.max(0.01, options.minZoomRatio);
  1812. var maxZoomRatio = Math.min(100, options.maxZoomRatio);
  1813. ratio = Math.min(Math.max(ratio, minZoomRatio), maxZoomRatio);
  1814. }
  1815. if (_originalEvent && ratio > 0.95 && ratio < 1.05) {
  1816. ratio = 1;
  1817. }
  1818. var newWidth = imageData.naturalWidth * ratio;
  1819. var newHeight = imageData.naturalHeight * ratio;
  1820. if (_originalEvent) {
  1821. var offset = getOffset(this.viewer);
  1822. var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : {
  1823. pageX: _originalEvent.pageX,
  1824. pageY: _originalEvent.pageY
  1825. };
  1826. // Zoom from the triggering point of the event
  1827. imageData.left -= (newWidth - imageData.width) * ((center.pageX - offset.left - imageData.left) / imageData.width);
  1828. imageData.top -= (newHeight - imageData.height) * ((center.pageY - offset.top - imageData.top) / imageData.height);
  1829. } else {
  1830. // Zoom from the center of the image
  1831. imageData.left -= (newWidth - imageData.width) / 2;
  1832. imageData.top -= (newHeight - imageData.height) / 2;
  1833. }
  1834. imageData.width = newWidth;
  1835. imageData.height = newHeight;
  1836. imageData.ratio = ratio;
  1837. this.renderImage();
  1838. if (hasTooltip) {
  1839. this.tooltip();
  1840. }
  1841. }
  1842. return this;
  1843. },
  1844. /**
  1845. * Rotate the image with a relative degree.
  1846. * @param {number} degree - The rotate degree.
  1847. * @returns {Viewer} this
  1848. */
  1849. rotate: function rotate(degree) {
  1850. this.rotateTo((this.imageData.rotate || 0) + Number(degree));
  1851. return this;
  1852. },
  1853. /**
  1854. * Rotate the image to an absolute degree.
  1855. * @param {number} degree - The rotate degree.
  1856. * @returns {Viewer} this
  1857. */
  1858. rotateTo: function rotateTo(degree) {
  1859. var imageData = this.imageData;
  1860. degree = Number(degree);
  1861. if (isNumber(degree) && this.viewed && !this.played && this.options.rotatable) {
  1862. imageData.rotate = degree;
  1863. this.renderImage();
  1864. }
  1865. return this;
  1866. },
  1867. /**
  1868. * Scale the image on the x-axis.
  1869. * @param {number} scaleX - The scale ratio on the x-axis.
  1870. * @returns {Viewer} this
  1871. */
  1872. scaleX: function scaleX(_scaleX) {
  1873. this.scale(_scaleX, this.imageData.scaleY);
  1874. return this;
  1875. },
  1876. /**
  1877. * Scale the image on the y-axis.
  1878. * @param {number} scaleY - The scale ratio on the y-axis.
  1879. * @returns {Viewer} this
  1880. */
  1881. scaleY: function scaleY(_scaleY) {
  1882. this.scale(this.imageData.scaleX, _scaleY);
  1883. return this;
  1884. },
  1885. /**
  1886. * Scale the image.
  1887. * @param {number} scaleX - The scale ratio on the x-axis.
  1888. * @param {number} [scaleY=scaleX] - The scale ratio on the y-axis.
  1889. * @returns {Viewer} this
  1890. */
  1891. scale: function scale(scaleX) {
  1892. var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX;
  1893. var imageData = this.imageData;
  1894. scaleX = Number(scaleX);
  1895. scaleY = Number(scaleY);
  1896. if (this.viewed && !this.played && this.options.scalable) {
  1897. var changed = false;
  1898. if (isNumber(scaleX)) {
  1899. imageData.scaleX = scaleX;
  1900. changed = true;
  1901. }
  1902. if (isNumber(scaleY)) {
  1903. imageData.scaleY = scaleY;
  1904. changed = true;
  1905. }
  1906. if (changed) {
  1907. this.renderImage();
  1908. }
  1909. }
  1910. return this;
  1911. },
  1912. /**
  1913. * Play the images
  1914. * @param {boolean} [fullscreen=false] - Indicate if request fullscreen or not.
  1915. * @returns {Viewer} this
  1916. */
  1917. play: function play() {
  1918. var _this2 = this;
  1919. var fullscreen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1920. if (!this.isShown || this.played) {
  1921. return this;
  1922. }
  1923. var options = this.options,
  1924. player = this.player;
  1925. var onLoad = this.loadImage.bind(this);
  1926. var list = [];
  1927. var total = 0;
  1928. var index = 0;
  1929. this.played = true;
  1930. this.onLoadWhenPlay = onLoad;
  1931. if (fullscreen) {
  1932. this.requestFullscreen();
  1933. }
  1934. addClass(player, CLASS_SHOW);
  1935. forEach(this.items, function (item, i) {
  1936. var img = item.querySelector('img');
  1937. var image = document.createElement('img');
  1938. image.src = getData(img, 'originalUrl');
  1939. image.alt = img.getAttribute('alt');
  1940. total += 1;
  1941. addClass(image, CLASS_FADE);
  1942. toggleClass(image, CLASS_TRANSITION, options.transition);
  1943. if (hasClass(item, CLASS_ACTIVE)) {
  1944. addClass(image, CLASS_IN);
  1945. index = i;
  1946. }
  1947. list.push(image);
  1948. addListener(image, EVENT_LOAD, onLoad, {
  1949. once: true
  1950. });
  1951. player.appendChild(image);
  1952. });
  1953. if (isNumber(options.interval) && options.interval > 0) {
  1954. var play = function play() {
  1955. _this2.playing = setTimeout(function () {
  1956. removeClass(list[index], CLASS_IN);
  1957. index += 1;
  1958. index = index < total ? index : 0;
  1959. addClass(list[index], CLASS_IN);
  1960. play();
  1961. }, options.interval);
  1962. };
  1963. if (total > 1) {
  1964. play();
  1965. }
  1966. }
  1967. return this;
  1968. },
  1969. // Stop play
  1970. stop: function stop() {
  1971. var _this3 = this;
  1972. if (!this.played) {
  1973. return this;
  1974. }
  1975. var player = this.player;
  1976. this.played = false;
  1977. clearTimeout(this.playing);
  1978. forEach(player.getElementsByTagName('img'), function (image) {
  1979. removeListener(image, EVENT_LOAD, _this3.onLoadWhenPlay);
  1980. });
  1981. removeClass(player, CLASS_SHOW);
  1982. player.innerHTML = '';
  1983. this.exitFullscreen();
  1984. return this;
  1985. },
  1986. // Enter modal mode (only available in inline mode)
  1987. full: function full() {
  1988. var _this4 = this;
  1989. var options = this.options,
  1990. viewer = this.viewer,
  1991. image = this.image,
  1992. list = this.list;
  1993. if (!this.isShown || this.played || this.fulled || !options.inline) {
  1994. return this;
  1995. }
  1996. this.fulled = true;
  1997. this.open();
  1998. addClass(this.button, CLASS_FULLSCREEN_EXIT);
  1999. if (options.transition) {
  2000. removeClass(list, CLASS_TRANSITION);
  2001. if (this.viewed) {
  2002. removeClass(image, CLASS_TRANSITION);
  2003. }
  2004. }
  2005. addClass(viewer, CLASS_FIXED);
  2006. viewer.setAttribute('style', '');
  2007. setStyle(viewer, {
  2008. zIndex: options.zIndex
  2009. });
  2010. this.initContainer();
  2011. this.viewerData = assign({}, this.containerData);
  2012. this.renderList();
  2013. if (this.viewed) {
  2014. this.initImage(function () {
  2015. _this4.renderImage(function () {
  2016. if (options.transition) {
  2017. setTimeout(function () {
  2018. addClass(image, CLASS_TRANSITION);
  2019. addClass(list, CLASS_TRANSITION);
  2020. }, 0);
  2021. }
  2022. });
  2023. });
  2024. }
  2025. return this;
  2026. },
  2027. // Exit modal mode (only available in inline mode)
  2028. exit: function exit() {
  2029. var _this5 = this;
  2030. var options = this.options,
  2031. viewer = this.viewer,
  2032. image = this.image,
  2033. list = this.list;
  2034. if (!this.isShown || this.played || !this.fulled || !options.inline) {
  2035. return this;
  2036. }
  2037. this.fulled = false;
  2038. this.close();
  2039. removeClass(this.button, CLASS_FULLSCREEN_EXIT);
  2040. if (options.transition) {
  2041. removeClass(list, CLASS_TRANSITION);
  2042. if (this.viewed) {
  2043. removeClass(image, CLASS_TRANSITION);
  2044. }
  2045. }
  2046. removeClass(viewer, CLASS_FIXED);
  2047. setStyle(viewer, {
  2048. zIndex: options.zIndexInline
  2049. });
  2050. this.viewerData = assign({}, this.parentData);
  2051. this.renderViewer();
  2052. this.renderList();
  2053. if (this.viewed) {
  2054. this.initImage(function () {
  2055. _this5.renderImage(function () {
  2056. if (options.transition) {
  2057. setTimeout(function () {
  2058. addClass(image, CLASS_TRANSITION);
  2059. addClass(list, CLASS_TRANSITION);
  2060. }, 0);
  2061. }
  2062. });
  2063. });
  2064. }
  2065. return this;
  2066. },
  2067. // Show the current ratio of the image with percentage
  2068. tooltip: function tooltip() {
  2069. var _this6 = this;
  2070. var options = this.options,
  2071. tooltipBox = this.tooltipBox,
  2072. imageData = this.imageData;
  2073. if (!this.viewed || this.played || !options.tooltip) {
  2074. return this;
  2075. }
  2076. tooltipBox.textContent = Math.round(imageData.ratio * 100) + '%';
  2077. if (!this.tooltipping) {
  2078. if (options.transition) {
  2079. if (this.fading) {
  2080. dispatchEvent(tooltipBox, EVENT_TRANSITION_END);
  2081. }
  2082. addClass(tooltipBox, CLASS_SHOW);
  2083. addClass(tooltipBox, CLASS_FADE);
  2084. addClass(tooltipBox, CLASS_TRANSITION);
  2085. // Force reflow to enable CSS3 transition
  2086. // eslint-disable-next-line
  2087. tooltipBox.offsetWidth;
  2088. addClass(tooltipBox, CLASS_IN);
  2089. } else {
  2090. addClass(tooltipBox, CLASS_SHOW);
  2091. }
  2092. } else {
  2093. clearTimeout(this.tooltipping);
  2094. }
  2095. this.tooltipping = setTimeout(function () {
  2096. if (options.transition) {
  2097. addListener(tooltipBox, EVENT_TRANSITION_END, function () {
  2098. removeClass(tooltipBox, CLASS_SHOW);
  2099. removeClass(tooltipBox, CLASS_FADE);
  2100. removeClass(tooltipBox, CLASS_TRANSITION);
  2101. _this6.fading = false;
  2102. }, {
  2103. once: true
  2104. });
  2105. removeClass(tooltipBox, CLASS_IN);
  2106. _this6.fading = true;
  2107. } else {
  2108. removeClass(tooltipBox, CLASS_SHOW);
  2109. }
  2110. _this6.tooltipping = false;
  2111. }, 1000);
  2112. return this;
  2113. },
  2114. // Toggle the image size between its natural size and initial size
  2115. toggle: function toggle() {
  2116. if (this.imageData.ratio === 1) {
  2117. this.zoomTo(this.initialImageData.ratio, true);
  2118. } else {
  2119. this.zoomTo(1, true);
  2120. //pxn
  2121. var userAgent = window.navigator.userAgent;
  2122. if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i) || userAgent.match(/android/i))
  2123. {
  2124. var image = this.image,
  2125. viewerData = this.viewerData;
  2126. if (image.width>viewerData.width)
  2127. {
  2128. var gjLeft2=parseInt(this.ulLeftInitial);
  2129. var diff=parseInt(parseInt(image.style.width)-parseInt(viewerData.width));
  2130. if (diff>0)
  2131. {
  2132. if (this.intervalTime!==undefined)
  2133. {
  2134. clearInterval(this.intervalTime);
  2135. }
  2136. gjLeft2=gjLeft2-diff/2;
  2137. var ul=this.canvas.querySelector("ul");
  2138. this.ulLeft=gjLeft2;
  2139. ul.style.marginLeft = this.ulLeft+ 'px';
  2140. }
  2141. }
  2142. }
  2143. }
  2144. return this;
  2145. },
  2146. // Reset the image to its initial state
  2147. reset: function reset() {
  2148. if (this.viewed && !this.played) {
  2149. this.imageData = assign({}, this.initialImageData);
  2150. this.renderImage();
  2151. }
  2152. return this;
  2153. },
  2154. // Update viewer when images changed
  2155. update: function update() {
  2156. var element = this.element,
  2157. options = this.options,
  2158. isImg = this.isImg;
  2159. // Destroy viewer if the target image was deleted
  2160. if (isImg && !element.parentNode) {
  2161. return this.destroy();
  2162. }
  2163. var images = [];
  2164. forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
  2165. if (options.filter) {
  2166. if (options.filter(image)) {
  2167. images.push(image);
  2168. }
  2169. } else {
  2170. images.push(image);
  2171. }
  2172. });
  2173. if (!images.length) {
  2174. return this;
  2175. }
  2176. this.images = images;
  2177. this.length = images.length;
  2178. if (this.ready) {
  2179. var indexes = [];
  2180. forEach(this.items, function (item, i) {
  2181. var img = item.querySelector('img');
  2182. var image = images[i];
  2183. if (image) {
  2184. if (image.src !== img.src) {
  2185. indexes.push(i);
  2186. }
  2187. } else {
  2188. indexes.push(i);
  2189. }
  2190. });
  2191. setStyle(this.list, {
  2192. width: 'auto'
  2193. });
  2194. this.initList();
  2195. if (this.isShown) {
  2196. if (this.length) {
  2197. if (this.viewed) {
  2198. var index = indexes.indexOf(this.index);
  2199. if (index >= 0) {
  2200. this.viewed = false;
  2201. this.view(Math.max(this.index - (index + 1), 0));
  2202. } else {
  2203. addClass(this.items[this.index], CLASS_ACTIVE);
  2204. }
  2205. }
  2206. } else {
  2207. this.image = null;
  2208. this.viewed = false;
  2209. this.index = 0;
  2210. this.imageData = null;
  2211. this.canvas.innerHTML = '';
  2212. this.title.innerHTML = '';
  2213. }
  2214. }
  2215. } else {
  2216. this.build();
  2217. }
  2218. return this;
  2219. },
  2220. // Destroy the viewer
  2221. destroy: function destroy() {
  2222. var element = this.element,
  2223. options = this.options;
  2224. if (!getData(element, NAMESPACE)) {
  2225. return this;
  2226. }
  2227. this.destroyed = true;
  2228. if (this.ready) {
  2229. if (this.played) {
  2230. this.stop();
  2231. }
  2232. if (options.inline) {
  2233. if (this.fulled) {
  2234. this.exit();
  2235. }
  2236. this.unbind();
  2237. } else if (this.isShown) {
  2238. if (this.viewing) {
  2239. if (this.imageRendering) {
  2240. this.imageRendering.abort();
  2241. } else if (this.imageInitializing) {
  2242. this.imageInitializing.abort();
  2243. }
  2244. }
  2245. if (this.hiding) {
  2246. this.transitioning.abort();
  2247. }
  2248. this.hidden();
  2249. } else if (this.showing) {
  2250. this.transitioning.abort();
  2251. this.hidden();
  2252. }
  2253. this.ready = false;
  2254. this.viewer.parentNode.removeChild(this.viewer);
  2255. } else if (options.inline) {
  2256. if (this.delaying) {
  2257. this.delaying.abort();
  2258. } else if (this.initializing) {
  2259. this.initializing.abort();
  2260. }
  2261. }
  2262. if (!options.inline) {
  2263. removeListener(element, EVENT_CLICK, this.onStart);
  2264. }
  2265. removeData(element, NAMESPACE);
  2266. return this;
  2267. }
  2268. };
  2269. var others = {
  2270. open: function open() {
  2271. var body = this.body;
  2272. addClass(body, CLASS_OPEN);
  2273. body.style.paddingRight = this.scrollbarWidth + (parseFloat(this.initialBodyPaddingRight) || 0) + 'px';
  2274. },
  2275. close: function close() {
  2276. var body = this.body;
  2277. removeClass(body, CLASS_OPEN);
  2278. body.style.paddingRight = this.initialBodyPaddingRight;
  2279. },
  2280. shown: function shown() {
  2281. var element = this.element,
  2282. options = this.options;
  2283. this.fulled = true;
  2284. this.isShown = true;
  2285. this.render();
  2286. this.bind();
  2287. this.showing = false;
  2288. if (isFunction(options.shown)) {
  2289. addListener(element, EVENT_SHOWN, options.shown, {
  2290. once: true
  2291. });
  2292. }
  2293. if (dispatchEvent(element, EVENT_SHOWN) === false) {
  2294. return;
  2295. }
  2296. if (this.ready && this.isShown && !this.hiding) {
  2297. this.view(this.index);
  2298. }
  2299. },
  2300. hidden: function hidden() {
  2301. var element = this.element,
  2302. options = this.options;
  2303. this.fulled = false;
  2304. this.viewed = false;
  2305. this.isShown = false;
  2306. this.close();
  2307. this.unbind();
  2308. addClass(this.viewer, CLASS_HIDE);
  2309. this.resetList();
  2310. this.resetImage();
  2311. this.hiding = false;
  2312. if (!this.destroyed) {
  2313. if (isFunction(options.hidden)) {
  2314. addListener(element, EVENT_HIDDEN, options.hidden, {
  2315. once: true
  2316. });
  2317. }
  2318. dispatchEvent(element, EVENT_HIDDEN);
  2319. }
  2320. },
  2321. requestFullscreen: function requestFullscreen() {
  2322. var document = this.element.ownerDocument;
  2323. if (this.fulled && !document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
  2324. var documentElement = document.documentElement;
  2325. if (documentElement.requestFullscreen) {
  2326. documentElement.requestFullscreen();
  2327. } else if (documentElement.msRequestFullscreen) {
  2328. documentElement.msRequestFullscreen();
  2329. } else if (documentElement.mozRequestFullScreen) {
  2330. documentElement.mozRequestFullScreen();
  2331. } else if (documentElement.webkitRequestFullscreen) {
  2332. documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  2333. }
  2334. }
  2335. },
  2336. exitFullscreen: function exitFullscreen() {
  2337. if (this.fulled) {
  2338. var document = this.element.ownerDocument;
  2339. if (document.exitFullscreen) {
  2340. document.exitFullscreen();
  2341. } else if (document.msExitFullscreen) {
  2342. document.msExitFullscreen();
  2343. } else if (document.mozCancelFullScreen) {
  2344. document.mozCancelFullScreen();
  2345. } else if (document.webkitExitFullscreen) {
  2346. document.webkitExitFullscreen();
  2347. }
  2348. }
  2349. },
  2350. change: function change(e) {
  2351. var options = this.options,
  2352. pointers = this.pointers;
  2353. var pointer = pointers[Object.keys(pointers)[0]];
  2354. var offsetX = pointer.endX - pointer.startX;
  2355. var offsetY = pointer.endY - pointer.startY;
  2356. switch (this.action) {
  2357. // Move the current image
  2358. case ACTION_MOVE:
  2359. var userAgent = window.navigator.userAgent;
  2360. if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i) || userAgent.match(/android/i))
  2361. {
  2362. this.moveSj(offsetX,offsetY);
  2363. }else {
  2364. this.move(offsetX, offsetY);
  2365. }
  2366. break;
  2367. // Zoom the current image
  2368. case ACTION_ZOOM:
  2369. this.zoom(getMaxZoomRatio(pointers), false, e);
  2370. break;
  2371. case ACTION_SWITCH:
  2372. this.action = 'switched';
  2373. // Empty `pointers` as `touchend` event will not be fired after swiped in iOS browsers.
  2374. this.pointers = {};
  2375. if (Math.abs(offsetX) > Math.abs(offsetY)) {
  2376. if (offsetX > 1) {
  2377. this.prev(options.loop);
  2378. } else if (offsetX < -1) {
  2379. this.next(options.loop);
  2380. }
  2381. }
  2382. break;
  2383. default:
  2384. }
  2385. // Override
  2386. forEach(pointers, function (p) {
  2387. p.startX = p.endX;
  2388. p.startY = p.endY;
  2389. });
  2390. },
  2391. isSwitchable: function isSwitchable() {
  2392. var imageData = this.imageData,
  2393. viewerData = this.viewerData;
  2394. return this.length > 1&&imageData.width <= viewerData.width && imageData.height <= viewerData.height;
  2395. // return this.length > 1&& imageData.left >= 0&& imageData.top >= 0 && imageData.width <= viewerData.width && imageData.height <= viewerData.height;
  2396. },
  2397. isSwitchable2: function isSwitchable2() {
  2398. var imageData = this.imageData,
  2399. image = this.image,
  2400. viewerData = this.viewerData,
  2401. canvas = this.canvas;
  2402. if (this.length <= 1)
  2403. {
  2404. return false;
  2405. }
  2406. var moveLeft=parseInt(this.ulLeft);
  2407. if (moveLeft<this.ulLeftInitial)
  2408. {
  2409. var gjLeft=parseInt(this.ulLeftInitial)-parseInt(1/3*viewerData.width);
  2410. var diff=parseInt(parseInt(image.style.width)-parseInt(viewerData.width));
  2411. if (diff>0)
  2412. {
  2413. gjLeft=gjLeft-diff;
  2414. }
  2415. if (moveLeft<gjLeft)
  2416. {
  2417. return true;
  2418. }
  2419. }else if (moveLeft>this.ulLeftInitial) {
  2420. if (moveLeft>parseInt(this.ulLeftInitial)+parseInt(1/3*viewerData.width))
  2421. {
  2422. return true;
  2423. }
  2424. }
  2425. return false;
  2426. },
  2427. isSwitchable3: function isSwitchable3() {
  2428. var image = this.image,
  2429. viewerData = this.viewerData;
  2430. if (this.length <= 1)
  2431. {
  2432. return ;
  2433. }
  2434. var moveLeft=parseInt(this.ulLeft);
  2435. if (moveLeft<this.ulLeftInitial)
  2436. {
  2437. var gjLeft2=parseInt(this.ulLeftInitial);
  2438. var diff=parseInt(parseInt(image.style.width)-parseInt(viewerData.width));
  2439. if (diff>0)
  2440. {
  2441. gjLeft2=gjLeft2-diff;
  2442. }
  2443. if (moveLeft>gjLeft2)
  2444. {
  2445. return ;
  2446. }else {
  2447. this.springMove(gjLeft2);
  2448. }
  2449. }else if (moveLeft>this.ulLeftInitial) {
  2450. this.springMove(this.ulLeftInitial);
  2451. }else {
  2452. this.springMove(this.ulLeftInitial);
  2453. }
  2454. return;
  2455. },
  2456. springMove:function springMove(iTarget) {
  2457. var than=this;
  2458. clearInterval(this.intervalTime);//清空定时器
  2459. than.intervalTime=null;
  2460. var iSpeed = 0;
  2461. var ul=this.canvas.querySelector("ul");
  2462. this.intervalTime = setInterval(function(){ //开启定时器
  2463. iSpeed += (iTarget - parseInt(ul.style.marginLeft))/6;
  2464. iSpeed *= 0.75;
  2465. if( Math.abs(iSpeed)<=1 && Math.abs(iTarget - parseInt(ul.style.marginLeft))<=1 ){
  2466. clearInterval(than.intervalTime);
  2467. than.intervalTime=null;
  2468. iSpeed = 0;
  2469. ul.style.marginLeft= iTarget + 'px';
  2470. }
  2471. else{
  2472. ul.style.marginLeft = (parseInt(ul.style.marginLeft)+ parseInt(iSpeed)).toString() + 'px';
  2473. }
  2474. },30);
  2475. },
  2476. };
  2477. var AnotherViewer = WINDOW.Viewer;
  2478. var Viewer = function () {
  2479. /**
  2480. * Create a new Viewer.
  2481. * @param {Element} element - The target element for viewing.
  2482. * @param {Object} [options={}] - The configuration options.
  2483. */
  2484. function Viewer(element) {
  2485. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2486. classCallCheck(this, Viewer);
  2487. if (!element || element.nodeType !== 1) {
  2488. throw new Error('The first argument is required and must be an element.');
  2489. }
  2490. this.element = element;
  2491. this.options = assign({}, DEFAULTS, isPlainObject(options) && options);
  2492. this.action = false;
  2493. this.fading = false;
  2494. this.fulled = false;
  2495. this.hiding = false;
  2496. this.index = 0;
  2497. this.isImg = false;
  2498. this.length = 0;
  2499. this.played = false;
  2500. this.playing = false;
  2501. this.pointers = {};
  2502. this.ready = false;
  2503. this.showing = false;
  2504. this.timeout = false;
  2505. this.tooltipping = false;
  2506. this.viewed = false;
  2507. this.viewing = false;
  2508. this.isShown = false;
  2509. this.wheeling = false;
  2510. this.init();
  2511. }
  2512. createClass(Viewer, [{
  2513. key: 'init',
  2514. value: function init() {
  2515. var _this = this;
  2516. var element = this.element,
  2517. options = this.options;
  2518. if (getData(element, NAMESPACE)) {
  2519. return;
  2520. }
  2521. setData(element, NAMESPACE, this);
  2522. var isImg = element.tagName.toLowerCase() === 'img';
  2523. var images = [];
  2524. forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
  2525. if (isFunction(options.filter)) {
  2526. if (options.filter.call(_this, image)) {
  2527. images.push(image);
  2528. }
  2529. } else {
  2530. images.push(image);
  2531. }
  2532. });
  2533. if (!images.length) {
  2534. return;
  2535. }
  2536. this.isImg = isImg;
  2537. this.length = images.length;
  2538. this.images = images;
  2539. this.dealOriginal=[];
  2540. var ownerDocument = element.ownerDocument;
  2541. var body = ownerDocument.body || ownerDocument.documentElement;
  2542. this.body = body;
  2543. this.scrollbarWidth = window.innerWidth - ownerDocument.documentElement.clientWidth;
  2544. this.initialBodyPaddingRight = window.getComputedStyle(body).paddingRight;
  2545. // Override `transition` option if it is not supported
  2546. if (isUndefined(document.createElement(NAMESPACE).style.transition)) {
  2547. options.transition = false;
  2548. }
  2549. if (options.inline) {
  2550. var count = 0;
  2551. var progress = function progress() {
  2552. count += 1;
  2553. if (count === _this.length) {
  2554. var timeout = void 0;
  2555. _this.initializing = false;
  2556. _this.delaying = {
  2557. abort: function abort() {
  2558. clearTimeout(timeout);
  2559. }
  2560. };
  2561. // build asynchronously to keep `this.viewer` is accessible in `ready` event handler.
  2562. timeout = setTimeout(function () {
  2563. _this.delaying = false;
  2564. _this.build();
  2565. }, 0);
  2566. }
  2567. };
  2568. this.initializing = {
  2569. abort: function abort() {
  2570. forEach(images, function (image) {
  2571. if (!image.complete) {
  2572. removeListener(image, EVENT_LOAD, progress);
  2573. }
  2574. });
  2575. }
  2576. };
  2577. forEach(images, function (image) {
  2578. if (image.complete) {
  2579. progress();
  2580. } else {
  2581. addListener(image, EVENT_LOAD, progress, {
  2582. once: true
  2583. });
  2584. }
  2585. });
  2586. } else {
  2587. addListener(element, EVENT_CLICK, this.onStart = function (_ref) {
  2588. var target = _ref.target;
  2589. var dataUpdate=document.getElementById("docsPictures").getAttribute('data-update');
  2590. if (dataUpdate=='1')
  2591. {
  2592. _this.update();
  2593. document.getElementById("docsPictures").setAttribute('data-update','0');
  2594. }
  2595. if (target.tagName.toLowerCase() === 'img') {
  2596. _this.view(_this.images.indexOf(target));
  2597. }
  2598. });
  2599. }
  2600. }
  2601. }, {
  2602. key: 'build',
  2603. value: function build() {
  2604. if (this.ready) {
  2605. return;
  2606. }
  2607. var element = this.element,
  2608. options = this.options;
  2609. var parent = element.parentNode;
  2610. var template = document.createElement('div');
  2611. template.innerHTML = TEMPLATE;
  2612. var viewer = template.querySelector('.' + NAMESPACE + '-container');
  2613. var title = viewer.querySelector('.' + NAMESPACE + '-title');
  2614. var toolbar = viewer.querySelector('.' + NAMESPACE + '-toolbar');
  2615. var navbar = viewer.querySelector('.' + NAMESPACE + '-navbar');
  2616. var button = viewer.querySelector('.' + NAMESPACE + '-button');
  2617. var canvas = viewer.querySelector('.' + NAMESPACE + '-canvas');
  2618. if ($(window).width()>700)
  2619. {
  2620. toolbar.style.display = "flex";
  2621. toolbar.style.justifyContent= "center";
  2622. }
  2623. this.parent = parent;
  2624. this.viewer = viewer;
  2625. this.title = title;
  2626. this.toolbar = toolbar;
  2627. this.navbar = navbar;
  2628. this.button = button;
  2629. this.canvas = canvas;
  2630. this.footer = viewer.querySelector('.' + NAMESPACE + '-footer');
  2631. this.tooltipBox = viewer.querySelector('.' + NAMESPACE + '-tooltip');
  2632. this.player = viewer.querySelector('.' + NAMESPACE + '-player');
  2633. this.list = viewer.querySelector('.' + NAMESPACE + '-list');
  2634. addClass(title, !options.title ? CLASS_HIDE : getResponsiveClass(options.title));
  2635. addClass(navbar, !options.navbar ? CLASS_HIDE : getResponsiveClass(options.navbar));
  2636. toggleClass(button, CLASS_HIDE, !options.button);
  2637. if (options.backdrop) {
  2638. addClass(viewer, NAMESPACE + '-backdrop');
  2639. if (!options.inline && options.backdrop === true) {
  2640. setData(canvas, 'action', 'hide');
  2641. }
  2642. }
  2643. if (options.toolbar) {
  2644. var list = document.createElement('ul');
  2645. var custom = isPlainObject(options.toolbar);
  2646. var zoomButtons = BUTTONS.slice(0, 3);
  2647. var rotateButtons = BUTTONS.slice(7, 9);
  2648. var scaleButtons = BUTTONS.slice(9);
  2649. if (!custom) {
  2650. addClass(toolbar, getResponsiveClass(options.toolbar));
  2651. }
  2652. forEach(custom ? options.toolbar : BUTTONS, function (value, index) {
  2653. var deep = custom && isPlainObject(value);
  2654. var name = custom ? hyphenate(index) : value;
  2655. var show = deep && !isUndefined(value.show) ? value.show : value;
  2656. if (!show || !options.zoomable && zoomButtons.indexOf(name) !== -1 || !options.rotatable && rotateButtons.indexOf(name) !== -1 || !options.scalable && scaleButtons.indexOf(name) !== -1) {
  2657. return;
  2658. }
  2659. var size = deep && !isUndefined(value.size) ? value.size : value;
  2660. var click = deep && !isUndefined(value.click) ? value.click : value;
  2661. var item = document.createElement('li');
  2662. item.setAttribute('role', 'button');
  2663. addClass(item, NAMESPACE + '-' + name);
  2664. if (!isFunction(click)) {
  2665. setData(item, 'action', name);
  2666. }
  2667. if (isNumber(show)) {
  2668. addClass(item, getResponsiveClass(show));
  2669. }
  2670. if (['small', 'large'].indexOf(size) !== -1) {
  2671. addClass(item, NAMESPACE + '-' + size);
  2672. } else if (name === 'play') {
  2673. addClass(item, NAMESPACE + '-large');
  2674. }
  2675. if (isFunction(click)) {
  2676. addListener(item, EVENT_CLICK, click);
  2677. }
  2678. list.appendChild(item);
  2679. });
  2680. toolbar.appendChild(list);
  2681. } else {
  2682. addClass(toolbar, CLASS_HIDE);
  2683. }
  2684. if (!options.rotatable) {
  2685. var rotates = toolbar.querySelectorAll('li[class*="rotate"]');
  2686. addClass(rotates, CLASS_INVISIBLE);
  2687. forEach(rotates, function (rotate) {
  2688. toolbar.appendChild(rotate);
  2689. });
  2690. }
  2691. if (options.inline) {
  2692. addClass(button, CLASS_FULLSCREEN);
  2693. setStyle(viewer, {
  2694. zIndex: options.zIndexInline
  2695. });
  2696. if (window.getComputedStyle(parent).position === 'static') {
  2697. setStyle(parent, {
  2698. position: 'relative'
  2699. });
  2700. }
  2701. parent.insertBefore(viewer, element.nextSibling);
  2702. } else {
  2703. addClass(button, CLASS_CLOSE);
  2704. addClass(viewer, CLASS_FIXED);
  2705. addClass(viewer, CLASS_FADE);
  2706. addClass(viewer, CLASS_HIDE);
  2707. setStyle(viewer, {
  2708. zIndex: options.zIndex
  2709. });
  2710. var container = options.container;
  2711. if (isString(container)) {
  2712. container = element.ownerDocument.querySelector(container);
  2713. }
  2714. if (!container) {
  2715. container = this.body;
  2716. }
  2717. container.appendChild(viewer);
  2718. }
  2719. if (options.inline) {
  2720. this.render();
  2721. this.bind();
  2722. this.isShown = true;
  2723. }
  2724. this.ready = true;
  2725. if (isFunction(options.ready)) {
  2726. addListener(element, EVENT_READY, options.ready, {
  2727. once: true
  2728. });
  2729. }
  2730. if (dispatchEvent(element, EVENT_READY) === false) {
  2731. this.ready = false;
  2732. return;
  2733. }
  2734. if (this.ready && options.inline) {
  2735. this.view();
  2736. }
  2737. }
  2738. /**
  2739. * Get the no conflict viewer class.
  2740. * @returns {Viewer} The viewer class.
  2741. */
  2742. }], [{
  2743. key: 'noConflict',
  2744. value: function noConflict() {
  2745. window.Viewer = AnotherViewer;
  2746. return Viewer;
  2747. }
  2748. /**
  2749. * Change the default options.
  2750. * @param {Object} options - The new default options.
  2751. */
  2752. }, {
  2753. key: 'setDefaults',
  2754. value: function setDefaults(options) {
  2755. assign(DEFAULTS, isPlainObject(options) && options);
  2756. }
  2757. }]);
  2758. return Viewer;
  2759. }();
  2760. assign(Viewer.prototype, render, events, handlers, methods, others);
  2761. if ($.fn) {
  2762. var AnotherViewer$1 = $.fn.viewer;
  2763. var NAMESPACE$1 = 'viewer';
  2764. $.fn.viewer = function jQueryViewer(option) {
  2765. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  2766. args[_key - 1] = arguments[_key];
  2767. }
  2768. var result = void 0;
  2769. this.each(function (i, element) {
  2770. var $element = $(element);
  2771. var isDestroy = option === 'destroy';
  2772. var viewer = $element.data(NAMESPACE$1);
  2773. if (!viewer) {
  2774. if (isDestroy) {
  2775. return;
  2776. }
  2777. var options = $.extend({}, $element.data(), $.isPlainObject(option) && option);
  2778. viewer = new Viewer(element, options);
  2779. $element.data(NAMESPACE$1, viewer);
  2780. }
  2781. if (typeof option === 'string') {
  2782. var fn = viewer[option];
  2783. if ($.isFunction(fn)) {
  2784. result = fn.apply(viewer, args);
  2785. if (result === viewer) {
  2786. result = undefined;
  2787. }
  2788. if (isDestroy) {
  2789. $element.removeData(NAMESPACE$1);
  2790. }
  2791. }
  2792. }
  2793. });
  2794. return result !== undefined ? result : this;
  2795. };
  2796. $.fn.viewer.Constructor = Viewer;
  2797. $.fn.viewer.setDefaults = Viewer.setDefaults;
  2798. $.fn.viewer.noConflict = function noConflict() {
  2799. $.fn.viewer = AnotherViewer$1;
  2800. return this;
  2801. };
  2802. }
  2803. })));