МедияУики: Gadget-Quick diff.js

От Уики на Читанка
Направо към: навигация, търсене

Забележка: За да се видят промените, необходимо е след съхраняване на страницата, кешът на браузъра да бъде изтрит.

  • Firefox / Safari: Задържа се клавиш Shift и се щраква върху Презареждане (Reload) или чрез клавишната комбинация Ctrl-F5 or Ctrl-R (⌘-R за Mac);
  • Google Chrome: клавишна комбинация Ctrl-Shift-R (⌘-Shift-R за Mac)
  • Internet Explorer: Задържа се клавиш Ctrl и се щраква върху Refresh или чрез клавишната комбинация Ctrl-F5;
  • Opera: кешът се изчиства през менюто Tools → Settings (Opera → Preferences за Mac) след което Privacy & security → Clear browsing data → Cached images and files.
/**
 * Enhance recent changes diff links.
 * Author: Borislav Manolov
 * License: Public domain
 * Documentation: [[МедияУики:Gadget-Quick diff.js/doc]]
 */

/**
 * @uses jQuery
 */
var QuickDiff = {

	enable: function()
	{
		jQuery("a[href*=diff=]").click(function(event){
			var $link = jQuery(this).addClass("working");
			var href = this.href + "&action=render"
				+ ( event.ctrlKey ? "" : "&diffonly=1" );
			jQuery.get(href, function(data){
				QuickDiff.viewDiff(data, $link);
				$link.removeClass("working").addClass("done");
			});
			return false;
		});
	},

	viewDiff: function(content, $link)
	{
		this.getViewWindow().css("top", $link.offset().top)
			.find("#quickdiff-content").html(content)
			.end().show();
		this.enableBunchPatroller($link);
	},

	viewWindow: null,

	getViewWindow: function()
	{
		if ( null === this.viewWindow ) {
			this.prepareViewWindow();
		}

		return this.viewWindow;
	},

	prepareViewWindow: function()
	{
		this.viewWindow = this.buildViewWindow();

		importStylesheetURI(stylepath + "/common/diff.css");

		this.enableQuickPatroller();
	},

	buildViewWindow: function()
	{
		var $win = jQuery('<div id="quickdiff"><div id="quickdiff-close"/><div id="quickdiff-content"/></div>')
			.dblclick(function(){
				jQuery(this).hide();
			})
			.appendTo("#content");
		$win.find("#quickdiff-close").click(function(){
			$win.hide();
		});

		return $win;
	},

	enableQuickPatroller: function()
	{
		if ( window.QuickPattroler ) QuickPattroler.enable();
	},

	enableBunchPatroller: function($link)
	{
		if ( window.BunchPatroller ) {
			WebRequest.setRequestUrl($link[0].href);
			BunchPatroller.enable();
		}
	}
};

// prepare for fight
addOnloadHook(function(){
	if ( /^(Recentchanges|Watchlist|Contributions)/.test(wgCanonicalSpecialPageName)
			|| "history" == wgAction
	) {
		QuickDiff.enable();
	}
});