Permalink
Browse files

Events: Separate out scroll and make transitions depend on scroll alone

Fixes gh-7805
Closes gh-7889
  • Loading branch information...
gabrielschulhof committed Dec 19, 2014
1 parent e9e3b56 commit 31cc90ddc8c051cb01db46e270478c12be9685bb
View
@@ -3,6 +3,11 @@
//>>label: Events
//>>group: Events
define( [ "jquery", "./events/navigate", "./events/touch", "./events/orientationchange" ], function() {
define( [
"jquery",
"./events/navigate",
"./events/touch",
"./events/scroll",
"./events/orientationchange" ], function() {
});
//>>excludeEnd("jqmBuildExclude");
View
@@ -0,0 +1,85 @@
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Scroll events including: scrollstart, scrollstop
//>>label: Scroll
//>>group: Events
define( [ "jquery" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, window, undefined ) {
var scrollEvent = "touchmove scroll";
// setup new event shortcuts
$.each( [ "scrollstart", "scrollstop" ], function( i, name ) {
$.fn[ name ] = function( fn ) {
return fn ? this.bind( name, fn ) : this.trigger( name );
};
// jQuery < 1.8
if ( $.attrFn ) {
$.attrFn[ name ] = true;
}
});
// also handles scrollstop
$.event.special.scrollstart = {
enabled: true,
setup: function() {
var thisObject = this,
$this = $( thisObject ),
scrolling,
timer;
function trigger( event, state ) {
var originalEventType = event.type;
scrolling = state;
event.type = scrolling ? "scrollstart" : "scrollstop";
$.event.dispatch.call( thisObject, event );
event.type = originalEventType;
}
// iPhone triggers scroll after a small delay; use touchmove instead
$this.bind( scrollEvent, function( event ) {
if ( !$.event.special.scrollstart.enabled ) {
return;
}
if ( !scrolling ) {
trigger( event, true );
}
clearTimeout( timer );
timer = setTimeout( function() {
trigger( event, false );
}, 50 );
});
},
teardown: function() {
$( this ).unbind( scrollEvent );
}
};
$.each({
scrollstop: "scrollstart"
}, function( event, sourceEvent ) {
$.event.special[ event ] = {
setup: function() {
$( this ).bind( sourceEvent, $.noop );
},
teardown: function() {
$( this ).unbind( sourceEvent );
}
};
});
})( jQuery, this );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");
View
@@ -1,5 +1,5 @@
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Touch events including: touchstart, touchmove, touchend, tap, taphold, swipe, swipeleft, swiperight, scrollstart, scrollstop
//>>description: Touch events including: touchstart, touchmove, touchend, tap, taphold, swipe, swipeleft, swiperight
//>>label: Touch
//>>group: Events
@@ -9,16 +9,14 @@ define( [ "jquery", "../vmouse", "../support/touch" ], function( jQuery ) {
(function( $, window, undefined ) {
var $document = $( document ),
supportTouch = $.mobile.support.touch,
scrollEvent = "touchmove scroll",
touchStartEvent = supportTouch ? "touchstart" : "mousedown",
touchStopEvent = supportTouch ? "touchend" : "mouseup",
touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
// setup new event shortcuts
$.each( ( "touchstart touchmove touchend " +
"tap taphold " +
"swipe swipeleft swiperight " +
"scrollstart scrollstop" ).split( " " ), function( i, name ) {
"swipe swipeleft swiperight" ).split( " " ), function( i, name ) {
$.fn[ name ] = function( fn ) {
return fn ? this.bind( name, fn ) : this.trigger( name );
@@ -41,44 +39,6 @@ define( [ "jquery", "../vmouse", "../support/touch" ], function( jQuery ) {
event.type = originalType;
}
// also handles scrollstop
$.event.special.scrollstart = {
enabled: true,
setup: function() {
var thisObject = this,
$this = $( thisObject ),
scrolling,
timer;
function trigger( event, state ) {
scrolling = state;
triggerCustomEvent( thisObject, scrolling ? "scrollstart" : "scrollstop", event );
}
// iPhone triggers scroll after a small delay; use touchmove instead
$this.bind( scrollEvent, function( event ) {
if ( !$.event.special.scrollstart.enabled ) {
return;
}
if ( !scrolling ) {
trigger( event, true );
}
clearTimeout( timer );
timer = setTimeout( function() {
trigger( event, false );
}, 50 );
});
},
teardown: function() {
$( this ).unbind( scrollEvent );
}
};
// also handles taphold
$.event.special.tap = {
tapholdThreshold: 750,
@@ -311,7 +271,6 @@ define( [ "jquery", "../vmouse", "../support/touch" ], function( jQuery ) {
}
};
$.each({
scrollstop: "scrollstart",
taphold: "tap",
swipeleft: "swipe.left",
swiperight: "swipe.right"
View
@@ -15,6 +15,7 @@
'support.js',
'vmouse.js',
'events/touch.js',
'events/scroll.js',
'events/throttledresize.js',
'events/orientationchange.js',
'../external/jquery-ui/jquery.ui.core.js',
View
@@ -10,7 +10,6 @@ define( [
"./navigation/history",
"./navigation/navigator",
"./navigation/method",
"./events",
"./support",
"./animationComplete",
"./widgets/pagecontainer",
@@ -5,15 +5,16 @@
//>>css.structure: ../css/structure/jquery.mobile.transition.css, ../css/structure/jquery.mobile.transition.fade.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
define( [ "jquery",
"../core",
define( [
"jquery",
"../core",
// TODO event.special.scrollstart
"../events/touch",
"../animationComplete",
// TODO event.special.scrollstart
"../events/scroll",
"../animationComplete",
// TODO $.mobile.focusPage reference
"../navigation" ], function( jQuery ) {
// TODO $.mobile.focusPage reference
"../navigation" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, window, undefined ) {
@@ -11,7 +11,7 @@ define( [
"../navigation/history",
"../navigation/navigator",
"../navigation/method",
"../events",
"../events/scroll",
"../support",
"../widgets/page",
"../transitions/handlers" ], function( jQuery ) {
@@ -4,7 +4,8 @@
(function($){
var libName = "jquery.mobile.events.js",
components = [ "events/touch.js", "events/throttledresize.js", "events/orientationchange.js" ],
components = [ "events/touch.js", "events/throttledresize.js", "events/scroll.js",
"events/orientationchange.js" ],
absFn = Math.abs,
originalPageContainer = $.mobile.pageContainer,
originalEventFn = $.Event.prototype.originalEvent,
@@ -18,6 +18,7 @@
<script src="../../../js/events.js"></script>
<script src="../../../js/vmouse.js"></script>
<script src="../../../js/events/touch.js"></script>
<script src="../../../js/events/scroll.js"></script>
<script src="../../../js/events/throttledresize.js"></script>
<script src="../../../js/events/orientationchange.js"></script>

0 comments on commit 31cc90d

Please sign in to comment.