MediaWiki:Common.js: Difference between revisions
Jump to navigation
mNo edit summary |
(Sidebar) |
||
Line 1: | Line 1: | ||
/ * Any JavaScript here will be loaded for all users on every page load. * / | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
document.write ("<script src='/index.php?title=Global.js&action=raw&smaxage=0&ctype=text/javascript' type='text/javascript'> </ script>"); | document.write("<script src='/index.php?title=Global.js&action=raw&smaxage=0&ctype=text/javascript' type='text/javascript'></script>"); | ||
importScript_ = | importScript_ = importScript | ||
save_sidebar | // Makes the sidebar foldable (by Menidan) | ||
var sidebar_settings = JSON.parse (localStorage.getItem ("sidebar_settings")) || {}; | |||
function save_sidebar () { | |||
localStorage.setItem ("sidebar_settings", JSON.stringify (sidebar_settings)); | localStorage.setItem ("sidebar_settings", JSON.stringify (sidebar_settings)); | ||
} | } | ||
set_sidebar | function set_sidebar (id, folded) { | ||
if (document.getElementById (id). parentElement.id! = "column-one") | if (document.getElementById (id).parentElement.id != "column-one") | ||
return; | return; | ||
if (folded) | if (folded) | ||
sidebar_settings [id] = true; | sidebar_settings [id] = true; | ||
else | else | ||
sidebar_settings | delete sidebar_settings [id]; | ||
save_sidebar (); | save_sidebar (); | ||
} | } | ||
var fold = "http://wiki.de.grepolis.com/images/7/7e/Einklappen.png"; | var fold = "http://wiki.de.grepolis.com/images/7/7e/Einklappen.png"; | ||
unfold | var unfold = "http://wiki.de.grepolis.com/images/0/06/Ausklappen.png"; | ||
sidebar_click | function sidebar_click (node) { | ||
var content = $ (node.parentElement.lastElementChild); | var content = $ (node.parentElement.lastElementChild); | ||
if (content.css ("display") == "none") { | if (content.css ("display") == "none") { | ||
Line 31: | Line 32: | ||
node.firstElementChild.src = fold; | node.firstElementChild.src = fold; | ||
set_sidebar (node.parentElement.id, false); | set_sidebar (node.parentElement.id, false); | ||
} else { | |||
content.css ("display", "none"); | content.css ("display", "none"); | ||
node.firstElementChild.alt = "[+]"; | node.firstElementChild.alt = "[+]"; | ||
Line 40: | Line 41: | ||
} | } | ||
sidebar_links | var sidebar_links = $ ("#column-one .generated-sidebar.portlet h5").slice (1).replaceWith (function () { | ||
if (sidebar_settings [this.parentElement.id]) | if (! sidebar_settings [this.parentElement.id]) | ||
return $ ('<a href="#" style="text-align:center"> <img src="' + fold +'" style="float:left" alt="[-]" /> <h5 > '+ this.innerHTML +' </ h5> </ a> '). click (function () { | return $ ('<a href="#" style="text-align:center"><img src="' + fold + '" style="float:left" alt="[-]" /><h5>' + this.innerHTML + '</h5></a>').click (function () { | ||
sidebar_click | return sidebar_click (this); | ||
}); | }); | ||
$ (this.nextElementSibling).css ("display", "none"); | |||
return $ ('<a href="#" style="text-align:center"> <img src="' + unfold +'" style="float:left" alt="[+]" /> <h5 > '+ this.innerHTML +' </ h5> </ a> '). click (function () { | return $ ('<a href="#" style="text-align:center"><img src="' + unfold + '" style="float:left" alt="[+]" /><h5>' + this.innerHTML + '</h5></a>').click (function () { | ||
sidebar_click | return sidebar_click (this); | ||
}); | }); | ||
}); | }); | ||
console.log ("sidebar ready"); | console.log ("sidebar ready"); | ||
Revision as of 12:14, 1 November 2013
/* Any JavaScript here will be loaded for all users on every page load. */ document.write("<script src='/index.php?title=Global.js&action=raw&smaxage=0&ctype=text/javascript' type='text/javascript'></script>"); importScript_ = importScript // Makes the sidebar foldable (by Menidan) var sidebar_settings = JSON.parse (localStorage.getItem ("sidebar_settings")) || {}; function save_sidebar () { localStorage.setItem ("sidebar_settings", JSON.stringify (sidebar_settings)); } function set_sidebar (id, folded) { if (document.getElementById (id).parentElement.id != "column-one") return; if (folded) sidebar_settings [id] = true; else delete sidebar_settings [id]; save_sidebar (); } var fold = "http://wiki.de.grepolis.com/images/7/7e/Einklappen.png"; var unfold = "http://wiki.de.grepolis.com/images/0/06/Ausklappen.png"; function sidebar_click (node) { var content = $ (node.parentElement.lastElementChild); if (content.css ("display") == "none") { content.css ("display", "block"); node.firstElementChild.alt = "[-]"; node.firstElementChild.src = fold; set_sidebar (node.parentElement.id, false); } else { content.css ("display", "none"); node.firstElementChild.alt = "[+]"; node.firstElementChild.src = unfold; set_sidebar (node.parentElement.id, true); } return false; } var sidebar_links = $ ("#column-one .generated-sidebar.portlet h5").slice (1).replaceWith (function () { if (! sidebar_settings [this.parentElement.id]) return $ ('<a href="#" style="text-align:center"><img src="' + fold + '" style="float:left" alt="[-]" /><h5>' + this.innerHTML + '</h5></a>').click (function () { return sidebar_click (this); }); $ (this.nextElementSibling).css ("display", "none"); return $ ('<a href="#" style="text-align:center"><img src="' + unfold + '" style="float:left" alt="[+]" /><h5>' + this.innerHTML + '</h5></a>').click (function () { return sidebar_click (this); }); }); console.log ("sidebar ready");