Site for researching all meanings of Hebrew Bible.

Difference between revisions of "MediaWiki:Common.js"

From Without Vowels project
Jump to: navigation, search
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
  
mwCustomEditButtons[mwCustomEditButtons.length] = {
+
var customizeToolbar = function() {
        "imageId": "button-hebrew-word",
+
  if($( '#wpTextbox1' ).size())
        "imageFile": "http://www.withoutvowels.org/w/images/9/95/Button_hebrew_word.png",
+
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        "speedTip": "Insert a Hebrew word with a reference to the dictionary",
+
      'section': 'main',
        "tagOpen": "",
+
      'group': 'format',
        "tagClose": "",
+
      'tools': {
        "sampleText": "",
+
'hebrew_link': {
         callback: function() {
+
  label: 'Hebrew word with dictionary link',
                 alert("Test");
+
  type: 'button',
         }
+
  icon: '/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(word == null) return;
 +
      }
 +
      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 }
 +
      );
 +
    }
 +
  }
 +
}
 +
      }
 +
    } );
 +
}
 +
 
 +
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
 +
         mw.loader.using( 'user.options', function () {
 +
                 if ( mw.user.options.get('usebetatoolbar') ) {
 +
                        mw.loader.using( 'ext.wikiEditor.toolbar', function () {
 +
                                $(document).ready( customizeToolbar );
 +
                        } );
 +
                }
 +
         } );
 +
}

Latest revision as of 16:20, 9 June 2016

/* Any JavaScript here will be loaded for all users on every page load. */

var customizeToolbar = function() {
  if($( '#wpTextbox1' ).size())
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
      'section': 'main',
      'group': 'format',
      'tools': {
	'hebrew_link': {
	  label: 'Hebrew word with dictionary link',
	  type: 'button',
	  icon: '/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(word == null) return;
	      }
	      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 }
	      );
	    }
	  }
	}
      }
    } );
}

if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.using( 'user.options', function () {
                if ( mw.user.options.get('usebetatoolbar') ) {
                        mw.loader.using( 'ext.wikiEditor.toolbar', function () {
                                $(document).ready( customizeToolbar );
                        } );
                }
        } );
}