User:Matěj Grabovský/common.js

From mediawiki.org

Note: After publishing, 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: Press Ctrl-F5.
var tab2tabHandler = function(e) {
	if(e.keyCode === 9) {
		insertTags('	', '', '');
		e.preventDefault();
	}
};

jQuery(function($) {
	mediaWiki.loader.load([ 'jquery.textSelection' ]);
	mediaWiki.loader.using('jquery.textSelection', function() {
		var $editBox = $('#wpTextbox1');
		$editBox.after('<input type="checkbox" id="useTab2tab">&nbsp;<label for="useTab2tab">Use tab2tab</label>');
		var $useTab2tab = $('#useTab2tab');
		$useTab2tab.change(function() {
			if($useTab2tab.is(':checked')) {
				$editBox.bind('keydown', tab2tabHandler);
				localStorage['mw.useTab2tab'] = true;
			} else {
				$editBox.unbind('keydown', tab2tabHandler);
				localStorage['mw.useTab2tab'] = false;
			}
		});

		if(localStorage['mw.useTab2tab'] === "true")
			$useTab2tab.attr('checked', true);
	});
});