User:Mike Dillon/Scripts/preloadNewArticle.js

This is an old revision of this page, as edited by Mike Dillon (talk | contribs) at 15:50, 31 December 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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]]

/* <pre><nowiki> */

var preloadNewArticleOptions;

addOnloadHook(function () {
    if (preloadNewArticleOptions == null) {
        alert("No preload template found");
        return;
    }

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

    with (easyDom) {
        newarticletext.appendChild(hr());

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

        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("Article template: "), preloadSelect, " ",
                input({ type: "submit", value: "Preload article template" }))
        ));
    }
});

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