|
@@ -9,3024 +9,3089 @@
|
|
|
*/
|
|
|
|
|
|
(function (global, factory) {
|
|
|
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) :
|
|
|
- typeof define === 'function' && define.amd ? define(['jquery'], factory) :
|
|
|
- (factory(global.jQuery));
|
|
|
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) :
|
|
|
+ typeof define === 'function' && define.amd ? define(['jquery'], factory) :
|
|
|
+ (factory(global.jQuery));
|
|
|
}(this, (function ($) { 'use strict';
|
|
|
|
|
|
- $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
|
|
|
+ $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
|
|
|
|
|
|
- var DEFAULTS = {
|
|
|
- // Enable inline mode
|
|
|
- inline: false,
|
|
|
+ var DEFAULTS = {
|
|
|
+ // Enable inline mode
|
|
|
+ inline: false,
|
|
|
|
|
|
- // Show the button on the top-right of the viewer
|
|
|
- button: true,
|
|
|
+ // Show the button on the top-right of the viewer
|
|
|
+ button: true,
|
|
|
|
|
|
- // Show the navbar
|
|
|
- navbar: true,
|
|
|
+ // Show the navbar
|
|
|
+ navbar: true,
|
|
|
|
|
|
- // Show the title
|
|
|
- title: true,
|
|
|
+ // Show the title
|
|
|
+ title: true,
|
|
|
|
|
|
- // Show the toolbar
|
|
|
- toolbar: true,
|
|
|
+ // Show the toolbar
|
|
|
+ toolbar: true,
|
|
|
|
|
|
- // Show the tooltip with image ratio (percentage) when zoom in or zoom out
|
|
|
- tooltip: true,
|
|
|
+ // Show the tooltip with image ratio (percentage) when zoom in or zoom out
|
|
|
+ tooltip: true,
|
|
|
|
|
|
- // Enable to move the image
|
|
|
- movable: true,
|
|
|
+ // Enable to move the image
|
|
|
+ movable: true,
|
|
|
|
|
|
- // Enable to zoom the image
|
|
|
- zoomable: true,
|
|
|
+ // Enable to zoom the image
|
|
|
+ zoomable: true,
|
|
|
|
|
|
- // Enable to rotate the image
|
|
|
- rotatable: true,
|
|
|
+ // Enable to rotate the image
|
|
|
+ rotatable: true,
|
|
|
|
|
|
- // Enable to scale the image
|
|
|
- scalable: true,
|
|
|
+ // Enable to scale the image
|
|
|
+ scalable: true,
|
|
|
|
|
|
- // Enable CSS3 Transition for some special elements
|
|
|
- transition: true,
|
|
|
+ // Enable CSS3 Transition for some special elements
|
|
|
+ transition: true,
|
|
|
|
|
|
- // Enable to request fullscreen when play
|
|
|
- fullscreen: true,
|
|
|
-
|
|
|
- // The amount of time to delay between automatically cycling an image when playing.
|
|
|
- interval: 5000,
|
|
|
-
|
|
|
- // Enable keyboard support
|
|
|
- keyboard: true,
|
|
|
-
|
|
|
- // Enable a modal backdrop, specify `static` for a backdrop which doesn't close the modal on click
|
|
|
- backdrop: true,
|
|
|
-
|
|
|
- // Indicate if show a loading spinner when load image or not.
|
|
|
- loading: true,
|
|
|
-
|
|
|
- // Indicate if enable loop viewing or not.
|
|
|
- loop: true,
|
|
|
-
|
|
|
- // Min width of the viewer in inline mode
|
|
|
- minWidth: 200,
|
|
|
-
|
|
|
- // Min height of the viewer in inline mode
|
|
|
- minHeight: 100,
|
|
|
-
|
|
|
- // Define the ratio when zoom the image by wheeling mouse
|
|
|
- zoomRatio: 0.1,
|
|
|
-
|
|
|
- // Define the min ratio of the image when zoom out
|
|
|
- minZoomRatio: 0.01,
|
|
|
-
|
|
|
- // Define the max ratio of the image when zoom in
|
|
|
- maxZoomRatio: 100,
|
|
|
-
|
|
|
- // Define the CSS `z-index` value of viewer in modal mode.
|
|
|
- zIndex: 2015,
|
|
|
-
|
|
|
- // Define the CSS `z-index` value of viewer in inline mode.
|
|
|
- zIndexInline: 0,
|
|
|
-
|
|
|
- // Define where to get the original image URL for viewing
|
|
|
- // Type: String (an image attribute) or Function (should return an image URL)
|
|
|
- url: 'src',
|
|
|
-
|
|
|
- // Define where to put the viewer in modal mode.
|
|
|
- // Type: String | Element
|
|
|
- container: 'body',
|
|
|
-
|
|
|
- // Filter the images for viewing.
|
|
|
- // Type: Function (return true if the image is viewable)
|
|
|
- filter: null,
|
|
|
-
|
|
|
- // Event shortcuts
|
|
|
- ready: null,
|
|
|
- show: null,
|
|
|
- shown: null,
|
|
|
- hide: null,
|
|
|
- hidden: null,
|
|
|
- view: null,
|
|
|
- viewed: null
|
|
|
- };
|
|
|
-
|
|
|
- var TEMPLATE = '<div class="viewer-container" touch-action="none">' + '<div class="viewer-canvas"></div>' + '<div class="viewer-footer">' + '<div class="viewer-title"></div>' + '<div class="viewer-toolbar"></div>' + '<div class="viewer-navbar">' + '<ul class="viewer-list"></ul>' + '</div>' + '</div>' + '<div class="viewer-tooltip"></div>' + '<div role="button" class="viewer-button" data-action="mix"></div>' + '<div class="viewer-player"></div>' + '</div>';
|
|
|
-
|
|
|
- var IN_BROWSER = typeof window !== 'undefined';
|
|
|
- var WINDOW = IN_BROWSER ? window : {};
|
|
|
- var NAMESPACE = 'viewer';
|
|
|
-
|
|
|
- // Actions
|
|
|
- var ACTION_MOVE = 'move';
|
|
|
- var ACTION_SWITCH = 'switch';
|
|
|
- var ACTION_ZOOM = 'zoom';
|
|
|
-
|
|
|
- // Classes
|
|
|
- var CLASS_ACTIVE = NAMESPACE + '-active';
|
|
|
- var CLASS_CLOSE = NAMESPACE + '-close';
|
|
|
- var CLASS_FADE = NAMESPACE + '-fade';
|
|
|
- var CLASS_FIXED = NAMESPACE + '-fixed';
|
|
|
- var CLASS_FULLSCREEN = NAMESPACE + '-fullscreen';
|
|
|
- var CLASS_FULLSCREEN_EXIT = NAMESPACE + '-fullscreen-exit';
|
|
|
- var CLASS_HIDE = NAMESPACE + '-hide';
|
|
|
- var CLASS_HIDE_MD_DOWN = NAMESPACE + '-hide-md-down';
|
|
|
- var CLASS_HIDE_SM_DOWN = NAMESPACE + '-hide-sm-down';
|
|
|
- var CLASS_HIDE_XS_DOWN = NAMESPACE + '-hide-xs-down';
|
|
|
- var CLASS_IN = NAMESPACE + '-in';
|
|
|
- var CLASS_INVISIBLE = NAMESPACE + '-invisible';
|
|
|
- var CLASS_LOADING = NAMESPACE + '-loading';
|
|
|
- var CLASS_MOVE = NAMESPACE + '-move';
|
|
|
- var CLASS_OPEN = NAMESPACE + '-open';
|
|
|
- var CLASS_SHOW = NAMESPACE + '-show';
|
|
|
- var CLASS_TRANSITION = NAMESPACE + '-transition';
|
|
|
-
|
|
|
- // Events
|
|
|
- var EVENT_READY = 'ready';
|
|
|
- var EVENT_SHOW = 'show';
|
|
|
- var EVENT_SHOWN = 'shown';
|
|
|
- var EVENT_HIDE = 'hide';
|
|
|
- var EVENT_HIDDEN = 'hidden';
|
|
|
- var EVENT_VIEW = 'view';
|
|
|
- var EVENT_VIEWED = 'viewed';
|
|
|
- var EVENT_CLICK = 'click';
|
|
|
- var EVENT_DRAG_START = 'dragstart';
|
|
|
- var EVENT_KEY_DOWN = 'keydown';
|
|
|
- var EVENT_LOAD = 'load';
|
|
|
- var EVENT_POINTER_DOWN = WINDOW.PointerEvent ? 'pointerdown' : 'touchstart mousedown';
|
|
|
- var EVENT_POINTER_MOVE = WINDOW.PointerEvent ? 'pointermove' : 'touchmove mousemove';
|
|
|
- var EVENT_POINTER_UP = WINDOW.PointerEvent ? 'pointerup pointercancel' : 'touchend touchcancel mouseup';
|
|
|
- var EVENT_RESIZE = 'resize';
|
|
|
- var EVENT_TRANSITION_END = 'transitionend';
|
|
|
- var EVENT_WHEEL = 'wheel mousewheel DOMMouseScroll';
|
|
|
-
|
|
|
- var BUTTONS = ['zoom-in', 'zoom-out', 'one-to-one', 'reset', 'prev', 'play', 'next', 'rotate-left', 'rotate-right', 'flip-horizontal', 'flip-vertical'];
|
|
|
-
|
|
|
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
|
|
- return typeof obj;
|
|
|
- } : function (obj) {
|
|
|
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
|
- };
|
|
|
-
|
|
|
- var classCallCheck = function (instance, Constructor) {
|
|
|
- if (!(instance instanceof Constructor)) {
|
|
|
- throw new TypeError("Cannot call a class as a function");
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- var createClass = function () {
|
|
|
- function defineProperties(target, props) {
|
|
|
- for (var i = 0; i < props.length; i++) {
|
|
|
- var descriptor = props[i];
|
|
|
- descriptor.enumerable = descriptor.enumerable || false;
|
|
|
- descriptor.configurable = true;
|
|
|
- if ("value" in descriptor) descriptor.writable = true;
|
|
|
- Object.defineProperty(target, descriptor.key, descriptor);
|
|
|
- }
|
|
|
- }
|
|
|
+ // Enable to request fullscreen when play
|
|
|
+ fullscreen: true,
|
|
|
|
|
|
- return function (Constructor, protoProps, staticProps) {
|
|
|
- if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
|
|
- if (staticProps) defineProperties(Constructor, staticProps);
|
|
|
- return Constructor;
|
|
|
- };
|
|
|
- }();
|
|
|
-
|
|
|
- /**
|
|
|
- * Check if the given value is a string.
|
|
|
- * @param {*} value - The value to check.
|
|
|
- * @returns {boolean} Returns `true` if the given value is a string, else `false`.
|
|
|
- */
|
|
|
- function isString(value) {
|
|
|
- return typeof value === 'string';
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Check if the given value is not a number.
|
|
|
- */
|
|
|
- var isNaN = Number.isNaN || WINDOW.isNaN;
|
|
|
-
|
|
|
- /**
|
|
|
- * Check if the given value is a number.
|
|
|
- * @param {*} value - The value to check.
|
|
|
- * @returns {boolean} Returns `true` if the given value is a number, else `false`.
|
|
|
- */
|
|
|
- function isNumber(value) {
|
|
|
- return typeof value === 'number' && !isNaN(value);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Check if the given value is undefined.
|
|
|
- * @param {*} value - The value to check.
|
|
|
- * @returns {boolean} Returns `true` if the given value is undefined, else `false`.
|
|
|
- */
|
|
|
- function isUndefined(value) {
|
|
|
- return typeof value === 'undefined';
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Check if the given value is an object.
|
|
|
- * @param {*} value - The value to check.
|
|
|
- * @returns {boolean} Returns `true` if the given value is an object, else `false`.
|
|
|
- */
|
|
|
- function isObject(value) {
|
|
|
- return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null;
|
|
|
- }
|
|
|
-
|
|
|
- var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
|
-
|
|
|
- /**
|
|
|
- * Check if the given value is a plain object.
|
|
|
- * @param {*} value - The value to check.
|
|
|
- * @returns {boolean} Returns `true` if the given value is a plain object, else `false`.
|
|
|
- */
|
|
|
-
|
|
|
- function isPlainObject(value) {
|
|
|
- if (!isObject(value)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // The amount of time to delay between automatically cycling an image when playing.
|
|
|
+ interval: 2000,
|
|
|
|
|
|
- try {
|
|
|
- var _constructor = value.constructor;
|
|
|
- var prototype = _constructor.prototype;
|
|
|
+ // Enable keyboard support
|
|
|
+ keyboard: true,
|
|
|
|
|
|
+ // Enable a modal backdrop, specify `static` for a backdrop which doesn't close the modal on click
|
|
|
+ backdrop: true,
|
|
|
|
|
|
- return _constructor && prototype && hasOwnProperty.call(prototype, 'isPrototypeOf');
|
|
|
- } catch (e) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Check if the given value is a function.
|
|
|
- * @param {*} value - The value to check.
|
|
|
- * @returns {boolean} Returns `true` if the given value is a function, else `false`.
|
|
|
- */
|
|
|
- function isFunction(value) {
|
|
|
- return typeof value === 'function';
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Iterate the given data.
|
|
|
- * @param {*} data - The data to iterate.
|
|
|
- * @param {Function} callback - The process function for each element.
|
|
|
- * @returns {*} The original data.
|
|
|
- */
|
|
|
- function forEach(data, callback) {
|
|
|
- if (data && isFunction(callback)) {
|
|
|
- if (Array.isArray(data) || isNumber(data.length) /* array-like */) {
|
|
|
- var length = data.length;
|
|
|
-
|
|
|
- var i = void 0;
|
|
|
-
|
|
|
- for (i = 0; i < length; i += 1) {
|
|
|
- if (callback.call(data, data[i], i, data) === false) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (isObject(data)) {
|
|
|
- Object.keys(data).forEach(function (key) {
|
|
|
- callback.call(data, data[key], key, data);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
+ // Indicate if show a loading spinner when load image or not.
|
|
|
+ loading: true,
|
|
|
|
|
|
- return data;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Extend the given object.
|
|
|
- * @param {*} obj - The object to be extended.
|
|
|
- * @param {*} args - The rest objects which will be merged to the first object.
|
|
|
- * @returns {Object} The extended object.
|
|
|
- */
|
|
|
- var assign = Object.assign || function assign(obj) {
|
|
|
- for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
|
- args[_key - 1] = arguments[_key];
|
|
|
- }
|
|
|
+ // Indicate if enable loop viewing or not.
|
|
|
+ loop: true,
|
|
|
+
|
|
|
+ // Min width of the viewer in inline mode
|
|
|
+ minWidth: 200,
|
|
|
+
|
|
|
+ // Min height of the viewer in inline mode
|
|
|
+ minHeight: 100,
|
|
|
+
|
|
|
+ // Define the ratio when zoom the image by wheeling mouse
|
|
|
+ zoomRatio: 0.1,
|
|
|
+
|
|
|
+ // Define the min ratio of the image when zoom out
|
|
|
+ minZoomRatio: 0.01,
|
|
|
+
|
|
|
+ // Define the max ratio of the image when zoom in
|
|
|
+ maxZoomRatio: 100,
|
|
|
|
|
|
- if (isObject(obj) && args.length > 0) {
|
|
|
- args.forEach(function (arg) {
|
|
|
- if (isObject(arg)) {
|
|
|
- Object.keys(arg).forEach(function (key) {
|
|
|
- obj[key] = arg[key];
|
|
|
- });
|
|
|
+ // Define the CSS `z-index` value of viewer in modal mode.
|
|
|
+ zIndex: 2015,
|
|
|
+
|
|
|
+ // Define the CSS `z-index` value of viewer in inline mode.
|
|
|
+ zIndexInline: 0,
|
|
|
+
|
|
|
+ // Define where to get the original image URL for viewing
|
|
|
+ // Type: String (an image attribute) or Function (should return an image URL)
|
|
|
+ url: 'src',
|
|
|
+
|
|
|
+ url_original:'src',
|
|
|
+
|
|
|
+ // Define where to put the viewer in modal mode.
|
|
|
+ // Type: String | Element
|
|
|
+ container: 'body',
|
|
|
+
|
|
|
+ // Filter the images for viewing.
|
|
|
+ // Type: Function (return true if the image is viewable)
|
|
|
+ filter: null,
|
|
|
+
|
|
|
+ // Event shortcuts
|
|
|
+ ready: null,
|
|
|
+ show: null,
|
|
|
+ shown: null,
|
|
|
+ hide: null,
|
|
|
+ hidden: null,
|
|
|
+ view: null,
|
|
|
+ viewed: null
|
|
|
+ };
|
|
|
+
|
|
|
+ var TEMPLATE = '<div class="viewer-container" touch-action="none">' +
|
|
|
+ '<div class="viewer-canvas"></div>' +
|
|
|
+
|
|
|
+ '<div class="viewer-footer">' +
|
|
|
+
|
|
|
+ '<div class="viewer-toolbar">'+
|
|
|
+ '<div class="viewer-title"></div>'+'</div>' +
|
|
|
+ '<div class="viewer-navbar" style="display: none">' + '<ul class="viewer-list"></ul>' + '</div>' + '</div>' +
|
|
|
+
|
|
|
+ '<div class="viewer-tooltip"></div>' +
|
|
|
+ '<div role="button" class="viewer-button" data-action="mix"></div>' +
|
|
|
+ '<div class="viewer-player"></div>' + '</div>';
|
|
|
+
|
|
|
+ var IN_BROWSER = typeof window !== 'undefined';
|
|
|
+ var WINDOW = IN_BROWSER ? window : {};
|
|
|
+ var NAMESPACE = 'viewer';
|
|
|
+
|
|
|
+ // Actions
|
|
|
+ var ACTION_MOVE = 'move';
|
|
|
+ var ACTION_SWITCH = 'switch';
|
|
|
+ var ACTION_ZOOM = 'zoom';
|
|
|
+
|
|
|
+ // Classes
|
|
|
+ var CLASS_ACTIVE = NAMESPACE + '-active';
|
|
|
+ var CLASS_CLOSE = NAMESPACE + '-close';
|
|
|
+ var CLASS_FADE = NAMESPACE + '-fade';
|
|
|
+ var CLASS_FIXED = NAMESPACE + '-fixed';
|
|
|
+ var CLASS_FULLSCREEN = NAMESPACE + '-fullscreen';
|
|
|
+ var CLASS_FULLSCREEN_EXIT = NAMESPACE + '-fullscreen-exit';
|
|
|
+ var CLASS_HIDE = NAMESPACE + '-hide';
|
|
|
+ var CLASS_HIDE_MD_DOWN = NAMESPACE + '-hide-md-down';
|
|
|
+ var CLASS_HIDE_SM_DOWN = NAMESPACE + '-hide-sm-down';
|
|
|
+ var CLASS_HIDE_XS_DOWN = NAMESPACE + '-hide-xs-down';
|
|
|
+ var CLASS_IN = NAMESPACE + '-in';
|
|
|
+ var CLASS_INVISIBLE = NAMESPACE + '-invisible';
|
|
|
+ var CLASS_LOADING = NAMESPACE + '-loading';
|
|
|
+ var CLASS_MOVE = NAMESPACE + '-move';
|
|
|
+ var CLASS_OPEN = NAMESPACE + '-open';
|
|
|
+ var CLASS_SHOW = NAMESPACE + '-show';
|
|
|
+ var CLASS_TRANSITION = NAMESPACE + '-transition';
|
|
|
+
|
|
|
+ // Events
|
|
|
+ var EVENT_READY = 'ready';
|
|
|
+ var EVENT_SHOW = 'show';
|
|
|
+ var EVENT_SHOWN = 'shown';
|
|
|
+ var EVENT_HIDE = 'hide';
|
|
|
+ var EVENT_HIDDEN = 'hidden';
|
|
|
+ var EVENT_VIEW = 'view';
|
|
|
+ var EVENT_VIEWED = 'viewed';
|
|
|
+ var EVENT_CLICK = 'click';
|
|
|
+ var EVENT_DRAG_START = 'dragstart';
|
|
|
+ var EVENT_KEY_DOWN = 'keydown';
|
|
|
+ var EVENT_LOAD = 'load';
|
|
|
+ var EVENT_POINTER_DOWN = WINDOW.PointerEvent ? 'pointerdown' : 'touchstart mousedown';
|
|
|
+ var EVENT_POINTER_MOVE = WINDOW.PointerEvent ? 'pointermove' : 'touchmove mousemove';
|
|
|
+ var EVENT_POINTER_UP = WINDOW.PointerEvent ? 'pointerup pointercancel' : 'touchend touchcancel mouseup';
|
|
|
+ var EVENT_RESIZE = 'resize';
|
|
|
+ var EVENT_TRANSITION_END = 'transitionend';
|
|
|
+ var EVENT_WHEEL = 'wheel mousewheel DOMMouseScroll';
|
|
|
+
|
|
|
+ //var BUTTONS = ['zoom-in', 'zoom-out', 'one-to-one', 'reset', 'prev', 'play', 'next', 'rotate-left', 'rotate-right', 'flip-horizontal', 'flip-vertical'];
|
|
|
+ var BUTTONS = [ 'one-to-ones','enlarge','zoom-ins', 'zoom-outs', 'prevs', 'plays', 'nexts',];
|
|
|
+
|
|
|
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
|
|
+ return typeof obj;
|
|
|
+ } : function (obj) {
|
|
|
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
|
+ };
|
|
|
+
|
|
|
+ var classCallCheck = function (instance, Constructor) {
|
|
|
+ if (!(instance instanceof Constructor)) {
|
|
|
+ throw new TypeError("Cannot call a class as a function");
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- return obj;
|
|
|
- };
|
|
|
-
|
|
|
- var REGEXP_SUFFIX = /^(?:width|height|left|top|marginLeft|marginTop)$/;
|
|
|
-
|
|
|
- /**
|
|
|
- * Apply styles to the given element.
|
|
|
- * @param {Element} element - The target element.
|
|
|
- * @param {Object} styles - The styles for applying.
|
|
|
- */
|
|
|
- function setStyle(element, styles) {
|
|
|
- var style = element.style;
|
|
|
-
|
|
|
-
|
|
|
- forEach(styles, function (value, property) {
|
|
|
- if (REGEXP_SUFFIX.test(property) && isNumber(value)) {
|
|
|
- value += 'px';
|
|
|
- }
|
|
|
-
|
|
|
- style[property] = value;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Check if the given element has a special class.
|
|
|
- * @param {Element} element - The element to check.
|
|
|
- * @param {string} value - The class to search.
|
|
|
- * @returns {boolean} Returns `true` if the special class was found.
|
|
|
- */
|
|
|
- function hasClass(element, value) {
|
|
|
- return element.classList ? element.classList.contains(value) : element.className.indexOf(value) > -1;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Add classes to the given element.
|
|
|
- * @param {Element} element - The target element.
|
|
|
- * @param {string} value - The classes to be added.
|
|
|
- */
|
|
|
- function addClass(element, value) {
|
|
|
- if (!value) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ var createClass = function () {
|
|
|
+ function defineProperties(target, props) {
|
|
|
+ for (var i = 0; i < props.length; i++) {
|
|
|
+ var descriptor = props[i];
|
|
|
+ descriptor.enumerable = descriptor.enumerable || false;
|
|
|
+ descriptor.configurable = true;
|
|
|
+ if ("value" in descriptor) descriptor.writable = true;
|
|
|
+ Object.defineProperty(target, descriptor.key, descriptor);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (isNumber(element.length)) {
|
|
|
- forEach(element, function (elem) {
|
|
|
- addClass(elem, value);
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
+ return function (Constructor, protoProps, staticProps) {
|
|
|
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
|
|
+ if (staticProps) defineProperties(Constructor, staticProps);
|
|
|
+ return Constructor;
|
|
|
+ };
|
|
|
+ }();
|
|
|
|
|
|
- if (element.classList) {
|
|
|
- element.classList.add(value);
|
|
|
- return;
|
|
|
+ /**
|
|
|
+ * Check if the given value is a string.
|
|
|
+ * @param {*} value - The value to check.
|
|
|
+ * @returns {boolean} Returns `true` if the given value is a string, else `false`.
|
|
|
+ */
|
|
|
+ function isString(value) {
|
|
|
+ return typeof value === 'string';
|
|
|
}
|
|
|
|
|
|
- var className = element.className.trim();
|
|
|
+ /**
|
|
|
+ * Check if the given value is not a number.
|
|
|
+ */
|
|
|
+ var isNaN = Number.isNaN || WINDOW.isNaN;
|
|
|
|
|
|
- if (!className) {
|
|
|
- element.className = value;
|
|
|
- } else if (className.indexOf(value) < 0) {
|
|
|
- element.className = className + ' ' + value;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Remove classes from the given element.
|
|
|
- * @param {Element} element - The target element.
|
|
|
- * @param {string} value - The classes to be removed.
|
|
|
- */
|
|
|
- function removeClass(element, value) {
|
|
|
- if (!value) {
|
|
|
- return;
|
|
|
+ /**
|
|
|
+ * Check if the given value is a number.
|
|
|
+ * @param {*} value - The value to check.
|
|
|
+ * @returns {boolean} Returns `true` if the given value is a number, else `false`.
|
|
|
+ */
|
|
|
+ function isNumber(value) {
|
|
|
+ return typeof value === 'number' && !isNaN(value);
|
|
|
}
|
|
|
|
|
|
- if (isNumber(element.length)) {
|
|
|
- forEach(element, function (elem) {
|
|
|
- removeClass(elem, value);
|
|
|
- });
|
|
|
- return;
|
|
|
+ /**
|
|
|
+ * Check if the given value is undefined.
|
|
|
+ * @param {*} value - The value to check.
|
|
|
+ * @returns {boolean} Returns `true` if the given value is undefined, else `false`.
|
|
|
+ */
|
|
|
+ function isUndefined(value) {
|
|
|
+ return typeof value === 'undefined';
|
|
|
}
|
|
|
|
|
|
- if (element.classList) {
|
|
|
- element.classList.remove(value);
|
|
|
- return;
|
|
|
+ /**
|
|
|
+ * Check if the given value is an object.
|
|
|
+ * @param {*} value - The value to check.
|
|
|
+ * @returns {boolean} Returns `true` if the given value is an object, else `false`.
|
|
|
+ */
|
|
|
+ function isObject(value) {
|
|
|
+ return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null;
|
|
|
}
|
|
|
|
|
|
- if (element.className.indexOf(value) >= 0) {
|
|
|
- element.className = element.className.replace(value, '');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Add or remove classes from the given element.
|
|
|
- * @param {Element} element - The target element.
|
|
|
- * @param {string} value - The classes to be toggled.
|
|
|
- * @param {boolean} added - Add only.
|
|
|
- */
|
|
|
- function toggleClass(element, value, added) {
|
|
|
- if (!value) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
|
|
|
|
- if (isNumber(element.length)) {
|
|
|
- forEach(element, function (elem) {
|
|
|
- toggleClass(elem, value, added);
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Check if the given value is a plain object.
|
|
|
+ * @param {*} value - The value to check.
|
|
|
+ * @returns {boolean} Returns `true` if the given value is a plain object, else `false`.
|
|
|
+ */
|
|
|
|
|
|
- // IE10-11 doesn't support the second parameter of `classList.toggle`
|
|
|
- if (added) {
|
|
|
- addClass(element, value);
|
|
|
- } else {
|
|
|
- removeClass(element, value);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var REGEXP_HYPHENATE = /([a-z\d])([A-Z])/g;
|
|
|
-
|
|
|
- /**
|
|
|
- * Transform the given string from camelCase to kebab-case
|
|
|
- * @param {string} value - The value to transform.
|
|
|
- * @returns {string} The transformed value.
|
|
|
- */
|
|
|
- function hyphenate(value) {
|
|
|
- return value.replace(REGEXP_HYPHENATE, '$1-$2').toLowerCase();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get data from the given element.
|
|
|
- * @param {Element} element - The target element.
|
|
|
- * @param {string} name - The data key to get.
|
|
|
- * @returns {string} The data value.
|
|
|
- */
|
|
|
- function getData(element, name) {
|
|
|
- if (isObject(element[name])) {
|
|
|
- return element[name];
|
|
|
- } else if (element.dataset) {
|
|
|
- return element.dataset[name];
|
|
|
- }
|
|
|
+ function isPlainObject(value) {
|
|
|
+ if (!isObject(value)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ var _constructor = value.constructor;
|
|
|
+ var prototype = _constructor.prototype;
|
|
|
|
|
|
- return element.getAttribute('data-' + hyphenate(name));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Set data to the given element.
|
|
|
- * @param {Element} element - The target element.
|
|
|
- * @param {string} name - The data key to set.
|
|
|
- * @param {string} data - The data value.
|
|
|
- */
|
|
|
- function setData(element, name, data) {
|
|
|
- if (isObject(data)) {
|
|
|
- element[name] = data;
|
|
|
- } else if (element.dataset) {
|
|
|
- element.dataset[name] = data;
|
|
|
- } else {
|
|
|
- element.setAttribute('data-' + hyphenate(name), data);
|
|
|
+
|
|
|
+ return _constructor && prototype && hasOwnProperty.call(prototype, 'isPrototypeOf');
|
|
|
+ } catch (e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Remove data from the given element.
|
|
|
- * @param {Element} element - The target element.
|
|
|
- * @param {string} name - The data key to remove.
|
|
|
- */
|
|
|
- function removeData(element, name) {
|
|
|
- if (isObject(element[name])) {
|
|
|
- try {
|
|
|
- delete element[name];
|
|
|
- } catch (e) {
|
|
|
- element[name] = undefined;
|
|
|
- }
|
|
|
- } else if (element.dataset) {
|
|
|
- // #128 Safari not allows to delete dataset property
|
|
|
- try {
|
|
|
- delete element.dataset[name];
|
|
|
- } catch (e) {
|
|
|
- element.dataset[name] = undefined;
|
|
|
- }
|
|
|
- } else {
|
|
|
- element.removeAttribute('data-' + hyphenate(name));
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Check if the given value is a function.
|
|
|
+ * @param {*} value - The value to check.
|
|
|
+ * @returns {boolean} Returns `true` if the given value is a function, else `false`.
|
|
|
+ */
|
|
|
+ function isFunction(value) {
|
|
|
+ return typeof value === 'function';
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- var REGEXP_SPACES = /\s\s*/;
|
|
|
- var onceSupported = function () {
|
|
|
- var supported = false;
|
|
|
-
|
|
|
- if (IN_BROWSER) {
|
|
|
- var once = false;
|
|
|
- var listener = function listener() {};
|
|
|
- var options = Object.defineProperty({}, 'once', {
|
|
|
- get: function get$$1() {
|
|
|
- supported = true;
|
|
|
- return once;
|
|
|
- },
|
|
|
|
|
|
+ /**
|
|
|
+ * Iterate the given data.
|
|
|
+ * @param {*} data - The data to iterate.
|
|
|
+ * @param {Function} callback - The process function for each element.
|
|
|
+ * @returns {*} The original data.
|
|
|
+ */
|
|
|
+ function forEach(data, callback) {
|
|
|
+ if (data && isFunction(callback)) {
|
|
|
+ if (Array.isArray(data) || isNumber(data.length) /* array-like */) {
|
|
|
+ var length = data.length;
|
|
|
|
|
|
- /**
|
|
|
- * This setter can fix a `TypeError` in strict mode
|
|
|
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only}
|
|
|
- * @param {boolean} value - The value to set
|
|
|
- */
|
|
|
- set: function set$$1(value) {
|
|
|
- once = value;
|
|
|
+ var i = void 0;
|
|
|
+
|
|
|
+ for (i = 0; i < length; i += 1) {
|
|
|
+ if (callback.call(data, data[i], i, data) === false) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (isObject(data)) {
|
|
|
+ Object.keys(data).forEach(function (key) {
|
|
|
+ callback.call(data, data[key], key, data);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
|
|
|
- WINDOW.addEventListener('test', listener, options);
|
|
|
- WINDOW.removeEventListener('test', listener, options);
|
|
|
+ return data;
|
|
|
}
|
|
|
|
|
|
- return supported;
|
|
|
- }();
|
|
|
+ /**
|
|
|
+ * Extend the given object.
|
|
|
+ * @param {*} obj - The object to be extended.
|
|
|
+ * @param {*} args - The rest objects which will be merged to the first object.
|
|
|
+ * @returns {Object} The extended object.
|
|
|
+ */
|
|
|
+ var assign = Object.assign || function assign(obj) {
|
|
|
+ for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
|
+ args[_key - 1] = arguments[_key];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isObject(obj) && args.length > 0) {
|
|
|
+ args.forEach(function (arg) {
|
|
|
+ if (isObject(arg)) {
|
|
|
+ Object.keys(arg).forEach(function (key) {
|
|
|
+ obj[key] = arg[key];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return obj;
|
|
|
+ };
|
|
|
|
|
|
- /**
|
|
|
- * Remove event listener from the target element.
|
|
|
- * @param {Element} element - The event target.
|
|
|
- * @param {string} type - The event type(s).
|
|
|
- * @param {Function} listener - The event listener.
|
|
|
- * @param {Object} options - The event options.
|
|
|
- */
|
|
|
- function removeListener(element, type, listener) {
|
|
|
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
|
+ var REGEXP_SUFFIX = /^(?:width|height|left|top|marginLeft|marginTop)$/;
|
|
|
|
|
|
- var handler = listener;
|
|
|
+ /**
|
|
|
+ * Apply styles to the given element.
|
|
|
+ * @param {Element} element - The target element.
|
|
|
+ * @param {Object} styles - The styles for applying.
|
|
|
+ */
|
|
|
+ function setStyle(element, styles) {
|
|
|
+ var style = element.style;
|
|
|
|
|
|
- type.trim().split(REGEXP_SPACES).forEach(function (event) {
|
|
|
- if (!onceSupported) {
|
|
|
- var listeners = element.listeners;
|
|
|
|
|
|
+ forEach(styles, function (value, property) {
|
|
|
+ if (REGEXP_SUFFIX.test(property) && isNumber(value)) {
|
|
|
+ value += 'px';
|
|
|
+ }
|
|
|
|
|
|
- if (listeners && listeners[event] && listeners[event][listener]) {
|
|
|
- handler = listeners[event][listener];
|
|
|
- delete listeners[event][listener];
|
|
|
+ style[property] = value;
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- if (Object.keys(listeners[event]).length === 0) {
|
|
|
- delete listeners[event];
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Check if the given element has a special class.
|
|
|
+ * @param {Element} element - The element to check.
|
|
|
+ * @param {string} value - The class to search.
|
|
|
+ * @returns {boolean} Returns `true` if the special class was found.
|
|
|
+ */
|
|
|
+ function hasClass(element, value) {
|
|
|
+ return element.classList ? element.classList.contains(value) : element.className.indexOf(value) > -1;
|
|
|
+ }
|
|
|
|
|
|
- if (Object.keys(listeners).length === 0) {
|
|
|
- delete element.listeners;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Add classes to the given element.
|
|
|
+ * @param {Element} element - The target element.
|
|
|
+ * @param {string} value - The classes to be added.
|
|
|
+ */
|
|
|
+ function addClass(element, value) {
|
|
|
+ if (!value) {
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- element.removeEventListener(event, handler, options);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Add event listener to the target element.
|
|
|
- * @param {Element} element - The event target.
|
|
|
- * @param {string} type - The event type(s).
|
|
|
- * @param {Function} listener - The event listener.
|
|
|
- * @param {Object} options - The event options.
|
|
|
- */
|
|
|
- function addListener(element, type, listener) {
|
|
|
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
|
-
|
|
|
- var _handler = listener;
|
|
|
-
|
|
|
- type.trim().split(REGEXP_SPACES).forEach(function (event) {
|
|
|
- if (options.once && !onceSupported) {
|
|
|
- var _element$listeners = element.listeners,
|
|
|
- listeners = _element$listeners === undefined ? {} : _element$listeners;
|
|
|
-
|
|
|
-
|
|
|
- _handler = function handler() {
|
|
|
- for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
|
- args[_key2] = arguments[_key2];
|
|
|
- }
|
|
|
-
|
|
|
- delete listeners[event][listener];
|
|
|
- element.removeEventListener(event, _handler, options);
|
|
|
- listener.apply(element, args);
|
|
|
- };
|
|
|
|
|
|
- if (!listeners[event]) {
|
|
|
- listeners[event] = {};
|
|
|
+ if (isNumber(element.length)) {
|
|
|
+ forEach(element, function (elem) {
|
|
|
+ addClass(elem, value);
|
|
|
+ });
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- if (listeners[event][listener]) {
|
|
|
- element.removeEventListener(event, listeners[event][listener], options);
|
|
|
+ if (element.classList) {
|
|
|
+ element.classList.add(value);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- listeners[event][listener] = _handler;
|
|
|
- element.listeners = listeners;
|
|
|
- }
|
|
|
-
|
|
|
- element.addEventListener(event, _handler, options);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Dispatch event on the target element.
|
|
|
- * @param {Element} element - The event target.
|
|
|
- * @param {string} type - The event type(s).
|
|
|
- * @param {Object} data - The additional event data.
|
|
|
- * @returns {boolean} Indicate if the event is default prevented or not.
|
|
|
- */
|
|
|
- function dispatchEvent(element, type, data) {
|
|
|
- var event = void 0;
|
|
|
-
|
|
|
- // Event and CustomEvent on IE9-11 are global objects, not constructors
|
|
|
- if (isFunction(Event) && isFunction(CustomEvent)) {
|
|
|
- event = new CustomEvent(type, {
|
|
|
- detail: data,
|
|
|
- bubbles: true,
|
|
|
- cancelable: true
|
|
|
- });
|
|
|
- } else {
|
|
|
- event = document.createEvent('CustomEvent');
|
|
|
- event.initCustomEvent(type, true, true, data);
|
|
|
+ var className = element.className.trim();
|
|
|
+
|
|
|
+ if (!className) {
|
|
|
+ element.className = value;
|
|
|
+ } else if (className.indexOf(value) < 0) {
|
|
|
+ element.className = className + ' ' + value;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- return element.dispatchEvent(event);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Remove classes from the given element.
|
|
|
+ * @param {Element} element - The target element.
|
|
|
+ * @param {string} value - The classes to be removed.
|
|
|
+ */
|
|
|
+ function removeClass(element, value) {
|
|
|
+ if (!value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * Get the offset base on the document.
|
|
|
- * @param {Element} element - The target element.
|
|
|
- * @returns {Object} The offset data.
|
|
|
- */
|
|
|
- function getOffset(element) {
|
|
|
- var box = element.getBoundingClientRect();
|
|
|
+ if (isNumber(element.length)) {
|
|
|
+ forEach(element, function (elem) {
|
|
|
+ removeClass(elem, value);
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- return {
|
|
|
- left: box.left + (window.pageXOffset - document.documentElement.clientLeft),
|
|
|
- top: box.top + (window.pageYOffset - document.documentElement.clientTop)
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get transforms base on the given object.
|
|
|
- * @param {Object} obj - The target object.
|
|
|
- * @returns {string} A string contains transform values.
|
|
|
- */
|
|
|
- function getTransforms(_ref) {
|
|
|
- var rotate = _ref.rotate,
|
|
|
- scaleX = _ref.scaleX,
|
|
|
- scaleY = _ref.scaleY,
|
|
|
- translateX = _ref.translateX,
|
|
|
- translateY = _ref.translateY;
|
|
|
-
|
|
|
- var values = [];
|
|
|
-
|
|
|
- if (isNumber(translateX) && translateX !== 0) {
|
|
|
- values.push('translateX(' + translateX + 'px)');
|
|
|
- }
|
|
|
+ if (element.classList) {
|
|
|
+ element.classList.remove(value);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (isNumber(translateY) && translateY !== 0) {
|
|
|
- values.push('translateY(' + translateY + 'px)');
|
|
|
+ if (element.className.indexOf(value) >= 0) {
|
|
|
+ element.className = element.className.replace(value, '');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // Rotate should come first before scale to match orientation transform
|
|
|
- if (isNumber(rotate) && rotate !== 0) {
|
|
|
- values.push('rotate(' + rotate + 'deg)');
|
|
|
+ /**
|
|
|
+ * Add or remove classes from the given element.
|
|
|
+ * @param {Element} element - The target element.
|
|
|
+ * @param {string} value - The classes to be toggled.
|
|
|
+ * @param {boolean} added - Add only.
|
|
|
+ */
|
|
|
+ function toggleClass(element, value, added) {
|
|
|
+ if (!value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isNumber(element.length)) {
|
|
|
+ forEach(element, function (elem) {
|
|
|
+ toggleClass(elem, value, added);
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // IE10-11 doesn't support the second parameter of `classList.toggle`
|
|
|
+ if (added) {
|
|
|
+ addClass(element, value);
|
|
|
+ } else {
|
|
|
+ removeClass(element, value);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (isNumber(scaleX) && scaleX !== 1) {
|
|
|
- values.push('scaleX(' + scaleX + ')');
|
|
|
+ var REGEXP_HYPHENATE = /([a-z\d])([A-Z])/g;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Transform the given string from camelCase to kebab-case
|
|
|
+ * @param {string} value - The value to transform.
|
|
|
+ * @returns {string} The transformed value.
|
|
|
+ */
|
|
|
+ function hyphenate(value) {
|
|
|
+ return value.replace(REGEXP_HYPHENATE, '$1-$2').toLowerCase();
|
|
|
}
|
|
|
|
|
|
- if (isNumber(scaleY) && scaleY !== 1) {
|
|
|
- values.push('scaleY(' + scaleY + ')');
|
|
|
+ /**
|
|
|
+ * Get data from the given element.
|
|
|
+ * @param {Element} element - The target element.
|
|
|
+ * @param {string} name - The data key to get.
|
|
|
+ * @returns {string} The data value.
|
|
|
+ */
|
|
|
+ function getData(element, name) {
|
|
|
+ if (isObject(element[name])) {
|
|
|
+ return element[name];
|
|
|
+ } else if (element.dataset) {
|
|
|
+ return element.dataset[name];
|
|
|
+ }
|
|
|
+
|
|
|
+ return element.getAttribute('data-' + hyphenate(name));
|
|
|
}
|
|
|
|
|
|
- var transform = values.length ? values.join(' ') : 'none';
|
|
|
+ /**
|
|
|
+ * Set data to the given element.
|
|
|
+ * @param {Element} element - The target element.
|
|
|
+ * @param {string} name - The data key to set.
|
|
|
+ * @param {string} data - The data value.
|
|
|
+ */
|
|
|
+ function setData(element, name, data) {
|
|
|
+ if (isObject(data)) {
|
|
|
+ element[name] = data;
|
|
|
+ } else if (element.dataset) {
|
|
|
+ element.dataset[name] = data;
|
|
|
+ } else {
|
|
|
+ element.setAttribute('data-' + hyphenate(name), data);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return {
|
|
|
- WebkitTransform: transform,
|
|
|
- msTransform: transform,
|
|
|
- transform: transform
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get an image name from an image url.
|
|
|
- * @param {string} url - The target url.
|
|
|
- * @example
|
|
|
- * // picture.jpg
|
|
|
- * getImageNameFromURL('http://domain.com/path/to/picture.jpg?size=1280×960')
|
|
|
- * @returns {string} A string contains the image name.
|
|
|
- */
|
|
|
- function getImageNameFromURL(url) {
|
|
|
- return isString(url) ? url.replace(/^.*\//, '').replace(/[?&#].*$/, '') : '';
|
|
|
- }
|
|
|
-
|
|
|
- var IS_SAFARI = WINDOW.navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(WINDOW.navigator.userAgent);
|
|
|
-
|
|
|
- /**
|
|
|
- * Get an image's natural sizes.
|
|
|
- * @param {string} image - The target image.
|
|
|
- * @param {Function} callback - The callback function.
|
|
|
- * @returns {HTMLImageElement} The new image.
|
|
|
- */
|
|
|
- function getImageNaturalSizes(image, callback) {
|
|
|
- var newImage = document.createElement('img');
|
|
|
-
|
|
|
- // Modern browsers (except Safari)
|
|
|
- if (image.naturalWidth && !IS_SAFARI) {
|
|
|
- callback(image.naturalWidth, image.naturalHeight);
|
|
|
- return newImage;
|
|
|
+ /**
|
|
|
+ * Remove data from the given element.
|
|
|
+ * @param {Element} element - The target element.
|
|
|
+ * @param {string} name - The data key to remove.
|
|
|
+ */
|
|
|
+ function removeData(element, name) {
|
|
|
+ if (isObject(element[name])) {
|
|
|
+ try {
|
|
|
+ delete element[name];
|
|
|
+ } catch (e) {
|
|
|
+ element[name] = undefined;
|
|
|
+ }
|
|
|
+ } else if (element.dataset) {
|
|
|
+ // #128 Safari not allows to delete dataset property
|
|
|
+ try {
|
|
|
+ delete element.dataset[name];
|
|
|
+ } catch (e) {
|
|
|
+ element.dataset[name] = undefined;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ element.removeAttribute('data-' + hyphenate(name));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- var body = document.body || document.documentElement;
|
|
|
+ var REGEXP_SPACES = /\s\s*/;
|
|
|
+ var onceSupported = function () {
|
|
|
+ var supported = false;
|
|
|
+
|
|
|
+ if (IN_BROWSER) {
|
|
|
+ var once = false;
|
|
|
+ var listener = function listener() {};
|
|
|
+ var options = Object.defineProperty({}, 'once', {
|
|
|
+ get: function get$$1() {
|
|
|
+ supported = true;
|
|
|
+ return once;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * This setter can fix a `TypeError` in strict mode
|
|
|
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only}
|
|
|
+ * @param {boolean} value - The value to set
|
|
|
+ */
|
|
|
+ set: function set$$1(value) {
|
|
|
+ once = value;
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- newImage.onload = function () {
|
|
|
- callback(newImage.width, newImage.height);
|
|
|
+ WINDOW.addEventListener('test', listener, options);
|
|
|
+ WINDOW.removeEventListener('test', listener, options);
|
|
|
+ }
|
|
|
|
|
|
- if (!IS_SAFARI) {
|
|
|
- body.removeChild(newImage);
|
|
|
- }
|
|
|
- };
|
|
|
+ return supported;
|
|
|
+ }();
|
|
|
|
|
|
- newImage.src = image.src;
|
|
|
+ /**
|
|
|
+ * Remove event listener from the target element.
|
|
|
+ * @param {Element} element - The event target.
|
|
|
+ * @param {string} type - The event type(s).
|
|
|
+ * @param {Function} listener - The event listener.
|
|
|
+ * @param {Object} options - The event options.
|
|
|
+ */
|
|
|
+ function removeListener(element, type, listener) {
|
|
|
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
|
|
|
|
- // iOS Safari will convert the image automatically
|
|
|
- // with its orientation once append it into DOM
|
|
|
- if (!IS_SAFARI) {
|
|
|
- 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;';
|
|
|
- body.appendChild(newImage);
|
|
|
- }
|
|
|
+ var handler = listener;
|
|
|
|
|
|
- return newImage;
|
|
|
- }
|
|
|
+ type.trim().split(REGEXP_SPACES).forEach(function (event) {
|
|
|
+ if (!onceSupported) {
|
|
|
+ var listeners = element.listeners;
|
|
|
|
|
|
- /**
|
|
|
- * Get the related class name of a responsive type number.
|
|
|
- * @param {string} type - The responsive type.
|
|
|
- * @returns {string} The related class name.
|
|
|
- */
|
|
|
- function getResponsiveClass(type) {
|
|
|
- switch (type) {
|
|
|
- case 2:
|
|
|
- return CLASS_HIDE_XS_DOWN;
|
|
|
|
|
|
- case 3:
|
|
|
- return CLASS_HIDE_SM_DOWN;
|
|
|
+ if (listeners && listeners[event] && listeners[event][listener]) {
|
|
|
+ handler = listeners[event][listener];
|
|
|
+ delete listeners[event][listener];
|
|
|
|
|
|
- case 4:
|
|
|
- return CLASS_HIDE_MD_DOWN;
|
|
|
+ if (Object.keys(listeners[event]).length === 0) {
|
|
|
+ delete listeners[event];
|
|
|
+ }
|
|
|
|
|
|
- default:
|
|
|
- return '';
|
|
|
+ if (Object.keys(listeners).length === 0) {
|
|
|
+ delete element.listeners;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ element.removeEventListener(event, handler, options);
|
|
|
+ });
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get the max ratio of a group of pointers.
|
|
|
- * @param {string} pointers - The target pointers.
|
|
|
- * @returns {number} The result ratio.
|
|
|
- */
|
|
|
- function getMaxZoomRatio(pointers) {
|
|
|
- var pointers2 = assign({}, pointers);
|
|
|
- var ratios = [];
|
|
|
-
|
|
|
- forEach(pointers, function (pointer, pointerId) {
|
|
|
- delete pointers2[pointerId];
|
|
|
-
|
|
|
- forEach(pointers2, function (pointer2) {
|
|
|
- var x1 = Math.abs(pointer.startX - pointer2.startX);
|
|
|
- var y1 = Math.abs(pointer.startY - pointer2.startY);
|
|
|
- var x2 = Math.abs(pointer.endX - pointer2.endX);
|
|
|
- var y2 = Math.abs(pointer.endY - pointer2.endY);
|
|
|
- var z1 = Math.sqrt(x1 * x1 + y1 * y1);
|
|
|
- var z2 = Math.sqrt(x2 * x2 + y2 * y2);
|
|
|
- var ratio = (z2 - z1) / z1;
|
|
|
-
|
|
|
- ratios.push(ratio);
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- ratios.sort(function (a, b) {
|
|
|
- return Math.abs(a) < Math.abs(b);
|
|
|
- });
|
|
|
-
|
|
|
- return ratios[0];
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get a pointer from an event object.
|
|
|
- * @param {Object} event - The target event object.
|
|
|
- * @param {boolean} endOnly - Indicates if only returns the end point coordinate or not.
|
|
|
- * @returns {Object} The result pointer contains start and/or end point coordinates.
|
|
|
- */
|
|
|
- function getPointer(_ref2, endOnly) {
|
|
|
- var pageX = _ref2.pageX,
|
|
|
- pageY = _ref2.pageY;
|
|
|
-
|
|
|
- var end = {
|
|
|
- endX: pageX,
|
|
|
- endY: pageY
|
|
|
- };
|
|
|
|
|
|
- return endOnly ? end : assign({
|
|
|
- startX: pageX,
|
|
|
- startY: pageY
|
|
|
- }, end);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get the center point coordinate of a group of pointers.
|
|
|
- * @param {Object} pointers - The target pointers.
|
|
|
- * @returns {Object} The center point coordinate.
|
|
|
- */
|
|
|
- function getPointersCenter(pointers) {
|
|
|
- var pageX = 0;
|
|
|
- var pageY = 0;
|
|
|
- var count = 0;
|
|
|
-
|
|
|
- forEach(pointers, function (_ref3) {
|
|
|
- var startX = _ref3.startX,
|
|
|
- startY = _ref3.startY;
|
|
|
-
|
|
|
- pageX += startX;
|
|
|
- pageY += startY;
|
|
|
- count += 1;
|
|
|
- });
|
|
|
-
|
|
|
- pageX /= count;
|
|
|
- pageY /= count;
|
|
|
-
|
|
|
- return {
|
|
|
- pageX: pageX,
|
|
|
- pageY: pageY
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- var render = {
|
|
|
- render: function render() {
|
|
|
- this.initContainer();
|
|
|
- this.initViewer();
|
|
|
- this.initList();
|
|
|
- this.renderViewer();
|
|
|
- },
|
|
|
- initContainer: function initContainer() {
|
|
|
- this.containerData = {
|
|
|
- width: window.innerWidth,
|
|
|
- height: window.innerHeight
|
|
|
- };
|
|
|
- },
|
|
|
- initViewer: function initViewer() {
|
|
|
- var options = this.options,
|
|
|
- parent = this.parent;
|
|
|
-
|
|
|
- var viewerData = void 0;
|
|
|
-
|
|
|
- if (options.inline) {
|
|
|
- viewerData = {
|
|
|
- width: Math.max(parent.offsetWidth, options.minWidth),
|
|
|
- height: Math.max(parent.offsetHeight, options.minHeight)
|
|
|
- };
|
|
|
+ /**
|
|
|
+ * Add event listener to the target element.
|
|
|
+ * @param {Element} element - The event target.
|
|
|
+ * @param {string} type - The event type(s).
|
|
|
+ * @param {Function} listener - The event listener.
|
|
|
+ * @param {Object} options - The event options.
|
|
|
+ */
|
|
|
+ function addListener(element, type, listener) {
|
|
|
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
|
|
|
|
- this.parentData = viewerData;
|
|
|
- }
|
|
|
+ var _handler = listener;
|
|
|
|
|
|
- if (this.fulled || !viewerData) {
|
|
|
- viewerData = this.containerData;
|
|
|
- }
|
|
|
+ type.trim().split(REGEXP_SPACES).forEach(function (event) {
|
|
|
+ if (options.once && !onceSupported) {
|
|
|
+ var _element$listeners = element.listeners,
|
|
|
+ listeners = _element$listeners === undefined ? {} : _element$listeners;
|
|
|
|
|
|
- this.viewerData = assign({}, viewerData);
|
|
|
- },
|
|
|
- renderViewer: function renderViewer() {
|
|
|
- if (this.options.inline && !this.fulled) {
|
|
|
- setStyle(this.viewer, this.viewerData);
|
|
|
- }
|
|
|
- },
|
|
|
- initList: function initList() {
|
|
|
- var _this = this;
|
|
|
|
|
|
- var element = this.element,
|
|
|
- options = this.options,
|
|
|
- list = this.list;
|
|
|
+ _handler = function handler() {
|
|
|
+ for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
|
+ args[_key2] = arguments[_key2];
|
|
|
+ }
|
|
|
|
|
|
- var items = [];
|
|
|
+ delete listeners[event][listener];
|
|
|
+ element.removeEventListener(event, _handler, options);
|
|
|
+ listener.apply(element, args);
|
|
|
+ };
|
|
|
|
|
|
- forEach(this.images, function (image, i) {
|
|
|
- var src = image.src;
|
|
|
+ if (!listeners[event]) {
|
|
|
+ listeners[event] = {};
|
|
|
+ }
|
|
|
|
|
|
- var alt = image.alt || getImageNameFromURL(src);
|
|
|
- var url = options.url;
|
|
|
+ if (listeners[event][listener]) {
|
|
|
+ element.removeEventListener(event, listeners[event][listener], options);
|
|
|
+ }
|
|
|
|
|
|
+ listeners[event][listener] = _handler;
|
|
|
+ element.listeners = listeners;
|
|
|
+ }
|
|
|
|
|
|
- if (isString(url)) {
|
|
|
- url = image.getAttribute(url);
|
|
|
- } else if (isFunction(url)) {
|
|
|
- url = url.call(_this, image);
|
|
|
- }
|
|
|
+ element.addEventListener(event, _handler, options);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- if (src || url) {
|
|
|
- items.push('<li>' + '<img' + (' src="' + (src || url) + '"') + ' role="button"' + ' data-action="view"' + (' data-index="' + i + '"') + (' data-original-url="' + (url || src) + '"') + (' alt="' + alt + '"') + '>' + '</li>');
|
|
|
+ /**
|
|
|
+ * Dispatch event on the target element.
|
|
|
+ * @param {Element} element - The event target.
|
|
|
+ * @param {string} type - The event type(s).
|
|
|
+ * @param {Object} data - The additional event data.
|
|
|
+ * @returns {boolean} Indicate if the event is default prevented or not.
|
|
|
+ */
|
|
|
+ function dispatchEvent(element, type, data) {
|
|
|
+ var event = void 0;
|
|
|
+
|
|
|
+ // Event and CustomEvent on IE9-11 are global objects, not constructors
|
|
|
+ if (isFunction(Event) && isFunction(CustomEvent)) {
|
|
|
+ event = new CustomEvent(type, {
|
|
|
+ detail: data,
|
|
|
+ bubbles: true,
|
|
|
+ cancelable: true
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ event = document.createEvent('CustomEvent');
|
|
|
+ event.initCustomEvent(type, true, true, data);
|
|
|
}
|
|
|
- });
|
|
|
|
|
|
- list.innerHTML = items.join('');
|
|
|
- this.items = list.getElementsByTagName('li');
|
|
|
- forEach(this.items, function (item) {
|
|
|
- var image = item.firstElementChild;
|
|
|
+ return element.dispatchEvent(event);
|
|
|
+ }
|
|
|
|
|
|
- setData(image, 'filled', true);
|
|
|
+ /**
|
|
|
+ * Get the offset base on the document.
|
|
|
+ * @param {Element} element - The target element.
|
|
|
+ * @returns {Object} The offset data.
|
|
|
+ */
|
|
|
+ function getOffset(element) {
|
|
|
+ var box = element.getBoundingClientRect();
|
|
|
|
|
|
- if (options.loading) {
|
|
|
- addClass(item, CLASS_LOADING);
|
|
|
- }
|
|
|
+ return {
|
|
|
+ left: box.left + (window.pageXOffset - document.documentElement.clientLeft),
|
|
|
+ top: box.top + (window.pageYOffset - document.documentElement.clientTop)
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
- addListener(image, EVENT_LOAD, function (event) {
|
|
|
- if (options.loading) {
|
|
|
- removeClass(item, CLASS_LOADING);
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Get transforms base on the given object.
|
|
|
+ * @param {Object} obj - The target object.
|
|
|
+ * @returns {string} A string contains transform values.
|
|
|
+ */
|
|
|
+ function getTransforms(_ref) {
|
|
|
+ var rotate = _ref.rotate,
|
|
|
+ scaleX = _ref.scaleX,
|
|
|
+ scaleY = _ref.scaleY,
|
|
|
+ translateX = _ref.translateX,
|
|
|
+ translateY = _ref.translateY;
|
|
|
|
|
|
- _this.loadImage(event);
|
|
|
- }, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- });
|
|
|
+ var values = [];
|
|
|
|
|
|
- if (options.transition) {
|
|
|
- addListener(element, EVENT_VIEWED, function () {
|
|
|
- addClass(list, CLASS_TRANSITION);
|
|
|
- }, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
- renderList: function renderList(index) {
|
|
|
- var i = index || this.index;
|
|
|
- var width = this.items[i].offsetWidth || 30;
|
|
|
- var outerWidth = width + 1; // 1 pixel of `margin-left` width
|
|
|
-
|
|
|
- // Place the active item in the center of the screen
|
|
|
- setStyle(this.list, assign({
|
|
|
- width: outerWidth * this.length
|
|
|
- }, getTransforms({
|
|
|
- translateX: (this.viewerData.width - width) / 2 - outerWidth * i
|
|
|
- })));
|
|
|
- },
|
|
|
- resetList: function resetList() {
|
|
|
- var list = this.list;
|
|
|
-
|
|
|
-
|
|
|
- list.innerHTML = '';
|
|
|
- removeClass(list, CLASS_TRANSITION);
|
|
|
- setStyle(list, getTransforms({
|
|
|
- translateX: 0
|
|
|
- }));
|
|
|
- },
|
|
|
- initImage: function initImage(done) {
|
|
|
- var _this2 = this;
|
|
|
-
|
|
|
- var options = this.options,
|
|
|
- image = this.image,
|
|
|
- viewerData = this.viewerData;
|
|
|
-
|
|
|
- var footerHeight = this.footer.offsetHeight;
|
|
|
- var viewerWidth = viewerData.width;
|
|
|
- var viewerHeight = Math.max(viewerData.height - footerHeight, footerHeight);
|
|
|
- var oldImageData = this.imageData || {};
|
|
|
- var sizingImage = void 0;
|
|
|
-
|
|
|
- this.imageInitializing = {
|
|
|
- abort: function abort() {
|
|
|
- sizingImage.onload = null;
|
|
|
+ if (isNumber(translateX) && translateX !== 0) {
|
|
|
+ values.push('translateX(' + translateX + 'px)');
|
|
|
}
|
|
|
- };
|
|
|
|
|
|
- sizingImage = getImageNaturalSizes(image, function (naturalWidth, naturalHeight) {
|
|
|
- var aspectRatio = naturalWidth / naturalHeight;
|
|
|
- var width = viewerWidth;
|
|
|
- var height = viewerHeight;
|
|
|
+ if (isNumber(translateY) && translateY !== 0) {
|
|
|
+ values.push('translateY(' + translateY + 'px)');
|
|
|
+ }
|
|
|
|
|
|
- _this2.imageInitializing = false;
|
|
|
+ // Rotate should come first before scale to match orientation transform
|
|
|
+ if (isNumber(rotate) && rotate !== 0) {
|
|
|
+ values.push('rotate(' + rotate + 'deg)');
|
|
|
+ }
|
|
|
|
|
|
- if (viewerHeight * aspectRatio > viewerWidth) {
|
|
|
- height = viewerWidth / aspectRatio;
|
|
|
- } else {
|
|
|
- width = viewerHeight * aspectRatio;
|
|
|
+ if (isNumber(scaleX) && scaleX !== 1) {
|
|
|
+ values.push('scaleX(' + scaleX + ')');
|
|
|
}
|
|
|
|
|
|
- width = Math.min(width * 0.9, naturalWidth);
|
|
|
- height = Math.min(height * 0.9, naturalHeight);
|
|
|
-
|
|
|
- var imageData = {
|
|
|
- naturalWidth: naturalWidth,
|
|
|
- naturalHeight: naturalHeight,
|
|
|
- aspectRatio: aspectRatio,
|
|
|
- ratio: width / naturalWidth,
|
|
|
- width: width,
|
|
|
- height: height,
|
|
|
- left: (viewerWidth - width) / 2,
|
|
|
- top: (viewerHeight - height) / 2
|
|
|
+ if (isNumber(scaleY) && scaleY !== 1) {
|
|
|
+ values.push('scaleY(' + scaleY + ')');
|
|
|
+ }
|
|
|
+
|
|
|
+ var transform = values.length ? values.join(' ') : 'none';
|
|
|
+
|
|
|
+ return {
|
|
|
+ WebkitTransform: transform,
|
|
|
+ msTransform: transform,
|
|
|
+ transform: transform
|
|
|
};
|
|
|
- var initialImageData = assign({}, imageData);
|
|
|
+ }
|
|
|
|
|
|
- if (options.rotatable) {
|
|
|
- imageData.rotate = oldImageData.rotate || 0;
|
|
|
- initialImageData.rotate = 0;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Get an image name from an image url.
|
|
|
+ * @param {string} url - The target url.
|
|
|
+ * @example
|
|
|
+ * // picture.jpg
|
|
|
+ * getImageNameFromURL('http://domain.com/path/to/picture.jpg?size=1280×960')
|
|
|
+ * @returns {string} A string contains the image name.
|
|
|
+ */
|
|
|
+ function getImageNameFromURL(url) {
|
|
|
+ return isString(url) ? url.replace(/^.*\//, '').replace(/[?&#].*$/, '') : '';
|
|
|
+ }
|
|
|
|
|
|
- if (options.scalable) {
|
|
|
- imageData.scaleX = oldImageData.scaleX || 1;
|
|
|
- imageData.scaleY = oldImageData.scaleY || 1;
|
|
|
- initialImageData.scaleX = 1;
|
|
|
- initialImageData.scaleY = 1;
|
|
|
- }
|
|
|
+ var IS_SAFARI = WINDOW.navigator && /(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(WINDOW.navigator.userAgent);
|
|
|
|
|
|
- _this2.imageData = imageData;
|
|
|
- _this2.initialImageData = initialImageData;
|
|
|
+ /**
|
|
|
+ * Get an image's natural sizes.
|
|
|
+ * @param {string} image - The target image.
|
|
|
+ * @param {Function} callback - The callback function.
|
|
|
+ * @returns {HTMLImageElement} The new image.
|
|
|
+ */
|
|
|
+ function getImageNaturalSizes(image, callback) {
|
|
|
+ var newImage = document.createElement('img');
|
|
|
|
|
|
- if (done) {
|
|
|
- done();
|
|
|
+ // Modern browsers (except Safari)
|
|
|
+ if (image.naturalWidth && !IS_SAFARI) {
|
|
|
+ callback(image.naturalWidth, image.naturalHeight);
|
|
|
+ return newImage;
|
|
|
}
|
|
|
- });
|
|
|
- },
|
|
|
- renderImage: function renderImage(done) {
|
|
|
- var _this3 = this;
|
|
|
-
|
|
|
- var image = this.image,
|
|
|
- imageData = this.imageData;
|
|
|
-
|
|
|
-
|
|
|
- setStyle(image, assign({
|
|
|
- width: imageData.width,
|
|
|
- height: imageData.height,
|
|
|
- marginLeft: imageData.left,
|
|
|
- marginTop: imageData.top
|
|
|
- }, getTransforms(imageData)));
|
|
|
-
|
|
|
- if (done) {
|
|
|
- if (this.viewing && this.options.transition) {
|
|
|
- var onTransitionEnd = function onTransitionEnd() {
|
|
|
- _this3.imageRendering = false;
|
|
|
- done();
|
|
|
- };
|
|
|
-
|
|
|
- this.imageRendering = {
|
|
|
- abort: function abort() {
|
|
|
- removeListener(image, EVENT_TRANSITION_END, onTransitionEnd);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- addListener(image, EVENT_TRANSITION_END, onTransitionEnd, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- } else {
|
|
|
- done();
|
|
|
+
|
|
|
+ var body = document.body || document.documentElement;
|
|
|
+
|
|
|
+ newImage.onload = function () {
|
|
|
+ callback(newImage.width, newImage.height);
|
|
|
+
|
|
|
+ if (!IS_SAFARI) {
|
|
|
+ body.removeChild(newImage);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ newImage.src = image.src;
|
|
|
+
|
|
|
+ // iOS Safari will convert the image automatically
|
|
|
+ // with its orientation once append it into DOM
|
|
|
+ if (!IS_SAFARI) {
|
|
|
+ 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;';
|
|
|
+ body.appendChild(newImage);
|
|
|
}
|
|
|
- }
|
|
|
- },
|
|
|
- resetImage: function resetImage() {
|
|
|
- // this.image only defined after viewed
|
|
|
- if (this.viewing || this.viewed) {
|
|
|
- var image = this.image;
|
|
|
|
|
|
+ return newImage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get the related class name of a responsive type number.
|
|
|
+ * @param {string} type - The responsive type.
|
|
|
+ * @returns {string} The related class name.
|
|
|
+ */
|
|
|
+ function getResponsiveClass(type) {
|
|
|
+ switch (type) {
|
|
|
+ case 2:
|
|
|
+ return CLASS_HIDE_XS_DOWN;
|
|
|
+
|
|
|
+ case 3:
|
|
|
+ return CLASS_HIDE_SM_DOWN;
|
|
|
|
|
|
- if (this.viewing) {
|
|
|
- this.viewing.abort();
|
|
|
+ case 4:
|
|
|
+ return CLASS_HIDE_MD_DOWN;
|
|
|
+
|
|
|
+ default:
|
|
|
+ return '';
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- image.parentNode.removeChild(image);
|
|
|
- this.image = null;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Get the max ratio of a group of pointers.
|
|
|
+ * @param {string} pointers - The target pointers.
|
|
|
+ * @returns {number} The result ratio.
|
|
|
+ */
|
|
|
+ function getMaxZoomRatio(pointers) {
|
|
|
+ var pointers2 = assign({}, pointers);
|
|
|
+ var ratios = [];
|
|
|
+
|
|
|
+ forEach(pointers, function (pointer, pointerId) {
|
|
|
+ delete pointers2[pointerId];
|
|
|
+
|
|
|
+ forEach(pointers2, function (pointer2) {
|
|
|
+ var x1 = Math.abs(pointer.startX - pointer2.startX);
|
|
|
+ var y1 = Math.abs(pointer.startY - pointer2.startY);
|
|
|
+ var x2 = Math.abs(pointer.endX - pointer2.endX);
|
|
|
+ var y2 = Math.abs(pointer.endY - pointer2.endY);
|
|
|
+ var z1 = Math.sqrt(x1 * x1 + y1 * y1);
|
|
|
+ var z2 = Math.sqrt(x2 * x2 + y2 * y2);
|
|
|
+ var ratio = (z2 - z1) / z1;
|
|
|
+
|
|
|
+ ratios.push(ratio);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ ratios.sort(function (a, b) {
|
|
|
+ return Math.abs(a) < Math.abs(b);
|
|
|
+ });
|
|
|
+
|
|
|
+ return ratios[0];
|
|
|
}
|
|
|
- };
|
|
|
-
|
|
|
- var events = {
|
|
|
- bind: function bind() {
|
|
|
- var element = this.element,
|
|
|
- viewer = this.viewer;
|
|
|
-
|
|
|
-
|
|
|
- addListener(viewer, EVENT_CLICK, this.onClick = this.click.bind(this));
|
|
|
- addListener(viewer, EVENT_WHEEL, this.onWheel = this.wheel.bind(this));
|
|
|
- addListener(viewer, EVENT_DRAG_START, this.onDragStart = this.dragstart.bind(this));
|
|
|
- addListener(this.canvas, EVENT_POINTER_DOWN, this.onPointerDown = this.pointerdown.bind(this));
|
|
|
- addListener(element.ownerDocument, EVENT_POINTER_MOVE, this.onPointerMove = this.pointermove.bind(this));
|
|
|
- addListener(element.ownerDocument, EVENT_POINTER_UP, this.onPointerUp = this.pointerup.bind(this));
|
|
|
- addListener(element.ownerDocument, EVENT_KEY_DOWN, this.onKeyDown = this.keydown.bind(this));
|
|
|
- addListener(window, EVENT_RESIZE, this.onResize = this.resize.bind(this));
|
|
|
- },
|
|
|
- unbind: function unbind() {
|
|
|
- var element = this.element,
|
|
|
- viewer = this.viewer;
|
|
|
-
|
|
|
-
|
|
|
- removeListener(viewer, EVENT_CLICK, this.onClick);
|
|
|
- removeListener(viewer, EVENT_WHEEL, this.onWheel);
|
|
|
- removeListener(viewer, EVENT_DRAG_START, this.onDragStart);
|
|
|
- removeListener(this.canvas, EVENT_POINTER_DOWN, this.onPointerDown);
|
|
|
- removeListener(element.ownerDocument, EVENT_POINTER_MOVE, this.onPointerMove);
|
|
|
- removeListener(element.ownerDocument, EVENT_POINTER_UP, this.onPointerUp);
|
|
|
- removeListener(element.ownerDocument, EVENT_KEY_DOWN, this.onKeyDown);
|
|
|
- removeListener(window, EVENT_RESIZE, this.onResize);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get a pointer from an event object.
|
|
|
+ * @param {Object} event - The target event object.
|
|
|
+ * @param {boolean} endOnly - Indicates if only returns the end point coordinate or not.
|
|
|
+ * @returns {Object} The result pointer contains start and/or end point coordinates.
|
|
|
+ */
|
|
|
+ function getPointer(_ref2, endOnly) {
|
|
|
+ var pageX = _ref2.pageX,
|
|
|
+ pageY = _ref2.pageY;
|
|
|
+
|
|
|
+ var end = {
|
|
|
+ endX: pageX,
|
|
|
+ endY: pageY
|
|
|
+ };
|
|
|
+
|
|
|
+ return endOnly ? end : assign({
|
|
|
+ startX: pageX,
|
|
|
+ startY: pageY
|
|
|
+ }, end);
|
|
|
}
|
|
|
- };
|
|
|
|
|
|
- var handlers = {
|
|
|
- click: function click(_ref) {
|
|
|
- var target = _ref.target;
|
|
|
- var options = this.options,
|
|
|
- imageData = this.imageData;
|
|
|
+ /**
|
|
|
+ * Get the center point coordinate of a group of pointers.
|
|
|
+ * @param {Object} pointers - The target pointers.
|
|
|
+ * @returns {Object} The center point coordinate.
|
|
|
+ */
|
|
|
+ function getPointersCenter(pointers) {
|
|
|
+ var pageX = 0;
|
|
|
+ var pageY = 0;
|
|
|
+ var count = 0;
|
|
|
|
|
|
- var action = getData(target, 'action');
|
|
|
+ forEach(pointers, function (_ref3) {
|
|
|
+ var startX = _ref3.startX,
|
|
|
+ startY = _ref3.startY;
|
|
|
|
|
|
- switch (action) {
|
|
|
- case 'mix':
|
|
|
- if (this.played) {
|
|
|
- this.stop();
|
|
|
- } else if (options.inline) {
|
|
|
- if (this.fulled) {
|
|
|
- this.exit();
|
|
|
- } else {
|
|
|
- this.full();
|
|
|
+ pageX += startX;
|
|
|
+ pageY += startY;
|
|
|
+ count += 1;
|
|
|
+ });
|
|
|
+
|
|
|
+ pageX /= count;
|
|
|
+ pageY /= count;
|
|
|
+
|
|
|
+ return {
|
|
|
+ pageX: pageX,
|
|
|
+ pageY: pageY
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ var render = {
|
|
|
+ render: function render() {
|
|
|
+ this.initContainer();
|
|
|
+ this.initViewer();
|
|
|
+ this.initList();
|
|
|
+ this.renderViewer();
|
|
|
+ },
|
|
|
+ initContainer: function initContainer() {
|
|
|
+ this.containerData = {
|
|
|
+ width: window.innerWidth,
|
|
|
+ height: window.innerHeight
|
|
|
+ };
|
|
|
+ },
|
|
|
+ initViewer: function initViewer() {
|
|
|
+ var options = this.options,
|
|
|
+ parent = this.parent;
|
|
|
+
|
|
|
+ var viewerData = void 0;
|
|
|
+
|
|
|
+ if (options.inline) {
|
|
|
+ viewerData = {
|
|
|
+ width: Math.max(parent.offsetWidth, options.minWidth),
|
|
|
+ height: Math.max(parent.offsetHeight, options.minHeight)
|
|
|
+ };
|
|
|
+
|
|
|
+ this.parentData = viewerData;
|
|
|
}
|
|
|
- } else {
|
|
|
- this.hide();
|
|
|
- }
|
|
|
|
|
|
- break;
|
|
|
+ if (this.fulled || !viewerData) {
|
|
|
+ viewerData = this.containerData;
|
|
|
+ }
|
|
|
|
|
|
- case 'hide':
|
|
|
- this.hide();
|
|
|
- break;
|
|
|
+ this.viewerData = assign({}, viewerData);
|
|
|
+ },
|
|
|
+ renderViewer: function renderViewer() {
|
|
|
+ if (this.options.inline && !this.fulled) {
|
|
|
+ setStyle(this.viewer, this.viewerData);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ initList: function initList() {
|
|
|
+ var _this = this;
|
|
|
|
|
|
- case 'view':
|
|
|
- this.view(getData(target, 'index'));
|
|
|
- break;
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options,
|
|
|
+ list = this.list;
|
|
|
|
|
|
- case 'zoom-in':
|
|
|
- this.zoom(0.1, true);
|
|
|
- break;
|
|
|
+ var items = [];
|
|
|
|
|
|
- case 'zoom-out':
|
|
|
- this.zoom(-0.1, true);
|
|
|
- break;
|
|
|
+ var dealOriginal= this.dealOriginal;
|
|
|
|
|
|
- case 'one-to-one':
|
|
|
- this.toggle();
|
|
|
- break;
|
|
|
+ forEach(this.images, function (image, i) {
|
|
|
+ var src = image.src;
|
|
|
|
|
|
- case 'reset':
|
|
|
- this.reset();
|
|
|
- break;
|
|
|
+ var alt = image.alt;// || getImageNameFromURL(src);
|
|
|
+ var url = options.url;
|
|
|
|
|
|
- case 'prev':
|
|
|
- this.prev(options.loop);
|
|
|
- break;
|
|
|
|
|
|
- case 'play':
|
|
|
- this.play(options.fullscreen);
|
|
|
- break;
|
|
|
+ var url_original = options.url_original;
|
|
|
|
|
|
- case 'next':
|
|
|
- this.next(options.loop);
|
|
|
- break;
|
|
|
+ if (isString(url_original)) {
|
|
|
+ url_original = image.getAttribute(url_original);
|
|
|
+ } else if (isFunction(url_original)) {
|
|
|
+ url_original = url_original.call(_this, image);
|
|
|
+ }
|
|
|
+ if (dealOriginal.includes(url_original))
|
|
|
+ {
|
|
|
+ url=url_original;
|
|
|
+ }else {
|
|
|
+ if (isString(url)) {
|
|
|
+ url = image.getAttribute(url);
|
|
|
+ } else if (isFunction(url)) {
|
|
|
+ url = url.call(_this, image);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- case 'rotate-left':
|
|
|
- this.rotate(-90);
|
|
|
- break;
|
|
|
+ if (src || url) {
|
|
|
+ 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>');
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- case 'rotate-right':
|
|
|
- this.rotate(90);
|
|
|
- break;
|
|
|
+ list.innerHTML = items.join('');
|
|
|
+ this.items = list.getElementsByTagName('li');
|
|
|
+ forEach(this.items, function (item) {
|
|
|
+ var image = item.firstElementChild;
|
|
|
|
|
|
- case 'flip-horizontal':
|
|
|
- this.scaleX(-imageData.scaleX || -1);
|
|
|
- break;
|
|
|
+ setData(image, 'filled', true);
|
|
|
|
|
|
- case 'flip-vertical':
|
|
|
- this.scaleY(-imageData.scaleY || -1);
|
|
|
- break;
|
|
|
+ if (options.loading) {
|
|
|
+ addClass(item, CLASS_LOADING);
|
|
|
+ }
|
|
|
|
|
|
- default:
|
|
|
- if (this.played) {
|
|
|
- this.stop();
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- load: function load() {
|
|
|
- var _this = this;
|
|
|
+ addListener(image, EVENT_LOAD, function (event) {
|
|
|
+ if (options.loading) {
|
|
|
+ removeClass(item, CLASS_LOADING);
|
|
|
+ }
|
|
|
|
|
|
- if (this.timeout) {
|
|
|
- clearTimeout(this.timeout);
|
|
|
- this.timeout = false;
|
|
|
- }
|
|
|
+ _this.loadImage(event);
|
|
|
+ }, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
- var element = this.element,
|
|
|
- options = this.options,
|
|
|
- image = this.image,
|
|
|
- index = this.index,
|
|
|
- viewerData = this.viewerData;
|
|
|
+ if (options.transition) {
|
|
|
+ addListener(element, EVENT_VIEWED, function () {
|
|
|
+ addClass(list, CLASS_TRANSITION);
|
|
|
+ }, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ renderList: function renderList(index) {
|
|
|
+ var i = index || this.index;
|
|
|
+ var width = this.items[i].offsetWidth || 30;
|
|
|
+ var outerWidth = width + 1; // 1 pixel of `margin-left` width
|
|
|
+
|
|
|
+ // Place the active item in the center of the screen
|
|
|
+ setStyle(this.list, assign({
|
|
|
+ width: outerWidth * this.length
|
|
|
+ }, getTransforms({
|
|
|
+ translateX: (this.viewerData.width - width) / 2 - outerWidth * i
|
|
|
+ })));
|
|
|
+ },
|
|
|
+ resetList: function resetList() {
|
|
|
+ var list = this.list;
|
|
|
+
|
|
|
+
|
|
|
+ list.innerHTML = '';
|
|
|
+ removeClass(list, CLASS_TRANSITION);
|
|
|
+ setStyle(list, getTransforms({
|
|
|
+ translateX: 0
|
|
|
+ }));
|
|
|
+ },
|
|
|
+ initImage: function initImage(done) {
|
|
|
+ var _this2 = this;
|
|
|
+ var options = this.options,
|
|
|
+ image = this.image,
|
|
|
+ viewerData = this.viewerData;
|
|
|
+ var footerHeight = this.footer.offsetHeight;
|
|
|
+ var viewerWidth = viewerData.width;
|
|
|
+ var viewerHeight = Math.max(viewerData.height - footerHeight, footerHeight);
|
|
|
+ var oldImageData = this.imageData || {};
|
|
|
+ var sizingImage = void 0;
|
|
|
+
|
|
|
+ this.imageInitializing = {
|
|
|
+ abort: function abort() {
|
|
|
+ sizingImage.onload = null;
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
+ sizingImage = getImageNaturalSizes(image, function (naturalWidth, naturalHeight) {
|
|
|
+ var aspectRatio = naturalWidth / naturalHeight;
|
|
|
+ var width = viewerWidth;
|
|
|
+ var height = viewerHeight;
|
|
|
|
|
|
- removeClass(image, CLASS_INVISIBLE);
|
|
|
+ _this2.imageInitializing = false;
|
|
|
|
|
|
- if (options.loading) {
|
|
|
- removeClass(this.canvas, CLASS_LOADING);
|
|
|
- }
|
|
|
+ if (viewerHeight * aspectRatio > viewerWidth) {
|
|
|
+ height = viewerWidth / aspectRatio;
|
|
|
+ } else {
|
|
|
+ width = viewerHeight * aspectRatio;
|
|
|
+ }
|
|
|
|
|
|
- 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;';
|
|
|
+ // width = Math.min(width * 0.9, naturalWidth);
|
|
|
+ // height = Math.min(height * 0.9, naturalHeight);
|
|
|
+
|
|
|
+ width = Math.min(width , naturalWidth);
|
|
|
+ height = Math.min(height, naturalHeight);
|
|
|
+
|
|
|
+ var imageData = {
|
|
|
+ naturalWidth: naturalWidth,
|
|
|
+ naturalHeight: naturalHeight,
|
|
|
+ aspectRatio: aspectRatio,
|
|
|
+ ratio: width / naturalWidth,
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ left: (viewerWidth - width) / 2,
|
|
|
+ top: (viewerHeight - height) / 2
|
|
|
+ };
|
|
|
+ var initialImageData = assign({}, imageData);
|
|
|
+
|
|
|
+ if (options.rotatable) {
|
|
|
+ imageData.rotate = oldImageData.rotate || 0;
|
|
|
+ initialImageData.rotate = 0;
|
|
|
+ }
|
|
|
|
|
|
- this.initImage(function () {
|
|
|
- toggleClass(image, CLASS_MOVE, options.movable);
|
|
|
- toggleClass(image, CLASS_TRANSITION, options.transition);
|
|
|
+ if (options.scalable) {
|
|
|
+ imageData.scaleX = oldImageData.scaleX || 1;
|
|
|
+ imageData.scaleY = oldImageData.scaleY || 1;
|
|
|
+ initialImageData.scaleX = 1;
|
|
|
+ initialImageData.scaleY = 1;
|
|
|
+ }
|
|
|
|
|
|
- _this.renderImage(function () {
|
|
|
- _this.viewed = true;
|
|
|
- _this.viewing = false;
|
|
|
+ _this2.imageData = imageData;
|
|
|
+ _this2.initialImageData = initialImageData;
|
|
|
|
|
|
- if (isFunction(options.viewed)) {
|
|
|
- addListener(element, EVENT_VIEWED, options.viewed, {
|
|
|
- once: true
|
|
|
+ if (done) {
|
|
|
+ done();
|
|
|
+ }
|
|
|
});
|
|
|
- }
|
|
|
+ },
|
|
|
+ renderImage: function renderImage(done) {
|
|
|
+ var _this3 = this;
|
|
|
+
|
|
|
+ var image = this.image,
|
|
|
+ imageData = this.imageData;
|
|
|
+
|
|
|
+
|
|
|
+ setStyle(image, assign({
|
|
|
+ width: imageData.width,
|
|
|
+ height: imageData.height,
|
|
|
+ marginLeft: imageData.left,
|
|
|
+ marginTop: imageData.top
|
|
|
+ }, getTransforms(imageData)));
|
|
|
+
|
|
|
+ if (done) {
|
|
|
+ if (this.viewing && this.options.transition) {
|
|
|
+ var onTransitionEnd = function onTransitionEnd() {
|
|
|
+ _this3.imageRendering = false;
|
|
|
+ done();
|
|
|
+ };
|
|
|
+
|
|
|
+ this.imageRendering = {
|
|
|
+ abort: function abort() {
|
|
|
+ removeListener(image, EVENT_TRANSITION_END, onTransitionEnd);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ addListener(image, EVENT_TRANSITION_END, onTransitionEnd, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ done();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ resetImage: function resetImage() {
|
|
|
+ // this.image only defined after viewed
|
|
|
+ if (this.viewing || this.viewed) {
|
|
|
+ var image = this.image;
|
|
|
|
|
|
- dispatchEvent(element, EVENT_VIEWED, {
|
|
|
- originalImage: _this.images[index],
|
|
|
- index: index,
|
|
|
- image: image
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
- loadImage: function loadImage(e) {
|
|
|
- var image = e.target;
|
|
|
- var parent = image.parentNode;
|
|
|
- var parentWidth = parent.offsetWidth || 30;
|
|
|
- var parentHeight = parent.offsetHeight || 50;
|
|
|
- var filled = !!getData(image, 'filled');
|
|
|
-
|
|
|
- getImageNaturalSizes(image, function (naturalWidth, naturalHeight) {
|
|
|
- var aspectRatio = naturalWidth / naturalHeight;
|
|
|
- var width = parentWidth;
|
|
|
- var height = parentHeight;
|
|
|
-
|
|
|
- if (parentHeight * aspectRatio > parentWidth) {
|
|
|
- if (filled) {
|
|
|
- width = parentHeight * aspectRatio;
|
|
|
- } else {
|
|
|
- height = parentWidth / aspectRatio;
|
|
|
- }
|
|
|
- } else if (filled) {
|
|
|
- height = parentWidth / aspectRatio;
|
|
|
- } else {
|
|
|
- width = parentHeight * aspectRatio;
|
|
|
+
|
|
|
+ if (this.viewing) {
|
|
|
+ this.viewing.abort();
|
|
|
+ }
|
|
|
+
|
|
|
+ image.parentNode.removeChild(image);
|
|
|
+ this.image = null;
|
|
|
+ }
|
|
|
}
|
|
|
+ };
|
|
|
|
|
|
- setStyle(image, assign({
|
|
|
- width: width,
|
|
|
- height: height
|
|
|
- }, getTransforms({
|
|
|
- translateX: (parentWidth - width) / 2,
|
|
|
- translateY: (parentHeight - height) / 2
|
|
|
- })));
|
|
|
- });
|
|
|
- },
|
|
|
- keydown: function keydown(e) {
|
|
|
- var options = this.options;
|
|
|
-
|
|
|
-
|
|
|
- if (!this.fulled || !options.keyboard) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- switch (e.keyCode || e.which || e.charCode) {
|
|
|
- // Escape
|
|
|
- case 27:
|
|
|
- if (this.played) {
|
|
|
- this.stop();
|
|
|
- } else if (options.inline) {
|
|
|
- if (this.fulled) {
|
|
|
- this.exit();
|
|
|
- }
|
|
|
- } else {
|
|
|
- this.hide();
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- // Space
|
|
|
- case 32:
|
|
|
- if (this.played) {
|
|
|
- this.stop();
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- // ArrowLeft
|
|
|
- case 37:
|
|
|
- this.prev(options.loop);
|
|
|
- break;
|
|
|
-
|
|
|
- // ArrowUp
|
|
|
- case 38:
|
|
|
- // Prevent scroll on Firefox
|
|
|
- e.preventDefault();
|
|
|
-
|
|
|
- // Zoom in
|
|
|
- this.zoom(options.zoomRatio, true);
|
|
|
- break;
|
|
|
-
|
|
|
- // ArrowRight
|
|
|
- case 39:
|
|
|
- this.next(options.loop);
|
|
|
- break;
|
|
|
-
|
|
|
- // ArrowDown
|
|
|
- case 40:
|
|
|
- // Prevent scroll on Firefox
|
|
|
- e.preventDefault();
|
|
|
-
|
|
|
- // Zoom out
|
|
|
- this.zoom(-options.zoomRatio, true);
|
|
|
- break;
|
|
|
-
|
|
|
- // Ctrl + 0
|
|
|
- case 48:
|
|
|
- // Fall through
|
|
|
-
|
|
|
- // Ctrl + 1
|
|
|
- // eslint-disable-next-line no-fallthrough
|
|
|
- case 49:
|
|
|
- if (e.ctrlKey) {
|
|
|
- e.preventDefault();
|
|
|
- this.toggle();
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- }
|
|
|
- },
|
|
|
- dragstart: function dragstart(e) {
|
|
|
- if (e.target.tagName.toLowerCase() === 'img') {
|
|
|
- e.preventDefault();
|
|
|
- }
|
|
|
- },
|
|
|
- pointerdown: function pointerdown(e) {
|
|
|
- var options = this.options,
|
|
|
- pointers = this.pointers;
|
|
|
-
|
|
|
-
|
|
|
- if (!this.viewed || this.showing || this.viewing || this.hiding) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (e.changedTouches) {
|
|
|
- forEach(e.changedTouches, function (touch) {
|
|
|
- pointers[touch.identifier] = getPointer(touch);
|
|
|
- });
|
|
|
- } else {
|
|
|
- pointers[e.pointerId || 0] = getPointer(e);
|
|
|
- }
|
|
|
+ var events = {
|
|
|
+ bind: function bind() {
|
|
|
+ var element = this.element,
|
|
|
+ viewer = this.viewer;
|
|
|
|
|
|
- var action = options.movable ? ACTION_MOVE : false;
|
|
|
|
|
|
- if (Object.keys(pointers).length > 1) {
|
|
|
- action = ACTION_ZOOM;
|
|
|
- } else if ((e.pointerType === 'touch' || e.type === 'touchstart') && this.isSwitchable()) {
|
|
|
- action = ACTION_SWITCH;
|
|
|
- }
|
|
|
+ addListener(viewer, EVENT_CLICK, this.onClick = this.click.bind(this));
|
|
|
+ addListener(viewer, EVENT_WHEEL, this.onWheel = this.wheel.bind(this));
|
|
|
+ addListener(viewer, EVENT_DRAG_START, this.onDragStart = this.dragstart.bind(this));
|
|
|
+ addListener(this.canvas, EVENT_POINTER_DOWN, this.onPointerDown = this.pointerdown.bind(this));
|
|
|
+ addListener(element.ownerDocument, EVENT_POINTER_MOVE, this.onPointerMove = this.pointermove.bind(this));
|
|
|
+ addListener(element.ownerDocument, EVENT_POINTER_UP, this.onPointerUp = this.pointerup.bind(this));
|
|
|
+ addListener(element.ownerDocument, EVENT_KEY_DOWN, this.onKeyDown = this.keydown.bind(this));
|
|
|
+ addListener(window, EVENT_RESIZE, this.onResize = this.resize.bind(this));
|
|
|
+ },
|
|
|
+ unbind: function unbind() {
|
|
|
+ var element = this.element,
|
|
|
+ viewer = this.viewer;
|
|
|
+
|
|
|
+
|
|
|
+ removeListener(viewer, EVENT_CLICK, this.onClick);
|
|
|
+ removeListener(viewer, EVENT_WHEEL, this.onWheel);
|
|
|
+ removeListener(viewer, EVENT_DRAG_START, this.onDragStart);
|
|
|
+ removeListener(this.canvas, EVENT_POINTER_DOWN, this.onPointerDown);
|
|
|
+ removeListener(element.ownerDocument, EVENT_POINTER_MOVE, this.onPointerMove);
|
|
|
+ removeListener(element.ownerDocument, EVENT_POINTER_UP, this.onPointerUp);
|
|
|
+ removeListener(element.ownerDocument, EVENT_KEY_DOWN, this.onKeyDown);
|
|
|
+ removeListener(window, EVENT_RESIZE, this.onResize);
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- this.action = action;
|
|
|
- },
|
|
|
- pointermove: function pointermove(e) {
|
|
|
- var options = this.options,
|
|
|
- pointers = this.pointers,
|
|
|
- action = this.action,
|
|
|
- image = this.image;
|
|
|
+ var handlers = {
|
|
|
+ click: function click(_ref) {
|
|
|
+ var target = _ref.target;
|
|
|
+ var options = this.options,
|
|
|
+ imageData = this.imageData;
|
|
|
+
|
|
|
+ var action = getData(target, 'action');
|
|
|
+ switch (action) {
|
|
|
+ case 'mix':
|
|
|
+ if (this.played) {
|
|
|
+ this.stop();
|
|
|
+ } else if (options.inline) {
|
|
|
+ if (this.fulled) {
|
|
|
+ this.exit();
|
|
|
+ } else {
|
|
|
+ this.full();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.hide();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'hide':
|
|
|
+ this.hide();
|
|
|
+ break;
|
|
|
+ case 'view':
|
|
|
+ this.view(getData(target, 'index'));
|
|
|
+ break;
|
|
|
+ case 'zoom-ins':
|
|
|
+ this.zoom(0.1, true);
|
|
|
+ break;
|
|
|
+ case 'zoom-outs':
|
|
|
+ this.zoom(-0.1, true);
|
|
|
+ break;
|
|
|
+ case 'reset':
|
|
|
+ this.reset();
|
|
|
+ break;
|
|
|
+ case 'prevs':
|
|
|
+ this.prev(options.loop);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'plays':
|
|
|
+ this.play(options.fullscreen);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'nexts':
|
|
|
+ this.next(options.loop);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'one-to-ones':
|
|
|
+ this.normal();
|
|
|
+ break;
|
|
|
+
|
|
|
+ //放大
|
|
|
+ case 'enlarge':
|
|
|
+ this.toggle();
|
|
|
+ break;
|
|
|
+
|
|
|
+ //case 'rotate-left':
|
|
|
+ // this.rotate(-90);
|
|
|
+ // break;
|
|
|
+ //
|
|
|
+ //case 'rotate-right':
|
|
|
+ // this.rotate(90);
|
|
|
+ // break;
|
|
|
+ //
|
|
|
+ //case 'flip-horizontal':
|
|
|
+ // this.scaleX(-imageData.scaleX || -1);
|
|
|
+ // break;
|
|
|
+ //
|
|
|
+ //case 'flip-vertical':
|
|
|
+ // this.scaleY(-imageData.scaleY || -1);
|
|
|
+ // break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ if (this.played) {
|
|
|
+ this.stop();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.hide();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ load: function load() {
|
|
|
+ var _this = this;
|
|
|
|
|
|
+ if (this.timeout) {
|
|
|
+ clearTimeout(this.timeout);
|
|
|
+ this.timeout = false;
|
|
|
+ }
|
|
|
|
|
|
- if (!this.viewed || !action) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options,
|
|
|
+ image = this.image,
|
|
|
+ index = this.index,
|
|
|
+ viewerData = this.viewerData;
|
|
|
|
|
|
- e.preventDefault();
|
|
|
|
|
|
- if (e.changedTouches) {
|
|
|
- forEach(e.changedTouches, function (touch) {
|
|
|
- assign(pointers[touch.identifier], getPointer(touch, true));
|
|
|
- });
|
|
|
- } else {
|
|
|
- assign(pointers[e.pointerId || 0], getPointer(e, true));
|
|
|
- }
|
|
|
+ removeClass(image, CLASS_INVISIBLE);
|
|
|
|
|
|
- if (action === ACTION_MOVE && options.transition && hasClass(image, CLASS_TRANSITION)) {
|
|
|
- removeClass(image, CLASS_TRANSITION);
|
|
|
- }
|
|
|
+ if (options.loading) {
|
|
|
+ removeClass(this.canvas, CLASS_LOADING);
|
|
|
+ }
|
|
|
|
|
|
- this.change(e);
|
|
|
- },
|
|
|
- pointerup: function pointerup(e) {
|
|
|
- var action = this.action,
|
|
|
- pointers = this.pointers;
|
|
|
+ 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;';
|
|
|
|
|
|
+ this.initImage(function () {
|
|
|
+ toggleClass(image, CLASS_MOVE, options.movable);
|
|
|
+ toggleClass(image, CLASS_TRANSITION, options.transition);
|
|
|
|
|
|
- if (e.changedTouches) {
|
|
|
- forEach(e.changedTouches, function (touch) {
|
|
|
- delete pointers[touch.identifier];
|
|
|
- });
|
|
|
- } else {
|
|
|
- delete pointers[e.pointerId || 0];
|
|
|
- }
|
|
|
-
|
|
|
- if (!action) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (action === ACTION_MOVE && this.options.transition) {
|
|
|
- addClass(this.image, CLASS_TRANSITION);
|
|
|
- }
|
|
|
-
|
|
|
- this.action = false;
|
|
|
- },
|
|
|
- resize: function resize() {
|
|
|
- var _this2 = this;
|
|
|
-
|
|
|
- if (!this.isShown || this.hiding) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- this.initContainer();
|
|
|
- this.initViewer();
|
|
|
- this.renderViewer();
|
|
|
- this.renderList();
|
|
|
-
|
|
|
- if (this.viewed) {
|
|
|
- this.initImage(function () {
|
|
|
- _this2.renderImage();
|
|
|
- });
|
|
|
- }
|
|
|
+ _this.renderImage(function () {
|
|
|
+ _this.viewed = true;
|
|
|
+ _this.viewing = false;
|
|
|
|
|
|
- if (this.played) {
|
|
|
- if (this.options.fullscreen && this.fulled && !document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
|
|
|
- this.stop();
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (isFunction(options.viewed)) {
|
|
|
+ addListener(element, EVENT_VIEWED, options.viewed, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- forEach(this.player.getElementsByTagName('img'), function (image) {
|
|
|
- addListener(image, EVENT_LOAD, _this2.loadImage.bind(_this2), {
|
|
|
- once: true
|
|
|
- });
|
|
|
- dispatchEvent(image, EVENT_LOAD);
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
- wheel: function wheel(e) {
|
|
|
- var _this3 = this;
|
|
|
+ dispatchEvent(element, EVENT_VIEWED, {
|
|
|
+ originalImage: _this.images[index],
|
|
|
+ index: index,
|
|
|
+ image: image
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ loadImage: function loadImage(e) {
|
|
|
+ var image = e.target;
|
|
|
+ var parent = image.parentNode;
|
|
|
+ var parentWidth = parent.offsetWidth || 30;
|
|
|
+ var parentHeight = parent.offsetHeight || 50;
|
|
|
+ var filled = !!getData(image, 'filled');
|
|
|
+
|
|
|
+ getImageNaturalSizes(image, function (naturalWidth, naturalHeight) {
|
|
|
+ var aspectRatio = naturalWidth / naturalHeight;
|
|
|
+ var width = parentWidth;
|
|
|
+ var height = parentHeight;
|
|
|
+
|
|
|
+ if (parentHeight * aspectRatio > parentWidth) {
|
|
|
+ if (filled) {
|
|
|
+ width = parentHeight * aspectRatio;
|
|
|
+ } else {
|
|
|
+ height = parentWidth / aspectRatio;
|
|
|
+ }
|
|
|
+ } else if (filled) {
|
|
|
+ height = parentWidth / aspectRatio;
|
|
|
+ } else {
|
|
|
+ width = parentHeight * aspectRatio;
|
|
|
+ }
|
|
|
|
|
|
- if (!this.viewed) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ setStyle(image, assign({
|
|
|
+ width: width,
|
|
|
+ height: height
|
|
|
+ }, getTransforms({
|
|
|
+ translateX: (parentWidth - width) / 2,
|
|
|
+ translateY: (parentHeight - height) / 2
|
|
|
+ })));
|
|
|
+ });
|
|
|
+ },
|
|
|
+ keydown: function keydown(e) {
|
|
|
+ var options = this.options;
|
|
|
|
|
|
- e.preventDefault();
|
|
|
|
|
|
- // Limit wheel speed to prevent zoom too fast
|
|
|
- if (this.wheeling) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (!this.fulled || !options.keyboard) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- this.wheeling = true;
|
|
|
+ switch (e.keyCode || e.which || e.charCode) {
|
|
|
+ // Escape
|
|
|
+ case 27:
|
|
|
+ if (this.played) {
|
|
|
+ this.stop();
|
|
|
+ } else if (options.inline) {
|
|
|
+ if (this.fulled) {
|
|
|
+ this.exit();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.hide();
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ // Space
|
|
|
+ case 32:
|
|
|
+ if (this.played) {
|
|
|
+ this.stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ // ArrowLeft
|
|
|
+ case 37:
|
|
|
+ this.prev(options.loop);
|
|
|
+ break;
|
|
|
+
|
|
|
+ // ArrowUp
|
|
|
+ case 38:
|
|
|
+ // Prevent scroll on Firefox
|
|
|
+ e.preventDefault();
|
|
|
+
|
|
|
+ // Zoom in
|
|
|
+ this.zoom(options.zoomRatio, true);
|
|
|
+ break;
|
|
|
+
|
|
|
+ // ArrowRight
|
|
|
+ case 39:
|
|
|
+ this.next(options.loop);
|
|
|
+ break;
|
|
|
+
|
|
|
+ // ArrowDown
|
|
|
+ case 40:
|
|
|
+ // Prevent scroll on Firefox
|
|
|
+ e.preventDefault();
|
|
|
+
|
|
|
+ // Zoom out
|
|
|
+ this.zoom(-options.zoomRatio, true);
|
|
|
+ break;
|
|
|
+
|
|
|
+ // Ctrl + 0
|
|
|
+ case 48:
|
|
|
+ // Fall through
|
|
|
+
|
|
|
+ // Ctrl + 1
|
|
|
+ // eslint-disable-next-line no-fallthrough
|
|
|
+ case 49:
|
|
|
+ if (e.ctrlKey) {
|
|
|
+ e.preventDefault();
|
|
|
+ this.toggle();
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ }
|
|
|
+ },
|
|
|
+ dragstart: function dragstart(e) {
|
|
|
+ if (e.target.tagName.toLowerCase() === 'img') {
|
|
|
+ e.preventDefault();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ pointerdown: function pointerdown(e) {
|
|
|
+ var options = this.options,
|
|
|
+ pointers = this.pointers;
|
|
|
|
|
|
- setTimeout(function () {
|
|
|
- _this3.wheeling = false;
|
|
|
- }, 50);
|
|
|
|
|
|
- var ratio = Number(this.options.zoomRatio) || 0.1;
|
|
|
- var delta = 1;
|
|
|
+ if (!this.viewed || this.showing || this.viewing || this.hiding) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (e.deltaY) {
|
|
|
- delta = e.deltaY > 0 ? 1 : -1;
|
|
|
- } else if (e.wheelDelta) {
|
|
|
- delta = -e.wheelDelta / 120;
|
|
|
- } else if (e.detail) {
|
|
|
- delta = e.detail > 0 ? 1 : -1;
|
|
|
- }
|
|
|
+ if (e.changedTouches) {
|
|
|
+ forEach(e.changedTouches, function (touch) {
|
|
|
+ pointers[touch.identifier] = getPointer(touch);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ pointers[e.pointerId || 0] = getPointer(e);
|
|
|
+ }
|
|
|
|
|
|
- this.zoom(-delta * ratio, true, e);
|
|
|
- }
|
|
|
- };
|
|
|
+ var action = options.movable ? ACTION_MOVE : false;
|
|
|
|
|
|
- var methods = {
|
|
|
- /** Show the viewer (only available in modal mode)
|
|
|
- * @param {boolean} [immediate=false] - Indicates if show the viewer immediately or not.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- show: function show() {
|
|
|
- var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
- var element = this.element,
|
|
|
- options = this.options;
|
|
|
+ if (Object.keys(pointers).length > 1) {
|
|
|
+ action = ACTION_ZOOM;
|
|
|
+ } else if ((e.pointerType === 'touch' || e.type === 'touchstart') && this.isSwitchable()) {
|
|
|
+ action = ACTION_SWITCH;
|
|
|
+ }
|
|
|
|
|
|
+ this.action = action;
|
|
|
+ },
|
|
|
+ pointermove: function pointermove(e) {
|
|
|
+ var options = this.options,
|
|
|
+ pointers = this.pointers,
|
|
|
+ action = this.action,
|
|
|
+ image = this.image;
|
|
|
|
|
|
- if (options.inline || this.showing || this.isShown || this.showing) {
|
|
|
- return this;
|
|
|
- }
|
|
|
|
|
|
- if (!this.ready) {
|
|
|
- this.build();
|
|
|
+ if (!this.viewed || !action) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (this.ready) {
|
|
|
- this.show(immediate);
|
|
|
- }
|
|
|
+ e.preventDefault();
|
|
|
|
|
|
- return this;
|
|
|
- }
|
|
|
+ if (e.changedTouches) {
|
|
|
+ forEach(e.changedTouches, function (touch) {
|
|
|
+ assign(pointers[touch.identifier], getPointer(touch, true));
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ var pointerTmep=pointers[e.pointerId || 0];
|
|
|
+ if (pointerTmep==null||pointerTmep==undefined)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ assign(pointerTmep, getPointer(e, true));
|
|
|
+ }
|
|
|
|
|
|
- if (isFunction(options.show)) {
|
|
|
- addListener(element, EVENT_SHOW, options.show, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- }
|
|
|
+ if (action === ACTION_MOVE && options.transition && hasClass(image, CLASS_TRANSITION)) {
|
|
|
+ removeClass(image, CLASS_TRANSITION);
|
|
|
+ }
|
|
|
|
|
|
- if (dispatchEvent(element, EVENT_SHOW) === false || !this.ready) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ this.change(e);
|
|
|
+ },
|
|
|
+ pointerup: function pointerup(e) {
|
|
|
+ var action = this.action,
|
|
|
+ pointers = this.pointers;
|
|
|
|
|
|
- if (this.hiding) {
|
|
|
- this.transitioning.abort();
|
|
|
- }
|
|
|
|
|
|
- this.showing = true;
|
|
|
- this.open();
|
|
|
+ if (e.changedTouches) {
|
|
|
+ forEach(e.changedTouches, function (touch) {
|
|
|
+ delete pointers[touch.identifier];
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ delete pointers[e.pointerId || 0];
|
|
|
+ }
|
|
|
|
|
|
- var viewer = this.viewer;
|
|
|
+ if (!action) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
+ if (action === ACTION_MOVE && this.options.transition) {
|
|
|
+ addClass(this.image, CLASS_TRANSITION);
|
|
|
+ }
|
|
|
|
|
|
- removeClass(viewer, CLASS_HIDE);
|
|
|
+ this.action = false;
|
|
|
+ },
|
|
|
+ resize: function resize() {
|
|
|
+ var _this2 = this;
|
|
|
|
|
|
- if (options.transition && !immediate) {
|
|
|
- var shown = this.shown.bind(this);
|
|
|
+ if (!this.isShown || this.hiding) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- this.transitioning = {
|
|
|
- abort: function abort() {
|
|
|
- removeListener(viewer, EVENT_TRANSITION_END, shown);
|
|
|
- removeClass(viewer, CLASS_IN);
|
|
|
- }
|
|
|
- };
|
|
|
+ this.initContainer();
|
|
|
+ this.initViewer();
|
|
|
+ this.renderViewer();
|
|
|
+ this.renderList();
|
|
|
|
|
|
- addClass(viewer, CLASS_TRANSITION);
|
|
|
+ if (this.viewed) {
|
|
|
+ this.initImage(function () {
|
|
|
+ _this2.renderImage();
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- // Force reflow to enable CSS3 transition
|
|
|
- // eslint-disable-next-line
|
|
|
- viewer.offsetWidth;
|
|
|
- addListener(viewer, EVENT_TRANSITION_END, shown, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- addClass(viewer, CLASS_IN);
|
|
|
- } else {
|
|
|
- addClass(viewer, CLASS_IN);
|
|
|
- this.shown();
|
|
|
- }
|
|
|
+ if (this.played) {
|
|
|
+ if (this.options.fullscreen && this.fulled && !document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
|
|
|
+ this.stop();
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ forEach(this.player.getElementsByTagName('img'), function (image) {
|
|
|
+ addListener(image, EVENT_LOAD, _this2.loadImage.bind(_this2), {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ dispatchEvent(image, EVENT_LOAD);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ wheel: function wheel(e) {
|
|
|
+ var _this3 = this;
|
|
|
|
|
|
+ if (!this.viewed) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * Hide the viewer (only available in modal mode)
|
|
|
- * @param {boolean} [immediate=false] - Indicates if hide the viewer immediately or not.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- hide: function hide() {
|
|
|
- var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
- var element = this.element,
|
|
|
- options = this.options;
|
|
|
+ e.preventDefault();
|
|
|
|
|
|
+ // Limit wheel speed to prevent zoom too fast
|
|
|
+ if (this.wheeling) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (options.inline || this.hiding || !(this.isShown || this.showing)) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ this.wheeling = true;
|
|
|
|
|
|
- if (isFunction(options.hide)) {
|
|
|
- addListener(element, EVENT_HIDE, options.hide, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- }
|
|
|
+ setTimeout(function () {
|
|
|
+ _this3.wheeling = false;
|
|
|
+ }, 50);
|
|
|
|
|
|
- if (dispatchEvent(element, EVENT_HIDE) === false) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ var ratio = Number(this.options.zoomRatio) || 0.1;
|
|
|
+ var delta = 1;
|
|
|
|
|
|
- if (this.showing) {
|
|
|
- this.transitioning.abort();
|
|
|
- }
|
|
|
+ if (e.deltaY) {
|
|
|
+ delta = e.deltaY > 0 ? 1 : -1;
|
|
|
+ } else if (e.wheelDelta) {
|
|
|
+ delta = -e.wheelDelta / 120;
|
|
|
+ } else if (e.detail) {
|
|
|
+ delta = e.detail > 0 ? 1 : -1;
|
|
|
+ }
|
|
|
|
|
|
- this.hiding = true;
|
|
|
+ this.zoom(-delta * ratio, true, e);
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- if (this.played) {
|
|
|
- this.stop();
|
|
|
- } else if (this.viewing) {
|
|
|
- this.viewing.abort();
|
|
|
- }
|
|
|
+ var methods = {
|
|
|
+ /** Show the viewer (only available in modal mode)
|
|
|
+ * @param {boolean} [immediate=false] - Indicates if show the viewer immediately or not.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ show: function show() {
|
|
|
+ var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options;
|
|
|
|
|
|
- var viewer = this.viewer;
|
|
|
|
|
|
+ if (options.inline || this.showing || this.isShown || this.showing) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
- if (options.transition && !immediate) {
|
|
|
- var hidden = this.hidden.bind(this);
|
|
|
- var hide = function hide() {
|
|
|
- addListener(viewer, EVENT_TRANSITION_END, hidden, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- removeClass(viewer, CLASS_IN);
|
|
|
- };
|
|
|
+ if (!this.ready) {
|
|
|
+ this.build();
|
|
|
|
|
|
- this.transitioning = {
|
|
|
- abort: function abort() {
|
|
|
- if (this.viewed) {
|
|
|
- removeListener(this.image, EVENT_TRANSITION_END, hide);
|
|
|
- } else {
|
|
|
- removeListener(viewer, EVENT_TRANSITION_END, hidden);
|
|
|
+ if (this.ready) {
|
|
|
+ this.show(immediate);
|
|
|
+ }
|
|
|
+
|
|
|
+ return this;
|
|
|
}
|
|
|
- }
|
|
|
- };
|
|
|
|
|
|
- if (this.viewed) {
|
|
|
- addListener(this.image, EVENT_TRANSITION_END, hide, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- this.zoomTo(0, false, false, true);
|
|
|
- } else {
|
|
|
- hide();
|
|
|
- }
|
|
|
- } else {
|
|
|
- removeClass(viewer, CLASS_IN);
|
|
|
- this.hidden();
|
|
|
- }
|
|
|
+ if (isFunction(options.show)) {
|
|
|
+ addListener(element, EVENT_SHOW, options.show, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ if (dispatchEvent(element, EVENT_SHOW) === false || !this.ready) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
+ if (this.hiding) {
|
|
|
+ this.transitioning.abort();
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * View one of the images with image's index
|
|
|
- * @param {number} index - The index of the image to view.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- view: function view() {
|
|
|
- var _this = this;
|
|
|
+ this.showing = true;
|
|
|
+ this.open();
|
|
|
|
|
|
- var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
|
+ var viewer = this.viewer;
|
|
|
|
|
|
- index = Number(index) || 0;
|
|
|
|
|
|
- if (!this.isShown) {
|
|
|
- this.index = index;
|
|
|
- return this.show();
|
|
|
- }
|
|
|
+ removeClass(viewer, CLASS_HIDE);
|
|
|
|
|
|
- if (this.hiding || this.played || index < 0 || index >= this.length || this.viewed && index === this.index) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ if (options.transition && !immediate) {
|
|
|
+ var shown = this.shown.bind(this);
|
|
|
|
|
|
- if (this.viewing) {
|
|
|
- this.viewing.abort();
|
|
|
- }
|
|
|
+ this.transitioning = {
|
|
|
+ abort: function abort() {
|
|
|
+ removeListener(viewer, EVENT_TRANSITION_END, shown);
|
|
|
+ removeClass(viewer, CLASS_IN);
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- var element = this.element,
|
|
|
- options = this.options,
|
|
|
- title = this.title,
|
|
|
- canvas = this.canvas;
|
|
|
+ addClass(viewer, CLASS_TRANSITION);
|
|
|
|
|
|
- var item = this.items[index];
|
|
|
- var img = item.querySelector('img');
|
|
|
- var url = getData(img, 'originalUrl');
|
|
|
- var alt = img.getAttribute('alt');
|
|
|
- var image = document.createElement('img');
|
|
|
+ // Force reflow to enable CSS3 transition
|
|
|
+ // eslint-disable-next-line
|
|
|
+ viewer.offsetWidth;
|
|
|
+ addListener(viewer, EVENT_TRANSITION_END, shown, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ addClass(viewer, CLASS_IN);
|
|
|
+ } else {
|
|
|
+ addClass(viewer, CLASS_IN);
|
|
|
+ this.shown();
|
|
|
+ }
|
|
|
|
|
|
- image.src = url;
|
|
|
- image.alt = alt;
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- if (isFunction(options.view)) {
|
|
|
- addListener(element, EVENT_VIEW, options.view, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
- if (dispatchEvent(element, EVENT_VIEW, {
|
|
|
- originalImage: this.images[index],
|
|
|
- index: index,
|
|
|
- image: image
|
|
|
- }) === false || !this.isShown || this.hiding || this.played) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Hide the viewer (only available in modal mode)
|
|
|
+ * @param {boolean} [immediate=false] - Indicates if hide the viewer immediately or not.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ hide: function hide() {
|
|
|
+ var immediate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options;
|
|
|
|
|
|
- this.image = image;
|
|
|
- removeClass(this.items[this.index], CLASS_ACTIVE);
|
|
|
- addClass(item, CLASS_ACTIVE);
|
|
|
- this.viewed = false;
|
|
|
- this.index = index;
|
|
|
- this.imageData = {};
|
|
|
- addClass(image, CLASS_INVISIBLE);
|
|
|
|
|
|
- if (options.loading) {
|
|
|
- addClass(canvas, CLASS_LOADING);
|
|
|
- }
|
|
|
+ if (options.inline || this.hiding || !(this.isShown || this.showing)) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
- canvas.innerHTML = '';
|
|
|
- canvas.appendChild(image);
|
|
|
+ if (isFunction(options.hide)) {
|
|
|
+ addListener(element, EVENT_HIDE, options.hide, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- // Center current item
|
|
|
- this.renderList();
|
|
|
+ if (dispatchEvent(element, EVENT_HIDE) === false) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
- // Clear title
|
|
|
- title.innerHTML = '';
|
|
|
+ if (this.showing) {
|
|
|
+ this.transitioning.abort();
|
|
|
+ }
|
|
|
|
|
|
- // Generate title after viewed
|
|
|
- var onViewed = function onViewed() {
|
|
|
- var imageData = _this.imageData;
|
|
|
+ this.hiding = true;
|
|
|
|
|
|
+ if (this.played) {
|
|
|
+ this.stop();
|
|
|
+ } else if (this.viewing) {
|
|
|
+ this.viewing.abort();
|
|
|
+ }
|
|
|
|
|
|
- title.textContent = alt + ' (' + imageData.naturalWidth + ' \xD7 ' + imageData.naturalHeight + ')';
|
|
|
- };
|
|
|
- var onLoad = void 0;
|
|
|
+ var viewer = this.viewer;
|
|
|
+
|
|
|
+
|
|
|
+ if (options.transition && !immediate) {
|
|
|
+ var hidden = this.hidden.bind(this);
|
|
|
+ var hide = function hide() {
|
|
|
+ addListener(viewer, EVENT_TRANSITION_END, hidden, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ removeClass(viewer, CLASS_IN);
|
|
|
+ };
|
|
|
+
|
|
|
+ this.transitioning = {
|
|
|
+ abort: function abort() {
|
|
|
+ if (this.viewed) {
|
|
|
+ removeListener(this.image, EVENT_TRANSITION_END, hide);
|
|
|
+ } else {
|
|
|
+ removeListener(viewer, EVENT_TRANSITION_END, hidden);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ if (this.viewed) {
|
|
|
+ addListener(this.image, EVENT_TRANSITION_END, hide, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ this.zoomTo(0, false, false, true);
|
|
|
+ } else {
|
|
|
+ hide();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ removeClass(viewer, CLASS_IN);
|
|
|
+ this.hidden();
|
|
|
+ }
|
|
|
+
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * View one of the images with image's index
|
|
|
+ * @param {number} index - The index of the image to view.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ view: function view() {
|
|
|
+ var _this = this;
|
|
|
|
|
|
- addListener(element, EVENT_VIEWED, onViewed, {
|
|
|
- once: true
|
|
|
- });
|
|
|
+ var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
|
|
|
|
- this.viewing = {
|
|
|
- abort: function abort() {
|
|
|
- removeListener(element, EVENT_VIEWED, onViewed);
|
|
|
+ var mandatory = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
|
|
|
|
- if (image.complete) {
|
|
|
- if (this.imageRendering) {
|
|
|
- this.imageRendering.abort();
|
|
|
- } else if (this.imageInitializing) {
|
|
|
- this.imageInitializing.abort();
|
|
|
+ index = Number(index) || 0;
|
|
|
+
|
|
|
+ if (!this.isShown) {
|
|
|
+ this.index = index;
|
|
|
+ return this.show();
|
|
|
}
|
|
|
- } else {
|
|
|
- removeListener(image, EVENT_LOAD, onLoad);
|
|
|
|
|
|
- if (this.timeout) {
|
|
|
- clearTimeout(this.timeout);
|
|
|
+ if (!mandatory)
|
|
|
+ {
|
|
|
+ if (this.hiding || this.played || index < 0 || index >= this.length || this.viewed && index === this.index) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
|
|
|
- if (image.complete) {
|
|
|
- this.load();
|
|
|
- } else {
|
|
|
- addListener(image, EVENT_LOAD, onLoad = this.load.bind(this), {
|
|
|
- once: true
|
|
|
- });
|
|
|
|
|
|
- if (this.timeout) {
|
|
|
- clearTimeout(this.timeout);
|
|
|
- }
|
|
|
+ if (this.viewing) {
|
|
|
+ this.viewing.abort();
|
|
|
+ }
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options,
|
|
|
+ title = this.title,
|
|
|
+ canvas = this.canvas;
|
|
|
|
|
|
- // Make the image visible if it fails to load within 1s
|
|
|
- this.timeout = setTimeout(function () {
|
|
|
- removeClass(image, CLASS_INVISIBLE);
|
|
|
- _this.timeout = false;
|
|
|
- }, 1000);
|
|
|
- }
|
|
|
+ var item = this.items[index];
|
|
|
+ var img = item.querySelector('img');
|
|
|
+ var url = getData(img, 'originalUrl');
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ var alt = img.getAttribute('alt');
|
|
|
+ var image = document.createElement('img');
|
|
|
|
|
|
+ image.src = url;
|
|
|
+ image.alt = alt;
|
|
|
|
|
|
- /**
|
|
|
- * View the previous image
|
|
|
- * @param {boolean} [loop=false] - Indicate if view the last one
|
|
|
- * when it is the first one at present.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- prev: function prev() {
|
|
|
- var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
+ if (isFunction(options.view)) {
|
|
|
+ addListener(element, EVENT_VIEW, options.view, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- var index = this.index - 1;
|
|
|
+ if (dispatchEvent(element, EVENT_VIEW, {
|
|
|
+ originalImage: this.images[index],
|
|
|
+ index: index,
|
|
|
+ image: image
|
|
|
+ }) === false || !this.isShown || this.hiding || this.played) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
- if (index < 0) {
|
|
|
- index = loop ? this.length - 1 : 0;
|
|
|
- }
|
|
|
+ this.image = image;
|
|
|
+ removeClass(this.items[this.index], CLASS_ACTIVE);
|
|
|
+ addClass(item, CLASS_ACTIVE);
|
|
|
+ this.viewed = false;
|
|
|
+ this.index = index;
|
|
|
+ this.imageData = {};
|
|
|
+ addClass(image, CLASS_INVISIBLE);
|
|
|
|
|
|
- this.view(index);
|
|
|
- return this;
|
|
|
- },
|
|
|
+ if (options.loading) {
|
|
|
+ addClass(canvas, CLASS_LOADING);
|
|
|
+ }
|
|
|
|
|
|
+ canvas.innerHTML = '';
|
|
|
+ canvas.appendChild(image);
|
|
|
|
|
|
- /**
|
|
|
- * View the next image
|
|
|
- * @param {boolean} [loop=false] - Indicate if view the first one
|
|
|
- * when it is the last one at present.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- next: function next() {
|
|
|
- var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
+ // Center current item
|
|
|
+ this.renderList();
|
|
|
|
|
|
- var maxIndex = this.length - 1;
|
|
|
- var index = this.index + 1;
|
|
|
+ // Clear title
|
|
|
+ // title.innerHTML = '';
|
|
|
+ title.textContent = (_this.index+1)+'/'+_this.images.length;
|
|
|
+ // Generate title after viewed
|
|
|
+ var onViewed = function onViewed() {
|
|
|
+ // var imageData = _this.imageData;
|
|
|
+ // title.textContent = alt + ' (' + imageData.naturalWidth + ' \xD7 ' + imageData.naturalHeight + ')';
|
|
|
|
|
|
- if (index > maxIndex) {
|
|
|
- index = loop ? 0 : maxIndex;
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- this.view(index);
|
|
|
- return this;
|
|
|
- },
|
|
|
+ if (this.dealOriginal.includes(url))
|
|
|
+ {
|
|
|
+ $('.viewer-one-to-ones').css('display','none');
|
|
|
+ }else {
|
|
|
+ $('.viewer-one-to-ones').css('display','block');
|
|
|
+ }
|
|
|
+ var onLoad = void 0;
|
|
|
+ addListener(element, EVENT_VIEWED, onViewed, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
|
|
|
+ this.viewing = {
|
|
|
+ abort: function abort() {
|
|
|
+ removeListener(element, EVENT_VIEWED, onViewed);
|
|
|
+
|
|
|
+ if (image.complete) {
|
|
|
+ if (this.imageRendering) {
|
|
|
+ this.imageRendering.abort();
|
|
|
+ } else if (this.imageInitializing) {
|
|
|
+ this.imageInitializing.abort();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ removeListener(image, EVENT_LOAD, onLoad);
|
|
|
+
|
|
|
+ if (this.timeout) {
|
|
|
+ clearTimeout(this.timeout);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- /**
|
|
|
- * Move the image with relative offsets.
|
|
|
- * @param {number} offsetX - The relative offset distance on the x-axis.
|
|
|
- * @param {number} offsetY - The relative offset distance on the y-axis.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- move: function move(offsetX, offsetY) {
|
|
|
- var imageData = this.imageData;
|
|
|
+ if (image.complete) {
|
|
|
+ this.load();
|
|
|
+ } else {
|
|
|
+ addListener(image, EVENT_LOAD, onLoad = this.load.bind(this), {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
|
|
|
+ if (this.timeout) {
|
|
|
+ clearTimeout(this.timeout);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Make the image visible if it fails to load within 1s
|
|
|
+ this.timeout = setTimeout(function () {
|
|
|
+ removeClass(image, CLASS_INVISIBLE);
|
|
|
+ _this.timeout = false;
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * View the previous image
|
|
|
+ * @param {boolean} [loop=false] - Indicate if view the last one
|
|
|
+ * when it is the first one at present.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ prev: function prev() {
|
|
|
+ var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
+
|
|
|
+ var index = this.index - 1;
|
|
|
+
|
|
|
+ if (index < 0) {
|
|
|
+ index = loop ? this.length - 1 : 0;
|
|
|
+ }
|
|
|
|
|
|
- this.moveTo(isUndefined(offsetX) ? offsetX : imageData.left + Number(offsetX), isUndefined(offsetY) ? offsetY : imageData.top + Number(offsetY));
|
|
|
+ this.view(index);
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
|
|
|
+ /**
|
|
|
+ * View the next image
|
|
|
+ * @param {boolean} [loop=false] - Indicate if view the first one
|
|
|
+ * when it is the last one at present.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ next: function next() {
|
|
|
+ var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
|
|
|
- /**
|
|
|
- * Move the image to an absolute point.
|
|
|
- * @param {number} x - The x-axis coordinate.
|
|
|
- * @param {number} [y=x] - The y-axis coordinate.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- moveTo: function moveTo(x) {
|
|
|
- var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;
|
|
|
- var imageData = this.imageData;
|
|
|
+ var maxIndex = this.length - 1;
|
|
|
+ var index = this.index + 1;
|
|
|
|
|
|
+ if (index > maxIndex) {
|
|
|
+ index = loop ? 0 : maxIndex;
|
|
|
+ }
|
|
|
|
|
|
- x = Number(x);
|
|
|
- y = Number(y);
|
|
|
+ this.view(index);
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+ normal: function normal() {
|
|
|
+ var index = this.index;
|
|
|
+ var item = this.items[index];
|
|
|
+ var img = item.querySelector('img');
|
|
|
+ var dealUrl = getData(img, 'dealUrl');
|
|
|
+ if (this.dealOriginal.includes(dealUrl))
|
|
|
+ {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ this.dealOriginal.push(dealUrl);
|
|
|
+ setData(img,'originalUrl',dealUrl);
|
|
|
+ this.view(index,true);
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- if (this.viewed && !this.played && this.options.movable) {
|
|
|
- var changed = false;
|
|
|
|
|
|
- if (isNumber(x)) {
|
|
|
- imageData.left = x;
|
|
|
- changed = true;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Move the image with relative offsets.
|
|
|
+ * @param {number} offsetX - The relative offset distance on the x-axis.
|
|
|
+ * @param {number} offsetY - The relative offset distance on the y-axis.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ move: function move(offsetX, offsetY) {
|
|
|
+ var imageData = this.imageData;
|
|
|
|
|
|
- if (isNumber(y)) {
|
|
|
- imageData.top = y;
|
|
|
- changed = true;
|
|
|
- }
|
|
|
|
|
|
- if (changed) {
|
|
|
- this.renderImage();
|
|
|
- }
|
|
|
- }
|
|
|
+ this.moveTo(isUndefined(offsetX) ? offsetX : imageData.left + Number(offsetX), isUndefined(offsetY) ? offsetY : imageData.top + Number(offsetY));
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * Zoom the image with a relative ratio.
|
|
|
- * @param {number} ratio - The target ratio.
|
|
|
- * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
|
|
|
- * @param {Event} [_originalEvent=null] - The original event if any.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- zoom: function zoom(ratio) {
|
|
|
- var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
|
+ /**
|
|
|
+ * Move the image to an absolute point.
|
|
|
+ * @param {number} x - The x-axis coordinate.
|
|
|
+ * @param {number} [y=x] - The y-axis coordinate.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ moveTo: function moveTo(x) {
|
|
|
+ var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;
|
|
|
+ var imageData = this.imageData;
|
|
|
|
|
|
- var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
|
|
|
|
- var imageData = this.imageData;
|
|
|
+ x = Number(x);
|
|
|
+ y = Number(y);
|
|
|
|
|
|
+ if (this.viewed && !this.played && this.options.movable) {
|
|
|
+ var changed = false;
|
|
|
|
|
|
- ratio = Number(ratio);
|
|
|
+ if (isNumber(x)) {
|
|
|
+ imageData.left = x;
|
|
|
+ changed = true;
|
|
|
+ }
|
|
|
|
|
|
- if (ratio < 0) {
|
|
|
- ratio = 1 / (1 - ratio);
|
|
|
- } else {
|
|
|
- ratio = 1 + ratio;
|
|
|
- }
|
|
|
+ if (isNumber(y)) {
|
|
|
+ imageData.top = y;
|
|
|
+ changed = true;
|
|
|
+ }
|
|
|
|
|
|
- this.zoomTo(imageData.width * ratio / imageData.naturalWidth, hasTooltip, _originalEvent);
|
|
|
+ if (changed) {
|
|
|
+ this.renderImage();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * Zoom the image to an absolute ratio.
|
|
|
- * @param {number} ratio - The target ratio.
|
|
|
- * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
|
|
|
- * @param {Event} [_originalEvent=null] - The original event if any.
|
|
|
- * @param {Event} [_zoomable=false] - Indicates if the current zoom is available or not.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- zoomTo: function zoomTo(ratio) {
|
|
|
- var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
|
+ /**
|
|
|
+ * Zoom the image with a relative ratio.
|
|
|
+ * @param {number} ratio - The target ratio.
|
|
|
+ * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
|
|
|
+ * @param {Event} [_originalEvent=null] - The original event if any.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ zoom: function zoom(ratio) {
|
|
|
+ var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
|
|
|
|
- var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
|
+ var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
|
|
|
|
- var _zoomable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
|
+ var imageData = this.imageData;
|
|
|
|
|
|
- var options = this.options,
|
|
|
- pointers = this.pointers,
|
|
|
- imageData = this.imageData;
|
|
|
|
|
|
+ ratio = Number(ratio);
|
|
|
|
|
|
- ratio = Math.max(0, ratio);
|
|
|
+ if (ratio < 0) {
|
|
|
+ ratio = 1 / (1 - ratio);
|
|
|
+ } else {
|
|
|
+ ratio = 1 + ratio;
|
|
|
+ }
|
|
|
|
|
|
- if (isNumber(ratio) && this.viewed && !this.played && (_zoomable || options.zoomable)) {
|
|
|
- if (!_zoomable) {
|
|
|
- var minZoomRatio = Math.max(0.01, options.minZoomRatio);
|
|
|
- var maxZoomRatio = Math.min(100, options.maxZoomRatio);
|
|
|
+ this.zoomTo(imageData.width * ratio / imageData.naturalWidth, hasTooltip, _originalEvent);
|
|
|
|
|
|
- ratio = Math.min(Math.max(ratio, minZoomRatio), maxZoomRatio);
|
|
|
- }
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- if (_originalEvent && ratio > 0.95 && ratio < 1.05) {
|
|
|
- ratio = 1;
|
|
|
- }
|
|
|
|
|
|
- var newWidth = imageData.naturalWidth * ratio;
|
|
|
- var newHeight = imageData.naturalHeight * ratio;
|
|
|
+ /**
|
|
|
+ * Zoom the image to an absolute ratio.
|
|
|
+ * @param {number} ratio - The target ratio.
|
|
|
+ * @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not.
|
|
|
+ * @param {Event} [_originalEvent=null] - The original event if any.
|
|
|
+ * @param {Event} [_zoomable=false] - Indicates if the current zoom is available or not.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ zoomTo: function zoomTo(ratio) {
|
|
|
+ var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
|
|
|
|
- if (_originalEvent) {
|
|
|
- var offset = getOffset(this.viewer);
|
|
|
- var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : {
|
|
|
- pageX: _originalEvent.pageX,
|
|
|
- pageY: _originalEvent.pageY
|
|
|
- };
|
|
|
+ var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
|
|
|
|
- // Zoom from the triggering point of the event
|
|
|
- imageData.left -= (newWidth - imageData.width) * ((center.pageX - offset.left - imageData.left) / imageData.width);
|
|
|
- imageData.top -= (newHeight - imageData.height) * ((center.pageY - offset.top - imageData.top) / imageData.height);
|
|
|
- } else {
|
|
|
- // Zoom from the center of the image
|
|
|
- imageData.left -= (newWidth - imageData.width) / 2;
|
|
|
- imageData.top -= (newHeight - imageData.height) / 2;
|
|
|
- }
|
|
|
+ var _zoomable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
|
|
|
|
- imageData.width = newWidth;
|
|
|
- imageData.height = newHeight;
|
|
|
- imageData.ratio = ratio;
|
|
|
- this.renderImage();
|
|
|
+ var options = this.options,
|
|
|
+ pointers = this.pointers,
|
|
|
+ imageData = this.imageData;
|
|
|
|
|
|
- if (hasTooltip) {
|
|
|
- this.tooltip();
|
|
|
- }
|
|
|
- }
|
|
|
+ ratio = Math.max(0, ratio);
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ if (isNumber(ratio) && this.viewed && !this.played && (_zoomable || options.zoomable)) {
|
|
|
+ if (!_zoomable) {
|
|
|
+ var minZoomRatio = Math.max(0.01, options.minZoomRatio);
|
|
|
+ var maxZoomRatio = Math.min(100, options.maxZoomRatio);
|
|
|
|
|
|
+ ratio = Math.min(Math.max(ratio, minZoomRatio), maxZoomRatio);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * Rotate the image with a relative degree.
|
|
|
- * @param {number} degree - The rotate degree.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- rotate: function rotate(degree) {
|
|
|
- this.rotateTo((this.imageData.rotate || 0) + Number(degree));
|
|
|
+ if (_originalEvent && ratio > 0.95 && ratio < 1.05) {
|
|
|
+ ratio = 1;
|
|
|
+ }
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ var newWidth = imageData.naturalWidth * ratio;
|
|
|
+ var newHeight = imageData.naturalHeight * ratio;
|
|
|
+
|
|
|
+ if (_originalEvent) {
|
|
|
+ var offset = getOffset(this.viewer);
|
|
|
+ var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : {
|
|
|
+ pageX: _originalEvent.pageX,
|
|
|
+ pageY: _originalEvent.pageY
|
|
|
+ };
|
|
|
+
|
|
|
+ // Zoom from the triggering point of the event
|
|
|
+ imageData.left -= (newWidth - imageData.width) * ((center.pageX - offset.left - imageData.left) / imageData.width);
|
|
|
+ imageData.top -= (newHeight - imageData.height) * ((center.pageY - offset.top - imageData.top) / imageData.height);
|
|
|
+ } else {
|
|
|
+ // Zoom from the center of the image
|
|
|
+ imageData.left -= (newWidth - imageData.width) / 2;
|
|
|
+ imageData.top -= (newHeight - imageData.height) / 2;
|
|
|
+ }
|
|
|
|
|
|
+ imageData.width = newWidth;
|
|
|
+ imageData.height = newHeight;
|
|
|
+ imageData.ratio = ratio;
|
|
|
+ this.renderImage();
|
|
|
|
|
|
- /**
|
|
|
- * Rotate the image to an absolute degree.
|
|
|
- * @param {number} degree - The rotate degree.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- rotateTo: function rotateTo(degree) {
|
|
|
- var imageData = this.imageData;
|
|
|
+ if (hasTooltip) {
|
|
|
+ this.tooltip();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- degree = Number(degree);
|
|
|
|
|
|
- if (isNumber(degree) && this.viewed && !this.played && this.options.rotatable) {
|
|
|
- imageData.rotate = degree;
|
|
|
- this.renderImage();
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Rotate the image with a relative degree.
|
|
|
+ * @param {number} degree - The rotate degree.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ rotate: function rotate(degree) {
|
|
|
+ this.rotateTo((this.imageData.rotate || 0) + Number(degree));
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * Scale the image on the x-axis.
|
|
|
- * @param {number} scaleX - The scale ratio on the x-axis.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- scaleX: function scaleX(_scaleX) {
|
|
|
- this.scale(_scaleX, this.imageData.scaleY);
|
|
|
+ /**
|
|
|
+ * Rotate the image to an absolute degree.
|
|
|
+ * @param {number} degree - The rotate degree.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ rotateTo: function rotateTo(degree) {
|
|
|
+ var imageData = this.imageData;
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
|
|
|
+ degree = Number(degree);
|
|
|
|
|
|
- /**
|
|
|
- * Scale the image on the y-axis.
|
|
|
- * @param {number} scaleY - The scale ratio on the y-axis.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- scaleY: function scaleY(_scaleY) {
|
|
|
- this.scale(this.imageData.scaleX, _scaleY);
|
|
|
+ if (isNumber(degree) && this.viewed && !this.played && this.options.rotatable) {
|
|
|
+ imageData.rotate = degree;
|
|
|
+ this.renderImage();
|
|
|
+ }
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * Scale the image.
|
|
|
- * @param {number} scaleX - The scale ratio on the x-axis.
|
|
|
- * @param {number} [scaleY=scaleX] - The scale ratio on the y-axis.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- scale: function scale(scaleX) {
|
|
|
- var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX;
|
|
|
- var imageData = this.imageData;
|
|
|
+ /**
|
|
|
+ * Scale the image on the x-axis.
|
|
|
+ * @param {number} scaleX - The scale ratio on the x-axis.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ scaleX: function scaleX(_scaleX) {
|
|
|
+ this.scale(_scaleX, this.imageData.scaleY);
|
|
|
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- scaleX = Number(scaleX);
|
|
|
- scaleY = Number(scaleY);
|
|
|
|
|
|
- if (this.viewed && !this.played && this.options.scalable) {
|
|
|
- var changed = false;
|
|
|
+ /**
|
|
|
+ * Scale the image on the y-axis.
|
|
|
+ * @param {number} scaleY - The scale ratio on the y-axis.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ scaleY: function scaleY(_scaleY) {
|
|
|
+ this.scale(this.imageData.scaleX, _scaleY);
|
|
|
|
|
|
- if (isNumber(scaleX)) {
|
|
|
- imageData.scaleX = scaleX;
|
|
|
- changed = true;
|
|
|
- }
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- if (isNumber(scaleY)) {
|
|
|
- imageData.scaleY = scaleY;
|
|
|
- changed = true;
|
|
|
- }
|
|
|
|
|
|
- if (changed) {
|
|
|
- this.renderImage();
|
|
|
- }
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Scale the image.
|
|
|
+ * @param {number} scaleX - The scale ratio on the x-axis.
|
|
|
+ * @param {number} [scaleY=scaleX] - The scale ratio on the y-axis.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ scale: function scale(scaleX) {
|
|
|
+ var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX;
|
|
|
+ var imageData = this.imageData;
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
|
|
|
+ scaleX = Number(scaleX);
|
|
|
+ scaleY = Number(scaleY);
|
|
|
|
|
|
- /**
|
|
|
- * Play the images
|
|
|
- * @param {boolean} [fullscreen=false] - Indicate if request fullscreen or not.
|
|
|
- * @returns {Viewer} this
|
|
|
- */
|
|
|
- play: function play() {
|
|
|
- var _this2 = this;
|
|
|
+ if (this.viewed && !this.played && this.options.scalable) {
|
|
|
+ var changed = false;
|
|
|
|
|
|
- var fullscreen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
+ if (isNumber(scaleX)) {
|
|
|
+ imageData.scaleX = scaleX;
|
|
|
+ changed = true;
|
|
|
+ }
|
|
|
|
|
|
- if (!this.isShown || this.played) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ if (isNumber(scaleY)) {
|
|
|
+ imageData.scaleY = scaleY;
|
|
|
+ changed = true;
|
|
|
+ }
|
|
|
|
|
|
- var options = this.options,
|
|
|
- player = this.player;
|
|
|
+ if (changed) {
|
|
|
+ this.renderImage();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- var onLoad = this.loadImage.bind(this);
|
|
|
- var list = [];
|
|
|
- var total = 0;
|
|
|
- var index = 0;
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- this.played = true;
|
|
|
- this.onLoadWhenPlay = onLoad;
|
|
|
|
|
|
- if (fullscreen) {
|
|
|
- this.requestFullscreen();
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Play the images
|
|
|
+ * @param {boolean} [fullscreen=false] - Indicate if request fullscreen or not.
|
|
|
+ * @returns {Viewer} this
|
|
|
+ */
|
|
|
+ play: function play() {
|
|
|
+ var _this2 = this;
|
|
|
|
|
|
- addClass(player, CLASS_SHOW);
|
|
|
- forEach(this.items, function (item, i) {
|
|
|
- var img = item.querySelector('img');
|
|
|
- var image = document.createElement('img');
|
|
|
+ var fullscreen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
|
|
|
|
- image.src = getData(img, 'originalUrl');
|
|
|
- image.alt = img.getAttribute('alt');
|
|
|
- total += 1;
|
|
|
- addClass(image, CLASS_FADE);
|
|
|
- toggleClass(image, CLASS_TRANSITION, options.transition);
|
|
|
+ if (!this.isShown || this.played) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
- if (hasClass(item, CLASS_ACTIVE)) {
|
|
|
- addClass(image, CLASS_IN);
|
|
|
- index = i;
|
|
|
- }
|
|
|
+ var options = this.options,
|
|
|
+ player = this.player;
|
|
|
|
|
|
- list.push(image);
|
|
|
- addListener(image, EVENT_LOAD, onLoad, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- player.appendChild(image);
|
|
|
- });
|
|
|
-
|
|
|
- if (isNumber(options.interval) && options.interval > 0) {
|
|
|
- var play = function play() {
|
|
|
- _this2.playing = setTimeout(function () {
|
|
|
- removeClass(list[index], CLASS_IN);
|
|
|
- index += 1;
|
|
|
- index = index < total ? index : 0;
|
|
|
- addClass(list[index], CLASS_IN);
|
|
|
- play();
|
|
|
- }, options.interval);
|
|
|
- };
|
|
|
+ var onLoad = this.loadImage.bind(this);
|
|
|
+ var list = [];
|
|
|
+ var total = 0;
|
|
|
+ var index = 0;
|
|
|
|
|
|
- if (total > 1) {
|
|
|
- play();
|
|
|
- }
|
|
|
- }
|
|
|
+ this.played = true;
|
|
|
+ this.onLoadWhenPlay = onLoad;
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ if (fullscreen) {
|
|
|
+ this.requestFullscreen();
|
|
|
+ }
|
|
|
|
|
|
+ addClass(player, CLASS_SHOW);
|
|
|
+ forEach(this.items, function (item, i) {
|
|
|
+ var img = item.querySelector('img');
|
|
|
+ var image = document.createElement('img');
|
|
|
|
|
|
- // Stop play
|
|
|
- stop: function stop() {
|
|
|
- var _this3 = this;
|
|
|
+ image.src = getData(img, 'originalUrl');
|
|
|
+ image.alt = img.getAttribute('alt');
|
|
|
+ total += 1;
|
|
|
+ addClass(image, CLASS_FADE);
|
|
|
+ toggleClass(image, CLASS_TRANSITION, options.transition);
|
|
|
|
|
|
- if (!this.played) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ if (hasClass(item, CLASS_ACTIVE)) {
|
|
|
+ addClass(image, CLASS_IN);
|
|
|
+ index = i;
|
|
|
+ }
|
|
|
|
|
|
- var player = this.player;
|
|
|
+ list.push(image);
|
|
|
+ addListener(image, EVENT_LOAD, onLoad, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ player.appendChild(image);
|
|
|
+ });
|
|
|
|
|
|
+ if (isNumber(options.interval) && options.interval > 0) {
|
|
|
+ var play = function play() {
|
|
|
+ _this2.playing = setTimeout(function () {
|
|
|
+ removeClass(list[index], CLASS_IN);
|
|
|
+ index += 1;
|
|
|
+ index = index < total ? index : 0;
|
|
|
+ addClass(list[index], CLASS_IN);
|
|
|
+ play();
|
|
|
+ }, options.interval);
|
|
|
+ };
|
|
|
+
|
|
|
+ if (total > 1) {
|
|
|
+ play();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- this.played = false;
|
|
|
- clearTimeout(this.playing);
|
|
|
- forEach(player.getElementsByTagName('img'), function (image) {
|
|
|
- removeListener(image, EVENT_LOAD, _this3.onLoadWhenPlay);
|
|
|
- });
|
|
|
- removeClass(player, CLASS_SHOW);
|
|
|
- player.innerHTML = '';
|
|
|
- this.exitFullscreen();
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
|
|
|
+ // Stop play
|
|
|
+ stop: function stop() {
|
|
|
+ var _this3 = this;
|
|
|
|
|
|
- // Enter modal mode (only available in inline mode)
|
|
|
- full: function full() {
|
|
|
- var _this4 = this;
|
|
|
+ if (!this.played) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
- var options = this.options,
|
|
|
- viewer = this.viewer,
|
|
|
- image = this.image,
|
|
|
- list = this.list;
|
|
|
+ var player = this.player;
|
|
|
|
|
|
|
|
|
- if (!this.isShown || this.played || this.fulled || !options.inline) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ this.played = false;
|
|
|
+ clearTimeout(this.playing);
|
|
|
+ forEach(player.getElementsByTagName('img'), function (image) {
|
|
|
+ removeListener(image, EVENT_LOAD, _this3.onLoadWhenPlay);
|
|
|
+ });
|
|
|
+ removeClass(player, CLASS_SHOW);
|
|
|
+ player.innerHTML = '';
|
|
|
+ this.exitFullscreen();
|
|
|
|
|
|
- this.fulled = true;
|
|
|
- this.open();
|
|
|
- addClass(this.button, CLASS_FULLSCREEN_EXIT);
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- if (options.transition) {
|
|
|
- removeClass(list, CLASS_TRANSITION);
|
|
|
|
|
|
- if (this.viewed) {
|
|
|
- removeClass(image, CLASS_TRANSITION);
|
|
|
- }
|
|
|
- }
|
|
|
+ // Enter modal mode (only available in inline mode)
|
|
|
+ full: function full() {
|
|
|
+ var _this4 = this;
|
|
|
|
|
|
- addClass(viewer, CLASS_FIXED);
|
|
|
- viewer.setAttribute('style', '');
|
|
|
- setStyle(viewer, {
|
|
|
- zIndex: options.zIndex
|
|
|
- });
|
|
|
+ var options = this.options,
|
|
|
+ viewer = this.viewer,
|
|
|
+ image = this.image,
|
|
|
+ list = this.list;
|
|
|
|
|
|
- this.initContainer();
|
|
|
- this.viewerData = assign({}, this.containerData);
|
|
|
- this.renderList();
|
|
|
|
|
|
- if (this.viewed) {
|
|
|
- this.initImage(function () {
|
|
|
- _this4.renderImage(function () {
|
|
|
- if (options.transition) {
|
|
|
- setTimeout(function () {
|
|
|
- addClass(image, CLASS_TRANSITION);
|
|
|
- addClass(list, CLASS_TRANSITION);
|
|
|
- }, 0);
|
|
|
+ if (!this.isShown || this.played || this.fulled || !options.inline) {
|
|
|
+ return this;
|
|
|
}
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ this.fulled = true;
|
|
|
+ this.open();
|
|
|
+ addClass(this.button, CLASS_FULLSCREEN_EXIT);
|
|
|
|
|
|
+ if (options.transition) {
|
|
|
+ removeClass(list, CLASS_TRANSITION);
|
|
|
|
|
|
- // Exit modal mode (only available in inline mode)
|
|
|
- exit: function exit() {
|
|
|
- var _this5 = this;
|
|
|
+ if (this.viewed) {
|
|
|
+ removeClass(image, CLASS_TRANSITION);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- var options = this.options,
|
|
|
- viewer = this.viewer,
|
|
|
- image = this.image,
|
|
|
- list = this.list;
|
|
|
+ addClass(viewer, CLASS_FIXED);
|
|
|
+ viewer.setAttribute('style', '');
|
|
|
+ setStyle(viewer, {
|
|
|
+ zIndex: options.zIndex
|
|
|
+ });
|
|
|
|
|
|
+ this.initContainer();
|
|
|
+ this.viewerData = assign({}, this.containerData);
|
|
|
+ this.renderList();
|
|
|
|
|
|
- if (!this.isShown || this.played || !this.fulled || !options.inline) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ if (this.viewed) {
|
|
|
+ this.initImage(function () {
|
|
|
+ _this4.renderImage(function () {
|
|
|
+ if (options.transition) {
|
|
|
+ setTimeout(function () {
|
|
|
+ addClass(image, CLASS_TRANSITION);
|
|
|
+ addClass(list, CLASS_TRANSITION);
|
|
|
+ }, 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- this.fulled = false;
|
|
|
- this.close();
|
|
|
- removeClass(this.button, CLASS_FULLSCREEN_EXIT);
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- if (options.transition) {
|
|
|
- removeClass(list, CLASS_TRANSITION);
|
|
|
|
|
|
- if (this.viewed) {
|
|
|
- removeClass(image, CLASS_TRANSITION);
|
|
|
- }
|
|
|
- }
|
|
|
+ // Exit modal mode (only available in inline mode)
|
|
|
+ exit: function exit() {
|
|
|
+ var _this5 = this;
|
|
|
|
|
|
- removeClass(viewer, CLASS_FIXED);
|
|
|
- setStyle(viewer, {
|
|
|
- zIndex: options.zIndexInline
|
|
|
- });
|
|
|
+ var options = this.options,
|
|
|
+ viewer = this.viewer,
|
|
|
+ image = this.image,
|
|
|
+ list = this.list;
|
|
|
|
|
|
- this.viewerData = assign({}, this.parentData);
|
|
|
- this.renderViewer();
|
|
|
- this.renderList();
|
|
|
|
|
|
- if (this.viewed) {
|
|
|
- this.initImage(function () {
|
|
|
- _this5.renderImage(function () {
|
|
|
- if (options.transition) {
|
|
|
- setTimeout(function () {
|
|
|
- addClass(image, CLASS_TRANSITION);
|
|
|
- addClass(list, CLASS_TRANSITION);
|
|
|
- }, 0);
|
|
|
+ if (!this.isShown || this.played || !this.fulled || !options.inline) {
|
|
|
+ return this;
|
|
|
}
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ this.fulled = false;
|
|
|
+ this.close();
|
|
|
+ removeClass(this.button, CLASS_FULLSCREEN_EXIT);
|
|
|
|
|
|
+ if (options.transition) {
|
|
|
+ removeClass(list, CLASS_TRANSITION);
|
|
|
|
|
|
- // Show the current ratio of the image with percentage
|
|
|
- tooltip: function tooltip() {
|
|
|
- var _this6 = this;
|
|
|
+ if (this.viewed) {
|
|
|
+ removeClass(image, CLASS_TRANSITION);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- var options = this.options,
|
|
|
- tooltipBox = this.tooltipBox,
|
|
|
- imageData = this.imageData;
|
|
|
+ removeClass(viewer, CLASS_FIXED);
|
|
|
+ setStyle(viewer, {
|
|
|
+ zIndex: options.zIndexInline
|
|
|
+ });
|
|
|
|
|
|
+ this.viewerData = assign({}, this.parentData);
|
|
|
+ this.renderViewer();
|
|
|
+ this.renderList();
|
|
|
|
|
|
- if (!this.viewed || this.played || !options.tooltip) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ if (this.viewed) {
|
|
|
+ this.initImage(function () {
|
|
|
+ _this5.renderImage(function () {
|
|
|
+ if (options.transition) {
|
|
|
+ setTimeout(function () {
|
|
|
+ addClass(image, CLASS_TRANSITION);
|
|
|
+ addClass(list, CLASS_TRANSITION);
|
|
|
+ }, 0);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- tooltipBox.textContent = Math.round(imageData.ratio * 100) + '%';
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- if (!this.tooltipping) {
|
|
|
- if (options.transition) {
|
|
|
- if (this.fading) {
|
|
|
- dispatchEvent(tooltipBox, EVENT_TRANSITION_END);
|
|
|
- }
|
|
|
|
|
|
- addClass(tooltipBox, CLASS_SHOW);
|
|
|
- addClass(tooltipBox, CLASS_FADE);
|
|
|
- addClass(tooltipBox, CLASS_TRANSITION);
|
|
|
+ // Show the current ratio of the image with percentage
|
|
|
+ tooltip: function tooltip() {
|
|
|
+ var _this6 = this;
|
|
|
|
|
|
- // Force reflow to enable CSS3 transition
|
|
|
- // eslint-disable-next-line
|
|
|
- tooltipBox.offsetWidth;
|
|
|
- addClass(tooltipBox, CLASS_IN);
|
|
|
- } else {
|
|
|
- addClass(tooltipBox, CLASS_SHOW);
|
|
|
- }
|
|
|
- } else {
|
|
|
- clearTimeout(this.tooltipping);
|
|
|
- }
|
|
|
-
|
|
|
- this.tooltipping = setTimeout(function () {
|
|
|
- if (options.transition) {
|
|
|
- addListener(tooltipBox, EVENT_TRANSITION_END, function () {
|
|
|
- removeClass(tooltipBox, CLASS_SHOW);
|
|
|
- removeClass(tooltipBox, CLASS_FADE);
|
|
|
- removeClass(tooltipBox, CLASS_TRANSITION);
|
|
|
- _this6.fading = false;
|
|
|
- }, {
|
|
|
- once: true
|
|
|
- });
|
|
|
-
|
|
|
- removeClass(tooltipBox, CLASS_IN);
|
|
|
- _this6.fading = true;
|
|
|
- } else {
|
|
|
- removeClass(tooltipBox, CLASS_SHOW);
|
|
|
- }
|
|
|
+ var options = this.options,
|
|
|
+ tooltipBox = this.tooltipBox,
|
|
|
+ imageData = this.imageData;
|
|
|
|
|
|
- _this6.tooltipping = false;
|
|
|
- }, 1000);
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ if (!this.viewed || this.played || !options.tooltip) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
+ tooltipBox.textContent = Math.round(imageData.ratio * 100) + '%';
|
|
|
|
|
|
- // Toggle the image size between its natural size and initial size
|
|
|
- toggle: function toggle() {
|
|
|
- if (this.imageData.ratio === 1) {
|
|
|
- this.zoomTo(this.initialImageData.ratio, true);
|
|
|
- } else {
|
|
|
- this.zoomTo(1, true);
|
|
|
- }
|
|
|
+ if (!this.tooltipping) {
|
|
|
+ if (options.transition) {
|
|
|
+ if (this.fading) {
|
|
|
+ dispatchEvent(tooltipBox, EVENT_TRANSITION_END);
|
|
|
+ }
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ addClass(tooltipBox, CLASS_SHOW);
|
|
|
+ addClass(tooltipBox, CLASS_FADE);
|
|
|
+ addClass(tooltipBox, CLASS_TRANSITION);
|
|
|
|
|
|
+ // Force reflow to enable CSS3 transition
|
|
|
+ // eslint-disable-next-line
|
|
|
+ tooltipBox.offsetWidth;
|
|
|
+ addClass(tooltipBox, CLASS_IN);
|
|
|
+ } else {
|
|
|
+ addClass(tooltipBox, CLASS_SHOW);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ clearTimeout(this.tooltipping);
|
|
|
+ }
|
|
|
|
|
|
- // Reset the image to its initial state
|
|
|
- reset: function reset() {
|
|
|
- if (this.viewed && !this.played) {
|
|
|
- this.imageData = assign({}, this.initialImageData);
|
|
|
- this.renderImage();
|
|
|
- }
|
|
|
+ this.tooltipping = setTimeout(function () {
|
|
|
+ if (options.transition) {
|
|
|
+ addListener(tooltipBox, EVENT_TRANSITION_END, function () {
|
|
|
+ removeClass(tooltipBox, CLASS_SHOW);
|
|
|
+ removeClass(tooltipBox, CLASS_FADE);
|
|
|
+ removeClass(tooltipBox, CLASS_TRANSITION);
|
|
|
+ _this6.fading = false;
|
|
|
+ }, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+
|
|
|
+ removeClass(tooltipBox, CLASS_IN);
|
|
|
+ _this6.fading = true;
|
|
|
+ } else {
|
|
|
+ removeClass(tooltipBox, CLASS_SHOW);
|
|
|
+ }
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ _this6.tooltipping = false;
|
|
|
+ }, 1000);
|
|
|
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- // Update viewer when images changed
|
|
|
- update: function update() {
|
|
|
- var element = this.element,
|
|
|
- options = this.options,
|
|
|
- isImg = this.isImg;
|
|
|
|
|
|
- // Destroy viewer if the target image was deleted
|
|
|
+ // Toggle the image size between its natural size and initial size
|
|
|
+ toggle: function toggle() {
|
|
|
+ if (this.imageData.ratio === 1) {
|
|
|
+ this.zoomTo(this.initialImageData.ratio, true);
|
|
|
+ } else {
|
|
|
+ this.zoomTo(1, true);
|
|
|
+ }
|
|
|
|
|
|
- if (isImg && !element.parentNode) {
|
|
|
- return this.destroy();
|
|
|
- }
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- var images = [];
|
|
|
|
|
|
- forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
|
|
|
- if (options.filter) {
|
|
|
- if (options.filter(image)) {
|
|
|
- images.push(image);
|
|
|
- }
|
|
|
- } else {
|
|
|
- images.push(image);
|
|
|
- }
|
|
|
- });
|
|
|
+ // Reset the image to its initial state
|
|
|
+ reset: function reset() {
|
|
|
+ if (this.viewed && !this.played) {
|
|
|
+ this.imageData = assign({}, this.initialImageData);
|
|
|
+ this.renderImage();
|
|
|
+ }
|
|
|
|
|
|
- if (!images.length) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
- this.images = images;
|
|
|
- this.length = images.length;
|
|
|
|
|
|
- if (this.ready) {
|
|
|
- var indexes = [];
|
|
|
+ // Update viewer when images changed
|
|
|
+ update: function update() {
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options,
|
|
|
+ isImg = this.isImg;
|
|
|
|
|
|
- forEach(this.items, function (item, i) {
|
|
|
- var img = item.querySelector('img');
|
|
|
- var image = images[i];
|
|
|
+ // Destroy viewer if the target image was deleted
|
|
|
|
|
|
- if (image) {
|
|
|
- if (image.src !== img.src) {
|
|
|
- indexes.push(i);
|
|
|
+ if (isImg && !element.parentNode) {
|
|
|
+ return this.destroy();
|
|
|
}
|
|
|
- } else {
|
|
|
- indexes.push(i);
|
|
|
- }
|
|
|
- });
|
|
|
|
|
|
- setStyle(this.list, {
|
|
|
- width: 'auto'
|
|
|
- });
|
|
|
+ var images = [];
|
|
|
|
|
|
- this.initList();
|
|
|
+ forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
|
|
|
+ if (options.filter) {
|
|
|
+ if (options.filter(image)) {
|
|
|
+ images.push(image);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ images.push(image);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- if (this.isShown) {
|
|
|
- if (this.length) {
|
|
|
- if (this.viewed) {
|
|
|
- var index = indexes.indexOf(this.index);
|
|
|
+ if (!images.length) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
- if (index >= 0) {
|
|
|
- this.viewed = false;
|
|
|
- this.view(Math.max(this.index - (index + 1), 0));
|
|
|
- } else {
|
|
|
- addClass(this.items[this.index], CLASS_ACTIVE);
|
|
|
- }
|
|
|
+ this.images = images;
|
|
|
+ this.length = images.length;
|
|
|
+
|
|
|
+ if (this.ready) {
|
|
|
+ var indexes = [];
|
|
|
+
|
|
|
+ forEach(this.items, function (item, i) {
|
|
|
+ var img = item.querySelector('img');
|
|
|
+ var image = images[i];
|
|
|
+
|
|
|
+ if (image) {
|
|
|
+ if (image.src !== img.src) {
|
|
|
+ indexes.push(i);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ indexes.push(i);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ setStyle(this.list, {
|
|
|
+ width: 'auto'
|
|
|
+ });
|
|
|
+
|
|
|
+ this.initList();
|
|
|
+
|
|
|
+ if (this.isShown) {
|
|
|
+ if (this.length) {
|
|
|
+ if (this.viewed) {
|
|
|
+ var index = indexes.indexOf(this.index);
|
|
|
+
|
|
|
+ if (index >= 0) {
|
|
|
+ this.viewed = false;
|
|
|
+ this.view(Math.max(this.index - (index + 1), 0));
|
|
|
+ } else {
|
|
|
+ addClass(this.items[this.index], CLASS_ACTIVE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.image = null;
|
|
|
+ this.viewed = false;
|
|
|
+ this.index = 0;
|
|
|
+ this.imageData = null;
|
|
|
+ this.canvas.innerHTML = '';
|
|
|
+ this.title.innerHTML = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.build();
|
|
|
}
|
|
|
- } else {
|
|
|
- this.image = null;
|
|
|
- this.viewed = false;
|
|
|
- this.index = 0;
|
|
|
- this.imageData = null;
|
|
|
- this.canvas.innerHTML = '';
|
|
|
- this.title.innerHTML = '';
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- this.build();
|
|
|
- }
|
|
|
|
|
|
- return this;
|
|
|
- },
|
|
|
+ return this;
|
|
|
+ },
|
|
|
|
|
|
|
|
|
- // Destroy the viewer
|
|
|
- destroy: function destroy() {
|
|
|
- var element = this.element,
|
|
|
- options = this.options;
|
|
|
+ // Destroy the viewer
|
|
|
+ destroy: function destroy() {
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options;
|
|
|
|
|
|
|
|
|
- if (!getData(element, NAMESPACE)) {
|
|
|
- return this;
|
|
|
- }
|
|
|
+ if (!getData(element, NAMESPACE)) {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
|
|
|
- this.destroyed = true;
|
|
|
+ this.destroyed = true;
|
|
|
|
|
|
- if (this.ready) {
|
|
|
- if (this.played) {
|
|
|
- this.stop();
|
|
|
- }
|
|
|
+ if (this.ready) {
|
|
|
+ if (this.played) {
|
|
|
+ this.stop();
|
|
|
+ }
|
|
|
|
|
|
- if (options.inline) {
|
|
|
- if (this.fulled) {
|
|
|
- this.exit();
|
|
|
- }
|
|
|
-
|
|
|
- this.unbind();
|
|
|
- } else if (this.isShown) {
|
|
|
- if (this.viewing) {
|
|
|
- if (this.imageRendering) {
|
|
|
- this.imageRendering.abort();
|
|
|
- } else if (this.imageInitializing) {
|
|
|
- this.imageInitializing.abort();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (this.hiding) {
|
|
|
- this.transitioning.abort();
|
|
|
- }
|
|
|
-
|
|
|
- this.hidden();
|
|
|
- } else if (this.showing) {
|
|
|
- this.transitioning.abort();
|
|
|
- this.hidden();
|
|
|
- }
|
|
|
+ if (options.inline) {
|
|
|
+ if (this.fulled) {
|
|
|
+ this.exit();
|
|
|
+ }
|
|
|
+
|
|
|
+ this.unbind();
|
|
|
+ } else if (this.isShown) {
|
|
|
+ if (this.viewing) {
|
|
|
+ if (this.imageRendering) {
|
|
|
+ this.imageRendering.abort();
|
|
|
+ } else if (this.imageInitializing) {
|
|
|
+ this.imageInitializing.abort();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.hiding) {
|
|
|
+ this.transitioning.abort();
|
|
|
+ }
|
|
|
+
|
|
|
+ this.hidden();
|
|
|
+ } else if (this.showing) {
|
|
|
+ this.transitioning.abort();
|
|
|
+ this.hidden();
|
|
|
+ }
|
|
|
|
|
|
- this.ready = false;
|
|
|
- this.viewer.parentNode.removeChild(this.viewer);
|
|
|
- } else if (options.inline) {
|
|
|
- if (this.delaying) {
|
|
|
- this.delaying.abort();
|
|
|
- } else if (this.initializing) {
|
|
|
- this.initializing.abort();
|
|
|
- }
|
|
|
- }
|
|
|
+ this.ready = false;
|
|
|
+ this.viewer.parentNode.removeChild(this.viewer);
|
|
|
+ } else if (options.inline) {
|
|
|
+ if (this.delaying) {
|
|
|
+ this.delaying.abort();
|
|
|
+ } else if (this.initializing) {
|
|
|
+ this.initializing.abort();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (!options.inline) {
|
|
|
- removeListener(element, EVENT_CLICK, this.onStart);
|
|
|
- }
|
|
|
+ if (!options.inline) {
|
|
|
+ removeListener(element, EVENT_CLICK, this.onStart);
|
|
|
+ }
|
|
|
|
|
|
- removeData(element, NAMESPACE);
|
|
|
- return this;
|
|
|
- }
|
|
|
- };
|
|
|
+ removeData(element, NAMESPACE);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- var others = {
|
|
|
- open: function open() {
|
|
|
- var body = this.body;
|
|
|
+ var others = {
|
|
|
+ open: function open() {
|
|
|
+ var body = this.body;
|
|
|
|
|
|
|
|
|
- addClass(body, CLASS_OPEN);
|
|
|
+ addClass(body, CLASS_OPEN);
|
|
|
|
|
|
- body.style.paddingRight = this.scrollbarWidth + (parseFloat(this.initialBodyPaddingRight) || 0) + 'px';
|
|
|
- },
|
|
|
- close: function close() {
|
|
|
- var body = this.body;
|
|
|
+ body.style.paddingRight = this.scrollbarWidth + (parseFloat(this.initialBodyPaddingRight) || 0) + 'px';
|
|
|
+ },
|
|
|
+ close: function close() {
|
|
|
+ var body = this.body;
|
|
|
|
|
|
|
|
|
- removeClass(body, CLASS_OPEN);
|
|
|
- body.style.paddingRight = this.initialBodyPaddingRight;
|
|
|
- },
|
|
|
- shown: function shown() {
|
|
|
- var element = this.element,
|
|
|
- options = this.options;
|
|
|
+ removeClass(body, CLASS_OPEN);
|
|
|
+ body.style.paddingRight = this.initialBodyPaddingRight;
|
|
|
+ },
|
|
|
+ shown: function shown() {
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options;
|
|
|
|
|
|
|
|
|
- this.fulled = true;
|
|
|
- this.isShown = true;
|
|
|
- this.render();
|
|
|
- this.bind();
|
|
|
- this.showing = false;
|
|
|
+ this.fulled = true;
|
|
|
+ this.isShown = true;
|
|
|
+ this.render();
|
|
|
+ this.bind();
|
|
|
+ this.showing = false;
|
|
|
|
|
|
- if (isFunction(options.shown)) {
|
|
|
- addListener(element, EVENT_SHOWN, options.shown, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- if (dispatchEvent(element, EVENT_SHOWN) === false) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (this.ready && this.isShown && !this.hiding) {
|
|
|
- this.view(this.index);
|
|
|
- }
|
|
|
- },
|
|
|
- hidden: function hidden() {
|
|
|
- var element = this.element,
|
|
|
- options = this.options;
|
|
|
-
|
|
|
-
|
|
|
- this.fulled = false;
|
|
|
- this.viewed = false;
|
|
|
- this.isShown = false;
|
|
|
- this.close();
|
|
|
- this.unbind();
|
|
|
- addClass(this.viewer, CLASS_HIDE);
|
|
|
- this.resetList();
|
|
|
- this.resetImage();
|
|
|
- this.hiding = false;
|
|
|
-
|
|
|
- if (!this.destroyed) {
|
|
|
- if (isFunction(options.hidden)) {
|
|
|
- addListener(element, EVENT_HIDDEN, options.hidden, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- }
|
|
|
+ if (isFunction(options.shown)) {
|
|
|
+ addListener(element, EVENT_SHOWN, options.shown, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- dispatchEvent(element, EVENT_HIDDEN);
|
|
|
- }
|
|
|
- },
|
|
|
- requestFullscreen: function requestFullscreen() {
|
|
|
- var document = this.element.ownerDocument;
|
|
|
+ if (dispatchEvent(element, EVENT_SHOWN) === false) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (this.fulled && !document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
|
|
|
- var documentElement = document.documentElement;
|
|
|
+ if (this.ready && this.isShown && !this.hiding) {
|
|
|
+ this.view(this.index);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ hidden: function hidden() {
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options;
|
|
|
|
|
|
|
|
|
- if (documentElement.requestFullscreen) {
|
|
|
- documentElement.requestFullscreen();
|
|
|
- } else if (documentElement.msRequestFullscreen) {
|
|
|
- documentElement.msRequestFullscreen();
|
|
|
- } else if (documentElement.mozRequestFullScreen) {
|
|
|
- documentElement.mozRequestFullScreen();
|
|
|
- } else if (documentElement.webkitRequestFullscreen) {
|
|
|
- documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- exitFullscreen: function exitFullscreen() {
|
|
|
- if (this.fulled) {
|
|
|
- var document = this.element.ownerDocument;
|
|
|
-
|
|
|
- if (document.exitFullscreen) {
|
|
|
- document.exitFullscreen();
|
|
|
- } else if (document.msExitFullscreen) {
|
|
|
- document.msExitFullscreen();
|
|
|
- } else if (document.mozCancelFullScreen) {
|
|
|
- document.mozCancelFullScreen();
|
|
|
- } else if (document.webkitExitFullscreen) {
|
|
|
- document.webkitExitFullscreen();
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- change: function change(e) {
|
|
|
- var options = this.options,
|
|
|
- pointers = this.pointers;
|
|
|
-
|
|
|
- var pointer = pointers[Object.keys(pointers)[0]];
|
|
|
- var offsetX = pointer.endX - pointer.startX;
|
|
|
- var offsetY = pointer.endY - pointer.startY;
|
|
|
-
|
|
|
- switch (this.action) {
|
|
|
- // Move the current image
|
|
|
- case ACTION_MOVE:
|
|
|
- this.move(offsetX, offsetY);
|
|
|
- break;
|
|
|
-
|
|
|
- // Zoom the current image
|
|
|
- case ACTION_ZOOM:
|
|
|
- this.zoom(getMaxZoomRatio(pointers), false, e);
|
|
|
- break;
|
|
|
-
|
|
|
- case ACTION_SWITCH:
|
|
|
- this.action = 'switched';
|
|
|
-
|
|
|
- // Empty `pointers` as `touchend` event will not be fired after swiped in iOS browsers.
|
|
|
- this.pointers = {};
|
|
|
-
|
|
|
- if (Math.abs(offsetX) > Math.abs(offsetY)) {
|
|
|
- if (offsetX > 1) {
|
|
|
- this.prev(options.loop);
|
|
|
- } else if (offsetX < -1) {
|
|
|
- this.next(options.loop);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- }
|
|
|
-
|
|
|
- // Override
|
|
|
- forEach(pointers, function (p) {
|
|
|
- p.startX = p.endX;
|
|
|
- p.startY = p.endY;
|
|
|
- });
|
|
|
- },
|
|
|
- isSwitchable: function isSwitchable() {
|
|
|
- var imageData = this.imageData,
|
|
|
- viewerData = this.viewerData;
|
|
|
-
|
|
|
-
|
|
|
- return this.length > 1 && imageData.left >= 0 && imageData.top >= 0 && imageData.width <= viewerData.width && imageData.height <= viewerData.height;
|
|
|
- }
|
|
|
- };
|
|
|
+ this.fulled = false;
|
|
|
+ this.viewed = false;
|
|
|
+ this.isShown = false;
|
|
|
+ this.close();
|
|
|
+ this.unbind();
|
|
|
+ addClass(this.viewer, CLASS_HIDE);
|
|
|
+ this.resetList();
|
|
|
+ this.resetImage();
|
|
|
+ this.hiding = false;
|
|
|
+
|
|
|
+ if (!this.destroyed) {
|
|
|
+ if (isFunction(options.hidden)) {
|
|
|
+ addListener(element, EVENT_HIDDEN, options.hidden, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- var AnotherViewer = WINDOW.Viewer;
|
|
|
+ dispatchEvent(element, EVENT_HIDDEN);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ requestFullscreen: function requestFullscreen() {
|
|
|
+ var document = this.element.ownerDocument;
|
|
|
|
|
|
- var Viewer = function () {
|
|
|
- /**
|
|
|
- * Create a new Viewer.
|
|
|
- * @param {Element} element - The target element for viewing.
|
|
|
- * @param {Object} [options={}] - The configuration options.
|
|
|
- */
|
|
|
- function Viewer(element) {
|
|
|
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
|
- classCallCheck(this, Viewer);
|
|
|
-
|
|
|
- if (!element || element.nodeType !== 1) {
|
|
|
- throw new Error('The first argument is required and must be an element.');
|
|
|
- }
|
|
|
-
|
|
|
- this.element = element;
|
|
|
- this.options = assign({}, DEFAULTS, isPlainObject(options) && options);
|
|
|
- this.action = false;
|
|
|
- this.fading = false;
|
|
|
- this.fulled = false;
|
|
|
- this.hiding = false;
|
|
|
- this.index = 0;
|
|
|
- this.isImg = false;
|
|
|
- this.length = 0;
|
|
|
- this.played = false;
|
|
|
- this.playing = false;
|
|
|
- this.pointers = {};
|
|
|
- this.ready = false;
|
|
|
- this.showing = false;
|
|
|
- this.timeout = false;
|
|
|
- this.tooltipping = false;
|
|
|
- this.viewed = false;
|
|
|
- this.viewing = false;
|
|
|
- this.isShown = false;
|
|
|
- this.wheeling = false;
|
|
|
- this.init();
|
|
|
- }
|
|
|
+ if (this.fulled && !document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
|
|
|
+ var documentElement = document.documentElement;
|
|
|
|
|
|
- createClass(Viewer, [{
|
|
|
- key: 'init',
|
|
|
- value: function init() {
|
|
|
- var _this = this;
|
|
|
|
|
|
- var element = this.element,
|
|
|
- options = this.options;
|
|
|
+ if (documentElement.requestFullscreen) {
|
|
|
+ documentElement.requestFullscreen();
|
|
|
+ } else if (documentElement.msRequestFullscreen) {
|
|
|
+ documentElement.msRequestFullscreen();
|
|
|
+ } else if (documentElement.mozRequestFullScreen) {
|
|
|
+ documentElement.mozRequestFullScreen();
|
|
|
+ } else if (documentElement.webkitRequestFullscreen) {
|
|
|
+ documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ exitFullscreen: function exitFullscreen() {
|
|
|
+ if (this.fulled) {
|
|
|
+ var document = this.element.ownerDocument;
|
|
|
+
|
|
|
+ if (document.exitFullscreen) {
|
|
|
+ document.exitFullscreen();
|
|
|
+ } else if (document.msExitFullscreen) {
|
|
|
+ document.msExitFullscreen();
|
|
|
+ } else if (document.mozCancelFullScreen) {
|
|
|
+ document.mozCancelFullScreen();
|
|
|
+ } else if (document.webkitExitFullscreen) {
|
|
|
+ document.webkitExitFullscreen();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ change: function change(e) {
|
|
|
+ var options = this.options,
|
|
|
+ pointers = this.pointers;
|
|
|
+
|
|
|
+ var pointer = pointers[Object.keys(pointers)[0]];
|
|
|
+ var offsetX = pointer.endX - pointer.startX;
|
|
|
+ var offsetY = pointer.endY - pointer.startY;
|
|
|
+
|
|
|
+ switch (this.action) {
|
|
|
+ // Move the current image
|
|
|
+ case ACTION_MOVE:
|
|
|
+ this.move(offsetX, offsetY);
|
|
|
+ break;
|
|
|
+
|
|
|
+ // Zoom the current image
|
|
|
+ case ACTION_ZOOM:
|
|
|
+ this.zoom(getMaxZoomRatio(pointers), false, e);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case ACTION_SWITCH:
|
|
|
+ this.action = 'switched';
|
|
|
+
|
|
|
+ // Empty `pointers` as `touchend` event will not be fired after swiped in iOS browsers.
|
|
|
+ this.pointers = {};
|
|
|
+
|
|
|
+ if (Math.abs(offsetX) > Math.abs(offsetY)) {
|
|
|
+ if (offsetX > 1) {
|
|
|
+ this.prev(options.loop);
|
|
|
+ } else if (offsetX < -1) {
|
|
|
+ this.next(options.loop);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ }
|
|
|
+
|
|
|
+ // Override
|
|
|
+ forEach(pointers, function (p) {
|
|
|
+ p.startX = p.endX;
|
|
|
+ p.startY = p.endY;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ isSwitchable: function isSwitchable() {
|
|
|
+ var imageData = this.imageData,
|
|
|
+ viewerData = this.viewerData;
|
|
|
|
|
|
|
|
|
- if (getData(element, NAMESPACE)) {
|
|
|
- return;
|
|
|
+ return this.length > 1 && imageData.left >= 0 && imageData.top >= 0 && imageData.width <= viewerData.width && imageData.height <= viewerData.height;
|
|
|
}
|
|
|
+ };
|
|
|
|
|
|
- setData(element, NAMESPACE, this);
|
|
|
+ var AnotherViewer = WINDOW.Viewer;
|
|
|
|
|
|
- var isImg = element.tagName.toLowerCase() === 'img';
|
|
|
- var images = [];
|
|
|
+ var Viewer = function () {
|
|
|
+ /**
|
|
|
+ * Create a new Viewer.
|
|
|
+ * @param {Element} element - The target element for viewing.
|
|
|
+ * @param {Object} [options={}] - The configuration options.
|
|
|
+ */
|
|
|
+ function Viewer(element) {
|
|
|
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
|
+ classCallCheck(this, Viewer);
|
|
|
|
|
|
- forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
|
|
|
- if (isFunction(options.filter)) {
|
|
|
- if (options.filter.call(_this, image)) {
|
|
|
- images.push(image);
|
|
|
+ if (!element || element.nodeType !== 1) {
|
|
|
+ throw new Error('The first argument is required and must be an element.');
|
|
|
}
|
|
|
- } else {
|
|
|
- images.push(image);
|
|
|
- }
|
|
|
- });
|
|
|
|
|
|
- if (!images.length) {
|
|
|
- return;
|
|
|
+ this.element = element;
|
|
|
+ this.options = assign({}, DEFAULTS, isPlainObject(options) && options);
|
|
|
+ this.action = false;
|
|
|
+ this.fading = false;
|
|
|
+ this.fulled = false;
|
|
|
+ this.hiding = false;
|
|
|
+ this.index = 0;
|
|
|
+ this.isImg = false;
|
|
|
+ this.length = 0;
|
|
|
+ this.played = false;
|
|
|
+ this.playing = false;
|
|
|
+ this.pointers = {};
|
|
|
+ this.ready = false;
|
|
|
+ this.showing = false;
|
|
|
+ this.timeout = false;
|
|
|
+ this.tooltipping = false;
|
|
|
+ this.viewed = false;
|
|
|
+ this.viewing = false;
|
|
|
+ this.isShown = false;
|
|
|
+ this.wheeling = false;
|
|
|
+ this.init();
|
|
|
}
|
|
|
|
|
|
- this.isImg = isImg;
|
|
|
- this.length = images.length;
|
|
|
- this.images = images;
|
|
|
+ createClass(Viewer, [{
|
|
|
+ key: 'init',
|
|
|
+ value: function init() {
|
|
|
+ var _this = this;
|
|
|
|
|
|
- var ownerDocument = element.ownerDocument;
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options;
|
|
|
|
|
|
- var body = ownerDocument.body || ownerDocument.documentElement;
|
|
|
|
|
|
- this.body = body;
|
|
|
- this.scrollbarWidth = window.innerWidth - ownerDocument.documentElement.clientWidth;
|
|
|
- this.initialBodyPaddingRight = window.getComputedStyle(body).paddingRight;
|
|
|
+ if (getData(element, NAMESPACE)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // Override `transition` option if it is not supported
|
|
|
- if (isUndefined(document.createElement(NAMESPACE).style.transition)) {
|
|
|
- options.transition = false;
|
|
|
- }
|
|
|
+ setData(element, NAMESPACE, this);
|
|
|
|
|
|
- if (options.inline) {
|
|
|
- var count = 0;
|
|
|
- var progress = function progress() {
|
|
|
- count += 1;
|
|
|
+ var isImg = element.tagName.toLowerCase() === 'img';
|
|
|
+ var images = [];
|
|
|
|
|
|
- if (count === _this.length) {
|
|
|
- var timeout = void 0;
|
|
|
+ forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) {
|
|
|
+ if (isFunction(options.filter)) {
|
|
|
+ if (options.filter.call(_this, image)) {
|
|
|
+ images.push(image);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ images.push(image);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- _this.initializing = false;
|
|
|
- _this.delaying = {
|
|
|
- abort: function abort() {
|
|
|
- clearTimeout(timeout);
|
|
|
+ if (!images.length) {
|
|
|
+ return;
|
|
|
}
|
|
|
- };
|
|
|
|
|
|
- // build asynchronously to keep `this.viewer` is accessible in `ready` event handler.
|
|
|
- timeout = setTimeout(function () {
|
|
|
- _this.delaying = false;
|
|
|
- _this.build();
|
|
|
- }, 0);
|
|
|
- }
|
|
|
- };
|
|
|
+ this.isImg = isImg;
|
|
|
+ this.length = images.length;
|
|
|
+ this.images = images;
|
|
|
+ this.dealOriginal=[];
|
|
|
+ var ownerDocument = element.ownerDocument;
|
|
|
|
|
|
- this.initializing = {
|
|
|
- abort: function abort() {
|
|
|
- forEach(images, function (image) {
|
|
|
- if (!image.complete) {
|
|
|
- removeListener(image, EVENT_LOAD, progress);
|
|
|
+ var body = ownerDocument.body || ownerDocument.documentElement;
|
|
|
+
|
|
|
+ this.body = body;
|
|
|
+ this.scrollbarWidth = window.innerWidth - ownerDocument.documentElement.clientWidth;
|
|
|
+ this.initialBodyPaddingRight = window.getComputedStyle(body).paddingRight;
|
|
|
+
|
|
|
+ // Override `transition` option if it is not supported
|
|
|
+ if (isUndefined(document.createElement(NAMESPACE).style.transition)) {
|
|
|
+ options.transition = false;
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
- };
|
|
|
|
|
|
- forEach(images, function (image) {
|
|
|
- if (image.complete) {
|
|
|
- progress();
|
|
|
- } else {
|
|
|
- addListener(image, EVENT_LOAD, progress, {
|
|
|
- once: true
|
|
|
- });
|
|
|
+ if (options.inline) {
|
|
|
+ var count = 0;
|
|
|
+ var progress = function progress() {
|
|
|
+ count += 1;
|
|
|
+
|
|
|
+ if (count === _this.length) {
|
|
|
+ var timeout = void 0;
|
|
|
+
|
|
|
+ _this.initializing = false;
|
|
|
+ _this.delaying = {
|
|
|
+ abort: function abort() {
|
|
|
+ clearTimeout(timeout);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // build asynchronously to keep `this.viewer` is accessible in `ready` event handler.
|
|
|
+ timeout = setTimeout(function () {
|
|
|
+ _this.delaying = false;
|
|
|
+ _this.build();
|
|
|
+ }, 0);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ this.initializing = {
|
|
|
+ abort: function abort() {
|
|
|
+ forEach(images, function (image) {
|
|
|
+ if (!image.complete) {
|
|
|
+ removeListener(image, EVENT_LOAD, progress);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ forEach(images, function (image) {
|
|
|
+ if (image.complete) {
|
|
|
+ progress();
|
|
|
+ } else {
|
|
|
+ addListener(image, EVENT_LOAD, progress, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ addListener(element, EVENT_CLICK, this.onStart = function (_ref) {
|
|
|
+ var target = _ref.target;
|
|
|
+
|
|
|
+ if (target.tagName.toLowerCase() === 'img') {
|
|
|
+ _this.view(_this.images.indexOf(target));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
- } else {
|
|
|
- addListener(element, EVENT_CLICK, this.onStart = function (_ref) {
|
|
|
- var target = _ref.target;
|
|
|
+ }, {
|
|
|
+ key: 'build',
|
|
|
+ value: function build() {
|
|
|
+ if (this.ready) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (target.tagName.toLowerCase() === 'img') {
|
|
|
- _this.view(_this.images.indexOf(target));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'build',
|
|
|
- value: function build() {
|
|
|
- if (this.ready) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ var element = this.element,
|
|
|
+ options = this.options;
|
|
|
|
|
|
- var element = this.element,
|
|
|
- options = this.options;
|
|
|
-
|
|
|
- var parent = element.parentNode;
|
|
|
- var template = document.createElement('div');
|
|
|
-
|
|
|
- template.innerHTML = TEMPLATE;
|
|
|
-
|
|
|
- var viewer = template.querySelector('.' + NAMESPACE + '-container');
|
|
|
- var title = viewer.querySelector('.' + NAMESPACE + '-title');
|
|
|
- var toolbar = viewer.querySelector('.' + NAMESPACE + '-toolbar');
|
|
|
- var navbar = viewer.querySelector('.' + NAMESPACE + '-navbar');
|
|
|
- var button = viewer.querySelector('.' + NAMESPACE + '-button');
|
|
|
- var canvas = viewer.querySelector('.' + NAMESPACE + '-canvas');
|
|
|
-
|
|
|
- this.parent = parent;
|
|
|
- this.viewer = viewer;
|
|
|
- this.title = title;
|
|
|
- this.toolbar = toolbar;
|
|
|
- this.navbar = navbar;
|
|
|
- this.button = button;
|
|
|
- this.canvas = canvas;
|
|
|
- this.footer = viewer.querySelector('.' + NAMESPACE + '-footer');
|
|
|
- this.tooltipBox = viewer.querySelector('.' + NAMESPACE + '-tooltip');
|
|
|
- this.player = viewer.querySelector('.' + NAMESPACE + '-player');
|
|
|
- this.list = viewer.querySelector('.' + NAMESPACE + '-list');
|
|
|
-
|
|
|
- addClass(title, !options.title ? CLASS_HIDE : getResponsiveClass(options.title));
|
|
|
- addClass(navbar, !options.navbar ? CLASS_HIDE : getResponsiveClass(options.navbar));
|
|
|
- toggleClass(button, CLASS_HIDE, !options.button);
|
|
|
-
|
|
|
- if (options.backdrop) {
|
|
|
- addClass(viewer, NAMESPACE + '-backdrop');
|
|
|
-
|
|
|
- if (!options.inline && options.backdrop === true) {
|
|
|
- setData(canvas, 'action', 'hide');
|
|
|
- }
|
|
|
- }
|
|
|
+ var parent = element.parentNode;
|
|
|
+ var template = document.createElement('div');
|
|
|
+
|
|
|
+ template.innerHTML = TEMPLATE;
|
|
|
|
|
|
- if (options.toolbar) {
|
|
|
- var list = document.createElement('ul');
|
|
|
- var custom = isPlainObject(options.toolbar);
|
|
|
- var zoomButtons = BUTTONS.slice(0, 3);
|
|
|
- var rotateButtons = BUTTONS.slice(7, 9);
|
|
|
- var scaleButtons = BUTTONS.slice(9);
|
|
|
+ var viewer = template.querySelector('.' + NAMESPACE + '-container');
|
|
|
+ var title = viewer.querySelector('.' + NAMESPACE + '-title');
|
|
|
+ var toolbar = viewer.querySelector('.' + NAMESPACE + '-toolbar');
|
|
|
+ var navbar = viewer.querySelector('.' + NAMESPACE + '-navbar');
|
|
|
+ var button = viewer.querySelector('.' + NAMESPACE + '-button');
|
|
|
+ var canvas = viewer.querySelector('.' + NAMESPACE + '-canvas');
|
|
|
|
|
|
- if (!custom) {
|
|
|
- addClass(toolbar, getResponsiveClass(options.toolbar));
|
|
|
- }
|
|
|
+ if ($(window).width()>700)
|
|
|
+ {
|
|
|
+ toolbar.style.display = "flex";
|
|
|
+ toolbar.style.justifyContent= "center";
|
|
|
+ }
|
|
|
+
|
|
|
+ this.parent = parent;
|
|
|
+ this.viewer = viewer;
|
|
|
+ this.title = title;
|
|
|
+ this.toolbar = toolbar;
|
|
|
+ this.navbar = navbar;
|
|
|
+ this.button = button;
|
|
|
+ this.canvas = canvas;
|
|
|
+ this.footer = viewer.querySelector('.' + NAMESPACE + '-footer');
|
|
|
+ this.tooltipBox = viewer.querySelector('.' + NAMESPACE + '-tooltip');
|
|
|
+ this.player = viewer.querySelector('.' + NAMESPACE + '-player');
|
|
|
+ this.list = viewer.querySelector('.' + NAMESPACE + '-list');
|
|
|
+
|
|
|
+
|
|
|
+ addClass(title, !options.title ? CLASS_HIDE : getResponsiveClass(options.title));
|
|
|
+ addClass(navbar, !options.navbar ? CLASS_HIDE : getResponsiveClass(options.navbar));
|
|
|
+ toggleClass(button, CLASS_HIDE, !options.button);
|
|
|
+
|
|
|
+ if (options.backdrop) {
|
|
|
+ addClass(viewer, NAMESPACE + '-backdrop');
|
|
|
+
|
|
|
+ if (!options.inline && options.backdrop === true) {
|
|
|
+ setData(canvas, 'action', 'hide');
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- forEach(custom ? options.toolbar : BUTTONS, function (value, index) {
|
|
|
- var deep = custom && isPlainObject(value);
|
|
|
- var name = custom ? hyphenate(index) : value;
|
|
|
- var show = deep && !isUndefined(value.show) ? value.show : value;
|
|
|
+ if (options.toolbar) {
|
|
|
+ var list = document.createElement('ul');
|
|
|
+ var custom = isPlainObject(options.toolbar);
|
|
|
+ var zoomButtons = BUTTONS.slice(0, 3);
|
|
|
+ var rotateButtons = BUTTONS.slice(7, 9);
|
|
|
+ var scaleButtons = BUTTONS.slice(9);
|
|
|
+
|
|
|
+ if (!custom) {
|
|
|
+ addClass(toolbar, getResponsiveClass(options.toolbar));
|
|
|
+ }
|
|
|
+
|
|
|
+ forEach(custom ? options.toolbar : BUTTONS, function (value, index) {
|
|
|
+ var deep = custom && isPlainObject(value);
|
|
|
+ var name = custom ? hyphenate(index) : value;
|
|
|
+ var show = deep && !isUndefined(value.show) ? value.show : value;
|
|
|
+
|
|
|
+ if (!show || !options.zoomable && zoomButtons.indexOf(name) !== -1 || !options.rotatable && rotateButtons.indexOf(name) !== -1 || !options.scalable && scaleButtons.indexOf(name) !== -1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var size = deep && !isUndefined(value.size) ? value.size : value;
|
|
|
+ var click = deep && !isUndefined(value.click) ? value.click : value;
|
|
|
+ var item = document.createElement('li');
|
|
|
+
|
|
|
+ item.setAttribute('role', 'button');
|
|
|
+ addClass(item, NAMESPACE + '-' + name);
|
|
|
+
|
|
|
+ if (!isFunction(click)) {
|
|
|
+ setData(item, 'action', name);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isNumber(show)) {
|
|
|
+ addClass(item, getResponsiveClass(show));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (['small', 'large'].indexOf(size) !== -1) {
|
|
|
+ addClass(item, NAMESPACE + '-' + size);
|
|
|
+ } else if (name === 'play') {
|
|
|
+ addClass(item, NAMESPACE + '-large');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isFunction(click)) {
|
|
|
+ addListener(item, EVENT_CLICK, click);
|
|
|
+ }
|
|
|
+
|
|
|
+ list.appendChild(item);
|
|
|
+ });
|
|
|
+
|
|
|
+ toolbar.appendChild(list);
|
|
|
+ } else {
|
|
|
+ addClass(toolbar, CLASS_HIDE);
|
|
|
+ }
|
|
|
|
|
|
- if (!show || !options.zoomable && zoomButtons.indexOf(name) !== -1 || !options.rotatable && rotateButtons.indexOf(name) !== -1 || !options.scalable && scaleButtons.indexOf(name) !== -1) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (!options.rotatable) {
|
|
|
+ var rotates = toolbar.querySelectorAll('li[class*="rotate"]');
|
|
|
|
|
|
- var size = deep && !isUndefined(value.size) ? value.size : value;
|
|
|
- var click = deep && !isUndefined(value.click) ? value.click : value;
|
|
|
- var item = document.createElement('li');
|
|
|
+ addClass(rotates, CLASS_INVISIBLE);
|
|
|
+ forEach(rotates, function (rotate) {
|
|
|
+ toolbar.appendChild(rotate);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- item.setAttribute('role', 'button');
|
|
|
- addClass(item, NAMESPACE + '-' + name);
|
|
|
+ if (options.inline) {
|
|
|
+ addClass(button, CLASS_FULLSCREEN);
|
|
|
+ setStyle(viewer, {
|
|
|
+ zIndex: options.zIndexInline
|
|
|
+ });
|
|
|
|
|
|
- if (!isFunction(click)) {
|
|
|
- setData(item, 'action', name);
|
|
|
- }
|
|
|
+ if (window.getComputedStyle(parent).position === 'static') {
|
|
|
+ setStyle(parent, {
|
|
|
+ position: 'relative'
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- if (isNumber(show)) {
|
|
|
- addClass(item, getResponsiveClass(show));
|
|
|
- }
|
|
|
+ parent.insertBefore(viewer, element.nextSibling);
|
|
|
+ } else {
|
|
|
+ addClass(button, CLASS_CLOSE);
|
|
|
+ addClass(viewer, CLASS_FIXED);
|
|
|
+ addClass(viewer, CLASS_FADE);
|
|
|
+ addClass(viewer, CLASS_HIDE);
|
|
|
|
|
|
- if (['small', 'large'].indexOf(size) !== -1) {
|
|
|
- addClass(item, NAMESPACE + '-' + size);
|
|
|
- } else if (name === 'play') {
|
|
|
- addClass(item, NAMESPACE + '-large');
|
|
|
- }
|
|
|
+ setStyle(viewer, {
|
|
|
+ zIndex: options.zIndex
|
|
|
+ });
|
|
|
|
|
|
- if (isFunction(click)) {
|
|
|
- addListener(item, EVENT_CLICK, click);
|
|
|
- }
|
|
|
+ var container = options.container;
|
|
|
|
|
|
- list.appendChild(item);
|
|
|
- });
|
|
|
|
|
|
- toolbar.appendChild(list);
|
|
|
- } else {
|
|
|
- addClass(toolbar, CLASS_HIDE);
|
|
|
- }
|
|
|
+ if (isString(container)) {
|
|
|
+ container = element.ownerDocument.querySelector(container);
|
|
|
+ }
|
|
|
|
|
|
- if (!options.rotatable) {
|
|
|
- var rotates = toolbar.querySelectorAll('li[class*="rotate"]');
|
|
|
+ if (!container) {
|
|
|
+ container = this.body;
|
|
|
+ }
|
|
|
|
|
|
- addClass(rotates, CLASS_INVISIBLE);
|
|
|
- forEach(rotates, function (rotate) {
|
|
|
- toolbar.appendChild(rotate);
|
|
|
- });
|
|
|
- }
|
|
|
+ container.appendChild(viewer);
|
|
|
+ }
|
|
|
|
|
|
- if (options.inline) {
|
|
|
- addClass(button, CLASS_FULLSCREEN);
|
|
|
- setStyle(viewer, {
|
|
|
- zIndex: options.zIndexInline
|
|
|
- });
|
|
|
+ if (options.inline) {
|
|
|
+ this.render();
|
|
|
+ this.bind();
|
|
|
+ this.isShown = true;
|
|
|
+ }
|
|
|
|
|
|
- if (window.getComputedStyle(parent).position === 'static') {
|
|
|
- setStyle(parent, {
|
|
|
- position: 'relative'
|
|
|
- });
|
|
|
- }
|
|
|
+ this.ready = true;
|
|
|
|
|
|
- parent.insertBefore(viewer, element.nextSibling);
|
|
|
- } else {
|
|
|
- addClass(button, CLASS_CLOSE);
|
|
|
- addClass(viewer, CLASS_FIXED);
|
|
|
- addClass(viewer, CLASS_FADE);
|
|
|
- addClass(viewer, CLASS_HIDE);
|
|
|
+ if (isFunction(options.ready)) {
|
|
|
+ addListener(element, EVENT_READY, options.ready, {
|
|
|
+ once: true
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- setStyle(viewer, {
|
|
|
- zIndex: options.zIndex
|
|
|
- });
|
|
|
+ if (dispatchEvent(element, EVENT_READY) === false) {
|
|
|
+ this.ready = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- var container = options.container;
|
|
|
+ if (this.ready && options.inline) {
|
|
|
+ this.view();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * Get the no conflict viewer class.
|
|
|
+ * @returns {Viewer} The viewer class.
|
|
|
+ */
|
|
|
|
|
|
- if (isString(container)) {
|
|
|
- container = element.ownerDocument.querySelector(container);
|
|
|
- }
|
|
|
+ }], [{
|
|
|
+ key: 'noConflict',
|
|
|
+ value: function noConflict() {
|
|
|
+ window.Viewer = AnotherViewer;
|
|
|
+ return Viewer;
|
|
|
+ }
|
|
|
|
|
|
- if (!container) {
|
|
|
- container = this.body;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * Change the default options.
|
|
|
+ * @param {Object} options - The new default options.
|
|
|
+ */
|
|
|
|
|
|
- container.appendChild(viewer);
|
|
|
- }
|
|
|
+ }, {
|
|
|
+ key: 'setDefaults',
|
|
|
+ value: function setDefaults(options) {
|
|
|
+ assign(DEFAULTS, isPlainObject(options) && options);
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+ return Viewer;
|
|
|
+ }();
|
|
|
|
|
|
- if (options.inline) {
|
|
|
- this.render();
|
|
|
- this.bind();
|
|
|
- this.isShown = true;
|
|
|
- }
|
|
|
+ assign(Viewer.prototype, render, events, handlers, methods, others);
|
|
|
|
|
|
- this.ready = true;
|
|
|
+ if ($.fn) {
|
|
|
+ var AnotherViewer$1 = $.fn.viewer;
|
|
|
+ var NAMESPACE$1 = 'viewer';
|
|
|
|
|
|
- if (isFunction(options.ready)) {
|
|
|
- addListener(element, EVENT_READY, options.ready, {
|
|
|
- once: true
|
|
|
- });
|
|
|
- }
|
|
|
+ $.fn.viewer = function jQueryViewer(option) {
|
|
|
+ for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
|
+ args[_key - 1] = arguments[_key];
|
|
|
+ }
|
|
|
|
|
|
- if (dispatchEvent(element, EVENT_READY) === false) {
|
|
|
- this.ready = false;
|
|
|
- return;
|
|
|
- }
|
|
|
+ var result = void 0;
|
|
|
|
|
|
- if (this.ready && options.inline) {
|
|
|
- this.view();
|
|
|
- }
|
|
|
- }
|
|
|
+ this.each(function (i, element) {
|
|
|
+ var $element = $(element);
|
|
|
+ var isDestroy = option === 'destroy';
|
|
|
+ var viewer = $element.data(NAMESPACE$1);
|
|
|
|
|
|
- /**
|
|
|
- * Get the no conflict viewer class.
|
|
|
- * @returns {Viewer} The viewer class.
|
|
|
- */
|
|
|
+ if (!viewer) {
|
|
|
+ if (isDestroy) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- }], [{
|
|
|
- key: 'noConflict',
|
|
|
- value: function noConflict() {
|
|
|
- window.Viewer = AnotherViewer;
|
|
|
- return Viewer;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Change the default options.
|
|
|
- * @param {Object} options - The new default options.
|
|
|
- */
|
|
|
-
|
|
|
- }, {
|
|
|
- key: 'setDefaults',
|
|
|
- value: function setDefaults(options) {
|
|
|
- assign(DEFAULTS, isPlainObject(options) && options);
|
|
|
- }
|
|
|
- }]);
|
|
|
- return Viewer;
|
|
|
- }();
|
|
|
-
|
|
|
- assign(Viewer.prototype, render, events, handlers, methods, others);
|
|
|
-
|
|
|
- if ($.fn) {
|
|
|
- var AnotherViewer$1 = $.fn.viewer;
|
|
|
- var NAMESPACE$1 = 'viewer';
|
|
|
-
|
|
|
- $.fn.viewer = function jQueryViewer(option) {
|
|
|
- for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
|
- args[_key - 1] = arguments[_key];
|
|
|
- }
|
|
|
-
|
|
|
- var result = void 0;
|
|
|
-
|
|
|
- this.each(function (i, element) {
|
|
|
- var $element = $(element);
|
|
|
- var isDestroy = option === 'destroy';
|
|
|
- var viewer = $element.data(NAMESPACE$1);
|
|
|
-
|
|
|
- if (!viewer) {
|
|
|
- if (isDestroy) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ var options = $.extend({}, $element.data(), $.isPlainObject(option) && option);
|
|
|
|
|
|
- var options = $.extend({}, $element.data(), $.isPlainObject(option) && option);
|
|
|
+ viewer = new Viewer(element, options);
|
|
|
+ $element.data(NAMESPACE$1, viewer);
|
|
|
+ }
|
|
|
|
|
|
- viewer = new Viewer(element, options);
|
|
|
- $element.data(NAMESPACE$1, viewer);
|
|
|
- }
|
|
|
+ if (typeof option === 'string') {
|
|
|
+ var fn = viewer[option];
|
|
|
|
|
|
- if (typeof option === 'string') {
|
|
|
- var fn = viewer[option];
|
|
|
+ if ($.isFunction(fn)) {
|
|
|
+ result = fn.apply(viewer, args);
|
|
|
|
|
|
- if ($.isFunction(fn)) {
|
|
|
- result = fn.apply(viewer, args);
|
|
|
+ if (result === viewer) {
|
|
|
+ result = undefined;
|
|
|
+ }
|
|
|
|
|
|
- if (result === viewer) {
|
|
|
- result = undefined;
|
|
|
- }
|
|
|
+ if (isDestroy) {
|
|
|
+ $element.removeData(NAMESPACE$1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- if (isDestroy) {
|
|
|
- $element.removeData(NAMESPACE$1);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ return result !== undefined ? result : this;
|
|
|
+ };
|
|
|
|
|
|
- return result !== undefined ? result : this;
|
|
|
- };
|
|
|
+ $.fn.viewer.Constructor = Viewer;
|
|
|
+ $.fn.viewer.setDefaults = Viewer.setDefaults;
|
|
|
+ $.fn.viewer.noConflict = function noConflict() {
|
|
|
+ $.fn.viewer = AnotherViewer$1;
|
|
|
+ return this;
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
- $.fn.viewer.Constructor = Viewer;
|
|
|
- $.fn.viewer.setDefaults = Viewer.setDefaults;
|
|
|
- $.fn.viewer.noConflict = function noConflict() {
|
|
|
- $.fn.viewer = AnotherViewer$1;
|
|
|
- return this;
|
|
|
- };
|
|
|
- }
|
|
|
|
|
|
})));
|