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

$(function {

/* retrieve key element nodes

var fe_link = document.getElementById("ca-formedit"); var is_fc = !!document.getElementById("ca-formcreate"); var ce_link = document.getElementById("ca-edit"); var is_ve = !!document.getElementById("ca-ve-edit"); var edit_link = $(".page-header__contribution-buttons .wds-button-group > a")[0]; // main button var link_list = $(".page-header__contribution-buttons ul")[0]; // dropdown list

/* detect situation and call corresponding function

if (fe_link && (fe_link !== edit_link)) { moveFormEdit; } else if (ce_link && ce_link.getAttribute("href").match(/flow=create-page-create-button$/) && !is_fc) { addCreateWithForm; } else if (document.body.classList.contains("mw-special-FormStart")) { // will not work in older browsers fillPageName; }

/* 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

function moveFormEdit { 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 = "Classic editor"; break; case "ca-ve-edit": fe_link.accessKey = edit_link.accessKey; edit_link.removeAttribute("accesskey"); fe_link.innerHTML = "VisualEditor"; 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 source editor and VisualEditor if found: add "Create with form" as 2nd in dropdown else: add "Create with form" to top of dropdown

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

/* 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]); } }

});