Jump to content

User:Jackmcbarn/parsoidview.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jackmcbarn (talk | contribs) at 04:04, 10 June 2014 (Created page with '(function(){ 'use strict'; var isParsoid = false, elem = $('#mw-content-text')[0], phpHTML = elem.innerHTML, parsoidHTML = null; var portletLink = mw.util.add...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function(){
	'use strict';
	var isParsoid = false, elem = $('#mw-content-text')[0], phpHTML = elem.innerHTML, parsoidHTML = null;
	var portletLink = mw.util.addPortletLink( 'p-tb', '#', 'Toggle Parsoid view', 't-parsoid-view-toggle' );
	$( portletLink ).click( function ( e ) {
		e.preventDefault();
		if(isParsoid) {
			elem.innerHTML = phpHTML;
			isParsoid = false;
		} else if(parsoidHTML) {
			elem.innerHTML = parsoidHTML;
			isParsoid = true;
		} else {
			elem.innerHTML = parsoidHTML = 'Loading HTML from Parsoid...';
			isParsoid = true;
			$.get('//parsoid-prod.wmflabs.org/enwiki/' + encodeURIComponent(mw.config.get('wgPageName')) + '?oldid=' + mw.config.get('wgRevisionId'), function(data) {
				var parsoidDom = new DOMParser().parseFromString(data, 'text/html');
				parsoidHTML = parsoidDom.body.innerHTML;
				if(isParsoid) {
					elem.innerHTML = parsoidHTML;
				}
			});
		}
	});
})()