Jump to content

User:Mike Dillon/Scripts/preloadNewArticle.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Requires: [[User:Mike Dillon/Scripts/easydom.js]], [[User:Mike Dillon/Scripts/i18n.js]]

/* <pre><nowiki> */

var preloadNewArticleOptions;

/* Message */
wfAddMsg("en", "preloadNewArticleLabel", "Article template");
wfAddMsg("en", "preloadNewArticleButtonText", "Preload article template");

addOnloadHook(function () {
    if (preloadNewArticleOptions == null) return;

    var newarticletext = document.getElementById("newarticletext");
    if (!newarticletext) return;

    with (easyDom) {
        var preloadSelect = select({ name: "preload" });
        for (var label in preloadNewArticleOptions) {
            var template = preloadNewArticleOptions[label];
            preloadSelect.appendChild(option({ value: template }, label));
        }

        if (preloadSelect.childNodes.length == 0) {
            return;
        }

        newarticletext.appendChild(hr());

        newarticletext.appendChild(form(
            { method: "GET", action: wgScriptPath + "/index.php" },
            input({ type: "hidden", name: "title", value: wgPageName }),
            input({ type: "hidden", name: "action", value: "edit" }),
            div(strong(wfMsg("preloadNewArticleLabel"), ": "), preloadSelect, " ",
                input({ type: "submit", value: wfMsg("preloadNewArticleButtonText") }))
        ));
    }
});

/* </nowiki></pre> */