; (function(g, fn) { var version = "", pdfjsversion = ""; 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 = ' ' + '