- Timestamp:
- 07/20/2015 03:56:19 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/imgareaselect/jquery.imgareaselect.js
r25545 r33329 1 1 /* 2 2 * imgAreaSelect jQuery plugin 3 * version 0.9.10 3 * version 0.9.10-monkey 4 4 * 5 5 * Copyright (c) 2008-2013 Michal Wojciechowski (odyniec.net) … … 190 190 */ 191 191 function evX(event) { 192 return event.pageX- parOfs.left;192 return max(event.pageX || 0, touchCoords(event).x) - parOfs.left; 193 193 } 194 194 … … 201 201 */ 202 202 function evY(event) { 203 return event.pageY - parOfs.top; 203 return max(event.pageY || 0, touchCoords(event).y) - parOfs.top; 204 } 205 206 /** 207 * Get X and Y coordinates of a touch event 208 * 209 * @param event 210 * The event object 211 * @return Coordinates object 212 */ 213 function touchCoords(event) { 214 var oev = event.originalEvent || {}; 215 216 if (oev.touches && oev.touches.length) 217 return { x: oev.touches[0].pageX, y: oev.touches[0].pageY }; 218 else 219 return { x: 0, y: 0 }; 204 220 } 205 221 … … 487 503 hide($box.add($outer), function () { $(this).hide(); }); 488 504 489 $(document). unbind('mousemove', selectingMouseMove);490 $box. mousemove(areaMouseMove);505 $(document).off('mousemove touchmove', selectingMouseMove); 506 $box.on('mousemove touchmove', areaMouseMove); 491 507 492 508 options.onSelectEnd(img, getSelection()); … … 501 517 */ 502 518 function areaMouseDown(event) { 503 if (event.which != 1) return false; 519 if (event.type == 'mousedown' && event.which != 1) return false; 520 521 /* 522 * With mobile browsers, there is no "moving the pointer over" action, 523 * so we need to simulate one mousemove event happening prior to 524 * mousedown/touchstart. 525 */ 526 areaMouseMove(event); 504 527 505 528 adjust(); … … 512 535 y1 = viewY(selection[/n/.test(resize) ? 'y2' : 'y1']); 513 536 514 $(document). mousemove(selectingMouseMove)515 .one('mouseup ', docMouseUp);516 $box. unbind('mousemove', areaMouseMove);537 $(document).on('mousemove touchmove', selectingMouseMove) 538 .one('mouseup touchend', docMouseUp); 539 $box.off('mousemove touchmove', areaMouseMove); 517 540 } 518 541 else if (options.movable) { … … 520 543 startY = top + selection.y1 - evY(event); 521 544 522 $box. unbind('mousemove', areaMouseMove);523 524 $(document). mousemove(movingMouseMove)525 .one('mouseup ', function () {545 $box.off('mousemove touchmove', areaMouseMove); 546 547 $(document).on('mousemove touchmove', movingMouseMove) 548 .one('mouseup touchend', function () { 526 549 options.onSelectEnd(img, getSelection()); 527 550 528 $(document). unbind('mousemove', movingMouseMove);529 $box. mousemove(areaMouseMove);551 $(document).off('mousemove touchmove', movingMouseMove); 552 $box.on('mousemove touchmove', areaMouseMove); 530 553 }); 531 554 } … … 677 700 */ 678 701 function startSelection() { 679 $(document). unbind('mousemove', startSelection);702 $(document).off('mousemove touchmove', startSelection); 680 703 adjust(); 681 704 … … 692 715 shown = true; 693 716 694 $(document).unbind('mouseup', cancelSelection) 695 .mousemove(selectingMouseMove).one('mouseup', docMouseUp); 696 $box.unbind('mousemove', areaMouseMove); 717 $(document).off('mouseup touchend', cancelSelection) 718 .on('mousemove touchmove', selectingMouseMove) 719 .one('mouseup touchend', docMouseUp); 720 $box.off('mousemove touchmove', areaMouseMove); 697 721 698 722 options.onSelectStart(img, getSelection()); … … 703 727 */ 704 728 function cancelSelection() { 705 $(document). unbind('mousemove', startSelection)706 . unbind('mouseup', cancelSelection);729 $(document).off('mousemove touchmove', startSelection) 730 .off('mouseup touchend', cancelSelection); 707 731 hide($box.add($outer)); 708 732 … … 732 756 733 757 /* Selection will start when the mouse is moved */ 734 $(document).mousemove(startSelection).mouseup(cancelSelection); 758 $(document).on({ 'mousemove touchmove': startSelection, 759 'mouseup touchend': cancelSelection }); 735 760 736 761 return false; … … 990 1015 if (options.disable || options.enable === false) { 991 1016 /* Disable the plugin */ 992 $box.unbind('mousemove', areaMouseMove).unbind('mousedown', areaMouseDown); 993 $(window).unbind('resize', windowResize); 1017 $box.off({ 'mousemove touchmove': areaMouseMove, 1018 'mousedown touchstart': areaMouseDown }); 1019 $(window).off('resize', windowResize); 994 1020 } 995 1021 else { … … 997 1023 /* Enable the plugin */ 998 1024 if (options.resizable || options.movable) 999 $box.mousemove(areaMouseMove).mousedown(areaMouseDown); 1025 $box.on({ 'mousemove touchmove': areaMouseMove, 1026 'mousedown touchstart': areaMouseDown }); 1000 1027 1001 1028 $(window).resize(windowResize); … … 1003 1030 1004 1031 if (!options.persistent) 1005 $img.add($outer). mousedown(imgMouseDown);1032 $img.add($outer).on('mousedown touchstart', imgMouseDown); 1006 1033 } 1007 1034
Note: See TracChangeset
for help on using the changeset viewer.