User:Tommy Jantarek/common.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

mw.loader.load('//en.wikisource.org/w/index.php?title=User:Samwilson/FullScreenEditing.js&action=raw&ctype=text/javascript');
mw.loader.load('//pl.wikipedia.org/w/index.php?title=User:Nux/hideSidebar.js&action=raw&ctype=text/javascript');
mw.loader.load('//pl.wikisource.org/w/index.php?title=MediaWiki:Gadget-lib-shortcuts.js&action=raw&ctype=text/javascript');

window.shortcutsGadget = {
	version: 3,
	pageLoaded: false,
	queue: [],

	addTextShortcut: function( keystroke, tagOpen, tagClose, sampleText ) {
		if ( tagClose === null ) {
			tagClose = '';
		}

		if ( sampleText === null ) {
			sampleText = '';
		}

		var callback = function() {
				$( ':focus' ).textSelection(
					'encapsulateSelection', {
						pre: tagOpen,
						peri: sampleText,
						post: tagClose
					}
				);
				return false;
			};

		var item = {
			keystroke: keystroke,
			callback: callback
		};

		if ( this.pageLoaded ) {
			this.addTextShortcutNow( item );
		} else {
			this.queue.push( item );
		}
	},

	addTextShortcutNow: function( item ) {
		shortcut.add( item.keystroke, item.callback, {
			target: document
		} );
	},

	removeAll: function() {
		this.queue = [];
	},

	bindShortcuts: function() {
		for ( var i = 0; i < this.queue.length; i++ ) {
			this.addTextShortcutNow( this.queue[i] );
		}
		this.removeAll();
	},

	init: function() {
		this.pageLoaded = true;
		this.bindShortcuts();
	}
};

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

setTimeout( function() {
    shortcutsGadget.addTextShortcut('alt+q', '—', '', '');
    shortcutsGadget.addTextShortcut('alt+t', 'ë', '', '');
    shortcutsGadget.addTextShortcut('alt+y', 'Ë', '', '');
    shortcutsGadget.addTextShortcut('alt+w', '<ref></ref>', '', '');
}, 1000 );