Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
"$( document )" and "$( window )" functions are repeatly called 73 times
Browse files Browse the repository at this point in the history
  • Loading branch information
Changsuk committed Dec 28, 2012
1 parent e5e50d2 commit 893fe10
Show file tree
Hide file tree
Showing 37 changed files with 79 additions and 75 deletions.
2 changes: 1 addition & 1 deletion js/events/navigate.js
Expand Up @@ -8,7 +8,7 @@ define([ "jquery", "./../jquery.mobile.support" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");

(function( $, undefined ) {
var $win = $( window ), self, history;
var $win = $.mobile.$window, self, history;

$.event.special.navigate = self = {
bound: false,
Expand Down
8 changes: 4 additions & 4 deletions js/events/orientationchange.js
Expand Up @@ -7,7 +7,7 @@ define( [ "jquery", "../jquery.mobile.support.orientation", "./throttledresize"
//>>excludeEnd("jqmBuildExclude");

(function( $, window ) {
var win = $( window ),
var win = $.mobile.$window,
event_name = "orientationchange",
special_event,
get_orientation,
Expand Down Expand Up @@ -44,8 +44,8 @@ define( [ "jquery", "../jquery.mobile.support.orientation", "./throttledresize"
// developer console. The actual threshold value is somewhat arbitrary, we just
// need to make sure it is large enough to exclude the developer console case.

var ww = window.innerWidth || $( window ).width(),
wh = window.innerHeight || $( window ).height(),
var ww = window.innerWidth || $.mobile.$window.width(),
wh = window.innerHeight || $.mobile.$window.height(),
landscape_threshold = 50;

initial_orientation_is_landscape = ww > wh && ( ww - wh ) > landscape_threshold;
Expand Down Expand Up @@ -151,4 +151,4 @@ define( [ "jquery", "../jquery.mobile.support.orientation", "./throttledresize"

//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");
//>>excludeEnd("jqmBuildExclude");
4 changes: 2 additions & 2 deletions js/events/touch.js
Expand Up @@ -99,7 +99,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"

$this.unbind( "vclick", clickHandler )
.unbind( "vmouseup", clearTapTimer );
$( document ).unbind( "vmousecancel", clearTapHandlers );
$.mobile.$document.unbind( "vmousecancel", clearTapHandlers );
}

function clickHandler( event ) {
Expand All @@ -114,7 +114,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"

$this.bind( "vmouseup", clearTapTimer )
.bind( "vclick", clickHandler );
$( document ).bind( "vmousecancel", clearTapHandlers );
$.mobile.$document.bind( "vmousecancel", clearTapHandlers );

timer = setTimeout( function() {
triggerCustomEvent( thisObject, "taphold", $.Event( "taphold", { target: origTarget } ) );
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.mobile.buttonMarkup.js
Expand Up @@ -212,7 +212,7 @@ function updateButtonClass( $btn, classToRemove, classToAdd, hover, state ) {
var attachEvents = function() {
var hoverDelay = $.mobile.buttonMarkup.hoverDelay, hov, foc;

$( document ).bind( {
$.mobile.$document.bind( {
"vmousedown vmousecancel vmouseup vmouseover vmouseout focus blur scrollstart": function( event ) {
var theme,
$btn = $( closestEnabledButton( event.target ) ),
Expand Down Expand Up @@ -266,7 +266,7 @@ var attachEvents = function() {

//links in bars, or those with data-role become buttons
//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.$document.bind( "pagecreate create", function( e ) {

$( ":jqmData(role='button'), .ui-bar > a, .ui-header > a, .ui-footer > a, .ui-bar > :jqmData(role='controlgroup') > a", e.target )
.jqmEnhanceable()
Expand Down
8 changes: 6 additions & 2 deletions js/jquery.mobile.core.js
Expand Up @@ -84,6 +84,10 @@ define( [ "jquery", "text!../version.txt" ], function( $, __version__ ) {
hoverDelay: 200
},

// define the window and the document objects
$window: $( window ),
$document: $( document ),

// TODO might be useful upstream in jquery itself ?
keyCode: {
ALT: 18,
Expand Down Expand Up @@ -134,7 +138,7 @@ define( [ "jquery", "text!../version.txt" ], function( $, __version__ ) {

setTimeout( function() {
window.scrollTo( 0, ypos );
$( document ).trigger( "silentscroll", { x: 0, y: ypos });
$.mobile.$document.trigger( "silentscroll", { x: 0, y: ypos });
}, 20 );

setTimeout( function() {
Expand Down Expand Up @@ -240,7 +244,7 @@ define( [ "jquery", "text!../version.txt" ], function( $, __version__ ) {
getScreenHeight: function() {
// Native innerHeight returns more accurate value for this across platforms,
// jQuery version is here as a normalized fallback for platforms like Symbian
return window.innerHeight || $( window ).height();
return window.innerHeight || $.mobile.$window.height();
}
}, $.mobile );

Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.degradeInputs.js
Expand Up @@ -26,7 +26,7 @@ $.mobile.page.prototype.options.degradeInputs = {


//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.$document.bind( "pagecreate create", function( e ) {

var page = $.mobile.closestPageData( $( e.target ) ), options;

Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.fieldContain.js
Expand Up @@ -19,7 +19,7 @@ $.fn.fieldcontain = function( options ) {
};

//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.$document.bind( "pagecreate create", function( e ) {
$( ":jqmData(role='fieldcontain')", e.target ).jqmEnhanceable().fieldcontain();
});

Expand Down
6 changes: 3 additions & 3 deletions js/jquery.mobile.init.js
Expand Up @@ -19,7 +19,7 @@ define([
(function( $, window, undefined ) {
var $html = $( "html" ),
$head = $( "head" ),
$window = $( window );
$window = $.mobile.$window;

//remove initial build class (only present on first pageshow)
function hideRenderingClass() {
Expand Down Expand Up @@ -143,7 +143,7 @@ define([
// if defaultHomeScroll hasn't been set yet, see if scrollTop is 1
// it should be 1 in most browsers, but android treats 1 as 0 (for hiding addr bar)
// so if it's 1, use 0 from now on
$.mobile.defaultHomeScroll = ( !$.support.scrollTop || $( window ).scrollTop() === 1 ) ? 0 : 1;
$.mobile.defaultHomeScroll = ( !$.support.scrollTop || $.mobile.$window.scrollTop() === 1 ) ? 0 : 1;

//dom-ready inits
if ( $.mobile.autoInitializePage ) {
Expand All @@ -159,7 +159,7 @@ define([
// by adding the 'ui-disabled' class to them. Using a JavaScript workaround for those browser.
// https://github.com/jquery/jquery-mobile/issues/3558

$( document ).delegate( ".ui-disabled", "vclick",
$.mobile.$document.delegate( ".ui-disabled", "vclick",
function( e ) {
e.preventDefault();
e.stopImmediatePropagation();
Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.links.js
Expand Up @@ -8,7 +8,7 @@ define( [ "jquery" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

$( document ).bind( "pagecreate create", function( e ) {
$.mobile.$document.bind( "pagecreate create", function( e ) {

//links within content areas, tests included with page
$( e.target )
Expand Down
14 changes: 7 additions & 7 deletions js/jquery.mobile.navigation.js
Expand Up @@ -20,7 +20,7 @@ define( [
(function( $, undefined ) {

//define vars for interal use
var $window = $( window ),
var $window = $.mobile.$window,
$html = $( 'html' ),
$head = $( 'head' ),

Expand Down Expand Up @@ -998,7 +998,7 @@ define( [
};

//bind to form submit events, handle with Ajax
$( document ).delegate( "form", "submit", function( event ) {
$.mobile.$document.delegate( "form", "submit", function( event ) {
var formData = getAjaxFormData( $( this ) );

if ( formData ) {
Expand All @@ -1008,7 +1008,7 @@ define( [
});

//add active state on vclick
$( document ).bind( "vclick", function( event ) {
$.mobile.$document.bind( "vclick", function( event ) {
var $btn, btnEls, target = event.target, needClosest = false;
// if this isn't a left click we don't care. Its important to note
// that when the virtual event is generated it will create the which attr
Expand Down Expand Up @@ -1071,7 +1071,7 @@ define( [
});

// click routing - direct to HTTP or Ajax, accordingly
$( document ).bind( "click", function( event ) {
$.mobile.$document.bind( "click", function( event ) {
if ( !$.mobile.linkBindingEnabled ) {
return;
}
Expand Down Expand Up @@ -1169,7 +1169,7 @@ define( [
});

//prefetch pages when anchors with data-prefetch are encountered
$( document ).delegate( ".ui-page", "pageshow.prefetch", function() {
$.mobile.$document.delegate( ".ui-page", "pageshow.prefetch", function() {
var urls = [];
$( this ).find( "a:jqmData(prefetch)" ).each(function() {
var $link = $( this ),
Expand Down Expand Up @@ -1276,8 +1276,8 @@ define( [
});

//set page min-heights to be device specific
$( document ).bind( "pageshow", resetActivePageHeight );
$( window ).bind( "throttledresize", resetActivePageHeight );
$.mobile.$document.bind( "pageshow", resetActivePageHeight );
$.mobile.$window.bind( "throttledresize", resetActivePageHeight );

};//navreadyDeferred done callback

Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.nojs.js
Expand Up @@ -7,7 +7,7 @@ define( [ "jquery" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

$( document ).bind( "pagecreate create", function( e ) {
$.mobile.$document.bind( "pagecreate create", function( e ) {
$( ":jqmData(role='nojs')", e.target ).addClass( "ui-nojs" );

});
Expand Down
8 changes: 4 additions & 4 deletions js/jquery.mobile.transition.js
Expand Up @@ -24,8 +24,8 @@ var createHandler = function( sequential ) {
active = $.mobile.urlHistory.getActive(),
toScroll = active.lastScroll || $.mobile.defaultHomeScroll,
screenHeight = $.mobile.getScreenHeight(),
maxTransitionOverride = $.mobile.maxTransitionWidth !== false && $( window ).width() > $.mobile.maxTransitionWidth,
none = !$.support.cssTransitions || maxTransitionOverride || !name || name === "none" || Math.max( $( window ).scrollTop(), toScroll ) > $.mobile.getMaxScrollForTransition(),
maxTransitionOverride = $.mobile.maxTransitionWidth !== false && $.mobile.$window.width() > $.mobile.maxTransitionWidth,
none = !$.support.cssTransitions || maxTransitionOverride || !name || name === "none" || Math.max( $.mobile.$window.scrollTop(), toScroll ) > $.mobile.getMaxScrollForTransition(),
toPreClass = " ui-page-pre-in",
toggleViewportClass = function() {
$.mobile.pageContainer.toggleClass( "ui-mobile-viewport-transitioning viewport-" + name );
Expand Down Expand Up @@ -59,7 +59,7 @@ var createHandler = function( sequential ) {
// Set the from page's height and start it transitioning out
// Note: setting an explicit height helps eliminate tiling in the transitions
$from
.height( screenHeight + $( window ).scrollTop() )
.height( screenHeight + $.mobile.$window.scrollTop() )
.addClass( name + " out" + reverseClass );
},

Expand Down Expand Up @@ -121,7 +121,7 @@ var createHandler = function( sequential ) {

// In some browsers (iOS5), 3D transitions block the ability to scroll to the desired location during transition
// This ensures we jump to that spot after the fact, if we aren't there already.
if ( $( window ).scrollTop() !== toScroll ) {
if ( $.mobile.$window.scrollTop() !== toScroll ) {
scrollPage();
}

Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.vmouse.js
Expand Up @@ -38,7 +38,7 @@ var dataPropertyName = "virtualMouseBindings",
blockMouseTriggers = false,
blockTouchTriggers = false,
eventCaptureSupported = "addEventListener" in document,
$document = $( document ),
$document = $.mobile.$document,
nextTouchID = 1,
lastTouchID = 0, threshold;

Expand Down
4 changes: 2 additions & 2 deletions js/jquery.mobile.zoom.iosorientationfix.js
Expand Up @@ -37,9 +37,9 @@ define( [ "jquery", "./jquery.mobile.core", "./jquery.mobile.zoom" ], function(
}
}

$( document ).on( "mobileinit", function(){
$.mobile.$document.on( "mobileinit", function(){
if( $.mobile.iosorientationfixEnabled ){
$( window )
$.mobile.$window
.bind( "orientationchange.iosorientationfix", zoom.enable )
.bind( "devicemotion.iosorientationfix", checkTilt );
}
Expand Down
4 changes: 2 additions & 2 deletions js/navigation/navigator.js
Expand Up @@ -10,7 +10,7 @@ define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ )
$.Navigator = function( history ) {
this.history = history;

$( window ).bind({
$.mobile.$window.bind({
"popstate.history": $.proxy( this.popstate, this ),
"hashchange.history": $.proxy( this.hashchange, this )
});
Expand Down Expand Up @@ -121,7 +121,7 @@ define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ )
// caught that was triggered by the hash setting above.
if( !noEvents ) {
this.ignoreNextPopState = true;
$( window ).trigger( popstateEvent );
$.mobile.$window.trigger( popstateEvent );
}
}

Expand Down
2 changes: 1 addition & 1 deletion js/widgets/collapsible.js
Expand Up @@ -158,7 +158,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
});

//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.$document.bind( "pagecreate create", function( e ) {
$.mobile.collapsible.prototype.enhanceWithin( e.target );
});

Expand Down
2 changes: 1 addition & 1 deletion js/widgets/collapsibleSet.js
Expand Up @@ -83,7 +83,7 @@ $.widget( "mobile.collapsibleset", $.mobile.widget, {
$.widget( "mobile.collapsibleset", $.mobile.collapsibleset, $.mobile.behaviors.addFirstLastClasses );

//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.$document.bind( "pagecreate create", function( e ) {
$.mobile.collapsibleset.prototype.enhanceWithin( e.target );
});

Expand Down
2 changes: 1 addition & 1 deletion js/widgets/controlgroup.js
Expand Up @@ -110,7 +110,7 @@ define( [ "jquery",
// already be in place, ensuring that all widgets that need to be grouped will
// already have been enhanced by the time the controlgroup is created.
$( function() {
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.$document.bind( "pagecreate create", function( e ) {
$.mobile.controlgroup.prototype.enhanceWithin( e.target, true );
});
});
Expand Down
2 changes: 1 addition & 1 deletion js/widgets/dialog.js
Expand Up @@ -138,7 +138,7 @@ $.widget( "mobile.dialog", $.mobile.widget, {
});

//auto self-init widgets
$( document ).delegate( $.mobile.dialog.prototype.options.initSelector, "pagecreate", function() {
$.mobile.$document.delegate( $.mobile.dialog.prototype.options.initSelector, "pagecreate", function() {
$.mobile.dialog.prototype.enhance( this );
});

Expand Down
8 changes: 4 additions & 4 deletions js/widgets/fixedToolbar.js
Expand Up @@ -142,7 +142,7 @@ define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.core", "../jque
_handlePageShow: function() {
this.updatePagePadding( this._thisPage );
if ( this.options.updatePagePadding ) {
this._on( $( window ), { "throttledresize": "updatePagePadding" } );
this._on( $.mobile.$window, { "throttledresize": "updatePagePadding" } );
}
},

Expand All @@ -153,7 +153,7 @@ define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.core", "../jque
$.mobile.zoom.enable( true );
}
if ( o.updatePagePadding ) {
this._off( $( window ), "throttledresize" );
this._off( $.mobile.$window, "throttledresize" );
}

if ( o.trackPersistentToolbars ) {
Expand Down Expand Up @@ -190,7 +190,7 @@ define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.core", "../jque
},

_useTransition: function( notransition ) {
var $win = $( window ),
var $win = $.mobile.$window,
$el = this.element,
scroll = $win.scrollTop(),
elHeight = $el.height(),
Expand Down Expand Up @@ -296,7 +296,7 @@ define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.core", "../jque
});

//auto self-init widgets
$( document )
$.mobile.$document
.bind( "pagecreate create", function( e ) {

// DEPRECATED in 1.1: support for data-fullscreen=true|false on the page element.
Expand Down
6 changes: 3 additions & 3 deletions js/widgets/fixedToolbar.workarounds.js
Expand Up @@ -47,9 +47,9 @@ define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.core", "../jque
_viewportOffset: function() {
var $el = this.element,
header = $el.is( ".ui-header" ),
offset = Math.abs($el.offset().top - $( window ).scrollTop());
offset = Math.abs($el.offset().top - $.mobile.$window.scrollTop());
if( !header ) {
offset = Math.round(offset - $( window ).height() + $el.outerHeight())-60;
offset = Math.round(offset - $.mobile.$window.height() + $el.outerHeight())-60;
}
return offset;
},
Expand All @@ -58,7 +58,7 @@ define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.core", "../jque
_bindScrollWorkaround: function() {
var self = this;
//bind to scrollstop and check if the toolbars are correctly positioned
this._on( $( window ), { scrollstop: function() {
this._on( $.mobile.$window, { scrollstop: function() {
var viewportOffset = self._viewportOffset();
//check if the header is visible and if its in the right place
if( viewportOffset > 2 && self._visible) {
Expand Down
4 changes: 2 additions & 2 deletions js/widgets/forms/button.js
Expand Up @@ -95,7 +95,7 @@ $.widget( "mobile.button", $.mobile.widget, {
}).insertBefore( $el );

// Bind to doc to remove after submit handling
$( document ).one( "submit", function() {
$.mobile.$document.one( "submit", function() {
$buttonPlaceholder.remove();

// reset the local var so that the hidden input
Expand Down Expand Up @@ -158,7 +158,7 @@ $.widget( "mobile.button", $.mobile.widget, {
});

//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ) {
$.mobile.$document.bind( "pagecreate create", function( e ) {
$.mobile.button.prototype.enhanceWithin( e.target, true );
});

Expand Down

0 comments on commit 893fe10

Please sign in to comment.