summaryrefslogtreecommitdiff
path: root/extensions/WikiEditor/modules/jquery.wikiEditor.js
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/WikiEditor/modules/jquery.wikiEditor.js')
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.js177
1 files changed, 99 insertions, 78 deletions
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.js b/extensions/WikiEditor/modules/jquery.wikiEditor.js
index c2fb4094..6e87a45f 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.js
@@ -2,13 +2,13 @@
* This plugin provides a way to build a wiki-text editing user interface around a textarea.
*
* @example To intialize without any modules:
- * $( 'div#edittoolbar' ).wikiEditor();
+ * $( 'div#edittoolbar' ).wikiEditor();
*
* @example To initialize with one or more modules, or to add modules after it's already been initialized:
- * $( 'textarea#wpTextbox1' ).wikiEditor( 'addModule', 'toolbar', { ... config ... } );
+ * $( 'textarea#wpTextbox1' ).wikiEditor( 'addModule', 'toolbar', { ... config ... } );
*
*/
-( function( $ ) {
+( function ( $ ) {
/**
* Global static object for wikiEditor that provides generally useful functionality to all modules and contexts.
@@ -19,63 +19,68 @@ $.wikiEditor = {
* module name. The existance of a module in this object only indicates the module is available. To check if a
* module is in use by a specific context check the context.modules object.
*/
- 'modules': {},
+ modules: {},
+
/**
* A context can be extended, such as adding iframe support, on a per-wikiEditor instance basis.
*/
- 'extensions': {},
+ extensions: {},
+
/**
* In some cases like with the iframe's HTML file, it's convienent to have a lookup table of all instances of the
* WikiEditor. Each context contains an instance field which contains a key that corrosponds to a reference to the
* textarea which the WikiEditor was build around. This way, by passing a simple integer you can provide a way back
* to a specific context.
*/
- 'instances': [],
+ instances: [],
+
/**
* For each browser name, an array of conditions that must be met are supplied in [operaton, value]-form where
* operation is a string containing a JavaScript compatible binary operator and value is either a number to be
* compared with $.browser.versionNumber or a string to be compared with $.browser.version. If a browser is not
* specifically mentioned, we just assume things will work.
*/
- 'browsers': {
+ browsers: {
// Left-to-right languages
- 'ltr': {
+ ltr: {
// The toolbar layout is broken in IE6
- 'msie': [['>=', 7]],
+ msie: [['>=', 7]],
// Layout issues in FF < 2
- 'firefox': [['>=', 2]],
+ firefox: [['>=', 2]],
// Text selection bugs galore - this may be a different situation with the new iframe-based solution
- 'opera': [['>=', 9.6]],
+ opera: [['>=', 9.6]],
// jQuery minimums
- 'safari': [['>=', 3]],
- 'chrome': [['>=', 3]],
- 'netscape': [['>=', 9]],
- 'blackberry': false,
- 'ipod': false,
- 'iphone': false
+ safari: [['>=', 3]],
+ chrome: [['>=', 3]],
+ netscape: [['>=', 9]],
+ blackberry: false,
+ ipod: false,
+ iphone: false
},
// Right-to-left languages
- 'rtl': {
+ rtl: {
// The toolbar layout is broken in IE 7 in RTL mode, and IE6 in any mode
- 'msie': [['>=', 8]],
+ msie: [['>=', 8]],
// Layout issues in FF < 2
- 'firefox': [['>=', 2]],
+ firefox: [['>=', 2]],
// Text selection bugs galore - this may be a different situation with the new iframe-based solution
- 'opera': [['>=', 9.6]],
+ opera: [['>=', 9.6]],
// jQuery minimums
- 'safari': [['>=', 3]],
- 'chrome': [['>=', 3]],
- 'netscape': [['>=', 9]],
- 'blackberry': false,
- 'ipod': false,
- 'iphone': false
+ safari: [['>=', 3]],
+ chrome: [['>=', 3]],
+ netscape: [['>=', 9]],
+ blackberry: false,
+ ipod: false,
+ iphone: false
}
},
+
/**
* Path to images - this is a bit messy, and it would need to change if this code (and images) gets moved into the
* core - or anywhere for that matter...
*/
- 'imgPath' : mw.config.get( 'wgExtensionAssetsPath' ) + '/WikiEditor/modules/images/',
+ imgPath : mw.config.get( 'wgExtensionAssetsPath' ) + '/WikiEditor/modules/images/',
+
/**
* Checks the current browser against the browsers object to determine if the browser has been black-listed or not.
* Because these rules are often very complex, the object contains configurable operators and can check against
@@ -88,7 +93,7 @@ $.wikiEditor = {
* "open-web" way to go.
* @param module Module object, defaults to $.wikiEditor
*/
- 'isSupported': function( module ) {
+ isSupported: function ( module ) {
// Fallback to the wikiEditor browser map if no special map is provided in the module
var mod = module && 'browsers' in module ? module : $.wikiEditor;
// Check for and make use of cached value and early opportunities to bail
@@ -99,21 +104,23 @@ $.wikiEditor = {
// Run a browser support test and then cache and return the result
return mod.supported = $.client.test( mod.browsers );
},
+
/**
* Checks if a module has a specific requirement
* @param module Module object
* @param requirement String identifying requirement
*/
- 'isRequired': function( module, requirement ) {
- if ( typeof module['req'] !== 'undefined' ) {
- for ( var req in module['req'] ) {
- if ( module['req'][req] == requirement ) {
+ isRequired: function ( module, requirement ) {
+ if ( typeof module.req !== 'undefined' ) {
+ for ( var req in module.req ) {
+ if ( module.req[req] == requirement ) {
return true;
}
}
}
return false;
},
+
/**
* Provides a way to extract messages from objects. Wraps the mediaWiki.msg() function, which
* may eventually become a wrapper for some kind of core MW functionality.
@@ -124,7 +131,7 @@ $.wikiEditor = {
* would return the raw text 'that', while passing property as 'foo' would return the internationalized message
* with the key 'bar'.
*/
- 'autoMsg': function( object, property ) {
+ autoMsg: function ( object, property ) {
// Accept array of possible properties, of which the first one found will be used
if ( typeof property == 'object' ) {
for ( var i in property ) {
@@ -147,6 +154,7 @@ $.wikiEditor = {
return '';
}
},
+
/**
* Provides a way to extract a property of an object in a certain language, falling back on the property keyed as
* 'default' or 'default-rtl'. If such key doesn't exist, the object itself is considered the actual value, which
@@ -156,10 +164,11 @@ $.wikiEditor = {
* @param object Object to extract property from
* @param lang Language code, defaults to wgUserLanguage
*/
- 'autoLang': function( object, lang ) {
+ autoLang: function ( object, lang ) {
var defaultKey = $( 'body' ).hasClass( 'rtl' ) ? 'default-rtl' : 'default';
return object[lang || mw.config.get( 'wgUserLanguage' )] || object[defaultKey] || object['default'] || object;
},
+
/**
* Provides a way to extract the path of an icon in a certain language, automatically appending a version number for
* caching purposes and prepending an image path when icon paths are relative.
@@ -168,7 +177,7 @@ $.wikiEditor = {
* @param path Default icon path, defaults to $.wikiEditor.imgPath
* @param lang Language code, defaults to wgUserLanguage
*/
- 'autoIcon': function( icon, path, lang ) {
+ autoIcon: function ( icon, path, lang ) {
var src = $.wikiEditor.autoLang( icon, lang );
path = path || $.wikiEditor.imgPath;
// Prepend path if src is not absolute
@@ -177,6 +186,7 @@ $.wikiEditor = {
}
return src + '?' + mw.loader.version( 'jquery.wikiEditor' );
},
+
/**
* Get the sprite offset for a language if available, icon for a language if available, or the default offset or icon,
* in that order of preference.
@@ -185,7 +195,7 @@ $.wikiEditor = {
* @param path Icon path, see autoIcon()
* @param lang Language code, defaults to wgUserLanguage
*/
- 'autoIconOrOffset': function( icon, offset, path, lang ) {
+ autoIconOrOffset: function ( icon, offset, path, lang ) {
lang = lang || mw.config.get( 'wgUserLanguage' );
if ( typeof offset == 'object' && lang in offset ) {
return offset[lang];
@@ -200,7 +210,7 @@ $.wikiEditor = {
/**
* jQuery plugin that provides a way to initialize a wikiEditor instance on a textarea.
*/
-$.fn.wikiEditor = function() {
+$.fn.wikiEditor = function () {
// Skip any further work when running in browsers that are unsupported
if ( !$.wikiEditor.isSupported() ) {
@@ -263,21 +273,22 @@ if ( !context || typeof context == 'undefined' ) {
* @param data Either a string of the name of a module to add without any additional configuration parameters,
* or an object with members keyed with module names and valued with configuration objects.
*/
- 'addModule': function( context, data ) {
- var modules = {};
+ 'addModule': function ( context, data ) {
+ var module, call,
+ modules = {};
if ( typeof data == 'string' ) {
modules[data] = {};
} else if ( typeof data == 'object' ) {
modules = data;
}
- for ( var module in modules ) {
+ for ( module in modules ) {
// Check for the existance of an available / supported module with a matching name and a create function
if ( typeof module == 'string' && typeof $.wikiEditor.modules[module] !== 'undefined' &&
$.wikiEditor.isSupported( $.wikiEditor.modules[module] ) )
{
// Extend the context's core API with this module's own API calls
if ( 'api' in $.wikiEditor.modules[module] ) {
- for ( var call in $.wikiEditor.modules[module].api ) {
+ for ( call in $.wikiEditor.modules[module].api ) {
// Modules may not overwrite existing API functions - first come, first serve
if ( !( call in context.api ) ) {
context.api[call] = $.wikiEditor.modules[module].api[call];
@@ -313,7 +324,7 @@ if ( !context || typeof context == 'undefined' ) {
/**
* Executes core event filters as well as event handlers provided by modules.
*/
- 'trigger': function( name, event ) {
+ trigger: function ( name, event ) {
// Event is an optional argument, but from here on out, at least the type field should be dependable
if ( typeof event == 'undefined' ) {
event = { 'type': 'custom' };
@@ -339,9 +350,9 @@ if ( !context || typeof context == 'undefined' ) {
name in $.wikiEditor.modules[module].evt
) {
var ret = $.wikiEditor.modules[module].evt[name]( context, event );
- if (ret != null) {
+ if (ret !== null) {
//if 1 returns false, the end result is false
- if( returnFromModules == null ) {
+ if( returnFromModules === null ) {
returnFromModules = ret;
} else {
returnFromModules = returnFromModules && ret;
@@ -349,45 +360,47 @@ if ( !context || typeof context == 'undefined' ) {
}
}
}
- if ( returnFromModules != null ) {
+ if ( returnFromModules !== null ) {
return returnFromModules;
} else {
return true;
}
},
+
/**
* Adds a button to the UI
*/
- 'addButton': function( options ) {
+ addButton: function ( options ) {
// Ensure that buttons and tabs are visible
context.$controls.show();
context.$buttons.show();
- return $( '<button />' )
+ return $( '<button>' )
.text( $.wikiEditor.autoMsg( options, 'caption' ) )
.click( options.action )
.appendTo( context.$buttons );
},
+
/**
* Adds a view to the UI, which is accessed using a set of tabs. Views are mutually exclusive and by default a
* wikitext view will be present. Only when more than one view exists will the tabs will be visible.
*/
- 'addView': function( options ) {
+ addView: function ( options ) {
// Adds a tab
function addTab( options ) {
// Ensure that buttons and tabs are visible
context.$controls.show();
context.$tabs.show();
// Return the newly appended tab
- return $( '<div></div>' )
+ return $( '<div>' )
.attr( 'rel', 'wikiEditor-ui-view-' + options.name )
.addClass( context.view == options.name ? 'current' : null )
- .append( $( '<a></a>' )
+ .append( $( '<a>' )
.attr( 'href', '#' )
- .mousedown( function() {
+ .mousedown( function () {
// No dragging!
return false;
} )
- .click( function( event ) {
+ .click( function ( event ) {
context.$ui.find( '.wikiEditor-ui-view' ).hide();
context.$ui.find( '.' + $(this).parent().attr( 'rel' ) ).show();
context.$tabs.find( 'div' ).removeClass( 'current' );
@@ -404,21 +417,22 @@ if ( !context || typeof context == 'undefined' ) {
.appendTo( context.$tabs );
}
// Automatically add the previously not-needed wikitext tab
- if ( !context.$tabs.children().size() ) {
+ if ( !context.$tabs.children().length ) {
addTab( { 'name': 'wikitext', 'titleMsg': 'wikieditor-wikitext-tab' } );
}
// Add the tab for the view we were actually asked to add
addTab( options );
// Return newly appended view
- return $( '<div></div>' )
+ return $( '<div>' )
.addClass( 'wikiEditor-ui-view wikiEditor-ui-view-' + options.name )
.hide()
.appendTo( context.$ui );
},
+
/**
* Save scrollTop and cursor position for IE
*/
- 'saveCursorAndScrollTop': function() {
+ saveCursorAndScrollTop: function () {
if ( $.client.profile().name === 'msie' ) {
var IHateIE = {
'scrollTop' : context.$textarea.scrollTop(),
@@ -427,10 +441,11 @@ if ( !context || typeof context == 'undefined' ) {
context.$textarea.data( 'IHateIE', IHateIE );
}
},
+
/**
* Restore scrollTo and cursor position for IE
*/
- 'restoreCursorAndScrollTop': function() {
+ restoreCursorAndScrollTop: function () {
if ( $.client.profile().name === 'msie' ) {
var IHateIE = context.$textarea.data( 'IHateIE' );
if ( IHateIE ) {
@@ -440,19 +455,21 @@ if ( !context || typeof context == 'undefined' ) {
}
}
},
+
/**
* Save text selection for IE
*/
- 'saveSelection': function() {
+ saveSelection: function () {
if ( $.client.profile().name === 'msie' ) {
context.$textarea.focus();
context.savedSelection = document.selection.createRange();
}
},
+
/**
* Restore text selection for IE
*/
- 'restoreSelection': function() {
+ restoreSelection: function () {
if ( $.client.profile().name === 'msie' && context.savedSelection !== null ) {
context.$textarea.focus();
context.savedSelection.select();
@@ -471,7 +488,7 @@ if ( !context || typeof context == 'undefined' ) {
// Assemble a temporary div to place over the wikiEditor while it's being constructed
/* Disabling our loading div for now
- var $loader = $( '<div></div>' )
+ var $loader = $( '<div>' )
.addClass( 'wikiEditor-ui-loading' )
.append( $( '<span>' + mediaWiki.msg( 'wikieditor-loading' ) + '</span>' )
.css( 'marginTop', context.$textarea.height() / 2 ) );
@@ -482,36 +499,38 @@ if ( !context || typeof context == 'undefined' ) {
.after( $loader )
.add( $loader )
*/
- .wrapAll( $( '<div></div>' ).addClass( 'wikiEditor-ui' ) )
- .wrapAll( $( '<div></div>' ).addClass( 'wikiEditor-ui-view wikiEditor-ui-view-wikitext' ) )
- .wrapAll( $( '<div></div>' ).addClass( 'wikiEditor-ui-left' ) )
- .wrapAll( $( '<div></div>' ).addClass( 'wikiEditor-ui-bottom' ) )
- .wrapAll( $( '<div></div>' ).addClass( 'wikiEditor-ui-text' ) );
+ .wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui' ) )
+ .wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui-view wikiEditor-ui-view-wikitext' ) )
+ .wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui-left' ) )
+ .wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui-bottom' ) )
+ .wrapAll( $( '<div>' ).addClass( 'wikiEditor-ui-text' ) );
// Get references to some of the newly created containers
context.$ui = context.$textarea.parent().parent().parent().parent().parent();
context.$wikitext = context.$textarea.parent().parent().parent().parent();
// Add in tab and button containers
context.$wikitext
.before(
- $( '<div></div>' ).addClass( 'wikiEditor-ui-controls' )
- .append( $( '<div></div>' ).addClass( 'wikiEditor-ui-tabs' ).hide() )
- .append( $( '<div></div>' ).addClass( 'wikiEditor-ui-buttons' ) )
+ $( '<div>' ).addClass( 'wikiEditor-ui-controls' )
+ .append( $( '<div>' ).addClass( 'wikiEditor-ui-tabs' ).hide() )
+ .append( $( '<div>' ).addClass( 'wikiEditor-ui-buttons' ) )
)
- .before( $( '<div style="clear:both;"></div>' ) );
+ .before( $( '<div style="clear: both;"></div>' ) );
// Get references to some of the newly created containers
context.$controls = context.$ui.find( '.wikiEditor-ui-buttons' ).hide();
context.$buttons = context.$ui.find( '.wikiEditor-ui-buttons' );
context.$tabs = context.$ui.find( '.wikiEditor-ui-tabs' );
// Clear all floating after the UI
- context.$ui.after( $( '<div style="clear:both;"></div>' ) );
+ context.$ui.after( $( '<div style="clear: both;"></div>' ) );
// Attach a right container
- context.$wikitext.append( $( '<div></div>' ).addClass( 'wikiEditor-ui-right' ) );
+ context.$wikitext.append( $( '<div>' ).addClass( 'wikiEditor-ui-right' ) );
// Attach a top container to the left pane
- context.$wikitext.find( '.wikiEditor-ui-left' ).prepend( $( '<div></div>' ).addClass( 'wikiEditor-ui-top' ) );
+ context.$wikitext.find( '.wikiEditor-ui-left' ).prepend( $( '<div>' ).addClass( 'wikiEditor-ui-top' ) );
// Setup the intial view
context.view = 'wikitext';
// Trigger the "resize" event anytime the window is resized
- $( window ).resize( function( event ) { context.fn.trigger( 'resize', event ); } );
+ $( window ).resize( function ( event ) {
+ context.fn.trigger( 'resize', event );
+ } );
}
/* API Execution */
@@ -520,9 +539,9 @@ if ( !context || typeof context == 'undefined' ) {
var args = $.makeArray( arguments );
// Dynamically setup core extensions for modules that are required
-if ( args[0] == 'addModule' && typeof args[1] != 'undefined' ) {
+if ( args[0] == 'addModule' && typeof args[1] !== 'undefined' ) {
var modules = args[1];
- if ( typeof modules != "object" ) {
+ if ( typeof modules !== "object" ) {
modules = {};
modules[args[1]] = '';
}
@@ -536,7 +555,7 @@ if ( args[0] == 'addModule' && typeof args[1] != 'undefined' ) {
$.inArray( e, context.extensions ) === -1
) {
context.extensions[context.extensions.length] = e;
- $.wikiEditor.extensions[e]( context );
+ $.wikiEditor.extensions[e]( context );
}
}
break;
@@ -549,11 +568,13 @@ if ( args.length > 0 ) {
// Handle API calls
var call = args.shift();
if ( call in context.api ) {
- context.api[call]( context, typeof args[0] == 'undefined' ? {} : args[0] );
+ context.api[call]( context, typeof args[0] === 'undefined' ? {} : args[0] );
}
}
// Store the context for next time, and support chaining
return $(this).data( 'wikiEditor-context', context );
-}; } )( jQuery );
+};
+
+}( jQuery ) );