r88143 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88142‎ | r88143 | r88144 >
Date:10:33, 15 May 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
(bug 27073) Lazy init the style marker and insert if not available (ie. when using resourceloader js on a non-mediawiki domain); fixing typo (r88074 CR)
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -584,11 +584,26 @@
585585 var jobs = [];
586586 // Flag inidicating that document ready has occured
587587 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;
590590
591591 /* Private Methods */
592592
 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+
593608 function compare( a, b ) {
594609 if ( a.length != b.length ) {
595610 return false;
@@ -748,14 +763,14 @@
749764 var style = registry[module].style[media];
750765 if ( $.isArray( style ) ) {
751766 for ( var i = 0; i < style.length; i++ ) {
752 - $marker.before( mw.html.element( 'link', {
 767+ getMarker().before( mw.html.element( 'link', {
753768 'type': 'text/css',
754769 'rel': 'stylesheet',
755770 'href': style[i]
756771 } ) );
757772 }
758773 } else if ( typeof style === 'string' ) {
759 - $marker.before( mw.html.element(
 774+ getMarker().before( mw.html.element(
760775 'style',
761776 { 'type': 'text/css', 'media': media },
762777 new mw.html.Cdata( style )
@@ -1134,7 +1149,7 @@
11351150 throw new Error( 'script must be a function or an array, not a ' + typeof script );
11361151 }
11371152 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 );
11391154 }
11401155 if ( !$.isPlainObject( msgs ) ) {
11411156 throw new Error( 'msgs must be an object, not a ' + typeof msgs );

Follow-up revisions

RevisionCommit summaryAuthorDate
r88395* Remove commented-out debug call (FU r88143)...krinkle22:10, 18 May 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r88074Fixed language in comments and error messages - see comments in r88053.tparscal13:21, 14 May 2011

Comments

#Comment by Catrope (talk | contribs)   16:06, 15 May 2011
+				//mw.log( 'getMarker> Caching marker' );

Don't introduce commented-out code like that, either uncomment or remove it.

Status & tagging log