मीडियाविकि:Gadget-dropdown-menus.js
स्वरूप
टिप्पणी सङ्ग्रह गरेपछि, परिवर्तन हेर्नको लागि तपाईंले आफ्नो ब्राउजरको क्याच बाईपास गर्नु पर्ने हुनसक्छ।
- फायरफक्स / सफारीमा: Shift कुञ्जी थिची राखेर Reload क्लिक गर्नुपर्छ, वा Ctrl-F5 वा Ctrl-R दबाउनुहोस् (म्याकमा ⌘-R)
- गुगल क्रोम: Ctrl-Shift-R कुञ्जी दबाउनुहोस् (म्याकमा ⌘-R)
- ओपेरा: Tools → Preferences मा गएर क्याश हटाउनुहोस्
- इन्टरनेट एक्सप्लोरर: Ctrl लाई थिची राखेर Refresh क्लिक गर्नुहोस् वा Ctrl-F5 थिच्नुहोस्
/*********************************************************************
** ***WARNING: GLOBAL GADGET FILE*** **
** any changes to this file will affect many users **
** please discuss changes on the talk page or at **
** [[Wikipedia talk:Gadget]] before editing **
** (consider dropping the script author a note as well...) **
** **
**********************************************************************
** Script: Drop-down menus **
** Version: 4.51g **
** Author: Haza-w **
** Modifier & Maintainer: Bhawani Gautam **
** **
*********************************************************************/
// "Fail gracefully" if skin not supported
switch (skin) {
case 'modern': case 'monobook': case 'vector':
// Global variables
var _cactions = {
admin: mw.config.get('wgUserGroups').join().indexOf('sysop') > -1 ? true : false,
areqs: [],
hovms: skin == 'vector' ? 50 : 400,
menus: [],
mouse: null,
pname: encodeURIComponent(mw.config.get('wgPageName')),
timer: [],
vectr: skin == 'vector' ? true : false
};
// Process XMLHttpRequests
function xhr(request,url,orsc) {
with (request) {
open('GET',url,true);
onreadystatechange = orsc;
send(null);
}
}
// Find absolute position of element
function findPos(eid,offset) {
var obj = document.getElementById(eid), pos = [0,0];
do with (obj) {
pos[0] += offsetLeft;
pos[1] += offsetTop;
} while (obj = obj.offsetParent);
pos[0] += offset[0]; pos[1] += offset[1];
return pos;
}
// Create menu div element
function createMenu(mid,vectorise,html) {
var menu = document.createElement('div');
with (menu) {
id = 'opt-' + mid;
className = 'ca-menu';
style.display = 'none';
}
menu.onmouseover = function () {showMenu('opt-'+mid)};
menu.onmouseout = function () {hideMenu('opt-'+mid)};
var elements = {
ul: document.createElement('ul'),
li: null,
a: null,
txt: null
};
with (elements) {
for (var i = 0; i < html.length; i++) if (html[i].length) {
li = document.createElement('li'); li.id = html[i][0];
a = document.createElement('a'); a.href = html[i][2];
txt = document.createTextNode(html[i][1]);
a.appendChild(txt); li.appendChild(a); ul.appendChild(li);
}
menu.appendChild(ul);
}
document.body.appendChild(menu);
if (vectorise) createTab(mid);
return 'opt-' + mid;
}
// Create cactions LI tab
function createTab(mid) {
var mtitle = mid[0].toUpperCase() + mid.substr(1);
if (_cactions.vectr) {
var cid = 'p-' + mid;
var elements = {
div: document.createElement('div'),
h5: document.createElement('h5'),
span: document.createElement('span'),
a: document.createElement('a'),
txt: null
};
with (elements) {
div.id = cid;
div.className = 'vectorMenu extraMenu';
txt = document.createTextNode(mtitle);
span.appendChild(txt); h5.appendChild(span);
a.href = '#';
a.onmouseover = function () {showMenu('opt-'+mid,findPos(cid,[0,40]))};
a.onmouseout = function () {hideMenu('opt-'+mid)};
span = document.createElement('span');
txt = document.createTextNode(mtitle);
span.appendChild(txt); a.appendChild(span); h5.appendChild(a);
div.appendChild(h5);
document.getElementById('right-navigation').insertBefore(div,document.getElementById('p-search'));
}
}
else {
var cid = 'ca-' + mid;
var elements = {
li: document.createElement('li'),
a: document.createElement('a'),
txt: document.createTextNode(mtitle)
};
with (elements) {
li.id = cid;
a.href = '#';
a.onmouseover = function () {showMenu('opt-'+mid,findPos(cid,[-10,20]))};
a.onmouseout = function () {hideMenu('opt-'+mid)};
a.appendChild(txt); li.appendChild(a);
document.getElementById('p-cactions').getElementsByTagName('div')[0].getElementsByTagName('ul')[0].appendChild(li);
}
}
}
// CSS hide elements
function hideElements(elements,conditionals) {
if (typeof(conditionals) == 'undefined') {
for (var i = 0; i < elements.length; i++) if (document.getElementById(elements[i])) document.getElementById(elements[i]).style.display = 'none';
}
else for (var i = 0; i < elements.length; i++) if (document.getElementById(elements[i])) {
document.getElementById(elements[i]).style.display = 'none';
if (conditionals[i]) document.getElementById(conditionals[i]).style.display = 'none';
}
}
// Show/hide menu functions
function showMenu(mid,pos) {
with (_cactions) {
mouse = mid;
if (pos) for (var i = 0; i < menus.length; i++) {
if (timer[menus[i]]) {
clearTimeout(timer[menus[i]]);
timer[menus[i]] = null;
}
if (mid.replace(/-[^-]+$/,'') == menus[i]) continue;
document.getElementById(menus[i]).style.display = 'none';
}
if (!timer[mid]) with (document.getElementById(mid).style) {
display = '';
if (pos) {
left = pos[0]+'px';
top = pos[1]+'px';
}
}
else {
clearTimeout(timer[mid]);
timer[mid] = null;
}
}
}
function hideMenu(mid) {
with (_cactions) {
if (mid == mouse.replace(/-[^-]+$/,'')) timer[mid] = null;
if (timer[mid]) {
timer[mid] = null;
document.getElementById(mid).style.display = 'none';
if (mid == mouse && mid.search(/opt-.*-/) != -1) document.getElementById(mid.replace(/-[^-]+$/,'')).style.display = 'none';
}
else timer[mid] = setTimeout('hideMenu(\''+mid+'\');',hovms);
}
}
// Delink element
function removeLink(eid) {
var element = document.getElementById(eid);
if (!element.getElementsByTagName('a').length) return false;
var a = element.getElementsByTagName('a')[0];
element.appendChild(a.removeChild(a.firstChild));
element.removeChild(a);
element.className = 'ca-disabled';
}
// User options hook
$(function () {
switch (mw.config.get('wgNamespaceNumber')) {
case 2: case 3: _cactions['uname'] = encodeURIComponent(mw.config.get('wgTitle').split('/')[0].replace(/ /g,'_'));
}
if (mw.config.get('wgCanonicalSpecialPageName') == 'Contributions') for (var i = 0, hl; hl = document.getElementById('contentSub').getElementsByTagName('a')[i]; i++) {
if (hl.href.indexOf('user=') > -1) {
_cactions['uname'] = hl.href.split('user=')[1].split('&')[0];
break;
}
}
if (_cactions.uname) {
with (_cactions) {
menus[menus.length] = createMenu('प्रयोगकर्ता',true,Array(
['c-u-logs', 'प्रयोगकर्ता लग>', '#'] ,
['c-u-rfx', 'RfX सितको लिङ्क>', '#'] ,
['c-u-blocks', 'रोकावट लग >', '#'] ,
['c-u-contribs', 'योगदान', mw.config.get('wgScript')+'?title=Special:Contributions/'+uname+'&action=view'] ,
['c-u-editcount', 'सम्पादन तथ्यांक', 'http://toolserver.org/~soxred93/count/index.php?lang=en&wiki=wikipedia&name='+uname.replace(/_/g,'+')] ,
['c-u-editsum', 'सम्पादन सारांश', 'http://toolserver.org/~soxred93/editsummary/index.php?lang=en&wiki=wikipedia&name='+uname.replace(/_/g,'+')] ,
['c-u-wcuser', 'सम्पादन विश्लेषण', 'http://en.wikichecker.com/user/?l=all&t='+uname] ,
['c-u-sul', 'वैश्विक खाताहरु', 'http://toolserver.org/~vvv/sulutil.php?user='+uname] ,
['c-u-subpages', 'उपपृष्ठ', mw.config.get('wgScript')+'?title=Special:PrefixIndex/User:'+uname+'/&action=view'] ,
['c-u-email', 'प्रयोगकर्तालाई ईमेल पठाउने', mw.config.get('wgScript')+'?title=Special:EmailUser/'+uname+'&action=view'] ,
['c-u-groups', 'प्रयोगकर्ता समूह', mw.config.get('wgScript')+'?title=Special:ListUsers&action=view&limit=1&username='+uname] ,
['c-u-rightslog', 'प्रयोगकर्ता अधिकार लग', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=rights&page=User:'+uname]
));
menus[menus.length] = createMenu('प्रयोगकर्ता-लगहरु',false,Array(
['c-ul-logs', 'सबै सार्वजनिक चिट्ठाहरु', mw.config.get('wgScript')+'?title=Special:Log&action=view&user='+uname] ,
['c-ul-blocks', 'ब्लक सूची', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=block&user='+uname] ,
['c-ul-deletes', 'हटाउने सूची', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=delete&user='+uname] ,
['c-ul-moves', 'स्थानान्तरण सूची', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=move&user='+uname] ,
['c-ul-patrols', 'अवलोकन सूची', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=patrol&user='+uname] ,
['c-ul-protects', 'सुरक्षा सूची', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=protect&user='+uname] ,
['c-ul-uploads', 'अपलोड्स', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=upload&user='+uname] ,
['c-ul-rights', 'प्रयोगकर्ता अधिकार', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=rights&user='+uname]
));
menus[menus.length] = createMenu('प्रयोगकर्ता-rfx',false,Array(
['c-ux-rfa', 'RfAs', mw.config.get('wgScript')+'?title=Special:PrefixIndex/Wikipedia:Requests_for_adminship/'+uname+'&action=view'] ,
['c-ux-rfb', 'RfBs', mw.config.get('wgScript')+'?title=Special:PrefixIndex/Wikipedia:Requests_for_bureaucratship/'+uname+'&action=view'] ,
['c-ux-rfar', 'RfAr', mw.config.get('wgScript')+'?title=Wikipedia:Requests_for_arbitration/'+uname+'&action=view'] ,
['c-ux-rfc', 'RfC', mw.config.get('wgScript')+'?title=Wikipedia:Requests_for_comment/'+uname+'&action=view'] ,
['c-ux-rfcu', 'RfCU', mw.config.get('wgScript')+'?title=Wikipedia:Requests_for_checkuser/Case/'+uname+'&action=view'] ,
['c-ux-spi', 'SPI', mw.config.get('wgScript')+'?title=Wikipedia:Sockpuppet_investigations/'+uname+'&action=view']
));
menus[menus.length] = createMenu('प्रयोगकर्ता-रोक',false,Array(
admin? ['c-ub-block', 'प्रयोगकर्तालाई रोक्ने', mw.config.get('wgScript')+'?title=Special:BlockIP/'+uname+'&action=view'] :[] ,
admin? ['c-ub-unblock', 'प्रयोगकर्ता रोक रद्द गर्ने', mw.config.get('wgScript')+'?title=Special:IPBlockList&action=unblock&ip='+uname] :[] ,
['c-ub-ipblock', 'ब्लक सूची हेर्ने', mw.config.get('wgScript')+'?title=Special:IPBlockList&action=view&ip='+uname] ,
['c-ub-blocklog', 'ब्लक लग', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=block&page=User:'+uname]
));
if (sajax_init_object() && true) {
if (uname.search(/(?:\d{1,3}\.){3}\d{1,3}/) == 0) {
areqs['ip'] = new sajax_init_object();
xhr(areqs['ip'],wgScriptPath+'/api.php?format=json&action=query&list=blocks&bkusers='+uname+'&bkprop=id&xhr='+Math.random(),function () {
with (areqs['ip']) if (readyState == 4 && status == 200) {
var api = eval('('+responseText+')');
if (api.query.blocks.length) {
hideElements(['c-ub-block']);
document.getElementById('c-ub-ipblock').getElementsByTagName('a')[0].style.color = '#EE1111';
}
else {
hideElements(['c-ub-unblock']);
removeLink('c-ub-ipblock');
}
}
} );
}
else {
areqs['user'] = new sajax_init_object();
xhr(areqs['user'],wgScriptPath+'/api.php?format=json&action=query&list=users&ususers='+uname+'&usprop=blockinfo|groups&xhr='+Math.random(),function () {
with (areqs['user']) if (readyState == 4 && status == 200) {
var api = eval('('+responseText+')');
with (api.query.users[0]) {
if (typeof(missing) != 'undefined') hideElements(['ca-user']);
else {
if (typeof(blockedby) != 'undefined') {
hideElements(['c-ub-block']);
document.getElementById('c-ub-ipblock').getElementsByTagName('a')[0].style.color = '#EE1111';
}
else {
hideElements(['c-ub-unblock']);
removeLink('c-ub-ipblock');
}
if (typeof(groups) == 'undefined' || groups.join().indexOf('sysop') == -1) hideElements(['c-ul-blocks','c-ul-deletes','c-ul-protects','c-ul-rights']);
}
}
}
} );
areqs['rfa'] = new sajax_init_object();
xhr(areqs['rfa'],wgScriptPath+'/api.php?format=json&action=query&list=allpages&apprefix=Requests_for_adminship%2F'+uname+'&apnamespace=4&aplimit=1&xhr='+Math.random(),function () {
with (areqs['rfa']) if (readyState == 4 && status == 200) {
var api = eval('('+responseText+')');
if (!api.query.allpages.length) removeLink('c-ux-rfa');
}
} );
areqs['rfb'] = new sajax_init_object();
xhr(areqs['rfb'],wgScriptPath+'/api.php?format=json&action=query&list=allpages&apprefix=Requests_for_bureaucratship%2F'+uname+'&apnamespace=4&aplimit=1&xhr='+Math.random(),function () {
with (areqs['rfb']) if (readyState == 4 && status == 200) {
var api = eval('('+responseText+')');
if (!api.query.allpages.length) removeLink('c-ux-rfb');
}
} );
areqs['uspace'] = new sajax_init_object();
xhr(areqs['uspace'],wgScriptPath+'/api.php?format=json&action=query&list=allpages&apprefix='+uname+'%2F&apnamespace=2&aplimit=1&xhr='+Math.random(),function () {
with (areqs['uspace']) if (readyState == 4 && status == 200) {
var api = eval('('+responseText+')');
if (!api.query.allpages.length) removeLink('c-u-subpages');
}
} );
}
areqs['rfx'] = new sajax_init_object();
xhr(areqs['rfx'],wgScriptPath+'/api.php?format=json&action=query&titles=Wikipedia:Requests_for_arbitration/'+uname+'|Wikipedia:Requests_for_comment/'+uname+'|Wikipedia:Requests_for_checkuser/Case/'+uname+'|Wikipedia:Sockpuppet_investigations/'+uname+'&letype=block&letitle=User:'+uname+'&prop=info&xhr='+Math.random(),function () {
with (areqs['rfx']) if (readyState == 4 && status == 200) {
var api = eval('('+responseText+')');
for (i in api.query.pages) switch (api.query.pages[i].title.split('/')[0]) {
case 'Wikipedia:Requests for arbitration': if (typeof(api.query.pages[i].missing) != 'undefined') removeLink('c-ux-rfar'); break;
case 'Wikipedia:Requests for comment': if (typeof(api.query.pages[i].missing) != 'undefined') removeLink('c-ux-rfc'); break;
case 'Wikipedia:Requests for checkuser': if (typeof(api.query.pages[i].missing) != 'undefined') removeLink('c-ux-rfcu'); break;
case 'Wikipedia:Sockpuppet investigations': if (typeof(api.query.pages[i].missing) != 'undefined') removeLink('c-ux-spi'); break;
}
}
} );
areqs['ublocks'] = new sajax_init_object();
xhr(areqs['ublocks'],wgScriptPath+'/api.php?format=json&action=query&list=logevents&letype=block&letitle=User:'+uname+'&lelimit=1&xhr='+Math.random(),function () {
with (areqs['ublocks']) if (readyState == 4 && status == 200) {
var api = eval('('+responseText+')');
if (!api.query.logevents.length) removeLink('c-ub-blocklog');
}
} );
}
else hideElements(['c-ub-ipblock','c-ul-blocks','c-ul-deletes','c-ul-protects','c-ul-rights']);
}
hideElements(['t-contributions','t-log','t-emailuser']);
document.getElementById('c-u-logs').onmouseover = function () {showMenu('opt-user-logs',findPos('c-u-logs',[40,0]))};
document.getElementById('c-u-logs').onmouseout = function () {hideMenu('opt-user-logs')};
document.getElementById('c-u-logs').style.fontWeight = 'bold';
document.getElementById('c-u-rfx').onmouseover = function () {showMenu('opt-user-rfx',findPos('c-u-rfx',[40,0]))};
document.getElementById('c-u-rfx').onmouseout = function () {hideMenu('opt-user-rfx')};
document.getElementById('c-u-rfx').style.fontWeight = 'bold';
document.getElementById('opt-user-rfx').style.width = '50px';
document.getElementById('c-u-blocks').onmouseover = function () {showMenu('opt-user-blocks',findPos('c-u-blocks',[40,0]))};
document.getElementById('c-u-blocks').onmouseout = function () {hideMenu('opt-user-blocks')};
document.getElementById('c-u-blocks').style.fontWeight = 'bold';
if (_cactions.uname.search(/(?:\d{1,3}\.){3}\d{1,3}/) == 0) hideElements(['c-u-logs','c-ux-rfa','c-ux-rfb','c-u-editcount','c-u-editsum','c-u-wcuser','c-u-subpages','c-u-email','c-u-groups','c-u-rightslog']);
}
} );
// Page options hook
$(function () {
if (!mw.config.get('wgCanonicalSpecialPageName')) {
with (_cactions) {
menus[menus.length] = createMenu('पृष्ठ ',true,Array(
['c-p-logs', 'पृष्ठ लग >', '#'],
wgArticleId? ['c-p-history', 'इतिहास', mw.config.get('wgScript')+'?title='+pname+'&action=history'] :[] ,
wgArticleId? ['c-p-move', 'स्थानान्तरण गर्ने', mw.config.get('wgScript')+'?title=Special:Movepage/'+pname+'&action=view'] :[] ,
!vectr? ['c-p-watch', 'अवलोकन सूचीमा हाल्ने', mw.config.get('wgScript')+'?title='+pname+'&action=watch'] :[] ,
!vectr? ['c-p-unwatch', 'अवलोकन सूचीबाट हटाउने', mw.config.get('wgScript')+'?title='+pname+'&action=unwatch'] :[] ,
admin? ['c-p-protect', 'सुरक्षित गर्ने', mw.config.get('wgScript')+'?title='+pname+'&action=protect'] :[] ,
admin? ['c-p-unprotect', 'सुरक्षा खारेज गर्ने', mw.config.get('wgScript')+'?title='+pname+'&action=unprotect'] :[] ,
admin? ['c-p-delete', 'पृष्ठ हटाउने', mw.config.get('wgScript')+'?title='+pname+'&action=delete'] :[] ,
admin? ['c-p-undelete', 'पुनर्स्थापित गर्ने', mw.config.get('wgScript')+'?title=Special:Undelete/'+pname+'&action=view'] :[] ,
wgArticleId? ['c-p-diff', 'भर्खरको अन्तर', mw.config.get('wgScript')+'?title='+pname+'&action=view&diff='+wgCurRevisionId] :[] ,
wgArticleId? ['c-p-editzero', 'प्रयोगकर्ता पृष्ठ सम्पादन', mw.config.get('wgScript')+'?title='+pname+'&action=edit§ion=0'] :[] ,
wgArticleId? ['c-p-wcpage', 'पृष्ठ विश्लेषण', 'http://en.wikichecker.com/article/?a='+pname] :[] ,
['c-p-purge', 'क्याश खाली गर्ने', mw.config.get('wgScript')+'?title='+pname+'&action=purge']
));
menus[menus.length] = createMenu('पृष्ठ-लगहरु',false,Array(
['c-pl-logs', 'सबै पृष्ठ लग', mw.config.get('wgScript')+'?title=Special:Log&action=view&page='+pname] ,
['c-pl-deletes', 'हटाउने सूची', mw.config.get('wgScript')+'?title=Special:Log&type=delete&page='+pname] ,
['c-pl-moves', 'स्थानान्तरण सूची', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=move&page='+pname] ,
wgArticleId? ['c-pl-patrols', 'अवलोकनमा राखिएका पृष्ठ', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=patrol&page='+pname] :[] ,
['c-pl-protects', 'सुरक्षित गरिएका पृष्ठ', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=protect&page='+pname] ,
mw.config.get('wgNamespaceNumber') == 6? ['c-pl-uploads', 'अपलोड लग', mw.config.get('wgScript')+'?title=Special:Log&action=view&type=upload&page='+pname] :[]
));
}
hideElements(['ca-protect','ca-unprotect','ca-delete','ca-undelete','ca-history','ca-move'],['c-p-unprotect','c-p-protect','c-p-undelete','p-c-delete']);
if (!_cactions.vectr) hideElements(['ca-watch','ca-unwatch'],['c-p-unwatch','c-p-watch']);
document.getElementById('c-p-logs').onmouseover = function () {showMenu('opt-page-logs',findPos('c-p-logs',[40,0]))};
document.getElementById('c-p-logs').onmouseout = function () {hideMenu('opt-page-logs')};
document.getElementById('c-p-logs').style.fontWeight = 'bold';
}
} );
}