; (function(g, fn) { var version = "1.3.18", pdfjsVersion = "2.3.200"; console.log("pdfh5.js v" + version + " https://www.gjtool.cn") if (typeof require !== 'undefined') { if (g.$ === undefined) { g.$ = require('./jquery-1.11.3.min.js'); } g.pdfjsWorker = require('./pdf.worker.js'); g.pdfjsLib = require('./pdf.js'); } var pdfjsLib = g.pdfjsLib, $ = g.$, pdfjsWorker = g.pdfjsWorker; if (typeof define === 'function' && define.amd) { define(function() { return fn(g, pdfjsWorker, pdfjsLib, $, version) }) } else if (typeof module !== 'undefined' && module.exports) { module.exports = fn(g, pdfjsWorker, pdfjsLib, $, version) } else { g.Pdfh5 = fn(g, pdfjsWorker, pdfjsLib, $, version) } })(typeof window !== 'undefined' ? window : this, function(g, pdfjsWorker, pdfjsLib, $, version) { 'use strict'; 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); } } return function(Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var renderTextLayer = pdfjsLib.renderTextLayer; var EXPAND_DIVS_TIMEOUT = 300; // ms var TextLayerBuilder = function() { function TextLayerBuilder(_ref) { var textLayerDiv = _ref.textLayerDiv; var eventBus = _ref.eventBus; var pageIndex = _ref.pageIndex; var viewport = _ref.viewport; var _ref$findController = _ref.findController; var findController = _ref$findController === undefined ? null : _ref$findController; var _ref$enhanceTextSelec = _ref.enhanceTextSelection; var enhanceTextSelection = _ref$enhanceTextSelec === undefined ? false : _ref$enhanceTextSelec; _classCallCheck(this, TextLayerBuilder); this.textLayerDiv = textLayerDiv; this.eventBus = eventBus; this.textContent = null; this.textContentItemsStr = []; this.textContentStream = null; this.renderingDone = false; this.pageIdx = pageIndex; this.pageNumber = this.pageIdx + 1; this.matches = []; this.viewport = viewport; this.textDivs = []; this.findController = findController; this.textLayerRenderTask = null; this.enhanceTextSelection = enhanceTextSelection; this._onUpdateTextLayerMatches = null; this._bindMouse(); } /** * @private */ _createClass(TextLayerBuilder, [{ key: "_finishRendering", value: function _finishRendering() { this.renderingDone = true; if (!this.enhanceTextSelection) { var endOfContent = document.createElement("div"); endOfContent.className = "endOfContent"; this.textLayerDiv.appendChild(endOfContent); } if (this.eventBus) { this.eventBus.dispatch("textlayerrendered", { source: this, pageNumber: this.pageNumber, numTextDivs: this.textDivs.length }); } } /** * Renders the text layer. * * @param {number} [timeout] - Wait for a specified amount of milliseconds * before rendering. */ }, { key: "render", value: function render() { var _this = this; var timeout = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; if (!(this.textContent || this.textContentStream) || this.renderingDone) { return; } this.cancel(); this.textDivs = []; var textLayerFrag = document.createDocumentFragment(); this.textLayerRenderTask = renderTextLayer({ textContent: this.textContent, textContentStream: this.textContentStream, container: textLayerFrag, viewport: this.viewport, textDivs: this.textDivs, textContentItemsStr: this.textContentItemsStr, timeout: timeout, enhanceTextSelection: this.enhanceTextSelection }); this.textLayerRenderTask.promise.then(function() { _this.textLayerDiv.appendChild(textLayerFrag); _this._finishRendering(); _this._updateMatches(); }, function(reason) { // Cancelled or failed to render text layer; skipping errors. }); if (!this._onUpdateTextLayerMatches) { this._onUpdateTextLayerMatches = function(evt) { if (evt.pageIndex === _this.pageIdx || evt.pageIndex === -1) { _this._updateMatches(); } }; if (this.eventBus) { this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches); } } } /** * Cancel rendering of the text layer. */ }, { key: "cancel", value: function cancel() { if (this.textLayerRenderTask) { this.textLayerRenderTask.cancel(); this.textLayerRenderTask = null; } if (this._onUpdateTextLayerMatches) { this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches); this._onUpdateTextLayerMatches = null; } } }, { key: "setTextContentStream", value: function setTextContentStream(readableStream) { this.cancel(); this.textContentStream = readableStream; } }, { key: "setTextContent", value: function setTextContent(textContent) { this.cancel(); this.textContent = textContent; } }, { key: "_convertMatches", value: function _convertMatches(matches, matchesLength) { // Early exit if there is nothing to convert. if (!matches) { return []; } var findController = this.findController; var textContentItemsStr = this.textContentItemsStr; var i = 0, iIndex = 0; var end = textContentItemsStr.length - 1; var queryLen = findController.state.query.length; var result = []; for (var m = 0, mm = matches.length; m < mm; m++) { // Calculate the start position. var matchIdx = matches[m]; // Loop over the divIdxs. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) { iIndex += textContentItemsStr[i].length; i++; } if (i === textContentItemsStr.length) { console.error("Could not find a matching mapping"); } var match = { begin: { divIdx: i, offset: matchIdx - iIndex } }; // Calculate the end position. if (matchesLength) { // Multiterm search. matchIdx += matchesLength[m]; } else { // Phrase search. matchIdx += queryLen; } // Somewhat the same array as above, but use > instead of >= to get // the end position right. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) { iIndex += textContentItemsStr[i].length; i++; } match.end = { divIdx: i, offset: matchIdx - iIndex }; result.push(match); } return result; } }, { key: "_renderMatches", value: function _renderMatches(matches) { // Early exit if there is nothing to render. if (matches.length === 0) { return; } var findController = this.findController; var pageIdx = this.pageIdx; var textContentItemsStr = this.textContentItemsStr; var textDivs = this.textDivs; var isSelectedPage = pageIdx === findController.selected.pageIdx; var selectedMatchIdx = findController.selected.matchIdx; var highlightAll = findController.state.highlightAll; var prevEnd = null; var infinity = { divIdx: -1, offset: undefined }; function beginText(begin, className) { var divIdx = begin.divIdx; textDivs[divIdx].textContent = ""; appendTextToDiv(divIdx, 0, begin.offset, className); } function appendTextToDiv(divIdx, fromOffset, toOffset, className) { var div = textDivs[divIdx]; var content = textContentItemsStr[divIdx].substring(fromOffset, toOffset); var node = document.createTextNode(content); if (className) { var span = document.createElement("span"); span.className = className; span.appendChild(node); div.appendChild(span); return; } div.appendChild(node); } var i0 = selectedMatchIdx, i1 = i0 + 1; if (highlightAll) { i0 = 0; i1 = matches.length; } else if (!isSelectedPage) { // Not highlighting all and this isn't the selected page, so do nothing. return; } for (var i = i0; i < i1; i++) { var match = matches[i]; var begin = match.begin; var end = match.end; var isSelected = isSelectedPage && i === selectedMatchIdx; var highlightSuffix = isSelected ? " selected" : ""; if (isSelected) { // Attempt to scroll the selected match into view. findController.scrollMatchIntoView({ element: textDivs[begin.divIdx], pageIndex: pageIdx, matchIndex: selectedMatchIdx }); } // Match inside new div. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) { // If there was a previous div, then add the text at the end. if (prevEnd !== null) { appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset); } // Clear the divs and set the content until the starting point. beginText(begin); } else { appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset); } if (begin.divIdx === end.divIdx) { appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix); } else { appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix); for (var n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) { textDivs[n0].className = "highlight middle" + highlightSuffix; } beginText(end, "highlight end" + highlightSuffix); } prevEnd = end; } if (prevEnd) { appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset); } } }, { key: "_updateMatches", value: function _updateMatches() { // Only show matches when all rendering is done. if (!this.renderingDone) { return; } var findController = this.findController; var matches = this.matches; var pageIdx = this.pageIdx; var textContentItemsStr = this.textContentItemsStr; var textDivs = this.textDivs; var clearedUntilDivIdx = -1; // Clear all current matches. for (var i = 0, ii = matches.length; i < ii; i++) { var match = matches[i]; var begin = Math.max(clearedUntilDivIdx, match.begin.divIdx); for (var n = begin, end = match.end.divIdx; n <= end; n++) { var div = textDivs[n]; div.textContent = textContentItemsStr[n]; div.className = ""; } clearedUntilDivIdx = match.end.divIdx + 1; } if (!findController || !findController.highlightMatches) { return; } // Convert the matches on the `findController` into the match format // used for the textLayer. var pageMatches = findController.pageMatches[pageIdx] || null; var pageMatchesLength = findController.pageMatchesLength[pageIdx] || null; this.matches = this._convertMatches(pageMatches, pageMatchesLength); this._renderMatches(this.matches); } /** * Improves text selection by adding an additional div where the mouse was * clicked. This reduces flickering of the content if the mouse is slowly * dragged up or down. * * @private */ }, { key: "_bindMouse", value: function _bindMouse() { var _this2 = this; var div = this.textLayerDiv; var expandDivsTimer = null; div.addEventListener("mousedown", function(evt) { if (_this2.enhanceTextSelection && _this2.textLayerRenderTask) { _this2.textLayerRenderTask.expandTextDivs(true); if ((typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) && expandDivsTimer) { clearTimeout(expandDivsTimer); expandDivsTimer = null; } return; } var end = div.querySelector(".endOfContent"); if (!end) { return; } if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { // On non-Firefox browsers, the selection will feel better if the height // of the `endOfContent` div is adjusted to start at mouse click // location. This avoids flickering when the selection moves up. // However it does not work when selection is started on empty space. var adjustTop = evt.target !== div; if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none"; } if (adjustTop) { var divBounds = div.getBoundingClientRect(); var r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height); end.style.top = (r * 100).toFixed(2) + "%"; } } end.classList.add("active"); }); div.addEventListener("mouseup", function() { if (_this2.enhanceTextSelection && _this2.textLayerRenderTask) { if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { expandDivsTimer = setTimeout(function() { if (_this2.textLayerRenderTask) { _this2.textLayerRenderTask.expandTextDivs(false); } expandDivsTimer = null; }, EXPAND_DIVS_TIMEOUT); } else { _this2.textLayerRenderTask.expandTextDivs(false); } return; } var end = div.querySelector(".endOfContent"); if (!end) { return; } if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { end.style.top = ""; } end.classList.remove("active"); }); } }]); return TextLayerBuilder; }(); /** * @implements IPDFTextLayerFactory */ var DefaultTextLayerFactory = function() { function DefaultTextLayerFactory() { _classCallCheck(this, DefaultTextLayerFactory); } _createClass(DefaultTextLayerFactory, [{ key: "createTextLayerBuilder", /** * @param {HTMLDivElement} textLayerDiv * @param {number} pageIndex * @param {PageViewport} viewport * @param {boolean} enhanceTextSelection * @param {EventBus} eventBus * @returns {TextLayerBuilder} */ value: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) { var enhanceTextSelection = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3]; var eventBus = arguments[4]; return new TextLayerBuilder({ textLayerDiv: textLayerDiv, pageIndex: pageIndex, viewport: viewport, enhanceTextSelection: enhanceTextSelection, eventBus: eventBus }); } }]); return DefaultTextLayerFactory; }(); g.TextLayerBuilder = TextLayerBuilder; g.DefaultTextLayerFactory = DefaultTextLayerFactory; var definePinchZoom = function($) { var PinchZoom = function(el, options, viewerContainer) { this.el = $(el); this.viewerContainer = viewerContainer; this.zoomFactor = 1; this.lastScale = 1; this.offset = { x: 0, y: 0 }; this.options = $.extend({}, this.defaults, options); this.options.zoomOutFactor = isNaN(options.zoomOutFactor) ? 1.2 : options.zoomOutFactor; this.options.animationDuration = isNaN(options.animationDuration) ? 300 : options.animationDuration; this.options.maxZoom = isNaN(options.maxZoom) ? 3 : options.maxZoom; this.options.minZoom = isNaN(options.minZoom) ? 0.8 : options.minZoom; this.setupMarkup(); this.bindEvents(); this.update(); this.enable(); this.height = 0; this.load = false; this.direction = null; this.clientY = null; this.lastclientY = null; }, sum = function(a, b) { return a + b; }, isCloseTo = function(value, expected) { return value > expected - 0.01 && value < expected + 0.01; }; PinchZoom.prototype = { defaults: { tapZoomFactor: 3, zoomOutFactor: 1.2, animationDuration: 300, maxZoom: 5, minZoom: 0.8, lockDragAxis: false, use2d: true, zoomStartEventName: 'pz_zoomstart', zoomEndEventName: 'pz_zoomend', dragStartEventName: 'pz_dragstart', dragEndEventName: 'pz_dragend', doubleTapEventName: 'pz_doubletap' }, handleDragStart: function(event) { this.el.trigger(this.options.dragStartEventName); this.stopAnimation(); this.lastDragPosition = false; this.hasInteraction = true; this.handleDrag(event); }, handleDrag: function(event) { if (this.zoomFactor > 1.0) { var touch = this.getTouches(event)[0]; this.drag(touch, this.lastDragPosition, event); this.offset = this.sanitizeOffset(this.offset); this.lastDragPosition = touch; } }, handleDragEnd: function() { this.el.trigger(this.options.dragEndEventName); this.end(); }, handleZoomStart: function(event) { this.el.trigger(this.options.zoomStartEventName); this.stopAnimation(); this.lastScale = 1; this.nthZoom = 0; this.lastZoomCenter = false; this.hasInteraction = true; }, handleZoom: function(event, newScale) { var touchCenter = this.getTouchCenter(this.getTouches(event)), scale = newScale / this.lastScale; this.lastScale = newScale; this.nthZoom += 1; if (this.nthZoom > 3) { this.scale(scale, touchCenter); this.drag(touchCenter, this.lastZoomCenter); } this.lastZoomCenter = touchCenter; }, handleZoomEnd: function() { this.el.trigger(this.options.zoomEndEventName); this.end(); }, handleDoubleTap: function(event) { var center = this.getTouches(event)[0], zoomFactor = this.zoomFactor > 1 ? 1 : this.options.tapZoomFactor, startZoomFactor = this.zoomFactor, updateProgress = (function(progress) { this.scaleTo(startZoomFactor + progress * (zoomFactor - startZoomFactor), center); }).bind(this); if (this.hasInteraction) { return; } if (startZoomFactor > zoomFactor) { center = this.getCurrentZoomCenter(); } this.animate(this.options.animationDuration, updateProgress, this.swing); this.el.trigger(this.options.doubleTapEventName); }, sanitizeOffset: function(offset) { var maxX = (this.zoomFactor - 1) * this.getContainerX(), maxY = (this.zoomFactor - 1) * this.getContainerY(), maxOffsetX = Math.max(maxX, 0), maxOffsetY = Math.max(maxY, 0), minOffsetX = Math.min(maxX, 0), minOffsetY = Math.min(maxY, 0); var x = Math.min(Math.max(offset.x, minOffsetX), maxOffsetX), y = Math.min(Math.max(offset.y, minOffsetY), maxOffsetY); return { x: x, y: y }; }, scaleTo: function(zoomFactor, center) { this.scale(zoomFactor / this.zoomFactor, center); }, scale: function(scale, center) { scale = this.scaleZoomFactor(scale); this.addOffset({ x: (scale - 1) * (center.x + this.offset.x), y: (scale - 1) * (center.y + this.offset.y) }); this.done && this.done.call(this, this.getInitialZoomFactor() * this.zoomFactor) }, scaleZoomFactor: function(scale) { var originalZoomFactor = this.zoomFactor; this.zoomFactor *= scale; this.zoomFactor = Math.min(this.options.maxZoom, Math.max(this.zoomFactor, this.options.minZoom)); return this.zoomFactor / originalZoomFactor; }, drag: function(center, lastCenter, event) { if (lastCenter) { if (this.options.lockDragAxis) { if (Math.abs(center.x - lastCenter.x) > Math.abs(center.y - lastCenter.y)) { this.addOffset({ x: -(center.x - lastCenter.x), y: 0 }); } else { this.addOffset({ y: -(center.y - lastCenter.y), x: 0 }); } } else { if (center.y - lastCenter.y < 0) { this.direction = "down"; } else if (center.y - lastCenter.y > 10) { this.direction = "up"; } this.addOffset({ y: -(center.y - lastCenter.y), x: -(center.x - lastCenter.x) }); } } }, getTouchCenter: function(touches) { return this.getVectorAvg(touches); }, getVectorAvg: function(vectors) { return { x: vectors.map(function(v) { return v.x; }).reduce(sum) / vectors.length, y: vectors.map(function(v) { return v.y; }).reduce(sum) / vectors.length }; }, addOffset: function(offset) { this.offset = { x: this.offset.x + offset.x, y: this.offset.y + offset.y }; }, sanitize: function() { if (this.zoomFactor < this.options.zoomOutFactor) { this.zoomOutAnimation(); } else if (this.isInsaneOffset(this.offset)) { this.sanitizeOffsetAnimation(); } }, isInsaneOffset: function(offset) { var sanitizedOffset = this.sanitizeOffset(offset); return sanitizedOffset.x !== offset.x || sanitizedOffset.y !== offset.y; }, sanitizeOffsetAnimation: function() { var targetOffset = this.sanitizeOffset(this.offset), startOffset = { x: this.offset.x, y: this.offset.y }, updateProgress = (function(progress) { this.offset.x = startOffset.x + progress * (targetOffset.x - startOffset.x); this.offset.y = startOffset.y + progress * (targetOffset.y - startOffset.y); this.update(); }).bind(this); this.animate( this.options.animationDuration, updateProgress, this.swing ); }, zoomOutAnimation: function() { var startZoomFactor = this.zoomFactor, zoomFactor = 1, center = this.getCurrentZoomCenter(), updateProgress = (function(progress) { this.scaleTo(startZoomFactor + progress * (zoomFactor - startZoomFactor), center); }).bind(this); this.animate( this.options.animationDuration, updateProgress, this.swing ); }, updateAspectRatio: function() { this.setContainerY(this.getContainerX() / this.getAspectRatio()); }, getInitialZoomFactor: function() { if (this.container[0] && this.el[0]) { return this.container[0].offsetWidth / this.el[0].offsetWidth; } else { return 0 } }, getAspectRatio: function() { if (this.el[0]) { var offsetHeight = this.el[0].offsetHeight; return this.container[0].offsetWidth / offsetHeight; } else { return 0 } }, getCurrentZoomCenter: function() { var length = this.container[0].offsetWidth * this.zoomFactor, offsetLeft = this.offset.x, offsetRight = length - offsetLeft - this.container[0].offsetWidth, widthOffsetRatio = offsetLeft / offsetRight, centerX = widthOffsetRatio * this.container[0].offsetWidth / (widthOffsetRatio + 1), height = this.container[0].offsetHeight * this.zoomFactor, offsetTop = this.offset.y, offsetBottom = height - offsetTop - this.container[0].offsetHeight, heightOffsetRatio = offsetTop / offsetBottom, centerY = heightOffsetRatio * this.container[0].offsetHeight / (heightOffsetRatio + 1); if (offsetRight === 0) { centerX = this.container[0].offsetWidth; } if (offsetBottom === 0) { centerY = this.container[0].offsetHeight; } return { x: centerX, y: centerY }; }, canDrag: function() { return !isCloseTo(this.zoomFactor, 1); }, getTouches: function(event) { var position = this.container.offset(); return Array.prototype.slice.call(event.touches).map(function(touch) { return { x: touch.pageX - position.left, y: touch.pageY - position.top }; }); }, animate: function(duration, framefn, timefn, callback) { var startTime = new Date().getTime(), renderFrame = (function() { if (!this.inAnimation) { return; } var frameTime = new Date().getTime() - startTime, progress = frameTime / duration; if (frameTime >= duration) { framefn(1); if (callback) { callback(); } this.update(); this.stopAnimation(); } else { if (timefn) { progress = timefn(progress); } framefn(progress); this.update(); requestAnimationFrame(renderFrame); } }).bind(this); this.inAnimation = true; requestAnimationFrame(renderFrame); }, stopAnimation: function() { this.inAnimation = false; }, swing: function(p) { return -Math.cos(p * Math.PI) / 2 + 0.5; }, getContainerX: function() { if (this.el[0]) { return this.el[0].offsetWidth; } else { return 0; } }, getContainerY: function() { return this.el[0].offsetHeight; }, setContainerY: function(y) { y = y.toFixed(2); return this.container.height(y); }, setupMarkup: function() { this.container = $('
'); this.el.before(this.container); this.container.append(this.el); this.container.css({ 'position': 'relative', }); this.el.css({ '-webkit-transform-origin': '0% 0%', '-moz-transform-origin': '0% 0%', '-ms-transform-origin': '0% 0%', '-o-transform-origin': '0% 0%', 'transform-origin': '0% 0%', 'position': 'relative' }); }, end: function() { this.hasInteraction = false; this.sanitize(); this.update(); }, bindEvents: function() { detectGestures(this.container.eq(0), this, this.viewerContainer); $(g).on('resize', this.update.bind(this)); $(this.el).find('img').on('load', this.update.bind(this)); }, update: function() { if (this.updatePlaned) { return; } this.updatePlaned = true; setTimeout((function() { this.updatePlaned = false; this.updateAspectRatio(); var zoomFactor = this.getInitialZoomFactor() * this.zoomFactor, offsetX = (-this.offset.x / zoomFactor).toFixed(3), offsetY = (-this.offset.y / zoomFactor).toFixed(3); this.lastclientY = offsetY; var transform3d = 'scale3d(' + zoomFactor + ', ' + zoomFactor + ',1) ' + 'translate3d(' + offsetX + 'px,' + offsetY + 'px,0px)', transform2d = 'scale(' + zoomFactor + ', ' + zoomFactor + ') ' + 'translate(' + offsetX + 'px,' + offsetY + 'px)', removeClone = (function() { if (this.clone) { this.clone.remove(); delete this.clone; } }).bind(this); if (!this.options.use2d || this.hasInteraction || this.inAnimation) { this.is3d = true; this.el.css({ '-webkit-transform': transform3d, '-o-transform': transform2d, '-ms-transform': transform2d, '-moz-transform': transform2d, 'transform': transform3d }); } else { this.el.css({ '-webkit-transform': transform2d, '-o-transform': transform2d, '-ms-transform': transform2d, '-moz-transform': transform2d, 'transform': transform2d }); this.is3d = false; } }).bind(this), 0); }, enable: function() { this.enabled = true; }, disable: function() { this.enabled = false; }, destroy: function() { var dom = this.el.clone(); var p = this.container.parent(); this.container.remove(); dom.removeAttr('style'); p.append(dom); } }; var detectGestures = function(el, target, viewerContainer) { var interaction = null, fingers = 0, lastTouchStart = null, startTouches = null, lastTouchY = null, clientY = null, lastclientY = 0, lastTop = 0, setInteraction = function(newInteraction, event) { if (interaction !== newInteraction) { if (interaction && !newInteraction) { switch (interaction) { case "zoom": target.handleZoomEnd(event); break; case 'drag': target.handleDragEnd(event); break; } } switch (newInteraction) { case 'zoom': target.handleZoomStart(event); break; case 'drag': target.handleDragStart(event); break; } } interaction = newInteraction; }, updateInteraction = function(event) { if (fingers === 2) { setInteraction('zoom'); } else if (fingers === 1 && target.canDrag()) { setInteraction('drag', event); } else { setInteraction(null, event); } }, targetTouches = function(touches) { return Array.prototype.slice.call(touches).map(function(touch) { return { x: touch.pageX, y: touch.pageY }; }); }, getDistance = function(a, b) { var x, y; x = a.x - b.x; y = a.y - b.y; return Math.sqrt(x * x + y * y); }, calculateScale = function(startTouches, endTouches) { var startDistance = getDistance(startTouches[0], startTouches[1]), endDistance = getDistance(endTouches[0], endTouches[1]); return endDistance / startDistance; }, cancelEvent = function(event) { event.stopPropagation(); event.preventDefault(); }, detectDoubleTap = function(event) { var time = (new Date()).getTime(); var pageY = event.changedTouches[0].pageY; var top = parentNode.scrollTop || 0; if (fingers > 1) { lastTouchStart = null; lastTouchY = null; cancelEvent(event); } if (time - lastTouchStart < 300 && Math.abs(pageY - lastTouchY) < 10 && Math.abs(lastTop - top) < 10) { cancelEvent(event); target.handleDoubleTap(event); switch (interaction) { case "zoom": target.handleZoomEnd(event); break; case 'drag': target.handleDragEnd(event); break; } } if (fingers === 1) { lastTouchStart = time; lastTouchY = pageY; lastTop = top; } }, firstMove = true; if (viewerContainer) { var parentNode = viewerContainer[0]; } if (parentNode) { parentNode.addEventListener('touchstart', function(event) { if (target.enabled) { firstMove = true; fingers = event.touches.length; detectDoubleTap(event); clientY = event.changedTouches[0].clientY; if (fingers > 1) { cancelEvent(event); } } }); parentNode.addEventListener('touchmove', function(event) { if (target.enabled) { lastclientY = event.changedTouches[0].clientY; if (firstMove) { updateInteraction(event); startTouches = targetTouches(event.touches); } else { switch (interaction) { case 'zoom': target.handleZoom(event, calculateScale(startTouches, targetTouches(event.touches))); break; case 'drag': target.handleDrag(event); break; } if (interaction) { target.update(lastclientY); } } if (fingers > 1) { cancelEvent(event); } firstMove = false; } }); parentNode.addEventListener('touchend', function(event) { if (target.enabled) { fingers = event.touches.length; if (fingers > 1) { cancelEvent(event); } updateInteraction(event); } }); } }; return PinchZoom; }; var PinchZoom = definePinchZoom($); var Pdfh5 = function(dom, options) { this.version = version; this.container = $(dom); this.options = options; this.thePDF = null; this.totalNum = null; this.pages = null; this.initTime = 0; this.scale = 1.5; this.currentNum = 1; this.loadedCount = 0; this.endTime = 0; this.pinchZoom = null; this.timer = null; this.docWidth = document.documentElement.clientWidth; this.winWidth = $(window).width(); this.cache = {}; this.eventType = {}; this.cacheNum = 1; this.resizeEvent = false; this.cacheData = null; this.pdfjsLibPromise = null; this.init(options); }; Pdfh5.prototype = { init: function(options) { var self = this; if (this.container[0].pdfLoaded) { this.destroy(); } if (options.cMapUrl) { pdfjsLib.cMapUrl = options.cMapUrl; } else { pdfjsLib.cMapUrl = 'https://unpkg.com/pdfjs-dist@2.0.943/cmaps/'; } pdfjsLib.cMapPacked = true; pdfjsLib.rangeChunkSize = 65536; this.container[0].pdfLoaded = false; this.container.addClass("pdfjs") this.initTime = new Date().getTime(); setTimeout(function() { var arr1 = self.eventType["scroll"]; if (arr1 && arr1 instanceof Array) { for (var i = 0; i < arr1.length; i++) { arr1[i] && arr1[i].call(self, self.initTime) } } }, 0) this.options = this.options ? this.options : {}; this.options.pdfurl = this.options.pdfurl ? this.options.pdfurl : null; this.options.data = this.options.data ? this.options.data : null; this.options.scale = this.options.scale ? this.options.scale : this.scale; this.options.zoomEnable = this.options.zoomEnable === false ? false : true; this.options.scrollEnable = this.options.scrollEnable === false ? false : true; this.options.loadingBar = this.options.loadingBar === false ? false : true; this.options.pageNum = this.options.pageNum === false ? false : true; this.options.backTop = this.options.backTop === false ? false : true; this.options.URIenable = this.options.URIenable === true ? true : false; this.options.fullscreen = this.options.fullscreen === false ? false : true; this.options.lazy = this.options.lazy === true ? true : false; this.options.renderType = this.options.renderType === "svg" ? "svg" : "canvas"; this.options.resize = this.options.resize === false ? false : true; this.options.textLayer = this.options.textLayer === true ? true : false; this.options.goto = isNaN(this.options.goto) ? 0 : this.options.goto; if (this.options.logo && Object.prototype.toString.call(this.options.logo) === '[object Object]' && this.options.logo .src) { this.options.logo.img = new Image(); this.options.logo.img.src = this.options.logo.src; this.options.logo.img.style.display = "none"; document.body.appendChild(this.options.logo.img) } else { this.options.logo = false; } if(!(this.options.background && (this.options.background.color || this.options.background.image))){ this.options.background = false } if (this.options.limit) { var n = parseFloat(this.options.limit) this.options.limit = isNaN(n) ? 0 : n < 0 ? 0 : n; } else { this.options.limit = 0 } this.options.type = this.options.type === "fetch" ? "fetch" : "ajax"; var html = '