User:Splarka/scapmap.js

/* Scap roadmap viewer, version [0.0.1] Originally from: http://www.mediawiki.org/wiki/User:Splarka/scapmap.js

Notes:
 * Silly.
 * Untested in browsers other than mozilla.
 * Popup could be done a lot better, quick and dirty for now.
 * Loads on, for exmaple: http://www.mediawiki.org/wiki/Special:Code/MediaWiki

var overviewTimeoutObj; var overviewPopupData = []; function reviewOverview { // check if we're on a page with a useful list of revisions var path = document.getElementById('path'); var table = getElementsByClassName(document,'table','TablePager'); if(!path || table.length == 0) return; addPortletLink('p-cactions','javascript:reviewOverviewDisplay;','Overview','ca-defrag','Show a graphical overview of this list.','1'); }

function reviewOverviewDisplay { //doublecheck that they're there and we can use them var table = getElementsByClassName(document,'table','TablePager'); var above = document.forms[0] //stick above the first form, no IDs on the forms currently! table = table[0]; var tr = table.getElementsByTagName('tr'); if(tr.length < 2 || document.getElementById('overviewmap')) return

appendCSS(   '#overviewmap {border:1px solid black;margin:.5em;padding:2px;position:relative;margin-right:10em;} '  + '#overviewmap .box-overview {border:1px solid black;float:left;width:1.5em;height:1.5em;margin:1px;overflow:hidden;} '  + '#overviewmap .summary {clear:both;} '  + '#overviewmap #overviewpop {width:10em;height:5em;padding:3px;border:1px solid black;position:absolute;display:none;background-color:white;font-size:80%;line-height:100%;overflow:hidden;white-space:pre;} '  + '.box-status-new {background: #ffffc0 !important;} .box-status-new:hover {background: #dfdfa0 !important;} '  + '.box-status-fixme {background: #ff9999 !important;} .box-status-fixme:hover {background: #df0000 !important;} '  + '.box-status-resolved {background: #c0ffc0 !important;} .box-status-resolved:hover {background: #a0dfa0 !important;} '  + '.box-status-reverted {background: #cceeff !important;} .box-status-reverted:hover {background: #66bbff !important;} ' + '.box-status-deferred td {color: #666;} ' ) var output = document.createElement('div');  output.setAttribute('id','overviewmap');  addHandler(document,'mouseover',mouseOverBox);  addHandler(document,'mouseout',mouseOutBox);  var totals = {};  for(var i=0;i<tr.length;i++) {    var td = tr[i].getElementsByTagName('td');    if(!td || td.length != 8) continue    overviewPopupData[i] = {};    var status = getInnerText(td[2])    if(!totals[status]) totals[status] = 0    totals[status]++;    overviewPopupData[i]['status'] = status;    overviewPopupData[i]['rev'] = getInnerText(td[1]);    overviewPopupData[i]['notes'] = getInnerText(td[3]);    overviewPopupData[i]['path'] = getInnerText(td[4]);    overviewPopupData[i]['author'] = getInnerText(td[6]);

var box = document.createElement('div'); box.setAttribute('class','box-overview box-status-' + status ); box.setAttribute('id','box-' + i ); //box.appendChild(document.createTextNode(rev)); output.appendChild(box); } var summary = document.createElement('div'); summary.setAttribute('class','summary'); var sumtext = ''; for(var i in totals) { sumtext += ', ' + i + ': ' + totals[i]; } summary.appendChild(document.createTextNode('Total revisions: ' + (tr.length-1) + sumtext)); output.appendChild(summary); var opop = document.createElement('div'); opop.setAttribute('id','overviewpop'); output.appendChild(opop); above.style.clear = 'both'; above.parentNode.insertBefore(output,above); } if(wgNamespaceNumber == -1 && wgCanonicalSpecialPageName == 'Code') addOnloadHook(reviewOverview)

function mouseOverBox(e) { var e = window.event || e; if(!e) return var target = e.target || e.srcElement if(!target) return if(target.className.indexOf('box-overview') != 0) { if(target.id != 'overviewpop') hideOverviewPopupBox(target) return; } var overviewTimeoutObj = setTimeout(function { showOverviewPopupBox(target); }, 300); }

function showOverviewPopupBox(target) { var opop = document.getElementById('overviewpop'); if(!opop || !target) return var left = target.offsetLeft + target.offsetWidth -10; var top = target.offsetTop + target.offsetHeight -10; while(opop.firstChild) opop.removeChild(opop.firstChild) var id = parseInt(target.id.replace(/box\-/i,'')); var txt = 'Rev: r' + overviewPopupData[id]['rev'] + '\nStatus: ' + overviewPopupData[id]['status'] + '\nNumber of notes: ' + overviewPopupData[id]['notes'] + '\nPath: ' + overviewPopupData[id]['path'] + '\nAuthor: ' + overviewPopupData[id]['author']; opop.appendChild(document.createTextNode(txt)); opop.style.left = left + 'px'; opop.style.top = top + 'px'; opop.style.display = 'block'; }

function mouseOutBox(e) { var e = window.event || e; if(!e) return var target = e.target || e.srcElement if(!target || target.className.indexOf('box-overview') == 0) return hideOverviewPopupBox(target); }

function hideOverviewPopupBox(target) { if(overviewTimeoutObj != null) { clearTimeout(overviewTimeoutObj); overviewTimeoutObj = null; } var opop = document.getElementById('overviewpop'); if(opop) opop.style.display = '' }