http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88143

Revision: 88143
Author:   krinkle
Date:     2011-05-15 10:33:07 +0000 (Sun, 15 May 2011)
Log Message:
-----------
(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: trunk/phase3/resources/mediawiki/mediawiki.js
===================================================================
--- trunk/phase3/resources/mediawiki/mediawiki.js       2011-05-15 10:31:14 UTC 
(rev 88142)
+++ trunk/phase3/resources/mediawiki/mediawiki.js       2011-05-15 10:33:07 UTC 
(rev 88143)
@@ -584,11 +584,26 @@
                var jobs = [];
                // Flag inidicating that document ready has occured
                var ready = false;
-               // Marker element for adding dynamic styles
-               var $marker = $( 'head meta[name=ResourceLoaderDynamicStyles]' 
);
+               // Selector cache for the marker element. Use getMarker() to 
get/use the marker!
+               var $marker = null;
 
                /* Private Methods */
 
+               function getMarker(){
+                       // Cached ?
+                       if ( $marker ) {
+                               return $marker;
+                       } else {
+                               //mw.log( 'getMarker> Caching marker' );
+                               $marker = $( 
'meta[name="ResourceLoaderDynamicStyles"]' );
+                               if ( $marker.length ) {
+                                       return $marker;
+                               }
+                               mw.log( 'getMarker> No <meta 
name="ResourceLoaderDynamicStyles"> found, inserting dynamically.' );
+                               return $marker = $( '<meta>' ).attr( 'name', 
'ResourceLoaderDynamicStyles' ).appendTo( 'head' );
+                       }
+               }
+
                function compare( a, b ) {
                        if ( a.length != b.length ) {
                                return false;
@@ -748,14 +763,14 @@
                                        var style = 
registry[module].style[media];
                                        if ( $.isArray( style ) ) {
                                                for ( var i = 0; i < 
style.length; i++ ) {
-                                                       $marker.before( 
mw.html.element( 'link', {
+                                                       getMarker().before( 
mw.html.element( 'link', {
                                                                'type': 
'text/css',
                                                                'rel': 
'stylesheet',
                                                                'href': style[i]
                                                        } ) );
                                                }
                                        } else if ( typeof style === 'string' ) 
{
-                                               $marker.before( mw.html.element(
+                                               getMarker().before( 
mw.html.element(
                                                        'style',
                                                        { 'type': 'text/css', 
'media': media },
                                                        new mw.html.Cdata( 
style )
@@ -1134,7 +1149,7 @@
                                throw new Error( 'script must be a function or 
an array, not a ' + typeof script );
                        }
                        if ( !$.isPlainObject( style ) ) {
-                               throw new Error( 'style must be an object or a 
string, not a ' + typeof style );
+                               throw new Error( 'style must be an object, not 
a ' + typeof style );
                        }
                        if ( !$.isPlainObject( msgs ) ) {
                                throw new Error( 'msgs must be an object, not a 
' + typeof msgs );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to