User:R4wrz0rz0r/quickpreview.js

From Team Fortress Wiki
Jump to: navigation, search

Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
 * Original script: User:Sander_Säde/quickpreview.js
 * Ported to use jQuery and Wikia compatibility
 */
 
if (wgAction == 'edit' || wgAction == 'submit') {
	$(document).ready(function() {
		var attrs = {
			tabindex: 6,
			accesskey: 'g',
			id: 'dlQuickPreview',
			title: 'Preview your changes'
		};
		var $button = $('<input type="button" />').val('Quick preview').attr(attrs).click(function() {
			$(this).val('Getting preview').attr('disabled', 'disabled');
 
			var f = document.editform;
 
			$.ajax({
				data: {
					'wpMinoredit': f.wpMinoredit.checked,
					'wpWatchthis': f.wpWatchthis.checked,
					'wpStarttime': f.wpStarttime.value,
					'wpEdittime': f.wpEdittime.value,
					'wpAutoSummary': f.wpAutoSummary.value,
					'wpEditToken': f.wpEditToken.value,
					'wpSummary': 'Quick preview',
					'wpTextbox1': f.wpTextbox1.value
				},
				dataType: 'text',
				type: 'POST',
				url: wgArticlePath.replace('$1',escape(wgPageName)) + document.location.search.replace('&action=edit', '&action=submit') + '&wpPreview=true&live=true',
				success: function(response) {
					$('#wikiPreview').css('display', 'block').html(response.replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&').replace(/&quot;/g, '"'));
					$('#dlQuickPreview').val('Quick preview').removeAttr('disabled');
				}
			});
 
		});

		$('.editOptions .editButtons input').eq(1).after($button);	
	});
}