User:Mwn3d/monobook.js: Difference between revisions

m
Updating
m (Grabbing a bug fix)
m (Updating)
 
Line 1:
//<lang javascript>
/*========================================
This comparison script was written by
Line 5 ⟶ 6:
Midori 0.2.2
========================================*/
 
var gadgetsAvailable = [
{
Line 14 ⟶ 15:
"&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"
},
{
Line 24 ⟶ 33:
}
];
 
function GadgetsAddHandler(el, handlerType, func)
{
Line 41 ⟶ 50:
}
}
 
function GadgetsScriptLoad(g)
{
Line 55 ⟶ 64:
}
}
 
function GadgetsScriptActivate(g)
{
Line 70 ⟶ 79:
}
}
 
function GadgetsScriptDeactivate(g)
{
Line 86 ⟶ 95:
}
}
 
function GadgetsCreateCheckboxClosure(el)
{
Line 93 ⟶ 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 108 ⟶ 117:
};
}
 
function GadgetsMouseOver()
{
Line 114 ⟶ 123:
document.getElementById("pt-jsgadgets-list").style.display = "block";
}
 
function GadgetsMouseOut()
{
Line 120 ⟶ 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)
Line 137 ⟶ 146:
}
}
//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();
}
 
function GadgetsGetCheckboxes()
{
Line 158 ⟶ 167:
}
var endPos = fullCookie.indexOf(";", gadgetsPos);
//split the gadget IDs by comma
var jsGadgets = fullCookie.substring(gadgetsPos + ("jsGadgets=").length,
(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
Line 180 ⟶ 189:
return checkIndices;
}
 
function GadgetsActivate()
{
Line 202 ⟶ 211:
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,
Line 210 ⟶ 219:
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 228 ⟶ 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
Line 236 ⟶ 245:
zEl.style.zIndex = 100;
}
//add each of the gadgets to the list
for(var m = 0; m < gadgetsAvailable.length; ++m)
Line 249 ⟶ 258:
liEl.style.margin = 0;
liEl.style.padding = 0;
//add the checkbox
var inputEl = document.createElement("input");
Line 258 ⟶ 267:
GadgetsAddHandler(inputEl, "click", GadgetsCreateCheckboxClosure(inputEl));
liEl.appendChild(inputEl);
//add the label
var labelEl = document.createElement("label");
Line 266 ⟶ 275:
liEl.appendChild(labelEl);
}
//fetch the saved checkboxes from the cookie
var checks = GadgetsGetCheckboxes();
Line 278 ⟶ 287:
}
}
 
//register the comparison script with the window's load event
GadgetsAddHandler(window, "load", GadgetsActivate);
//</lang>
Anonymous user