mediawiki-extensions-Catego.../CategoryTree.js

92 lines
3 KiB
JavaScript
Raw Normal View History

/*
2008-02-04 09:22:12 +00:00
* JavaScript functions for the CategoryTree extension, an AJAX based gadget
* to display the category structure of a wiki
*
* @package MediaWiki
* @subpackage Extensions
* @author Daniel Kinzler, brightbyte.de
* @copyright © 2006 Daniel Kinzler
* @licence GNU General Public Licence 2.0 or later
*/
// Default messages if new code loaded with old cached page
2008-02-04 09:22:12 +00:00
var categoryTreeErrorMsg = "Problem loading data.";
var categoryTreeRetryMsg = "Please wait a moment and try again.";
function categoryTreeNextDiv(e) {
var n= e.nextSibling;
while ( n && ( n.nodeType != 1 || n.nodeName != 'DIV') ) {
//alert('nodeType: ' + n.nodeType + '; nodeName: ' + n.nodeName);
n= n.nextSibling;
}
2008-02-04 09:22:12 +00:00
return n;
}
2008-02-04 09:22:12 +00:00
function categoryTreeExpandNode(cat, mode, lnk) {
var div= categoryTreeNextDiv( lnk.parentNode.parentNode );
2008-02-04 09:22:12 +00:00
div.style.display= 'block';
lnk.innerHTML= '–';
lnk.title= categoryTreeCollapseMsg;
lnk.onclick= function() { categoryTreeCollapseNode(cat, mode, lnk) }
2008-02-04 09:22:12 +00:00
if (lnk.className != "CategoryTreeLoaded") {
categoryTreeLoadNode(cat, mode, lnk, div);
}
}
2008-02-04 09:22:12 +00:00
function categoryTreeCollapseNode(cat, mode, lnk) {
var div= categoryTreeNextDiv( lnk.parentNode.parentNode );
2008-02-04 09:22:12 +00:00
div.style.display= 'none';
lnk.innerHTML= '+';
lnk.title= categoryTreeExpandMsg;
lnk.onclick= function() { categoryTreeExpandNode(cat, mode, lnk) }
}
2008-02-04 09:22:12 +00:00
function categoryTreeLoadNode(cat, mode, lnk, div) {
div.style.display= 'block';
lnk.className= 'CategoryTreeLoaded';
lnk.innerHTML= '–';
lnk.title= categoryTreeCollapseMsg;
lnk.onclick= function() { categoryTreeCollapseNode(cat, mode, lnk) }
categoryTreeLoadChildren(cat, mode, div)
}
2008-02-04 09:22:12 +00:00
function categoryTreeLoadChildren(cat, mode, div) {
div.innerHTML= '<i class="CategoryTreeNotice">' + categoryTreeLoadingMsg + '</i>';
2008-02-04 09:22:12 +00:00
function f( request ) {
if (request.status != 200) {
div.innerHTML = '<i class="CategoryTreeNotice">' + categoryTreeErrorMsg + ' </i>';
var retryLink = document.createElement('a');
retryLink.innerHTML = categoryTreeRetryMsg;
retryLink.onclick = function() {
categoryTreeLoadChildren(cat, mode, div);
}
div.appendChild(retryLink);
return;
}
result= request.responseText;
result= result.replace(/^\s+|\s+$/, '');
2008-02-04 09:22:12 +00:00
if ( result == '' ) {
result= '<i class="CategoryTreeNotice">';
2008-02-04 09:22:12 +00:00
if ( mode == 0 ) result= categoryTreeNoSubcategoriesMsg;
else if ( mode == 10 ) result= categoryTreeNoPagesMsg;
else result= categoryTreeNothingFoundMsg;
2008-02-04 09:22:12 +00:00
result+= '</i>';
}
2008-02-04 09:22:12 +00:00
result = result.replace(/##LOAD##/g, categoryTreeExpandMsg);
div.innerHTML= result;
}
2008-02-04 09:22:12 +00:00
sajax_do_call( "efCategoryTreeAjaxWrapper", [cat, mode] , f );
}