MediaWiki:Common.js

From Training Material
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/**
 Remote ugly stuff
*/
   var fullUrl = window.location.search;
    $urlArr = fullUrl.split("&");
    if($.inArray("printable=yes",$urlArr) == 1){
       var curInnerHTML = document.body.innerHTML;
       curInnerHTML = curInnerHTML.replace(/。/g, "");
       curInnerHTML = curInnerHTML.replace(/⌘/g, "");
       document.body.innerHTML = curInnerHTML;
    }


// NobleProg code for creating Table of Contents

function updateToc(code) {
	var toc = document.getElementById('s5slideshow-toc');
	
	if (toc) {
		toc.setAttribute('contenteditable', 'true');
		toc.setAttribute('onclick', 'updateToc(true)');
		toc.setAttribute('style', 'outline: none;');
		var base = document.getElementById('mw-content-text');
		var node = base.childNodes;
		var amount = node.length;
		var tag = '';
		var html = '';
		var counter = 2;
		
		html += '<table style="border-spacing: 0px; background: transparent;">\n';
		
		for (i = 0; i < amount; i++) {
			tag = node[i].nodeName;
			
			if (tag == 'H2' && node[i].childNodes[0].innerText.indexOf('⌘') > -1 && node[i].childNodes[0].innerText.indexOf('Table of contents') == -1) {
				counter += 1;
				html += '\t<tr>\n';
				html += '\t\t<td style="padding: 0em 4em 0.5em 0em;">' + node[i].childNodes[0].innerText.replace('⌘', '').replace('\n', ' ') + '</td>\n';
				html += '\t\t<td style="text-align: right; padding-bottom: 0.5em;">' + counter + '</td>\n';
				html += '\t</tr>\n';
			}
			
			if (tag == 'H3' || tag == 'H4' || tag == 'H5' || tag == 'H6') {
				counter += 1;
			}
		}
		
		html += '</table>';
		
		if (code !== undefined) {
			toc.removeAttribute('onclick');
			html = html.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {
			   return '&#'+i.charCodeAt(0)+';';
			});
			html = '<pre>' + html + '</pre>'
		}
		
		toc.innerHTML = html;
	}
}

updateToc();