| Index: trunk/phase3/resources/mediawiki/mediawiki.js |
| — | — | @@ -584,11 +584,26 @@ |
| 585 | 585 | var jobs = []; |
| 586 | 586 | // Flag inidicating that document ready has occured |
| 587 | 587 | var ready = false; |
| 588 | | - // Marker element for adding dynamic styles |
| 589 | | - var $marker = $( 'head meta[name=ResourceLoaderDynamicStyles]' ); |
| | 588 | + // Selector cache for the marker element. Use getMarker() to get/use the marker! |
| | 589 | + var $marker = null; |
| 590 | 590 | |
| 591 | 591 | /* Private Methods */ |
| 592 | 592 | |
| | 593 | + function getMarker(){ |
| | 594 | + // Cached ? |
| | 595 | + if ( $marker ) { |
| | 596 | + return $marker; |
| | 597 | + } else { |
| | 598 | + //mw.log( 'getMarker> Caching marker' ); |
| | 599 | + $marker = $( 'meta[name="ResourceLoaderDynamicStyles"]' ); |
| | 600 | + if ( $marker.length ) { |
| | 601 | + return $marker; |
| | 602 | + } |
| | 603 | + mw.log( 'getMarker> No <meta name="ResourceLoaderDynamicStyles"> found, inserting dynamically.' ); |
| | 604 | + return $marker = $( '<meta>' ).attr( 'name', 'ResourceLoaderDynamicStyles' ).appendTo( 'head' ); |
| | 605 | + } |
| | 606 | + } |
| | 607 | + |
| 593 | 608 | function compare( a, b ) { |
| 594 | 609 | if ( a.length != b.length ) { |
| 595 | 610 | return false; |
| — | — | @@ -748,14 +763,14 @@ |
| 749 | 764 | var style = registry[module].style[media]; |
| 750 | 765 | if ( $.isArray( style ) ) { |
| 751 | 766 | for ( var i = 0; i < style.length; i++ ) { |
| 752 | | - $marker.before( mw.html.element( 'link', { |
| | 767 | + getMarker().before( mw.html.element( 'link', { |
| 753 | 768 | 'type': 'text/css', |
| 754 | 769 | 'rel': 'stylesheet', |
| 755 | 770 | 'href': style[i] |
| 756 | 771 | } ) ); |
| 757 | 772 | } |
| 758 | 773 | } else if ( typeof style === 'string' ) { |
| 759 | | - $marker.before( mw.html.element( |
| | 774 | + getMarker().before( mw.html.element( |
| 760 | 775 | 'style', |
| 761 | 776 | { 'type': 'text/css', 'media': media }, |
| 762 | 777 | new mw.html.Cdata( style ) |
| — | — | @@ -1134,7 +1149,7 @@ |
| 1135 | 1150 | throw new Error( 'script must be a function or an array, not a ' + typeof script ); |
| 1136 | 1151 | } |
| 1137 | 1152 | if ( !$.isPlainObject( style ) ) { |
| 1138 | | - throw new Error( 'style must be an object or a string, not a ' + typeof style ); |
| | 1153 | + throw new Error( 'style must be an object, not a ' + typeof style ); |
| 1139 | 1154 | } |
| 1140 | 1155 | if ( !$.isPlainObject( msgs ) ) { |
| 1141 | 1156 | throw new Error( 'msgs must be an object, not a ' + typeof msgs ); |