ميډياويکي:Navbox.js
يادښت: د غوره توبونو د خوندي کولو وروسته، خپل د کتنمل (بروزر) ساتل شوې حافظه تازه کړی.د نور تفصيل لپاره د غځول په تنۍ کلېک وکړئ.
- فايرفاکس/ سفري: په دې کتنمل کې د Reload د ټکوهلو په وخت د Shift تڼۍ نيولې وساتی، او يا هم Ctrl-F5 يا Ctrl-Rتڼۍ کېښکاږۍ (په Apple Mac کمپيوټر باندې ⌘-R کېښکاږۍ)
- گووگل کروم: په دې کتنمل کې د Ctrl-Shift-R تڼۍ کېښکاږۍ (د مک لپاره ⌘-Shift-R)
- انټرنټ اېکسپلورر: په دې کتنمل کې د Refresh د ټکوهلو په وخت کې د Ctrl تڼۍ کېښکاږلې ونيسۍ، او يا هم د Ctrl-F5 تڼۍ کېښکاږۍ
- اوپرا: په دې کتنمل کې د خپل براوزر ساتل شوې حافظه پدې توگه سپينولی شی Tools→Preferences
لاسوند[جوړول]
/* Adapt a list structure and use it as a navigational aid **************************************
*
* Description: Gives a list some additional structuring and a collapse/expand functionality
* Maintainers: [[User:Jeblad]]
*/
// build an opaque function object
(function(mw, $, undefined){
// get the locally stored objects, clear out the objects on errors
var max = 128;
var values = {};
try {
values = JSON.parse( window.localStorage.getItem("navbox-items-value") || '{}' );
}
catch (e) {
window.localStorage.setItem("navbox-items-value", '{}' );
}
// private method for local storage
function store(key, idx, state) {
// only check whats the state
if (state === undefined)
return (values[key] ? values[key][idx] : null);
// build a copy where we start with our value and skip any later duplicates
var obj = {};
obj[key] = [];
obj[key][idx] = state;
var count = 0;
for (var x in values) {
if (x === key) {
if (!obj[x]) obj[x] = [];
for (var y in values[x])
if (!obj[x][y])
obj[x][y]=values[x][y];
}
else
obj[x]=values[x];
if (max<count++)
continue;
}
values = obj;
// rebuild indexes for local storage
var a = [];
for (var x in values) {
var b = [];
for (var y in values[x])
b.push('"'+values[x][y]+'"');
a.push('"'+x+'":['+b.join(',')+']');
}
window.localStorage.setItem("navbox-items-value", '{'+a.join(',')+'}' );
// return our set state
return state;
}
// worker process
$(function() {
// cache our navboxes
var navbox = $('div.statbox');
// we're running so remove no-script class
navbox
.removeClass('no-script');
// identify lead ins
navbox
.find('dd')
.find('ul,ol')
.each(function(i, el) {
var obj = el.previousSibling;
while (obj && !/\S/.test(obj.nodeValue))
obj = obj.previousSibling;
if (obj)
$(el)
.addClass('lead-in');
});
// is collapsible navigation enabled?
if (mw.config.get('wgVectorEnabledModules') && mw.config.get('wgVectorEnabledModules')['collapsiblenav']) {
// identify collapsible navigations
navbox
.addClass('collapsible');
// identify collapsed state and set up handlers
navbox
.find('dt')
.each(function(i, el){
var obj = el.nextSibling;
while (obj && obj.nodeType != 1)
obj = obj.nextSibling;
if (obj && obj.nodeName) {
$(el)
.addClass(function(index, currentClass){
var matches = $(el).closest('.navbox').attr('class').match(/navbox-([-\w]+)/);
var idx = $(this).closest('dl').prevAll('dl').length; // not sure
if (matches && 1<matches.length && store(matches[1], idx) == 'expanded') {
$(el)
.nextUntil('dt')
.css('display', 'block');
return 'expanded';
}
else return 'collapsed';
})
.wrapInner('<span class="title"/>')
.click(function(){
var matches = $(this).closest('.navbox').attr('class').match(/navbox-([-\w]+)/);
var idx = $(this).closest('dl').prevAll('dl').length; // not sure
$(this)
.closest('dt')
.toggleClass('collapsed expanded')
.each(function(i, el){
if (matches && 1<matches.length)
store(matches[1], idx, $(el).hasClass('collapsed') ? 'collapsed' : 'expanded');
})
.nextUntil('dt')
.slideToggle();
});
}
})
}
});
})(mediaWiki, jQuery);