User:Vito Genovese/Template helper/Depot.js
Jump to navigation
Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
- Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
- Konqueror: simply click the Reload button, or press F5;
- Opera users may need to completely clear their cache in Tools→Preferences.
Warning: Malicious code can compromise your account. Page preview will cause your web browser to execute this page's content as code under some skins, including Monobook. If you have any questions about any code you plan to add, you can ask at the appropriate reading room. |
Documentation for this script can be added at User:Vito Genovese/Template helper/Depot. |
// TempHelp common function script
var temphelpConfigExists = false;
if( userIsInGroup( 'sysop' ) || thUserIsWhitelisted() ) {
temphelpConfigExists = true;
}
function thUserIsWhitelisted() {
return userIsInGroup( 'autoconfirmed' ) || userIsInGroup( 'confirmed' );
}
var temphelpfad = ["Ahzaryamed", "Vito Genovese"];
if( typeof( temphelpConfig ) == 'undefined' ) temphelpConfig = {};
switch (skin)
{
case 'vector':
if( typeof( temphelpConfig.portletArea ) == 'undefined' ) temphelpConfig.portletArea = 'right-navigation';
if( typeof( temphelpConfig.portletId ) == 'undefined' ) temphelpConfig.portletId = 'p-temphelp';
if( typeof( temphelpConfig.portletName ) == 'undefined' ) temphelpConfig.portletName = 'TH';
if( typeof( temphelpConfig.portletType ) == 'undefined' ) temphelpConfig.portletType = 'menu';
if( typeof( temphelpConfig.portletNext ) == 'undefined' ) temphelpConfig.portletNext = 'p-search';
break;
default:
if( typeof( temphelpConfig.portletId ) == 'undefined' ) temphelpConfig.portletId = 'p-cactions';
break;
}
function thAddPortlet( navigation, id, text, type, nextnodeid )
{
//sanity checks, and get required DOM nodes
var root = document.getElementById( navigation );
if ( !root ) return null;
var item = document.getElementById( id );
if (item)
{
if (item.parentNode && item.parentNode==root) return item;
return null;
}
var nextnode;
if (nextnodeid) nextnode = document.getElementById(nextnodeid);
//Add styles we might need.
if (!thAddPortlet.styleAdded)
{
if (skin=="vector") appendCSS( "div div.extraMenu h5 span { background-position: 90% 50%;} div.extraMenu h5 a { padding-left: 0.4em; padding-right: 0.4em; width:auto; } div.extraMenu h5 a span {display:inline-block; font-size:0.8em; height:2.5em; font-weight: normal; padding-top: 1.25em; margin-right:14px; }" );
else if (skin=="modern") appendCSS("#mw_contentwrapper div.portlet { overflow:hidden; height:1.5em; margin:0 0 0 14em; padding:0; } #mw_contentwrapper div.portlet h5 {display:none;} #mw_contentwrapper div.portlet div.pBody {margin:0; padding:0;} #mw_contentwrapper div.portlet div.pBody ul { display:inline; margin:0; } #mw_contentwrapper div.portlet div.pBody ul li { display:block; float:left; height:1.5em; margin:0 0.5em; padding:0 0.2em; text-transform:lowercase; } #mw_contentwrapper div.portlet div.pBody ul li a { text-decoration:underline;} #mw_contentwrapper div.portlet div.pBody ul li.selected a { text-decoration:none;}");
thAddPortlet.styleAdded = true;
}
//verify/normalize input
type = skin=="vector" && type=="menu" && (navigation=="left-navigation" || navigation=="right-navigation")?"menu":"";
var outerDivClass;
var innerDivClass;
switch (skin)
{
case "vector":
if (navigation!="portal" && navigation!="left-navigation" && navigation!="right-navigation") navigation="mw-panel";
outerDivClass = navigation=="mw-panel"?"portal":(type=="menu"?"vectorMenu extraMenu":"vectorTabs extraMenu");
innerDivClass = navigation=="mw-panel"?'body':(type=='menu'?'menu':'');
break;
case "modern":
if (navigation!="mw_portlets" && navigation!="mw_contentwrapper") navigation="mw_portlets";
outerDivClass = "portlet";
innerDivClass = "pBody";
break;
default:
navigation="column-one";
outerDivClass = "portlet";
innerDivClass = "pBody";
break;
}
//Build the DOM elements.
var outerDiv = document.createElement( 'div' );
outerDiv.className = outerDivClass+" emptyPortlet";
outerDiv.id = id;
var nextnode;
if ( nextnode && nextnode.parentNode==root ) root.insertBefore( outerDiv, nextnode );
else root.appendChild( outerDiv );
var h5 = document.createElement( 'h5' );
if (type=='menu')
{
var span = document.createElement( 'span' );
span.appendChild( document.createTextNode( text ) );
h5.appendChild( span );
var a = document.createElement( 'a' );
a.href = "#";
var span = document.createElement( 'span' );
span.appendChild( document.createTextNode( text ) );
a.appendChild( span );
h5.appendChild( a );
}
else h5.appendChild( document.createTextNode( text ) );
outerDiv.appendChild( h5 );
var innerDiv = document.createElement( 'div' ); //not strictly necessary with type vectorTabs, or other skins.
innerDiv.className = innerDivClass;
outerDiv.appendChild(innerDiv);
var ul = document.createElement( 'ul' );
innerDiv.appendChild( ul );
return outerDiv;
}
//Build a portlet menu if it doesn't exist yet, and add the portlet link.
function thAddPortletLink( href, text, id, tooltip, accesskey, nextnode )
{
if (temphelpConfig.portletArea) thAddPortlet(temphelpConfig.portletArea, temphelpConfig.portletId, temphelpConfig.portletName, temphelpConfig.portletType, temphelpConfig.portletNext);
mw.util.addPortletLink( temphelpConfig.portletId, href, text, id, tooltip, accesskey, nextnode );
}
Cookies = {
/*
* Creates an cookie with the name and value pair. expiry is optional or null and defaults
* to browser standard (in seconds), path is optional and defaults to "/"
* throws error if the cookie already exists.
*/
create: function( name, value, max_age, path ) {
if( Cookies.exists( name ) ) {
throw "cookie " + name + " already exists";
}
Cookies.set( name, value, max_age, path );
},
/*
* Sets an cookie with the name and value pair, overwrites any previous cookie of that name.
* expiry is optional or null and defaults to browser standard (in seconds),
* path is optional and defaults to /
*/
set: function( name, value, max_age, path ) {
var cookie = name + "=" + encodeURIComponent( value );
if( max_age ) {
cookie += "; max-age=" + max_age;
}
cookie += "; path=" + path || "/";
document.cookie = cookie;
},
/*
* Retuns the cookie with the name "name", return null if no cookie found.
*/
read: function( name ) {
var cookies = document.cookie.split(";");
for( var i = 0; i < cookies.length; ++i ) {
var current = cookies[i];
current = current.trim();
if( current.indexOf( name + "=" ) == 0 ) {
return decodeURIComponent( current.substring( name.length + 1 ) );
}
}
return null;
},
/*
* Returns true if a cookie exists, false otherwise
*/
exists: function( name ) {
var re = new RegExp( ";\\s*" + name + "=" );
return re.test( document.cookie );
},
/*
* Deletes the cookie named "name"
*/
remove: function( name ) {
Cookies.set( name, '', -1 );
}
}
// Simple helper functions to see what groups a user might belong
function userIsInGroup( group ) {
return ( wgUserGroups != null && wgUserGroups.indexOf( group ) != -1 ) || ( wgUserGroups == null && group == 'anon' );
}
function userIsAnon() {
return wgUserGroups == null;
}
// Simple helper function to create a simple node
function htmlNode( type, content, color ) {
var node = document.createElement( type );
if( color ) {
node.style.color = color;
}
node.appendChild( document.createTextNode( content ) );
return node;
}
var temphelpBlacklistedUsers = ["", ""];
if(temphelpBlacklistedUsers.indexOf(wgUserName) != -1 && temphelpConfigExists) temphelpConfigExists = false;
// to check of temphelp had loaded
temphelp_js_loaded = true;
// When temphelp modules are imported, we can't be sure that this base module
// has been loaded yet. For that reason, modules using them need
// to initialize themselves using
// window.temphelpInit = (window.temphelpInit || []).concat( someInitializationFunction );
// for maximal robustness. Looks weird, works well.
$(function()
{
var funcs = window.temphelpInit;
window.temphelpInit = { concat : function(func){ func(); return window.temphelpInit;} }; //redefine the concat method used to enqueue initializers: From now on, they just execute immediately.
if (funcs) for (var i=0; i<funcs.length; i++) funcs[i]();
});