|
7 | 7 | ( function( $, undefined ) { |
8 | 8 |
|
9 | 9 | $.fn.buttonMarkup = function( options ) { |
10 | | - return this.each( function() { |
11 | | - var el = $( this ), |
| 10 | + options = options || {}; |
| 11 | + |
| 12 | + for ( var i = 0; i < this.length; i++ ) { |
| 13 | + var el = this.eq( i ), |
| 14 | + e = el[ 0 ], |
12 | 15 | o = $.extend( {}, $.fn.buttonMarkup.defaults, { |
13 | | - icon: el.jqmData( "icon" ), |
14 | | - iconpos: el.jqmData( "iconpos" ), |
15 | | - theme: el.jqmData( "theme" ), |
16 | | - inline: el.jqmData( "inline" ), |
17 | | - shadow: el.jqmData( "shadow" ), |
18 | | - corners: el.jqmData( "corners" ), |
19 | | - iconshadow: el.jqmData( "iconshadow" ) |
| 16 | + icon: options.icon || el.jqmData( "icon" ), |
| 17 | + iconpos: options.iconpos || el.jqmData( "iconpos" ), |
| 18 | + theme: options.theme || el.jqmData( "theme" ), |
| 19 | + inline: options.inline || el.jqmData( "inline" ), |
| 20 | + shadow: options.shadow || el.jqmData( "shadow" ), |
| 21 | + corners: options.corners || el.jqmData( "corners" ), |
| 22 | + iconshadow: options.iconshadow || el.jqmData( "iconshadow" ) |
20 | 23 | }, options ), |
21 | 24 |
|
22 | 25 | // Classes Defined |
23 | 26 | innerClass = "ui-btn-inner", |
24 | 27 | textClass = "ui-btn-text", |
25 | 28 | buttonClass, iconClass, |
26 | | - wrap; |
| 29 | + |
| 30 | + // Button inner markup |
| 31 | + buttonInner = document.createElement( o.wrapperEls ), |
| 32 | + buttonText = document.createElement( o.wrapperEls ), |
| 33 | + buttonIcon = o.icon ? document.createElement( "span" ) : null; |
27 | 34 |
|
28 | 35 | if ( attachEvents ) { |
29 | 36 | attachEvents(); |
@@ -71,17 +78,30 @@ $.fn.buttonMarkup = function( options ) { |
71 | 78 | el.attr( "data-" + $.mobile.ns + "theme", o.theme ) |
72 | 79 | .addClass( buttonClass ); |
73 | 80 |
|
74 | | - wrap = ( "<D class='" + innerClass + "' aria-hidden='true'><D class='" + textClass + "'></D>" + |
75 | | - ( o.icon ? "<span class='" + iconClass + "'></span>" : "" ) + |
76 | | - "</D>" ).replace( /D/g, o.wrapperEls ); |
| 81 | + buttonInner.className = innerClass; |
| 82 | + buttonInner.setAttribute("aria-hidden", "true"); |
| 83 | + |
| 84 | + buttonText.className = textClass; |
| 85 | + buttonInner.appendChild( buttonText ); |
| 86 | + |
| 87 | + if ( buttonIcon ) { |
| 88 | + buttonIcon.className = iconClass; |
| 89 | + buttonInner.appendChild( buttonIcon ); |
| 90 | + } |
77 | 91 |
|
78 | | - el.wrapInner( wrap ); |
| 92 | + while ( e.firstChild ) { |
| 93 | + buttonText.appendChild( e.firstChild ); |
| 94 | + } |
| 95 | + |
| 96 | + e.appendChild( buttonInner ); |
79 | 97 |
|
80 | 98 | // TODO obviously it would be nice to pull this element out instead of |
81 | 99 | // retrieving it from the DOM again, but this change is much less obtrusive |
82 | 100 | // and 1.0 draws nigh |
83 | | - el.data( 'textWrapper', el.find( "." + textClass ) ); |
84 | | - }); |
| 101 | + el.data( 'textWrapper', $( buttonText ) ); |
| 102 | + } |
| 103 | + |
| 104 | + return this; |
85 | 105 | }; |
86 | 106 |
|
87 | 107 | $.fn.buttonMarkup.defaults = { |
|
0 commit comments