User:Rovine/user contributions.js: Difference between revisions
Appearance
Content deleted Content added
reverting to older version to fix minor ui bug |
trial and improvement of ui |
||
Line 104: | Line 104: | ||
a.href = '#'; |
a.href = '#'; |
||
h3.onmouseover = function () {showMenu('opt-'+mid,findPos(cid,[0, |
h3.onmouseover = function () {showMenu('opt-'+mid,findPos(cid,[0,5]))}; |
||
h3.onmouseout = function () {hideMenu('opt-'+mid)}; |
h3.onmouseout = function () {hideMenu('opt-'+mid)}; |
||
Revision as of 09:18, 27 January 2015
/*********************************************************************
** ***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 **
** Documentation: [[User:Haza-w/Drop-down menus]] **
** **
*********************************************************************/
// "Fail gracefully" if skin not supported
switch (mw.config.get('skin')) {
case 'modern': case 'monobook': case 'vector':
// Global variables
var _cactions = {
admin: mw.config.get( 'wgUserGroups' ).join().indexOf('sysop') > -1 ? true : false,
areqs: [],
hovms: mw.config.get('skin') == 'vector' ? 50 : 400,
menus: [],
mouse: null,
pname: 'User:Rovine',
timer: [],
vectr: mw.config.get('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.charAt(0).toUpperCase() + mid.substr(1);
if (_cactions.vectr) {
var cid = 'p-' + mid;
var elements = {
div: document.createElement('div'),
h3: document.createElement('h3'),
span: document.createElement('span'),
a: document.createElement('a'),
txt: null
};
with (elements) {
div.id = cid;
div.className = 'vectorMenu';
txt = document.createTextNode(mtitle);
span.appendChild(txt); h3.appendChild(span);
a.href = '#';
h3.onmouseover = function () {showMenu('opt-'+mid,findPos(cid,[0,5]))};
h3.onmouseout = function () {hideMenu('opt-'+mid)};
span = document.createElement('span');
a.appendChild(span); h3.appendChild(a);
div.appendChild(h3);
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) {
var i;
if (typeof(conditionals) == 'undefined') {
for (i = 0; i < elements.length; i++) if (document.getElementById(elements[i])) document.getElementById(elements[i]).style.display = 'none';
}
else for (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';
}
// Page options hook
jQuery(function () {
if ( !mw.config.get( 'wgCanonicalSpecialPageName' ) ) {
with (_cactions) {
var script = mw.config.get( 'wgScript' ),
articleId = mw.config.get( 'wgArticleId')
menus[menus.length] = createMenu('Status',true,Array(
['c-p-somewhere', 'Somewhere', '#'],
articleId? ['c-p-online', 'Online', script+'?title='+pname+'/Status&action=edit&newstatus=Online'] :[] ,
articleId? ['c-p-offline', 'Offline', script+'?title=Special:Movepage/'+pname+'&action=view'] :[] ,
articleId? ['c-p-busy', 'Busy', script+'?title='+pname+'&action=watch'] :[] ,
articleId? ['c-p-school', 'In School', script+'?title='+pname+'&action=unwatch'] :[] ,
articleId? ['c-p-sleep', 'Sleeping', script+'?title='+pname+'&action=protect'] :[] ,
articleId? ['c-p-away', 'Away', script+'?title='+pname+'&action=unprotect'] :[] ,
articleId? ['c-p-wikibreak', 'On Wikibreak', script+'?title='+pname+'&action=delete'] :[] ,
articleId? ['c-p-holiday', 'On Holiday', script+'?title=Special:Undelete/'+pname+'&action=view'] :[] ,
articleId? ['c-p-working', 'Working', script+'?title='+pname+'&action=view&diff='+mw.config.get( 'wgCurRevisionId' )] :[] ,
articleId? ['c-p-huggle', 'Huggling', script+'?title='+pname+'&action=edit§ion=0'] :[] ,
articleId? ['c-p-office', 'At Office', 'http://en.wikichecker.com/article/?a='+pname] :[] ,
['c-p-purge', 'Purge cache', script+'?title='+pname+'&action=purge']
));
}
}
} );
}