MediaWiki:Gadget-QuickHistory.js

Z Wikiźródeł, wolnej biblioteki

Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
  • Opera: Naciśnij klawisze Ctrl+F5.
// Original version:
// - QuickHistory script by [[:pl:User:ChP94]]
// - Released under the [http://www.gnu.org/licenses/gpl.txt GNU Public License (GPL)]
// Modified by [[:pl:User:Beau]]

/* Translatable strings */
mw.messages.set( {
	'quickhistory-close': 'Zamknij.'
} );


window.quickHistoryGagdet = {
	/** Version of the gadget */
	version: 4,
	limit: 15,
	panel: null,
	timer: null,
	trigger: null,

	init: function() {
		var that = this;

		var events = {
			mousemove: function() {
				if ( !that.timer ) {
					that.timer = setTimeout( function() {
						that.showHistory()
					}, 500 );
					that.trigger = this;
				}
			},
			mouseout: function() {
				if ( that.timer ) {
					clearTimeout( that.timer );
					that.timer = null;
				}
			}
		};

		jQuery( "#ca-history" ).on( events );
		jQuery( "[rel=archives]" ).on( events );
	},

	showHistory: function() {
		var that = this;
		if ( this.panel ) {
			return;
		}
		this.panel = document.createElement( "div" );
		this.panel.style.cssText = "background-color: #FDF5E6; display: none; position: absolute; z-index: 200";

		var divClose = document.createElement( "div" );
		divClose.style.cssText = "background-color: #CD853F; width: 100%; text-align: center; cursor:pointer; color: #FDF5E6;";
		divClose.appendChild( document.createTextNode( mw.msg( 'quickhistory-close' ) ) );
		divClose.onclick = function() {
			that.hideHistory();
		};
		this.panel.appendChild( divClose );

		var divHistory = document.createElement( "div" );
		this.panel.appendChild( divHistory );

		this.panel.style.top = ( jQuery( this.trigger ).offset().top + jQuery( this.trigger ).height() + 2 ) + "px";
		var width = Math.round( document.body.clientWidth * 0.7 );

		var left = jQuery( this.trigger ).offset().left + ( jQuery( this.trigger ).width() / 2 ) - ( width / 2 );
		if ( left < 0 ) {
			left = 0;
		} else if ( left + width > document.body.clientWidth ) {
			left = document.body.clientWidth - width;
		}
		this.panel.style.width = width + "px";
		this.panel.style.left = left + "px";

		document.body.appendChild( this.panel );

		jQuery( divHistory ).load(
		mw.util.wikiScript() + '?limit=' + this.limit + '&title=' + encodeURIComponent( mw.config.get( "wgPageName" ) ) + '&action=history #mw-history-compare', function() {
			that.panel.style.display = "block";
		} );
	},

	hideHistory: function() {
		if ( this.panel ) {
			document.body.removeChild( this.panel );
			this.panel = null;
		}
	}
};

jQuery( document ).ready( function() {
	quickHistoryGagdet.init();
} );