Fix JQMIGRATE warnings in jQuery Mobile

jQuery Mobile 1.5 is supposed to be compatible with jQuery 3, but it isn't...

* Replace .bind() calls with .on()
* Replace .unbind() calls with .off()

Bug: T165816
Change-Id: I79639fd9ae8e6e785f93191273147866e52c4ed1
isekai
Bartosz Dziewoński 8 years ago
parent fc5b4be51c
commit f11212f7bd

@ -1,3 +1,7 @@
// Custom hacks:
// * Replaced .bind() calls with .on() for compatibility with jQuery 3
// * Replaced .unbind() calls with .off() for compatibility with jQuery 3
/* /*
* jQuery Mobile v1.4.5 * jQuery Mobile v1.4.5
* http://jquerymobile.com * http://jquerymobile.com
@ -366,14 +370,14 @@ function getSpecialEventObject( eventType ) {
activeDocHandlers[ eventType ] = ( activeDocHandlers[ eventType ] || 0 ) + 1; activeDocHandlers[ eventType ] = ( activeDocHandlers[ eventType ] || 0 ) + 1;
if ( activeDocHandlers[ eventType ] === 1 ) { if ( activeDocHandlers[ eventType ] === 1 ) {
$document.bind( realType, mouseEventCallback ); $document.on( realType, mouseEventCallback );
} }
// Some browsers, like Opera Mini, won't dispatch mouse/click events // Some browsers, like Opera Mini, won't dispatch mouse/click events
// for elements unless they actually have handlers registered on them. // for elements unless they actually have handlers registered on them.
// To get around this, we register dummy handlers on the elements. // To get around this, we register dummy handlers on the elements.
$( this ).bind( realType, dummyMouseHandler ); $( this ).on( realType, dummyMouseHandler );
// For now, if event capture is not supported, we rely on mouse handlers. // For now, if event capture is not supported, we rely on mouse handlers.
if ( eventCaptureSupported ) { if ( eventCaptureSupported ) {
@ -383,8 +387,8 @@ function getSpecialEventObject( eventType ) {
activeDocHandlers[ "touchstart" ] = ( activeDocHandlers[ "touchstart" ] || 0) + 1; activeDocHandlers[ "touchstart" ] = ( activeDocHandlers[ "touchstart" ] || 0) + 1;
if ( activeDocHandlers[ "touchstart" ] === 1 ) { if ( activeDocHandlers[ "touchstart" ] === 1 ) {
$document.bind( "touchstart", handleTouchStart ) $document.on( "touchstart", handleTouchStart )
.bind( "touchend", handleTouchEnd ) .on( "touchend", handleTouchEnd )
// On touch platforms, touching the screen and then dragging your finger // On touch platforms, touching the screen and then dragging your finger
// causes the window content to scroll after some distance threshold is // causes the window content to scroll after some distance threshold is
@ -396,8 +400,8 @@ function getSpecialEventObject( eventType ) {
// we need to watch both scroll and touchmove events to figure out whether // we need to watch both scroll and touchmove events to figure out whether
// or not a scroll happenens before the touchend event is fired. // or not a scroll happenens before the touchend event is fired.
.bind( "touchmove", handleTouchMove ) .on( "touchmove", handleTouchMove )
.bind( "scroll", handleScroll ); .on( "scroll", handleScroll );
} }
} }
}, },
@ -409,7 +413,7 @@ function getSpecialEventObject( eventType ) {
--activeDocHandlers[ eventType ]; --activeDocHandlers[ eventType ];
if ( !activeDocHandlers[ eventType ] ) { if ( !activeDocHandlers[ eventType ] ) {
$document.unbind( realType, mouseEventCallback ); $document.off( realType, mouseEventCallback );
} }
if ( eventCaptureSupported ) { if ( eventCaptureSupported ) {
@ -419,10 +423,10 @@ function getSpecialEventObject( eventType ) {
--activeDocHandlers[ "touchstart" ]; --activeDocHandlers[ "touchstart" ];
if ( !activeDocHandlers[ "touchstart" ] ) { if ( !activeDocHandlers[ "touchstart" ] ) {
$document.unbind( "touchstart", handleTouchStart ) $document.off( "touchstart", handleTouchStart )
.unbind( "touchmove", handleTouchMove ) .off( "touchmove", handleTouchMove )
.unbind( "touchend", handleTouchEnd ) .off( "touchend", handleTouchEnd )
.unbind( "scroll", handleScroll ); .off( "scroll", handleScroll );
} }
} }
@ -440,7 +444,7 @@ function getSpecialEventObject( eventType ) {
// Unregister the dummy event handler. // Unregister the dummy event handler.
$this.unbind( realType, dummyMouseHandler ); $this.off( realType, dummyMouseHandler );
// If this is the last virtual mouse binding on the // If this is the last virtual mouse binding on the
// element, remove the binding data from the element. // element, remove the binding data from the element.
@ -552,7 +556,7 @@ if ( eventCaptureSupported ) {
"scrollstart scrollstop" ).split( " " ), function( i, name ) { "scrollstart scrollstop" ).split( " " ), function( i, name ) {
$.fn[ name ] = function( fn ) { $.fn[ name ] = function( fn ) {
return fn ? this.bind( name, fn ) : this.trigger( name ); return fn ? this.on( name, fn ) : this.trigger( name );
}; };
// jQuery < 1.8 // jQuery < 1.8
@ -589,7 +593,7 @@ if ( eventCaptureSupported ) {
} }
// iPhone triggers scroll after a small delay; use touchmove instead // iPhone triggers scroll after a small delay; use touchmove instead
$this.bind( scrollEvent, function( event ) { $this.on( scrollEvent, function( event ) {
if ( !$.event.special.scrollstart.enabled ) { if ( !$.event.special.scrollstart.enabled ) {
return; return;
@ -606,7 +610,7 @@ if ( eventCaptureSupported ) {
}); });
}, },
teardown: function() { teardown: function() {
$( this ).unbind( scrollEvent ); $( this ).off( scrollEvent );
} }
}; };
@ -619,7 +623,7 @@ if ( eventCaptureSupported ) {
$this = $( thisObject ), $this = $( thisObject ),
isTaphold = false; isTaphold = false;
$this.bind( "vmousedown", function( event ) { $this.on( "vmousedown", function( event ) {
isTaphold = false; isTaphold = false;
if ( event.which && event.which !== 1 ) { if ( event.which && event.which !== 1 ) {
return false; return false;
@ -635,9 +639,9 @@ if ( eventCaptureSupported ) {
function clearTapHandlers() { function clearTapHandlers() {
clearTapTimer(); clearTapTimer();
$this.unbind( "vclick", clickHandler ) $this.off( "vclick", clickHandler )
.unbind( "vmouseup", clearTapTimer ); .off( "vmouseup", clearTapTimer );
$document.unbind( "vmousecancel", clearTapHandlers ); $document.off( "vmousecancel", clearTapHandlers );
} }
function clickHandler( event ) { function clickHandler( event ) {
@ -652,9 +656,9 @@ if ( eventCaptureSupported ) {
} }
} }
$this.bind( "vmouseup", clearTapTimer ) $this.on( "vmouseup", clearTapTimer )
.bind( "vclick", clickHandler ); .on( "vclick", clickHandler );
$document.bind( "vmousecancel", clearTapHandlers ); $document.on( "vmousecancel", clearTapHandlers );
timer = setTimeout( function() { timer = setTimeout( function() {
if ( !$.event.special.tap.emitTapOnTaphold ) { if ( !$.event.special.tap.emitTapOnTaphold ) {
@ -665,8 +669,8 @@ if ( eventCaptureSupported ) {
}); });
}, },
teardown: function() { teardown: function() {
$( this ).unbind( "vmousedown" ).unbind( "vclick" ).unbind( "vmouseup" ); $( this ).off( "vmousedown" ).off( "vclick" ).off( "vmouseup" );
$document.unbind( "vmousecancel" ); $document.off( "vmousecancel" );
} }
}; };
@ -850,10 +854,10 @@ if ( eventCaptureSupported ) {
$.event.special[ event ] = { $.event.special[ event ] = {
setup: function() { setup: function() {
$( this ).bind( sourceEvent, $.noop ); $( this ).on( sourceEvent, $.noop );
}, },
teardown: function() { teardown: function() {
$( this ).unbind( sourceEvent ); $( this ).off( sourceEvent );
} }
}; };
}); });

Loading…
Cancel
Save