| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
ve.init.mw.ViewportZoomHandler = function VeInitMwViewportZoomHandler() { |
| 32 |
|
| 33 |
this.$viewportMeta = $( 'meta[name="viewport"]' ); |
| 34 |
if ( !this.$viewportMeta.length ) { |
| 35 |
this.$viewportMeta = $( '<meta>' ).attr( 'name', 'viewport' ).appendTo( document.head ); |
| 36 |
} |
| 37 |
this.origViewportMetaContent = this.$viewportMeta.attr( 'content' ); |
| 38 |
|
| 39 |
this.onTouchStartHandler = this.onTouchStart.bind( this ); |
| 40 |
this.onTouchMoveHandler = this.onTouchMove.bind( this ); |
| 41 |
this.onTouchEndHandler = this.onTouchEnd.bind( this ); |
| 42 |
}; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
ve.init.mw.ViewportZoomHandler.prototype.preventZoom = function () { |
| 50 |
this.$viewportMeta.attr( 'content', ( i, val ) => { |
| 51 |
|
| 52 |
if ( val ) { |
| 53 |
val = val.replace( /maximum-scale=[\d.]+(,\s*|$)/, '' ); |
| 54 |
val += ', '; |
| 55 |
} else { |
| 56 |
val = ''; |
| 57 |
} |
| 58 |
return val + 'maximum-scale=1.0'; |
| 59 |
} ); |
| 60 |
}; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
ve.init.mw.ViewportZoomHandler.prototype.allowZoom = function () { |
| 66 |
this.$viewportMeta.attr( 'content', this.origViewportMetaContent ); |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
ve.init.mw.ViewportZoomHandler.prototype.attach = function ( surface ) { |
| 75 |
this.surface = surface; |
| 76 |
|
| 77 |
this.surface.getView().$element.on( { |
| 78 |
touchstart: this.onTouchStartHandler, |
| 79 |
touchmove: this.onTouchMoveHandler, |
| 80 |
touchend: this.onTouchEndHandler |
| 81 |
} ); |
| 82 |
this.surface.getModel().connect( this, { |
| 83 |
focus: 'onFocus' |
| 84 |
} ); |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
ve.init.mw.ViewportZoomHandler.prototype.detach = function () { |
| 91 |
this.surface.getView().$element.off( { |
| 92 |
touchstart: this.onTouchStartHandler, |
| 93 |
touchmove: this.onTouchMoveHandler, |
| 94 |
touchend: this.onTouchEndHandler |
| 95 |
} ); |
| 96 |
this.surface.getModel().disconnect( this, { |
| 97 |
focus: 'onFocus' |
| 98 |
} ); |
| 99 |
|
| 100 |
this.surface = null; |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
ve.init.mw.ViewportZoomHandler.prototype.onTouchStart = function ( e ) { |
| 109 |
if ( e.touches.length === 1 ) { |
| 110 |
this.wasMoved = false; |
| 111 |
} |
| 112 |
|
| 113 |
this.allowZoom(); |
| 114 |
}; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
ve.init.mw.ViewportZoomHandler.prototype.onTouchMove = function () { |
| 122 |
this.wasMoved = true; |
| 123 |
}; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
ve.init.mw.ViewportZoomHandler.prototype.onTouchEnd = function ( e ) { |
| 131 |
if ( e.touches.length === 0 && !this.wasMoved ) { |
| 132 |
|
| 133 |
|
| 134 |
this.preventZoom(); |
| 135 |
} else { |
| 136 |
|
| 137 |
this.allowZoom(); |
| 138 |
} |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
ve.init.mw.ViewportZoomHandler.prototype.onFocus = function () { |
| 145 |
this.allowZoom(); |
| 146 |
}; |