Skip to content

Commit 085bea9

Browse files
author
Gabriel Schulhof
committed
Popup: Performance improvements.
http://jsperf.com/improve-popup
1 parent 12c07c1 commit 085bea9

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

js/widgets/popup.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,21 @@ define( [
206206
},
207207
thisPage = this.element.closest( ".ui-page" ),
208208
myId = this.element.attr( "id" ),
209-
self = this;
209+
o = this.options,
210+
key, value;
210211

211212
// We need to adjust the history option to be false if there's no AJAX nav.
212213
// We can't do it in the option declarations because those are run before
213214
// it is determined whether there shall be AJAX nav.
214-
this.options.history = this.options.history && $.mobile.ajaxEnabled && $.mobile.hashListeningEnabled;
215+
o.history = o.history && $.mobile.ajaxEnabled && $.mobile.hashListeningEnabled;
215216

216217
if ( thisPage.length === 0 ) {
217218
thisPage = $( "body" );
218219
}
219220

220221
// define the container for navigation event bindings
221222
// TODO this would be nice at the the mobile widget level
222-
this.options.container = this.options.container || $.mobile.pageContainer || thisPage;
223+
o.container = o.container || $.mobile.pageContainer || thisPage;
223224

224225
// Apply the proto
225226
thisPage.append( ui.screen );
@@ -252,12 +253,15 @@ define( [
252253
_orientationchangeInProgress: false
253254
});
254255

255-
$.each( this.options, function( key, value ) {
256-
// Cause initial options to be applied by their handler by temporarily setting the option to undefined
257-
// - the handler then sets it to the initial value
258-
self.options[ key ] = undefined;
259-
self._setOption( key, value, true );
260-
});
256+
// This duplicates the code from the various option setters below for
257+
// better performance. It must be kept in sync with those setters.
258+
this._applyTheme( this.element, o.theme, "body" );
259+
this._applyTheme( this._ui.screen, o.overlayTheme, "overlay" );
260+
this._applyTransition( o.transition );
261+
this.element
262+
.toggleClass( "ui-overlay-shadow", o.shadow )
263+
.toggleClass( "ui-corner-all", o.corners );
264+
this._setTolerance( o.tolerance );
261265

262266
ui.screen.bind( "vclick", $.proxy( this, "_eatEventAndClose" ) );
263267

@@ -385,28 +389,13 @@ define( [
385389
},
386390

387391
_setOption: function( key, value ) {
388-
var exclusions, setter = "_set" + key.charAt( 0 ).toUpperCase() + key.slice( 1 );
392+
var setter = "_set" + key.charAt( 0 ).toUpperCase() + key.slice( 1 );
389393

390394
if ( this[ setter ] !== undefined ) {
391395
this[ setter ]( value );
392396
}
393397

394-
// TODO REMOVE FOR 1.2.1 by moving them out to a default options object
395-
exclusions = [
396-
"initSelector",
397-
"closeLinkSelector",
398-
"closeLinkEvents",
399-
"navigateEvents",
400-
"closeEvents",
401-
"history",
402-
"container"
403-
];
404-
405-
$.mobile.widget.prototype._setOption.apply( this, arguments );
406-
if ( $.inArray( key, exclusions ) === -1 ) {
407-
// Record the option change in the options and in the DOM data-* attributes
408-
this.element.attr( "data-" + ( $.mobile.ns || "" ) + ( key.replace( /([A-Z])/, "-$1" ).toLowerCase() ), value );
409-
}
398+
this._super( key, value );
410399
},
411400

412401
_clampPopupWidth: function( infoOnly ) {

0 commit comments

Comments
 (0)