From eece5d6b76797f849592689c84cd649b1937c5fe Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Mon, 9 Mar 2015 23:57:33 -0700 Subject: [PATCH] mediawiki.js: clean-ups * Inline canExpandStylesheetWith(). * Make resolve() take an array of module names instead of being flexible (taking either a string or an array). It's a private method, so it doesn't need to have a cute API. * Use simple string concatenation rather than [].join in pad() * Make allReady() more efficient by having it bail early as soon as any non-ready module is encountered. * Add anyFailed(), which is a complement to allReady(). * Remove filter(). In more than one place, it was used to check whether a module in some specified state existed in a list of modules, which is inefficient, since filter() continues iterating through the array of modules after finding a match and because it constructed an array with the matches, which was not needed. * Replace some verbose array iteration with $.grep / $.map / $.each. Change-Id: I22a2f824488ba39d03b546ac8560f551a3198d7f --- resources/src/mediawiki/mediawiki.js | 204 +++++++++------------------ 1 file changed, 67 insertions(+), 137 deletions(-) diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index 17b06ce432..2b48c85ae8 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -773,20 +773,6 @@ return s; } - /** - * Check whether given styles are safe to to a stylesheet. - * - * @private - * @param {string} cssText - * @return {boolean} False if a new one must be created. - */ - function canExpandStylesheetWith( cssText ) { - // Makes sure that cssText containing `@import` - // rules will end up in a new stylesheet (as those only work when - // placed at the start of a stylesheet; bug 35562). - return cssText.slice( 0, '@import'.length ) !== '@import'; - } - /** * Add a bit of CSS text to the current browser page. * @@ -809,8 +795,10 @@ // Appending a stylesheet and waiting for the browser to repaint // is fairly expensive, this reduces that (bug 45810) if ( cssText ) { - // Be careful not to extend the buffer with css that needs a new stylesheet - if ( !cssBuffer || canExpandStylesheetWith( cssText ) ) { + // Be careful not to extend the buffer with css that needs a new stylesheet. + // cssText containing `@import` rules needs to go at the start of a buffer, + // since those only work when placed at the start of a stylesheet; bug 35562. + if ( !cssBuffer || cssText.slice( 0, '@import'.length ) !== '@import' ) { // Linebreak for somewhat distinguishable sections // (the rl-cachekey comment separating each) cssBuffer += '\n' + cssText; @@ -851,7 +839,7 @@ // (not some other style tag or even a `` or `