Site for researching all meanings of Hebrew Bible.

MediaWiki:Common.js

From Without Vowels project
Revision as of 18:21, 28 October 2011 by Victor Porton (talk | contribs)
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: 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.
/* Any JavaScript here will be loaded for all users on every page load. */

$(document).ready(function() {
  $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    'section': 'main',
    'group': 'format',
    'tools': {
      'hebrew_link': {
	label: 'Hebrew word with dictionary link',
	type: 'button',
	icon: 'http://www.withoutvowels.org/w/images/9/95/Button_hebrew_word.png',
	action: {
	  type: 'callback',
	  execute: function(context) {
	    var selection = context.$textarea.textSelection( 'getSelection' );
	    var word;
	    if(selection) {
	      word = selection;
	    } else {
	      word = prompt("Enter a Hebrew word");
	    }
	    if(!/^[\u05d0-\u05fa]+$/.test(word)) {
	      alert("You must enter or select a Hebrew word without vowels!");
	      return;
	    }
	    var reference = "[[Hebrew:"+word+"|"+word+"]]";
	    context.$textarea.textSelection(
		    'encapsulateSelection',
		    { replace: true, peri: reference }
	    );
	  }
	}
      }
    }
  } );
});