pinchzoom.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /*
  2. Copyright (c) Manuel Stofer 2013 - rtp.ch - RTP.PinchZoom.js
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. /*global jQuery, console, define, setTimeout, window*/
  20. (function () {
  21. 'use strict';
  22. var definePinchZoom = function ($) {
  23. /**
  24. * Pinch zoom using jQuery
  25. * @version 0.0.2
  26. * @author Manuel Stofer <mst@rtp.ch>
  27. * @param el
  28. * @param options
  29. * @constructor
  30. */
  31. var PinchZoom = function (el, options) {
  32. this.el = $(el);
  33. this.zoomFactor = 1;
  34. this.lastScale = 1;
  35. this.offset = {
  36. x: 0,
  37. y: 0
  38. };
  39. this.options = $.extend({}, this.defaults, options);
  40. this.setupMarkup();
  41. this.bindEvents();
  42. this.update();
  43. // default enable.
  44. this.enable();
  45. },
  46. sum = function (a, b) {
  47. return a + b;
  48. },
  49. isCloseTo = function (value, expected) {
  50. return value > expected - 0.01 && value < expected + 0.01;
  51. };
  52. PinchZoom.prototype = {
  53. defaults: {
  54. tapZoomFactor: 2,
  55. zoomOutFactor: 1.3,
  56. animationDuration: 300,
  57. maxZoom: 4,
  58. minZoom: 0.5,
  59. lockDragAxis: false,
  60. use2d: true,
  61. zoomStartEventName: 'pz_zoomstart',
  62. zoomEndEventName: 'pz_zoomend',
  63. dragStartEventName: 'pz_dragstart',
  64. dragEndEventName: 'pz_dragend',
  65. doubleTapEventName: 'pz_doubletap'
  66. },
  67. /**
  68. * Event handler for 'dragstart'
  69. * @param event
  70. */
  71. handleDragStart: function (event) {
  72. this.el.trigger(this.options.dragStartEventName);
  73. this.stopAnimation();
  74. this.lastDragPosition = false;
  75. this.hasInteraction = true;
  76. this.handleDrag(event);
  77. },
  78. /**
  79. * Event handler for 'drag'
  80. * @param event
  81. */
  82. handleDrag: function (event) {
  83. if (this.zoomFactor > 1.0) {
  84. var touch = this.getTouches(event)[0];
  85. this.drag(touch, this.lastDragPosition);
  86. this.offset = this.sanitizeOffset(this.offset);
  87. this.lastDragPosition = touch;
  88. }
  89. },
  90. handleDragEnd: function () {
  91. this.el.trigger(this.options.dragEndEventName);
  92. this.end();
  93. },
  94. /**
  95. * Event handler for 'zoomstart'
  96. * @param event
  97. */
  98. handleZoomStart: function (event) {
  99. this.el.trigger(this.options.zoomStartEventName);
  100. this.stopAnimation();
  101. this.lastScale = 1;
  102. this.nthZoom = 0;
  103. this.lastZoomCenter = false;
  104. this.hasInteraction = true;
  105. },
  106. /**
  107. * Event handler for 'zoom'
  108. * @param event
  109. */
  110. handleZoom: function (event, newScale) {
  111. // a relative scale factor is used
  112. var touchCenter = this.getTouchCenter(this.getTouches(event)),
  113. scale = newScale / this.lastScale;
  114. this.lastScale = newScale;
  115. // the first touch events are thrown away since they are not precise
  116. this.nthZoom += 1;
  117. if (this.nthZoom > 3) {
  118. this.scale(scale, touchCenter);
  119. this.drag(touchCenter, this.lastZoomCenter);
  120. }
  121. this.lastZoomCenter = touchCenter;
  122. },
  123. handleZoomEnd: function () {
  124. this.el.trigger(this.options.zoomEndEventName);
  125. this.end();
  126. },
  127. /**
  128. * Event handler for 'doubletap'
  129. * @param event
  130. */
  131. handleDoubleTap: function (event) {
  132. var center = this.getTouches(event)[0],
  133. zoomFactor = this.zoomFactor > 1 ? 1 : this.options.tapZoomFactor,
  134. startZoomFactor = this.zoomFactor,
  135. updateProgress = (function (progress) {
  136. this.scaleTo(startZoomFactor + progress * (zoomFactor - startZoomFactor), center);
  137. }).bind(this);
  138. if (this.hasInteraction) {
  139. return;
  140. }
  141. if (startZoomFactor > zoomFactor) {
  142. center = this.getCurrentZoomCenter();
  143. }
  144. this.animate(this.options.animationDuration, updateProgress, this.swing);
  145. this.el.trigger(this.options.doubleTapEventName);
  146. },
  147. /**
  148. * Max / min values for the offset
  149. * @param offset
  150. * @return {Object} the sanitized offset
  151. */
  152. sanitizeOffset: function (offset) {
  153. var maxX = (this.zoomFactor - 1) * this.getContainerX(),
  154. maxY = (this.zoomFactor - 1) * this.getContainerY(),
  155. maxOffsetX = Math.max(maxX, 0),
  156. maxOffsetY = Math.max(maxY, 0),
  157. minOffsetX = Math.min(maxX, 0),
  158. minOffsetY = Math.min(maxY, 0);
  159. return {
  160. x:/*Math.min(Math.max(offset.y, minOffsetY), maxOffsetY),*/ Math.min(Math.max(offset.x, minOffsetX), maxOffsetX),
  161. y:/*Math.min(Math.max(offset.x, minOffsetX), maxOffsetX)*/ Math.min(Math.max(offset.y, minOffsetY), maxOffsetY)
  162. };
  163. },
  164. /**
  165. * Scale to a specific zoom factor (not relative)
  166. * @param zoomFactor
  167. * @param center
  168. */
  169. scaleTo: function (zoomFactor, center) {
  170. this.scale(zoomFactor / this.zoomFactor, center);
  171. },
  172. /**
  173. * Scales the element from specified center
  174. * @param scale
  175. * @param center
  176. */
  177. scale: function (scale, center) {
  178. scale = this.scaleZoomFactor(scale);
  179. this.addOffset({
  180. x: (scale - 1) * (center.x + this.offset.x),
  181. y: (scale - 1) * (center.y + this.offset.y)
  182. });
  183. },
  184. /**
  185. * Scales the zoom factor relative to current state
  186. * @param scale
  187. * @return the actual scale (can differ because of max min zoom factor)
  188. */
  189. scaleZoomFactor: function (scale) {
  190. var originalZoomFactor = this.zoomFactor;
  191. this.zoomFactor *= scale;
  192. this.zoomFactor = Math.min(this.options.maxZoom, Math.max(this.zoomFactor, this.options.minZoom));
  193. return this.zoomFactor / originalZoomFactor;
  194. },
  195. /**
  196. * Drags the element
  197. * @param center
  198. * @param lastCenter
  199. */
  200. drag: function (center, lastCenter) {
  201. if (lastCenter) {
  202. if(this.options.lockDragAxis) {
  203. //alert(111)
  204. // lock scroll to position that was changed the most
  205. if(Math.abs(center.x - lastCenter.x) > Math.abs(center.y - lastCenter.y)) {
  206. this.addOffset({
  207. x: -(center.x - lastCenter.x),
  208. y: 0
  209. });
  210. }
  211. else {
  212. this.addOffset({
  213. y: -(center.y - lastCenter.y),
  214. x: 0
  215. });
  216. }
  217. }
  218. else {
  219. //alert(111)
  220. this.addOffset({
  221. y: (center.x - lastCenter.x),//-(center.y - lastCenter.y),
  222. x: -(center.y - lastCenter.y)//-(center.x - lastCenter.x)
  223. });
  224. }
  225. }
  226. },
  227. /**
  228. * Calculates the touch center of multiple touches
  229. * @param touches
  230. * @return {Object}
  231. */
  232. getTouchCenter: function (touches) {
  233. return this.getVectorAvg(touches);
  234. },
  235. /**
  236. * Calculates the average of multiple vectors (x, y values)
  237. */
  238. getVectorAvg: function (vectors) {
  239. return {
  240. x: vectors.map(function (v) { return v.x; }).reduce(sum) / vectors.length,
  241. y: vectors.map(function (v) { return v.y; }).reduce(sum) / vectors.length
  242. };
  243. },
  244. /**
  245. * Adds an offset
  246. * @param offset the offset to add
  247. * @return return true when the offset change was accepted
  248. */
  249. addOffset: function (offset) {
  250. this.offset = {
  251. x: this.offset.x + offset.x,
  252. y: this.offset.y + offset.y
  253. };
  254. },
  255. sanitize: function () {
  256. if (this.zoomFactor < this.options.zoomOutFactor) {
  257. this.zoomOutAnimation();
  258. } else if (this.isInsaneOffset(this.offset)) {
  259. this.sanitizeOffsetAnimation();
  260. }
  261. },
  262. /**
  263. * Checks if the offset is ok with the current zoom factor
  264. * @param offset
  265. * @return {Boolean}
  266. */
  267. isInsaneOffset: function (offset) {
  268. var sanitizedOffset = this.sanitizeOffset(offset);
  269. return sanitizedOffset.x !== offset.x ||
  270. sanitizedOffset.y !== offset.y;
  271. },
  272. /**
  273. * Creates an animation moving to a sane offset
  274. */
  275. sanitizeOffsetAnimation: function () {
  276. var targetOffset = this.sanitizeOffset(this.offset),
  277. startOffset = {
  278. x: this.offset.x,
  279. y: this.offset.y
  280. },
  281. updateProgress = (function (progress) {
  282. this.offset.x = startOffset.x + progress * (targetOffset.x - startOffset.x);
  283. this.offset.y = startOffset.y + progress * (targetOffset.y - startOffset.y);
  284. this.update();
  285. }).bind(this);
  286. this.animate(
  287. this.options.animationDuration,
  288. updateProgress,
  289. this.swing
  290. );
  291. },
  292. /**
  293. * Zooms back to the original position,
  294. * (no offset and zoom factor 1)
  295. */
  296. zoomOutAnimation: function () {
  297. var startZoomFactor = this.zoomFactor,
  298. zoomFactor = 1,
  299. center = this.getCurrentZoomCenter(),
  300. updateProgress = (function (progress) {
  301. this.scaleTo(startZoomFactor + progress * (zoomFactor - startZoomFactor), center);
  302. }).bind(this);
  303. this.animate(
  304. this.options.animationDuration,
  305. updateProgress,
  306. this.swing
  307. );
  308. },
  309. /**
  310. * Updates the aspect ratio
  311. */
  312. updateAspectRatio: function () {
  313. this.setContainerY(this.getContainerX() / this.getAspectRatio());
  314. },
  315. /**
  316. * Calculates the initial zoom factor (for the element to fit into the container)
  317. * @return the initial zoom factor
  318. */
  319. getInitialZoomFactor: function () {
  320. // use .offsetWidth instead of width()
  321. // because jQuery-width() return the original width but Zepto-width() will calculate width with transform.
  322. // the same as .height()
  323. return this.container[0].offsetWidth / this.el[0].offsetWidth;
  324. },
  325. /**
  326. * Calculates the aspect ratio of the element
  327. * @return the aspect ratio
  328. */
  329. getAspectRatio: function () {
  330. return this.el[0].offsetWidth / this.el[0].offsetHeight;
  331. },
  332. /**
  333. * Calculates the virtual zoom center for the current offset and zoom factor
  334. * (used for reverse zoom)
  335. * @return {Object} the current zoom center
  336. */
  337. getCurrentZoomCenter: function () {
  338. // uses following formula to calculate the zoom center x value
  339. // offset_left / offset_right = zoomcenter_x / (container_x - zoomcenter_x)
  340. var length = this.container[0].offsetWidth * this.zoomFactor,
  341. offsetLeft = this.offset.x,
  342. offsetRight = length - offsetLeft -this.container[0].offsetWidth,
  343. widthOffsetRatio = offsetLeft / offsetRight,
  344. centerX = widthOffsetRatio * this.container[0].offsetWidth / (widthOffsetRatio + 1),
  345. // the same for the zoomcenter y
  346. height = this.container[0].offsetHeight * this.zoomFactor,
  347. offsetTop = this.offset.y,
  348. offsetBottom = height - offsetTop - this.container[0].offsetHeight,
  349. heightOffsetRatio = offsetTop / offsetBottom,
  350. centerY = heightOffsetRatio * this.container[0].offsetHeight / (heightOffsetRatio + 1);
  351. // prevents division by zero
  352. if (offsetRight === 0) { centerX = this.container[0].offsetWidth; }
  353. if (offsetBottom === 0) { centerY = this.container[0].offsetHeight; }
  354. return {
  355. x: centerX,
  356. y: centerY
  357. };
  358. },
  359. canDrag: function () {
  360. return !isCloseTo(this.zoomFactor, 1);
  361. },
  362. /**
  363. * Returns the touches of an event relative to the container offset
  364. * @param event
  365. * @return array touches
  366. */
  367. getTouches: function (event) {
  368. var position = this.container.offset();
  369. return Array.prototype.slice.call(event.touches).map(function (touch) {
  370. return {
  371. x: touch.pageX - position.left,
  372. y: touch.pageY - position.top
  373. };
  374. });
  375. },
  376. /**
  377. * Animation loop
  378. * does not support simultaneous animations
  379. * @param duration
  380. * @param framefn
  381. * @param timefn
  382. * @param callback
  383. */
  384. animate: function (duration, framefn, timefn, callback) {
  385. var startTime = new Date().getTime(),
  386. renderFrame = (function () {
  387. if (!this.inAnimation) { return; }
  388. var frameTime = new Date().getTime() - startTime,
  389. progress = frameTime / duration;
  390. if (frameTime >= duration) {
  391. framefn(1);
  392. if (callback) {
  393. callback();
  394. }
  395. this.update();
  396. this.stopAnimation();
  397. this.update();
  398. } else {
  399. if (timefn) {
  400. progress = timefn(progress);
  401. }
  402. framefn(progress);
  403. this.update();
  404. requestAnimationFrame(renderFrame);
  405. }
  406. }).bind(this);
  407. this.inAnimation = true;
  408. requestAnimationFrame(renderFrame);
  409. },
  410. /**
  411. * Stops the animation
  412. */
  413. stopAnimation: function () {
  414. this.inAnimation = false;
  415. },
  416. /**
  417. * Swing timing function for animations
  418. * @param p
  419. * @return {Number}
  420. */
  421. swing: function (p) {
  422. return -Math.cos(p * Math.PI) / 2 + 0.5;
  423. },
  424. getContainerX: function () {
  425. return this.container[0].offsetWidth;
  426. },
  427. getContainerY: function () {
  428. return this.container[0].offsetHeight;
  429. },
  430. setContainerY: function (y) {
  431. return this.container.height(y);
  432. },
  433. /**
  434. * Creates the expected html structure
  435. */
  436. setupMarkup: function () {
  437. this.container = $('<div class="pinch-zoom-container"></div>');
  438. this.el.before(this.container);
  439. this.container.append(this.el);
  440. this.container.css({
  441. 'overflow': 'hidden',
  442. 'position': 'relative'
  443. });
  444. // Zepto doesn't recognize `webkitTransform..` style
  445. this.el.css({
  446. '-webkit-transform-origin': '0% 0%',
  447. '-moz-transform-origin': '0% 0%',
  448. '-ms-transform-origin': '0% 0%',
  449. '-o-transform-origin': '0% 0%',
  450. 'transform-origin': '0% 0%',
  451. 'position': 'absolute'
  452. });
  453. },
  454. end: function () {
  455. this.hasInteraction = false;
  456. this.sanitize();
  457. this.update();
  458. },
  459. /**
  460. * Binds all required event listeners
  461. */
  462. bindEvents: function () {
  463. detectGestures(this.container.get(0), this);
  464. // Zepto and jQuery both know about `on`
  465. $(window).on('resize', this.update.bind(this));
  466. $(this.el).find('img').on('load', this.update.bind(this));
  467. },
  468. /**
  469. * Updates the css values according to the current zoom factor and offset
  470. */
  471. update: function () {
  472. if (this.updatePlaned) {
  473. return;
  474. }
  475. this.updatePlaned = true;
  476. setTimeout((function () {
  477. this.updatePlaned = false;
  478. this.updateAspectRatio();
  479. var zoomFactor = this.getInitialZoomFactor() * this.zoomFactor,
  480. offsetX = -this.offset.x / zoomFactor,
  481. offsetY = -this.offset.y / zoomFactor,
  482. transform3d = 'scale3d(' + zoomFactor + ', ' + zoomFactor + ',1) ' +
  483. 'translate3d(' + offsetX + 'px,' + offsetY + 'px,0px)',
  484. transform2d = 'scale(' + zoomFactor + ', ' + zoomFactor + ') ' +
  485. 'translate(' + offsetX + 'px,' + offsetY + 'px)',
  486. removeClone = (function () {
  487. if (this.clone) {
  488. this.clone.remove();
  489. delete this.clone;
  490. }
  491. }).bind(this);
  492. // Scale 3d and translate3d are faster (at least on ios)
  493. // but they also reduce the quality.
  494. // PinchZoom uses the 3d transformations during interactions
  495. // after interactions it falls back to 2d transformations
  496. if (!this.options.use2d || this.hasInteraction || this.inAnimation) {
  497. this.is3d = true;
  498. removeClone();
  499. this.el.css({
  500. '-webkit-transform': transform3d,
  501. '-o-transform': transform2d,
  502. '-ms-transform': transform2d,
  503. '-moz-transform': transform2d,
  504. 'transform': transform3d
  505. });
  506. } else {
  507. // When changing from 3d to 2d transform webkit has some glitches.
  508. // To avoid this, a copy of the 3d transformed element is displayed in the
  509. // foreground while the element is converted from 3d to 2d transform
  510. if (this.is3d) {
  511. this.clone = this.el.clone();
  512. this.clone.css('pointer-events', 'none');
  513. this.clone.appendTo(this.container);
  514. setTimeout(removeClone, 200);
  515. }
  516. this.el.css({
  517. '-webkit-transform': transform2d,
  518. '-o-transform': transform2d,
  519. '-ms-transform': transform2d,
  520. '-moz-transform': transform2d,
  521. 'transform': transform2d
  522. });
  523. this.is3d = false;
  524. }
  525. }).bind(this), 0);
  526. },
  527. /**
  528. * Enables event handling for gestures
  529. */
  530. enable: function() {
  531. this.enabled = true;
  532. },
  533. /**
  534. * Disables event handling for gestures
  535. */
  536. disable: function() {
  537. this.enabled = false;
  538. }
  539. };
  540. var detectGestures = function (el, target) {
  541. var interaction = null,
  542. fingers = 0,
  543. lastTouchStart = null,
  544. startTouches = null,
  545. setInteraction = function (newInteraction, event) {
  546. if (interaction !== newInteraction) {
  547. if (interaction && !newInteraction) {
  548. switch (interaction) {
  549. case "zoom":
  550. target.handleZoomEnd(event);
  551. break;
  552. case 'drag':
  553. target.handleDragEnd(event);
  554. break;
  555. }
  556. }
  557. switch (newInteraction) {
  558. case 'zoom':
  559. target.handleZoomStart(event);
  560. break;
  561. case 'drag':
  562. target.handleDragStart(event);
  563. break;
  564. }
  565. }
  566. interaction = newInteraction;
  567. },
  568. updateInteraction = function (event) {
  569. if (fingers === 2) {
  570. setInteraction('zoom');
  571. } else if (fingers === 1 && target.canDrag()) {
  572. setInteraction('drag', event);
  573. } else {
  574. setInteraction(null, event);
  575. }
  576. },
  577. targetTouches = function (touches) {
  578. return Array.prototype.slice.call(touches).map(function (touch) {
  579. return {
  580. x: touch.pageX,
  581. y: touch.pageY
  582. };
  583. });
  584. },
  585. getDistance = function (a, b) {
  586. var x, y;
  587. x = a.x - b.x;
  588. y = a.y - b.y;
  589. return Math.sqrt(x * x + y * y);
  590. },
  591. calculateScale = function (startTouches, endTouches) {
  592. var startDistance = getDistance(startTouches[0], startTouches[1]),
  593. endDistance = getDistance(endTouches[0], endTouches[1]);
  594. return endDistance / startDistance;
  595. },
  596. cancelEvent = function (event) {
  597. event.stopPropagation();
  598. event.preventDefault();
  599. },
  600. detectDoubleTap = function (event) {
  601. var time = (new Date()).getTime();
  602. if (fingers > 1) {
  603. lastTouchStart = null;
  604. }
  605. if (time - lastTouchStart < 300) {
  606. cancelEvent(event);
  607. target.handleDoubleTap(event);
  608. switch (interaction) {
  609. case "zoom":
  610. target.handleZoomEnd(event);
  611. break;
  612. case 'drag':
  613. target.handleDragEnd(event);
  614. break;
  615. }
  616. }
  617. if (fingers === 1) {
  618. lastTouchStart = time;
  619. }
  620. },
  621. firstMove = true;
  622. el.addEventListener('touchstart', function (event) {
  623. if(target.enabled) {
  624. firstMove = true;
  625. fingers = event.touches.length;
  626. detectDoubleTap(event);
  627. }
  628. });
  629. el.addEventListener('touchmove', function (event) {
  630. if(target.enabled) {
  631. if (firstMove) {
  632. updateInteraction(event);
  633. if (interaction) {
  634. cancelEvent(event);
  635. }
  636. startTouches = targetTouches(event.touches);
  637. } else {
  638. switch (interaction) {
  639. case 'zoom':
  640. target.handleZoom(event, calculateScale(startTouches, targetTouches(event.touches)));
  641. break;
  642. case 'drag':
  643. target.handleDrag(event);
  644. break;
  645. }
  646. if (interaction) {
  647. cancelEvent(event);
  648. target.update();
  649. }
  650. }
  651. firstMove = false;
  652. }
  653. });
  654. el.addEventListener('touchend', function (event) {
  655. if(target.enabled) {
  656. fingers = event.touches.length;
  657. updateInteraction(event);
  658. }
  659. });
  660. };
  661. return PinchZoom;
  662. };
  663. if (typeof define !== 'undefined' && define.amd) {
  664. define(['jquery'], function ($) {
  665. return definePinchZoom($);
  666. });
  667. } else {
  668. window.RTP = window.RTP || {};
  669. window.RTP.PinchZoom = definePinchZoom(window.$);
  670. }
  671. }).call(this);