User:Mwn3d/monobook.js: Difference between revisions

m
Updating
(Is this what I should do?)
m (Updating)
 
(One intermediate revision by the same user not shown)
Line 1:
//<lang javascript>
/*========================================
This comparison script was written by
Tyrok1, and has been tested on Fx 3.6.6,
Cr 5.0.375.99, Epiphany 2.30.2,
Midori 0.2.2
========================================*/
 
var gadgetsAvailable = [
{
{ id: "LanguageComparison", name: "Language comparison", url: "http://rosettacode.org/mw/index.php?title=Rosetta_Code:Language_comparison_script&action=raw&ctype=text/javascript", prefix: "Compare" },
id: "LanguageComparison",
{ id: "UtilityButtonBar", name: "Utility button bar", url: "http://rosettacode.org/mw/index.php?title=Rosetta_Code:Per-Code_Example_Buttonbar&action=raw&ctype=text/javascript", prefix: "ButtonBar" }
name: "Language comparison",
url: "http://rosettacode.org/mw/index.php" +
"?title=Rosetta_Code:Language_comparison_script" +
"&action=raw&ctype=text/javascript",
prefix: "Compare"
},
{
id: "Highlight",
name: "Syntax Highlight Color Picker",
url: "http://rosettacode.org/mw/index.php" +
"?title=Rosetta_Code:Syntax_Highlight_Color_Picker" +
"&action=raw&ctype=text/javascript",
prefix: "Highlight"
},
{
id: "UtilityButtonBar",
name: "Utility button bar",
url: "http://rosettacode.org/mw/index.php" +
"?title=Rosetta_Code:Per-Code_Example_Buttonbar" +
"&action=raw&ctype=text/javascript",
prefix: "ButtonBar"
}
];
 
function GadgetsAddHandler(el, handlerType, func)
{
Line 25 ⟶ 50:
}
}
 
function GadgetsScriptLoad(g)
{
Line 39 ⟶ 64:
}
}
 
function GadgetsScriptActivate(g)
{
Line 54 ⟶ 79:
}
}
 
function GadgetsScriptDeactivate(g)
{
Line 65 ⟶ 90:
else
{
//pop up a warning to the user to let them know the plugin will be disabled when they reload
//the plugin will be disabled when they reload
alert("This script will be disabled on next page load");
}
}
 
function GadgetsCreateCheckboxClosure(el)
{
Line 76 ⟶ 102:
//save the checkboxes to the cookie for next page load
GadgetsSaveCheckboxes();
//check to see if we need to activate or deactivate
if(el.checked)
Line 91 ⟶ 117:
};
}
 
function GadgetsMouseOver()
{
Line 97 ⟶ 123:
document.getElementById("pt-jsgadgets-list").style.display = "block";
}
 
function GadgetsMouseOut()
{
Line 103 ⟶ 129:
document.getElementById("pt-jsgadgets-list").style.display = "none";
}
 
function GadgetsSaveCheckboxes()
{
var checkedBoxes = "", checkboxEl = null;
//build a string representation of all of the checked boxes to save to the cookie
for(var c = 0; checkboxEl = document.getElementById("pt-jsgadgets-gadget" + c); ++c)
{
checkedBoxes += if(checkboxEl.checked ? (checkedBoxes != "" ? "," : "") + gadgetsAvailable[c].id : "");
{
if(checkedBoxes != "")
{
checkedBoxes += ",";
}
checkedBoxes += gadgetsAvailable[c].id;
}
}
//set an expiry date 1000 years into the future
var expireDate = new Date();
expireDate.setFullYear(expireDate.getFullYear() + 1000);
//store the cookie
document.cookie = "jsGadgets=" + escape(checkedBoxes) + "; expires=" + expireDate.toUTCString();
"; expires=" + expireDate.toUTCString();
}
 
function GadgetsGetCheckboxes()
{
Line 133 ⟶ 167:
}
var endPos = fullCookie.indexOf(";", gadgetsPos);
//split the gadget IDs by comma
var checkIDsjsGadgets = fullCookie.substring(gadgetsPos + ("jsGadgets=").length, (endPos > 0 ? endPos : fullCookie.length)).split(",");
(endPos > 0 ? endPos : fullCookie.length));
var checkIDs = unescape(jsGadgets).split(",");
//translate the list of IDs to a list of array indices, in keeping with the way the rest of this module works
//translate the list of IDs to a list of array indices, in keeping with the way the rest of this module works
//in keeping with the way the rest of this module works
var checkIndices = new Array();
for(var g = 0; g < gadgetsAvailable.length; ++g)
Line 152 ⟶ 189:
return checkIndices;
}
 
function GadgetsActivate()
{
Line 171 ⟶ 208:
prefsEl = liEls[liEls.length - 2];
}
var jsMenuEl = prefsEl.parentNode.insertBefore(document.createElement("li"), prefsEl.nextSibling);
document.createElement("li"), prefsEl.nextSibling);
jsMenuEl.setAttribute("id", "pt-jsgadgets");
//add a new link named "My scripts" in the new list item
//from a semantics point of view, this is not great, but this way the styling kicks in to keep it consistent with its siblings
//but this way the styling kicks in to keep it consistent with its siblings
var jsLinkEl = jsMenuEl.appendChild(document.createElement("a"));
jsLinkEl.appendChild(document.createTextNode("My scripts"));
jsLinkEl.setAttribute("href", "javascript: void(0);");
jsLinkEl.style.position = "relative";
//add handlers for showing on mouseover and hiding on mouseout
GadgetsAddHandler(jsLinkEl, "mouseover", GadgetsMouseOver);
GadgetsAddHandler(jsLinkEl, "mouseout", GadgetsMouseOut);
//build a list for showing available JS gadgets
var modulesListEl = jsLinkEl.appendChild(document.createElement("ol"));
Line 198 ⟶ 237:
modulesListEl.style.padding = "0.5em";
modulesListEl.style.display = "none";
//raise the zIndex of the new button (as well as a few parents) so the menu overlaps the page
//a few parents) so the menu overlaps the page
var zEl = modulesListEl;
for(var z = 0; z < 6 && zEl && zEl.style; ++z, zEl = zEl.parentNode)
Line 205 ⟶ 245:
zEl.style.zIndex = 100;
}
//add each of the gadgets to the list
for(var m = 0; m < gadgetsAvailable.length; ++m)
Line 218 ⟶ 258:
liEl.style.margin = 0;
liEl.style.padding = 0;
//add the checkbox
var inputEl = document.createElement("input");
Line 227 ⟶ 267:
GadgetsAddHandler(inputEl, "click", GadgetsCreateCheckboxClosure(inputEl));
liEl.appendChild(inputEl);
//add the label
var labelEl = document.createElement("label");
Line 235 ⟶ 275:
liEl.appendChild(labelEl);
}
//fetch the saved checkboxes from the cookie
var checks = GadgetsGetCheckboxes();
for(var c = 0; c < checks.length; ++c)
{
//for each one that should be checked on page load, check the box, load, and activate it
//check the box, load, and activate it
document.getElementById("pt-jsgadgets-gadget" + checks[c]).checked = true;
GadgetsScriptLoad(checks[c]);
Line 246 ⟶ 287:
}
}
 
//register the comparison script with the window's load event
GadgetsAddHandler(window, "load", GadgetsActivate);
//</lang>
Anonymous user