MediaWiki:CodeLoad.js/loader.js

/*jslint browser */ /*global console, codeLoad, importArticles */

(function (cl) {   'use strict';

var imports = { css: [], js: [] };

// check if article is suitable to add to imports, and if so, add it   function addToImports(article) { if (typeof article !== 'string') { console.warn('CodeLoad: article is not a string:', article); return; }

var type = article.split('.').pop; var fromDevWiki = article.slice(0, 4) === 'dev:';

// only imports with .css / .js extension accepted if (type !== 'css' && type !== 'js') { console.warn('CodeLoad: article does not have \'.css\' or \'.js\' extension:', article); return; }

// add MW namespace to import + handle imports from dev.wikia.com if (fromDevWiki && type === 'css') { // css pages on dev haven't been migrated to MW namespace article = 'external:dev:' + article.slice(4); } else if (fromDevWiki && type === 'js') { article = 'external:dev:MediaWiki:' + article.slice(4); } else { article = 'MediaWiki:' + article; }

// only add once if (imports[type] && imports[type].indexOf(article) === -1) { imports[type].push(article); }   }

// check if current code definition should be used function checkDefinition(id) { var articles = cl.definitions[id].articles;

if (           Array.isArray(articles) &&            cl.definitionEnabled(id) &&            cl.definitionAvailable(id)        ) { articles.forEach(addToImports); }   }

function main { Object.keys(cl.definitions).forEach(checkDefinition);

if (imports.css.length) { importArticles({               type: 'style',                articles: imports.css            }); }       if (imports.js.length) { importArticles({               type: 'script',                articles: imports.js            }); }   }

main;

}(codeLoad));