User:Andrewds1021/global.js

/********************* this comment is 80 characters long *********************/

/* check for Internet Explorer if found: load CSS corrections

if (["MSIE", "Trident/7."].some(function (arg) { return (navigator.userAgent.indexOf(arg) >= 0); })) {   importArticles({        type: "style",        article: "u:w:User:Andrewds1021/IE11.css"    }); }

/* form edit modifications and additions supports the Oasis and Monobook skins not applicable to the Mercury skin

(function {

/* detect situation and call corresponding function element.classList is not supported in older browsers

var fe_link = document.getElementById("ca-formedit"); var has_fc = !!document.getElementById("ca-formcreate"); var ce_link = document.getElementById("ca-edit"); var edit_link = $(".page-header__contribution-buttons .wds-button-group > a")[0]; // Oasis main edit button var link_list = $(".page-header__contribution-buttons ul")[0]; // Oasis edit dropdown list if (fe_link && edit_link && (fe_link !== edit_link)) { getSystemMessages("visualeditor-ca-classiceditor|visualeditor-ca-ve-edit").done(moveFormEdit); } else if (ce_link && !has_fc && ce_link.getAttribute("href").match(/flow=create-page-create-button$/)) { addOasisCreateWithForm; } else if (ce_link && !has_fc && ce_link.parentElement.firstElementChild.classList.contains("new")) { getSystemMessages("tooltip-ca-formedit|accesskey-ca-formedit").done(addMonobookCreateWithForm); } else if (document.body.classList.contains("mw-special-FormStart")) { fillPageName; }

/* retrieve specified system messages returns a JQuery promise

function getSystemMessages(messages) { return mw.loader.using("mediawiki.api").then(function {        return new mw.Api.get({ action: "query", meta: "allmessages", ammessages: messages, amlang: mw.config.get("wgUserLanguage") });   }).then(function (data) {        results = [];        for (i = 0; i < data.query.allmessages.length; i++) {            results.push(data.query.allmessages[i]["*"]);        }        return results;    }); }

/* check main button for either view source, classic editor, or VisualEditor if found: move main button action to top of dropdown move form edit to main button requires: button_texts: an array containing the button texts for the classic editor and VisualEditor for Oasis only

function moveFormEdit(button_texts) { var ll_temp = ""; switch (edit_link.id) { case "ca-viewsource": ll_temp = fe_link.innerHTML; fe_link.innerHTML = edit_link.lastElementChild.innerHTML; edit_link.lastElementChild.innerHTML = ll_temp; break; case "ca-edit": fe_link.accessKey = edit_link.accessKey; edit_link.removeAttribute("accesskey"); fe_link.innerHTML = button_texts[0]; break; case "ca-ve-edit": fe_link.accessKey = edit_link.accessKey; edit_link.removeAttribute("accesskey"); fe_link.innerHTML = button_texts[1]; break; default: return; }   ll_temp = fe_link.id; fe_link.id = edit_link.id; edit_link.id = ll_temp; ll_temp = fe_link.getAttribute("data-tracking"); fe_link.setAttribute("data-tracking", edit_link.getAttribute("data-tracking")+"-dropdown"); edit_link.setAttribute("data-tracking", ll_temp.replace("-dropdown", "")); ll_temp = fe_link.getAttribute("href"); fe_link.setAttribute("href", edit_link.getAttribute("href")); edit_link.setAttribute("href", ll_temp); link_list.insertBefore(fe_link.parentElement, link_list.firstElementChild); }

/* check for both classic editor and VisualEditor if both found: add "Create with form" as 2nd in dropdown else: add "Create with form" to top of dropdown for Oasis only

function addOasisCreateWithForm { var list_item = document.createElement("li"); var list_link = document.createElement("a"); var link_text = document.createTextNode("Create with form"); list_link.setAttribute("href", "/wiki/Special:FormStart?tfl_formstart_pagename="+encodeURIComponent(decodeURIComponent(location.pathname.substr(6)))); list_link.id = "ca-formcreate"; list_link.setAttribute("data-tracking", "ca-formcreate-dropdown"); list_link.appendChild(link_text); list_item.appendChild(list_link); if (document.getElementById("ca-ve-edit")) { link_list.insertBefore(list_item, link_list.children[1]); } else { link_list.insertBefore(list_item, link_list.children[0]); } }

/* add "Create with form" before source editor requires: messages: an array containing the formedit title message and accesskey for Monobook only

function addMonobookCreateWithForm(messages) { link_list = ce_link.parentElement; var list_item = document.createElement("li"); var list_link = document.createElement("a"); var link_text = document.createTextNode("Create with form"); list_link.setAttribute("href", "/wiki/Special:FormStart?tfl_formstart_pagename="+encodeURIComponent(decodeURIComponent(location.pathname.substr(6)))); list_link.title = messages[0]+" ["+messages[1]+"]"; list_link.accessKey = messages[1]; list_link.appendChild(link_text); list_item.id = "ca-formcreate"; list_item.appendChild(list_link); link_list.insertBefore(list_item, ce_link); }

/* check for URL query parameter "tfl_formstart_pagename" if found: place value in field for "page_name"

function fillPageName { var params = location.search.substr(1).split(/[&=]/); var param_idx = params.indexOf("tfl_formstart_pagename"); var field = $("form input[name='page_name']")[0]; if (field && (param_idx != -1) && (param_idx < (params.length-1))) { field.value = decodeURIComponent(params[param_idx+1]); } }

});