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

Performance: replace several jqmData() function calls with getAttribute() to improve performance. #5466

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions js/jquery.mobile.buttonMarkup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define( [ "jquery", "./jquery.mobile.core", "./jquery.mobile.vmouse" ], function

$.fn.buttonMarkup = function( options ) {
var $workingSet = this,
prefix = "data-" + $.mobile.ns,
mapToDataAttr = function( key, value ) {
e.setAttribute( "data-" + $.mobile.ns + key, value );
el.jqmData( key, value );
Expand All @@ -22,14 +23,14 @@ $.fn.buttonMarkup = function( options ) {
var el = $workingSet.eq( i ),
e = el[ 0 ],
o = $.extend( {}, $.fn.buttonMarkup.defaults, {
icon: options.icon !== undefined ? options.icon : el.jqmData( "icon" ),
iconpos: options.iconpos !== undefined ? options.iconpos : el.jqmData( "iconpos" ),
theme: options.theme !== undefined ? options.theme : el.jqmData( "theme" ) || $.mobile.getInheritedTheme( el, "c" ),
inline: options.inline !== undefined ? options.inline : el.jqmData( "inline" ),
shadow: options.shadow !== undefined ? options.shadow : el.jqmData( "shadow" ),
corners: options.corners !== undefined ? options.corners : el.jqmData( "corners" ),
iconshadow: options.iconshadow !== undefined ? options.iconshadow : el.jqmData( "iconshadow" ),
mini: options.mini !== undefined ? options.mini : el.jqmData( "mini" )
icon: options.icon !== undefined ? options.icon : ( e.getAttribute( prefix + "icon" ) || undefined ),
iconpos: options.iconpos !== undefined ? options.iconpos : ( e.getAttribute( prefix + "iconpos" ) || undefined ),
theme: options.theme !== undefined ? options.theme : e.getAttribute( prefix + "theme" ) || $.mobile.getInheritedTheme( el, "c" ),
inline: options.inline !== undefined ? options.inline : /^true$/i.test( e.getAttribute( prefix + "inline" ) ),
shadow: options.shadow !== undefined ? options.shadow : !/^false$/i.test( e.getAttribute( prefix + "shadow" ) ),
corners: options.corners !== undefined ? options.corners : !/^false$/i.test( e.getAttribute( prefix + "corners" ) ),
iconshadow: options.iconshadow !== undefined ? options.iconshadow : !/^false$/i.test( e.getAttribute( prefix + "iconshadow" ) ),
mini: options.mini !== undefined ? options.mini : /^true$/i.test( e.getAttribute( prefix + "mini" ) )
}, options ),

// Classes Defined
Expand All @@ -46,7 +47,7 @@ $.fn.buttonMarkup = function( options ) {

$.each( o, mapToDataAttr );

if ( el.jqmData( "rel" ) === "popup" && el.attr( "href" ) ) {
if ( e.getAttribute( prefix + "rel" ) === "popup" && el.attr( "href" ) ) {
e.setAttribute( "aria-haspopup", true );
e.setAttribute( "aria-owns", e.getAttribute( "href" ) );
}
Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ define([
var $this = $( this );

// unless the data url is already set set it to the pathname
if ( !$this.jqmData( "url" ) ) {
if ( !$this[0].getAttribute( "data-" + $.mobile.ns + "url" ) ) {
$this.attr( "data-" + $.mobile.ns + "url", $this.attr( "id" ) || location.pathname + location.search );
}
});
Expand Down
9 changes: 5 additions & 4 deletions js/widgets/page.sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ $.mobile.page.prototype.options.contentTheme = null;
$.mobile.document.bind( "pagecreate", function( e ) {
var $page = $( e.target ),
o = $page.data( "mobile-page" ).options,
pageRole = $page.jqmData( "role" ),
prefix = "data-"+$.mobile.ns,
pageRole = $page[0].getAttribute( prefix + "role" ) || undefined,
pageTheme = o.theme;

$( ":jqmData(role='header'), :jqmData(role='footer'), :jqmData(role='content')", $page )
.jqmEnhanceable()
.each(function() {

var $this = $( this ),
role = $this.jqmData( "role" ),
theme = $this.jqmData( "theme" ),
role = $this[0].getAttribute( prefix + "role" ) || undefined,
theme = $this[0].getAttribute( prefix + "theme" ) || undefined,
contentTheme = theme || o.contentTheme || ( pageRole === "dialog" && pageTheme ),
$headeranchors,
leftbtn,
Expand Down Expand Up @@ -65,7 +66,7 @@ $.mobile.document.bind( "pagecreate", function( e ) {
if ( o.addBackBtn &&
role === "header" &&
$( ".ui-page" ).length > 1 &&
$page.jqmData( "url" ) !== $.mobile.path.stripHash( location.hash ) &&
$page[0].getAttribute( prefix + "url" ) !== $.mobile.path.stripHash( location.hash ) &&
!leftbtn ) {

backBtn = $( "<a href='javascript:void(0);' class='ui-btn-left' data-"+ $.mobile.ns +"rel='back' data-"+ $.mobile.ns +"icon='arrow-l'>"+ o.backBtnText +"</a>" )
Expand Down