User:Emma/common.js: Difference between revisions

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
mNo edit summary
No edit summary
Line 39: Line 39:
});
});
   
   
showSubpagesCB(obj) {
var umstyle = document.createElement('style');
var pages = obj.query && obj.query.allpages;
umstyle.type = 'text/css';
umstyle.rel = 'stylesheet';
if (umstyle.styleSheet) umstyle.styleSheet.cssText = '.usermessage {display:none;}'
else umstyle.appendChild(document.createTextNode('.usermessage {display:none;}'))
document.getElementsByTagName('head')[0].appendChild(umstyle);
   
   
if ( !pages || pages.length == 0) {
/* If the page contains a usermessage div, style the pt-mytalk. */
$j('#deleteconfirm, #mw-img-eleteconfirm').append('<h2>Subpages</h2><p>No subpages exist for this page.</p>');
return;
}
   
   
var subpages = '<ul>';
addOnloadHook(gotNewMessages);
var cut = wgPageName.length+1, parent;
function gotNewMessages() {
  var um = getElementsByClassName(document.getElementById('bodyContent'),'div','usermessage');
for (var pg in pages) {
  if(um.length == 0) return
if ( !pages.hasOwnProperty(pg) ) {
  var links = um[0].getElementsByTagName('a');
continue;
  for(var i=0;i<links.length;i++) {
}
    if(links[i].href.indexOf('diff=cur') != -1) {
subpages += '<li>'
      var penultimate = links[i].href;
+ '<a href="' + wgArticlePath.replace('$1', pages[pg].title) + '">' + pages[pg].title.substr(cut) + '</a>'
    }
+ ' (<a href="' + wgScript + '?title=' + encodeURIComponent(pages[pg].title)
  }
.replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' )
  var mytalk = document.getElementById('pt-mytalk');
.replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /~/g, '%7E' )
  if(!mytalk) return
.replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' )
 
+ '&action=delete">delete</a>)'
  mytalk.style.fontWeight = 'bold';
+ '</li>';
  var img = 'http://zeldadungeon.net/wiki/thumb.php?f=Triforce_(Ocarina_of_Time).png&w=13';
}
  if(penultimate) {
    /* add a linked icon if the message contains a diff=cur */
subpages += '</ul>';
    var plink = document.createElement('a');
$j('#deleteconfirm, #mw-img-eleteconfirm').append('<h2>Subpages</h2>'+subpages);
    plink.setAttribute('href',penultimate);
return;
    plink.setAttribute('title','diff to last change');
    var pimg = document.createElement('img');
    pimg.setAttribute('src',img);
    pimg.style.width = '13px';
    pimg.style.height = '13px';
    pimg.style.marginLeft = '5px';
    plink.appendChild(pimg);
    plink.appendChild(document.createTextNode(' '));
    mytalk.appendChild(plink);
  } else {
    mytalk.style.background = 'transparent url("' + img + '") no-repeat center right';
    mytalk.style.paddingRight = '16px';
  }
}
}

Revision as of 05:17, November 8, 2011

function UserNameReplace() {
    if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || wgUserName == null) return;
    $("span.insertusername").html(wgUserName);
 }
 addOnloadHook(UserNameReplace);


function UserGroupsReplace() {
    if(typeof(disableUserGroupsReplace) != 'undefined' && disableUserGroupsReplace || wgUserName == null) return;
    $("span.insertusergroups").html(wgUserGroups);
 }
 addOnloadHook(UserGroupsReplace);

pattag = document.getElementById("patrol");
if (pattag) {
  if ( wgUserGroups.toString().indexOf('sysop')|| wgUserGroups.toString().indexOf('patroller')) {
    pattag.setAttribute("style","display:inline")
  }
}
admintag = document.getElementById("admin");
if (admintag) {
  if ( wgUserGroups.toString().indexOf('sysop')) {
    admintag.setAttribute("style","display:inline")
  }
}


addOnloadHook( function (){
        if (wgAction == 'delete') {
	$j(document).ready( function() {
		$j.getJSON(
			wgServer+wgScriptPath+'/api.php?action=query&list=allpages&aplimit=500&apnamespace='
			+ wgNamespaceNumber + '&apprefix=' + encodeURIComponent(wgTitle)+ '/' + '&format=json&callback=?',
			function( data ) { showSubpagesCB(data); }
		);
	});
}
}
});
 
var umstyle = document.createElement('style');
umstyle.type = 'text/css';
umstyle.rel = 'stylesheet';
if (umstyle.styleSheet) umstyle.styleSheet.cssText = '.usermessage {display:none;}'
else umstyle.appendChild(document.createTextNode('.usermessage {display:none;}'))
document.getElementsByTagName('head')[0].appendChild(umstyle);
 
/* If the page contains a usermessage div, style the pt-mytalk. */
 
addOnloadHook(gotNewMessages);
function gotNewMessages() {
  var um = getElementsByClassName(document.getElementById('bodyContent'),'div','usermessage');
  if(um.length == 0) return
  var links = um[0].getElementsByTagName('a');
  for(var i=0;i<links.length;i++) {
    if(links[i].href.indexOf('diff=cur') != -1) {
      var penultimate = links[i].href;
    }
  }
  var mytalk = document.getElementById('pt-mytalk');
  if(!mytalk) return

  mytalk.style.fontWeight = 'bold';
  var img = 'http://zeldadungeon.net/wiki/thumb.php?f=Triforce_(Ocarina_of_Time).png&w=13';
  if(penultimate) {
    /* add a linked icon if the message contains a diff=cur */
    var plink = document.createElement('a');
    plink.setAttribute('href',penultimate);
    plink.setAttribute('title','diff to last change');
    var pimg = document.createElement('img');
    pimg.setAttribute('src',img);
    pimg.style.width = '13px';
    pimg.style.height = '13px';
    pimg.style.marginLeft = '5px';
    plink.appendChild(pimg);
    plink.appendChild(document.createTextNode(' '));
    mytalk.appendChild(plink);
  } else {
    mytalk.style.background = 'transparent url("' + img + '") no-repeat center right';
    mytalk.style.paddingRight = '16px';
  }
}