Skip to content

Commit c692c05

Browse files
author
Gabriel Schulhof
committed
Collapsible: Replace jqmData with getAttribute.
A minute performance bump: http://jsperf.com/collapsible-jqmdata-vs-getattribute
1 parent 3f6a188 commit c692c05

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

js/widgets/collapsible.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.buttonMarkup",
99
//>>excludeEnd("jqmBuildExclude");
1010
(function( $, undefined ) {
1111

12+
var getAttr = $.mobile.getAttribute;
13+
1214
$.widget( "mobile.collapsible", $.mobile.widget, {
1315
options: {
1416
expandCueText: " click to expand contents",
@@ -45,33 +47,33 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
4547
if ( collapsibleSet.length ) {
4648
// Inherit the theme from collapsible-set
4749
if ( !o.theme ) {
48-
o.theme = collapsibleSet.jqmData( "theme" ) || $.mobile.getInheritedTheme( collapsibleSet, "c" );
50+
o.theme = getAttr( collapsibleSet[ 0 ], "theme", true ) || $.mobile.getInheritedTheme( collapsibleSet, "c" );
4951
}
5052
// Inherit the content-theme from collapsible-set
5153
if ( !o.contentTheme ) {
52-
o.contentTheme = collapsibleSet.jqmData( "content-theme" );
54+
o.contentTheme = getAttr( collapsibleSet[ 0 ], "content-theme", true );
5355
}
5456

5557
// Get the preference for collapsed icon in the set, but override with data- attribute on the individual collapsible
56-
o.collapsedIcon = $el.jqmData( "collapsed-icon" ) || collapsibleSet.jqmData( "collapsed-icon" ) || o.collapsedIcon;
58+
o.collapsedIcon = getAttr( $el[ 0 ], "collapsed-icon", true ) || getAttr( collapsibleSet[ 0 ], "collapsed-icon", true ) || o.collapsedIcon;
5759

5860
// Get the preference for expanded icon in the set, but override with data- attribute on the individual collapsible
59-
o.expandedIcon = $el.jqmData( "expanded-icon" ) || collapsibleSet.jqmData( "expanded-icon" ) || o.expandedIcon;
61+
o.expandedIcon = getAttr( $el[ 0 ], "expanded-icon", true ) || getAttr( collapsibleSet[ 0 ], "expanded-icon", true ) || o.expandedIcon;
6062

6163
// Gets the preference icon position in the set, but override with data- attribute on the individual collapsible
62-
o.iconpos = $el.jqmData( "iconpos" ) || collapsibleSet.jqmData( "iconpos" ) || o.iconpos;
64+
o.iconpos = getAttr( $el[ 0 ], "iconpos", true ) || getAttr( collapsibleSet[ 0 ], "iconpos", true ) || o.iconpos;
6365

6466
// Inherit the preference for inset from collapsible-set or set the default value to ensure equalty within a set
65-
if ( collapsibleSet.jqmData( "inset" ) !== undefined ) {
66-
o.inset = collapsibleSet.jqmData( "inset" );
67+
if ( getAttr( collapsibleSet[ 0 ], "inset", true ) !== undefined ) {
68+
o.inset = getAttr( collapsibleSet[ 0 ], "inset", true );
6769
} else {
6870
o.inset = true;
6971
}
7072
// Set corners for individual collapsibles to false when in a collapsible-set
7173
o.corners = false;
7274
// Gets the preference for mini in the set
7375
if ( !o.mini ) {
74-
o.mini = collapsibleSet.jqmData( "mini" );
76+
o.mini = getAttr( collapsibleSet[ 0 ], "mini", true );
7577
}
7678
} else {
7779
// get inherited theme if not a set and no theme has been set

0 commit comments

Comments
 (0)