summaryrefslogtreecommitdiff
path: root/extensions/WikiEditor/modules
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/WikiEditor/modules')
-rw-r--r--extensions/WikiEditor/modules/ext.wikiEditor.css8
-rw-r--r--extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js2
-rw-r--r--extensions/WikiEditor/modules/ext.wikiEditor.templateEditor.js4
-rw-r--r--extensions/WikiEditor/modules/ext.wikiEditor.templates.js6
-rw-r--r--extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js219
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.css9
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js2351
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.css14
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js409
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.highlight.js638
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.js177
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.preview.css9
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.preview.js103
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.previewDialog.css8
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.publish.js68
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.templateEditor.js4
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.toc.css35
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.toc.js57
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.config.js6
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.css10
-rw-r--r--extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js2
21 files changed, 2229 insertions, 1910 deletions
diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.css b/extensions/WikiEditor/modules/ext.wikiEditor.css
index 53e320d5..f0665730 100644
--- a/extensions/WikiEditor/modules/ext.wikiEditor.css
+++ b/extensions/WikiEditor/modules/ext.wikiEditor.css
@@ -1,4 +1,4 @@
-/*
+/**
* CSS for WikiEditor
*/
@@ -7,10 +7,13 @@ form#editform {
margin: 0;
padding: 0;
}
+
/* These IDs (#wpSummaryLabel and #wpSummary) could change in MediaWiki */
-#wpSummary, #wpSummaryLabel {
+#wpSummary,
+#wpSummaryLabel {
margin-bottom: 1em;
}
+
/* This ID (#wpTextbox1) could change in MediaWiki */
.wikiEditor-ui textarea#wpTextbox1 {
border: none;
@@ -19,6 +22,7 @@ form#editform {
line-height: 1.5em;
resize: vertical;
}
+
.wikiEditor-ui .wikiEditor-ui-text > textarea#wpTextbox1 {
margin: 0;
}
diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js b/extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js
index 45a19593..0e0dd090 100644
--- a/extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js
+++ b/extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js
@@ -12,4 +12,4 @@ $( document ).ready( function() {
// Add dialogs module
$( '#wpTextbox1' ).wikiEditor( 'addModule', $.wikiEditor.modules.dialogs.config.getDefaultConfig() );
-} ); \ No newline at end of file
+} );
diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.templateEditor.js b/extensions/WikiEditor/modules/ext.wikiEditor.templateEditor.js
index 650910d2..8879d10d 100644
--- a/extensions/WikiEditor/modules/ext.wikiEditor.templateEditor.js
+++ b/extensions/WikiEditor/modules/ext.wikiEditor.templateEditor.js
@@ -2,9 +2,9 @@
* JavaScript for WikiEditor Template Editor
*/
-$( document ).ready( function() {
+$( document ).ready( function () {
// Disable in template namespace
- if ( mw.config.get( 'wgNamespaceNumber' ) == 10 ) {
+ if ( mw.config.get( 'wgNamespaceNumber' ) === 10 ) {
return true;
}
// Add template editor module
diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.templates.js b/extensions/WikiEditor/modules/ext.wikiEditor.templates.js
index 4ac09b54..6eae6de5 100644
--- a/extensions/WikiEditor/modules/ext.wikiEditor.templates.js
+++ b/extensions/WikiEditor/modules/ext.wikiEditor.templates.js
@@ -2,11 +2,11 @@
* JavaScript for WikiEditor Templates
*/
-$( document ).ready( function() {
+$( document ).ready( function () {
// Disable for template namespace
- if ( mw.config.get( 'wgNamespaceNumber' ) == 10 ) {
+ if ( mw.config.get( 'wgNamespaceNumber' ) === 10 ) {
return true;
}
// Add templates module
$( '#wpTextbox1' ).wikiEditor( 'addModule', 'templates' );
-} ); \ No newline at end of file
+} );
diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js b/extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js
index 69fe2905..d4ffe5ae 100644
--- a/extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js
+++ b/extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js
@@ -4,9 +4,9 @@
var textareaId = '#wpTextbox1';
var wikiEditorTests = {
// Add emoticons section
- 'add_sections_toolbar': {
- 'call': 'addToToolbar',
- 'data': {
+ add_sections_toolbar: {
+ call: 'addToToolbar',
+ data: {
'sections': {
'emoticons': {
'type': 'toolbar',
@@ -14,30 +14,30 @@ var wikiEditorTests = {
}
}
},
- 'test': '*[rel=emoticons].section',
- 'pre': 0,
- 'post': 1
+ test: '*[rel=emoticons].section',
+ pre: 0,
+ post: 1
},
// Add faces group to emoticons section
'add_groups': {
- 'call': 'addToToolbar',
- 'data': {
- 'section': 'emoticons',
+ call: 'addToToolbar',
+ data: {
+ section: 'emoticons',
'groups': {
'faces': {
'label': 'Faces'
}
}
},
- 'test': '*[rel=emoticons].section *[rel=faces].group',
- 'pre': 0,
- 'post': 1
+ test: '*[rel=emoticons].section *[rel=faces].group',
+ pre: 0,
+ post: 1
},
// Add smile tool to faces group of emoticons section
'add_tools': {
- 'call': 'addToToolbar',
- 'data': {
- 'section': 'emoticons',
+ call: 'addToToolbar',
+ data: {
+ section: 'emoticons',
'group': 'faces',
'tools': {
'smile': {
@@ -47,20 +47,20 @@ var wikiEditorTests = {
action: {
type: 'encapsulate',
options: {
- pre: ":)"
+ pre: ':)'
}
}
}
}
},
- 'test': '*[rel=emoticons].section *[rel=faces].group *[rel=smile].tool',
- 'pre': 0,
- 'post': 1
+ test: '*[rel=emoticons].section *[rel=faces].group *[rel=smile].tool',
+ pre: 0,
+ post: 1
},
// Add info section
'add_sections_booklet': {
- 'call': 'addToToolbar',
- 'data': {
+ call: 'addToToolbar',
+ data: {
'sections': {
'info': {
'type': 'booklet',
@@ -68,16 +68,16 @@ var wikiEditorTests = {
}
}
},
- 'test': '*[rel=info].section',
- 'pre': 0,
- 'post': 1
+ test: '*[rel=info].section',
+ pre: 0,
+ post: 1
},
// Add info section
'add_pages_table': {
- 'call': 'addToToolbar',
- 'data': {
- 'section': 'info',
- 'pages': {
+ call: 'addToToolbar',
+ data: {
+ section: 'info',
+ pages: {
'colors': {
'layout': 'table',
'label': 'Colors',
@@ -89,44 +89,44 @@ var wikiEditorTests = {
}
}
},
- 'test': '*[rel=info].section *[rel=colors].page',
- 'pre': 0,
- 'post': 1
+ test: '*[rel=info].section *[rel=colors].page',
+ pre: 0,
+ post: 1
},
// Add colors rows
'add_rows': {
- 'call': 'addToToolbar',
- 'data': {
- 'section': 'info',
- 'page': 'colors',
+ call: 'addToToolbar',
+ data: {
+ section: 'info',
+ page: 'colors',
'rows': [
{
'name': { text: 'Red' },
'temp': { text: 'Warm' },
- 'swatch': { html: '<div style="width:10px;height:10px;background-color:red;">' }
+ 'swatch': { html: '<div style="width: 10px; height: 10px; background-color: red;">' }
},
{
'name': { text: 'Blue' },
'temp': { text: 'Cold' },
- 'swatch': { html: '<div style="width:10px;height:10px;background-color:blue;">' }
+ 'swatch': { html: '<div style="width: 10px; height: 10px; background-color: blue;">' }
},
{
'name': { text: 'Silver' },
'temp': { text: 'Neutral' },
- 'swatch': { html: '<div style="width:10px;height:10px;background-color:silver;">' }
+ 'swatch': { html: '<div style="width: 10px; height: 10px; background-color: silver;">' }
}
]
},
- 'test': '*[rel=info].section *[rel=colors].page tr td',
- 'pre': 0,
- 'post': 9
+ test: '*[rel=info].section *[rel=colors].page tr td',
+ pre: 0,
+ post: 9
},
// Add
'add_pages_characters': {
- 'call': 'addToToolbar',
- 'data': {
- 'section': 'info',
- 'pages': {
+ call: 'addToToolbar',
+ data: {
+ section: 'info',
+ pages: {
'emoticons': {
'layout': 'characters',
'label': 'Emoticons'
@@ -137,110 +137,119 @@ var wikiEditorTests = {
}
}
},
- 'test': '*[rel=info].section *[rel=emoticons].page',
- 'pre': 0,
- 'post': 1
+ test: '*[rel=info].section *[rel=emoticons].page',
+ pre: 0,
+ post: 1
},
// Add
'add_characters': {
- 'call': 'addToToolbar',
- 'data': {
- 'section': 'info',
- 'page': 'emoticons',
- 'characters': [ ':)', ':))', ':(', '<3', ';)' ]
+ call: 'addToToolbar',
+ data: {
+ section: 'info',
+ page: 'emoticons',
+ characters: [ ':)', ':))', ':(', '<3', ';)' ]
},
- 'test': '*[rel=info].section *[rel=emoticons].page *[rel=":)"]',
- 'pre': 0,
- 'post': 1
+ test: '*[rel=info].section *[rel=emoticons].page *[rel=":)"]',
+ pre: 0,
+ post: 1
},
// Remove page
'remove_page': {
- 'call': 'removeFromToolbar',
- 'data': {
- 'section': 'info',
- 'page': 'removeme'
+ call: 'removeFromToolbar',
+ data: {
+ section: 'info',
+ page: 'removeme'
},
- 'test': '*[rel=info].section *[rel=removeme].page',
- 'pre': 1,
- 'post': 0
+ test: '*[rel=info].section *[rel=removeme].page',
+ pre: 1,
+ post: 0
},
// Remove :)) from emoticon characters
'remove_character': {
- 'call': 'removeFromToolbar',
- 'data': {
- 'section': 'info',
- 'page': 'emoticons',
+ call: 'removeFromToolbar',
+ data: {
+ section: 'info',
+ page: 'emoticons',
'character': ':))'
},
- 'test': '*[rel=info].section *[rel=emoticons].page *[rel=":))"]',
- 'pre': 1,
- 'post': 0
+ test: '*[rel=info].section *[rel=emoticons].page *[rel=":))"]',
+ pre: 1,
+ post: 0
},
// Remove row from colors table of info section
'remove_row': {
- 'call': 'removeFromToolbar',
- 'data': {
- 'section': 'info',
- 'page': 'colors',
+ call: 'removeFromToolbar',
+ data: {
+ section: 'info',
+ page: 'colors',
'row': 0
},
- 'test': '*[rel=info].section *[rel=colors].page tr td',
- 'pre': 9,
- 'post': 6
+ test: '*[rel=info].section *[rel=colors].page tr td',
+ pre: 9,
+ post: 6
}
};
-$(document).ready( function() {
- var button = $( '<button>Run wikiEditor Tests!</button>' )
+
+jQuery(document).ready( function ( $ ) {
+ var $button = $( '<button>Run wikiEditor Tests!</button>' )
.css( {
- 'position': 'fixed',
- 'bottom': 0,
- 'right': 0,
- 'width': '100%',
- 'backgroundColor': '#333333',
- 'opacity': 0.75,
- 'color': '#DDDDDD',
- 'padding': '0.5em',
- 'border': 'none',
- 'display': 'none'
+ position: 'fixed',
+ bottom: 0,
+ right: 0,
+ width: '100%',
+ backgroundColor: '#333',
+ opacity: 0.75,
+ color: '#DDDDDD',
+ padding: '0.7em',
+ border: 'none',
+ display: 'none',
+ cursor: 'pointer'
} )
- .click( function() {
- if ( $(this).attr( 'enabled' ) == 'false' ) {
+ .click( function () {
+ if ( $(this).data( 'testDone' ) ) {
$(this).slideUp( 'fast' );
return false;
}
- var messages = [ 'Running tests for wikiEditor API' ];
- var $target = $( textareaId );
- var $ui = $target.data( 'wikiEditor-context' ).$ui;
- var passes = 0;
- var tests = 0;
- for ( var test in wikiEditorTests ) {
- var pre = $ui.find( wikiEditorTests[test].test ).size() ==
- wikiEditorTests[test].pre;
+
+ var test, pre, post,
+ messages = [ 'Running tests for wikiEditor API' ],
+ $target = $( textareaId ),
+ $ui = $target.data( 'wikiEditor-context' ).$ui,
+ passes = 0,
+ tests = 0;
+
+ for ( test in wikiEditorTests ) {
+ pre = $ui.find( wikiEditorTests[test].test ).length === wikiEditorTests[test].pre;
messages.push ( test + '-pre: ' + ( pre ? 'PASS' : 'FAIL' ) );
$target.wikiEditor(
wikiEditorTests[test].call,
wikiEditorTests[test].data
);
- var post = $ui.find( wikiEditorTests[test].test ).size() ==
- wikiEditorTests[test].post;
+ post = $ui.find( wikiEditorTests[test].test ).length === wikiEditorTests[test].post;
messages.push ( test + '-post: ' + ( post ? 'PASS' : 'FAIL' ) );
if ( pre && post ) {
passes++;
}
tests++;
}
- if ( window.console !== undefined ) {
+
+ if ( window.console ) {
for ( var i = 0; i < messages.length; i++ ) {
- console.log( messages[i] );
+ window.console.log( messages[i] );
}
}
+
$(this)
.attr( 'title', messages.join( " | " ) )
.text( passes + ' / ' + tests + ' were successful' )
.css( 'backgroundColor', passes < tests ? 'red' : 'green' )
- .attr( 'enabled', 'false' )
+ .data( 'testDone', 'true' )
.blur();
} )
.appendTo( $( 'body' ) );
- setTimeout( function() { button.slideDown( 'fast' ) }, 2000 );
+
+ setTimeout( function () {
+ $button.slideDown( 'fast' );
+ }, 1500 );
+
} );
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.css b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.css
index 15c1435b..efde00fb 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.css
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.css
@@ -80,6 +80,15 @@
background-image: url(images/dialogs/insert-link-external.png);
background-position: left;
}
+/* File dialog */
+#wikieditor-toolbar-file-target,
+#wikieditor-toolbar-file-caption {
+ width: 100%;
+}
+.wikieditor-toolbar-file-options .wikieditor-toolbar-field-wrapper {
+ float: left;
+ margin: 0 20px 0 0;
+}
/* Reference Dialog */
#wikieditor-toolbar-reference-dialog label {
float: left;
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js
index 0c24c368..ca8af558 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js
@@ -1,1201 +1,1372 @@
/**
* Configuration of Dialog module for wikiEditor
*/
-( function( $ ) { $.wikiEditor.modules.dialogs.config = {
+( function ( $, mw ) {
-replaceIcons: function( $textarea ) {
- $textarea
- .wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'xlink' } )
- .wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'ilink' } )
- .wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'reference' } )
- .wikiEditor( 'removeFromToolbar', { 'section': 'advanced', 'group': 'insert', 'tool': 'table' } )
- .wikiEditor( 'addToToolbar', {
- 'section': 'main',
- 'group': 'insert',
- 'tools': {
- 'link': {
- 'labelMsg': 'wikieditor-toolbar-tool-link',
- 'type': 'button',
- 'icon': 'insert-link.png',
- 'offset': [2, -1654],
- 'action': {
- 'type': 'dialog',
- 'module': 'insert-link'
- }
- },
- 'reference': {
- 'labelMsg': 'wikieditor-toolbar-tool-reference',
- 'filters': [ 'body.ns-subject' ],
- 'type': 'button',
- 'icon': 'insert-reference.png',
- 'offset': [2, -1798],
- 'action': {
- 'type': 'dialog',
- 'module': 'insert-reference'
+$.wikiEditor.modules.dialogs.config = {
+
+ replaceIcons: function ( $textarea ) {
+ $textarea
+ .wikiEditor( 'removeFromToolbar', { section: 'main', group: 'insert', tool: 'xlink' } )
+ .wikiEditor( 'removeFromToolbar', { section: 'main', group: 'insert', tool: 'ilink' } )
+ .wikiEditor( 'removeFromToolbar', { section: 'main', group: 'insert', tool: 'file' } )
+ .wikiEditor( 'removeFromToolbar', { section: 'main', group: 'insert', tool: 'reference' } )
+ .wikiEditor( 'removeFromToolbar', { section: 'advanced', group: 'insert', tool: 'table' } )
+ .wikiEditor( 'addToToolbar', {
+ section: 'main',
+ group: 'insert',
+ tools: {
+ 'link': {
+ labelMsg: 'wikieditor-toolbar-tool-link',
+ type: 'button',
+ icon: 'insert-link.png',
+ offset: [2, -1654],
+ action: {
+ type: 'dialog',
+ module: 'insert-link'
+ }
+ },
+ 'file': {
+ labelMsg: 'wikieditor-toolbar-tool-file',
+ type: 'button',
+ icon: 'insert-file.png',
+ offset: [2, -1438],
+ action: {
+ type: 'dialog',
+ module: 'insert-file'
+ }
+ },
+ 'reference': {
+ labelMsg: 'wikieditor-toolbar-tool-reference',
+ filters: [ 'body.ns-subject' ],
+ type: 'button',
+ icon: 'insert-reference.png',
+ offset: [2, -1798],
+ action: {
+ type: 'dialog',
+ module: 'insert-reference'
+ }
}
}
- }
- } )
- .wikiEditor( 'addToToolbar', {
- 'section': 'advanced',
- 'group': 'insert',
- 'tools': {
- 'table': {
- 'labelMsg': 'wikieditor-toolbar-tool-table',
- 'type': 'button',
- 'icon': 'insert-table.png',
- 'offset': [2, -1942],
- 'action': {
- 'type': 'dialog',
- 'module': 'insert-table'
+ } )
+ .wikiEditor( 'addToToolbar', {
+ section: 'advanced',
+ group: 'insert',
+ tools: {
+ 'table': {
+ labelMsg: 'wikieditor-toolbar-tool-table',
+ type: 'button',
+ icon: 'insert-table.png',
+ offset: [2, -1942],
+ action: {
+ type: 'dialog',
+ module: 'insert-table'
+ }
}
}
- }
- } )
- .wikiEditor( 'addToToolbar', {
- 'section': 'advanced',
- 'groups': {
- 'search': {
- 'tools': {
- 'replace': {
- 'labelMsg': 'wikieditor-toolbar-tool-replace',
- 'type': 'button',
- 'icon': 'search-replace.png',
- 'offset': [-70, -214],
- 'action': {
- 'type': 'dialog',
- 'module': 'search-and-replace'
+ } )
+ .wikiEditor( 'addToToolbar', {
+ section: 'advanced',
+ groups: {
+ 'search': {
+ tools: {
+ 'replace': {
+ labelMsg: 'wikieditor-toolbar-tool-replace',
+ type: 'button',
+ icon: 'search-replace.png',
+ offset: [-70, -214],
+ action: {
+ type: 'dialog',
+ module: 'search-and-replace'
+ }
}
}
}
}
- }
- } );
-},
+ } );
+ },
-getDefaultConfig: function () {
- return { 'dialogs': {
- 'insert-link': {
- titleMsg: 'wikieditor-toolbar-tool-link-title',
- id: 'wikieditor-toolbar-link-dialog',
- html: '\
- <fieldset>\
- <div class="wikieditor-toolbar-field-wrapper">\
- <label for="wikieditor-toolbar-link-int-target" rel="wikieditor-toolbar-tool-link-int-target" id="wikieditor-toolbar-tool-link-int-target-label"></label>\
- <div id="wikieditor-toolbar-link-int-target-status"></div>\
- <input type="text" id="wikieditor-toolbar-link-int-target" />\
- </div>\
- <div class="wikieditor-toolbar-field-wrapper">\
- <label for="wikieditor-toolbar-link-int-text" rel="wikieditor-toolbar-tool-link-int-text"></label>\
- <input type="text" id="wikieditor-toolbar-link-int-text" />\
- </div>\
- <div class="wikieditor-toolbar-field-wrapper">\
- <div class="wikieditor-toolbar-floated-field-wrapper">\
- <input type="radio" id="wikieditor-toolbar-link-type-int" name="wikieditor-toolbar-link-type" selected />\
- <label for="wikieditor-toolbar-link-type-int" rel="wikieditor-toolbar-tool-link-int"></label>\
+ getDefaultConfig: function () {
+ return { 'dialogs': {
+ 'insert-link': {
+ titleMsg: 'wikieditor-toolbar-tool-link-title',
+ id: 'wikieditor-toolbar-link-dialog',
+ html: '\
+ <fieldset>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-link-int-target" rel="wikieditor-toolbar-tool-link-int-target" id="wikieditor-toolbar-tool-link-int-target-label"></label>\
+ <div id="wikieditor-toolbar-link-int-target-status"></div>\
+ <input type="text" id="wikieditor-toolbar-link-int-target"/>\
</div>\
- <div class="wikieditor-toolbar-floated-field-wrapper">\
- <input type="radio" id="wikieditor-toolbar-link-type-ext" name="wikieditor-toolbar-link-type" />\
- <label for="wikieditor-toolbar-link-type-ext" rel="wikieditor-toolbar-tool-link-ext"></label>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-link-int-text" rel="wikieditor-toolbar-tool-link-int-text"></label>\
+ <input type="text" id="wikieditor-toolbar-link-int-text"/>\
</div>\
- </div>\
- </fieldset>',
- init: function() {
- function isExternalLink( s ) {
- // The following things are considered to be external links:
- // * Starts a URL protocol
- // * Starts with www.
- // All of these are potentially valid titles, and the latter two categories match about 6300
- // titles in enwiki's ns0. Out of 6.9M titles, that's 0.09%
- if ( typeof arguments.callee.regex == 'undefined' ) {
- // Cache the regex
- arguments.callee.regex =
- new RegExp( "^(" + mw.config.get( 'wgUrlProtocols' ) + "|www\\.)", 'i');
- }
- return s.match( arguments.callee.regex );
- }
- // Updates the status indicator above the target link
- function updateWidget( status ) {
- $( '#wikieditor-toolbar-link-int-target-status' ).children().hide();
- $( '#wikieditor-toolbar-link-int-target' ).parent()
- .removeClass(
- 'status-invalid status-external status-notexists status-exists status-loading'
- );
- if ( status ) {
- $( '#wikieditor-toolbar-link-int-target-status-' + status ).show();
- $( '#wikieditor-toolbar-link-int-target' ).parent().addClass( 'status-' + status );
- }
- if ( status == 'invalid' ) {
- $( '.ui-dialog:visible .ui-dialog-buttonpane button:first' )
- .attr( 'disabled', true )
- .addClass( 'disabled' );
- } else {
- $( '.ui-dialog:visible .ui-dialog-buttonpane button:first' )
- .removeAttr('disabled')
- .removeClass('disabled');
- }
- }
- // Updates the UI to show if the page title being inputed by the user exists or not
- // accepts parameter internal for bypassing external link detection
- function updateExistence( internal ) {
- // ensure the internal parameter is a boolean
- if ( internal != true ) internal = false;
- // Abort previous request
- var request = $( '#wikieditor-toolbar-link-int-target-status' ).data( 'request' );
- if ( request ) {
- request.abort();
- }
- var target = $( '#wikieditor-toolbar-link-int-target' ).val();
- var cache = $( '#wikieditor-toolbar-link-int-target-status' ).data( 'existencecache' );
- if ( cache[target] ) {
- updateWidget( cache[target] );
- return;
- }
- if ( target.replace( /^\s+$/,'' ) == '' ) {
- // Hide the widget when the textbox is empty
- updateWidget( false );
- return;
- }
- // If the forced internal paremter was not true, check if the target is an external link
- if ( !internal && isExternalLink( target ) ) {
- updateWidget( 'external' );
- return;
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <div class="wikieditor-toolbar-floated-field-wrapper">\
+ <input type="radio" id="wikieditor-toolbar-link-type-int" name="wikieditor-toolbar-link-type" selected/>\
+ <label for="wikieditor-toolbar-link-type-int" rel="wikieditor-toolbar-tool-link-int"></label>\
+ </div>\
+ <div class="wikieditor-toolbar-floated-field-wrapper">\
+ <input type="radio" id="wikieditor-toolbar-link-type-ext" name="wikieditor-toolbar-link-type"/>\
+ <label for="wikieditor-toolbar-link-type-ext" rel="wikieditor-toolbar-tool-link-ext"></label>\
+ </div>\
+ </div>\
+ </fieldset>',
+
+ init: function () {
+ function isExternalLink( s ) {
+ // The following things are considered to be external links:
+ // * Starts a URL protocol
+ // * Starts with www.
+ // All of these are potentially valid titles, and the latter two categories match about 6300
+ // titles in enwiki's ns0. Out of 6.9M titles, that's 0.09%
+ if ( typeof arguments.callee.regex === 'undefined' ) {
+ // Cache the regex
+ arguments.callee.regex =
+ new RegExp( "^(" + mw.config.get( 'wgUrlProtocols' ) + "|www\\.)", 'i');
+ }
+ return s.match( arguments.callee.regex );
}
- if ( target.indexOf( '|' ) != -1 ) {
- // Title contains | , which means it's invalid
- // but confuses the API. Show invalid and bypass API
- updateWidget( 'invalid' );
- return;
+
+ // Updates the status indicator above the target link
+ function updateWidget( status ) {
+ $( '#wikieditor-toolbar-link-int-target-status' ).children().hide();
+ $( '#wikieditor-toolbar-link-int-target' ).parent()
+ .removeClass(
+ 'status-invalid status-external status-notexists status-exists status-loading'
+ );
+ if ( status ) {
+ $( '#wikieditor-toolbar-link-int-target-status-' + status ).show();
+ $( '#wikieditor-toolbar-link-int-target' ).parent().addClass( 'status-' + status );
+ }
+ if ( status === 'invalid' ) {
+ $( '.ui-dialog:visible .ui-dialog-buttonpane button:first' )
+ .attr( 'disabled', true )
+ .addClass( 'disabled' );
+ } else {
+ $( '.ui-dialog:visible .ui-dialog-buttonpane button:first' )
+ .removeAttr('disabled')
+ .removeClass('disabled');
+ }
}
- // Show loading spinner while waiting for the API to respond
- updateWidget( 'loading' );
- // Call the API to check page status, saving the request object so it can be aborted if
- // necessary
- $( '#wikieditor-toolbar-link-int-target-status' ).data(
- 'request',
- $.ajax( {
- url: mw.util.wikiScript( 'api' ),
- dataType: 'json',
- data: {
- 'action': 'query',
- 'indexpageids': '',
- 'titles': target,
- 'converttitles': '',
- 'format': 'json'
- },
- success: function( data ) {
- var status;
- if ( !data || typeof data.query == 'undefined' ) {
- // This happens in some weird cases
- status = false;
- } else {
- var page = data.query.pages[data.query.pageids[0]];
- status = 'exists';
- if ( typeof page.missing != 'undefined' )
- status = 'notexists';
- else if ( typeof page.invalid != 'undefined' )
- status = 'invalid';
- }
- // Cache the status of the link target if the force internal parameter was not
- // passed
- if ( !internal ) cache[target] = status;
- updateWidget( status );
- }
- } )
- );
- }
- $( '#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext' ).click( function() {
- if( $( '#wikieditor-toolbar-link-type-ext' ).is( ':checked' ) ) {
+
+ // Updates the UI to show if the page title being inputed by the user exists or not
+ // accepts parameter internal for bypassing external link detection
+ function updateExistence( internal ) {
+ // ensure the internal parameter is a boolean
+ if ( internal !== true ) {
+ internal = false;
+ }
// Abort previous request
var request = $( '#wikieditor-toolbar-link-int-target-status' ).data( 'request' );
if ( request ) {
request.abort();
}
- updateWidget( 'external' );
- }
- if( $( '#wikieditor-toolbar-link-type-int' ).is( ':checked' ) )
- updateExistence( true );
- });
- // Set labels of tabs based on rel values
- $(this).find( '[rel]' ).each( function() {
- $(this).text( mediaWiki.msg( $(this).attr( 'rel' ) ) );
- });
- // Set tabindexes on form fields
- $.wikiEditor.modules.dialogs.fn.setTabindexes( $(this).find( 'input' ).not( '[tabindex]' ) );
- // Setup the tooltips in the textboxes
- $( '#wikieditor-toolbar-link-int-target' )
- .data( 'tooltip', mediaWiki.msg( 'wikieditor-toolbar-tool-link-int-target-tooltip' ) );
- $( '#wikieditor-toolbar-link-int-text' )
- .data( 'tooltip', mediaWiki.msg( 'wikieditor-toolbar-tool-link-int-text-tooltip' ) );
- $( '#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text' )
- .each( function() {
- var tooltip = mediaWiki.msg( $( this ).attr( 'id' ) + '-tooltip' );
- if ( $( this ).val() == '' )
- $( this )
- .addClass( 'wikieditor-toolbar-dialog-hint' )
- .val( $( this ).data( 'tooltip' ) )
- .data( 'tooltip-mode', true );
- } )
- .focus( function() {
- if( $( this ).val() == $( this ).data( 'tooltip' ) ) {
- $( this )
- .val( '' )
- .removeClass( 'wikieditor-toolbar-dialog-hint' )
- .data( 'tooltip-mode', false );
- }
- })
- .bind( 'change', function() {
- if ( $( this ).val() != $( this ).data( 'tooltip' ) ) {
- $( this )
- .removeClass( 'wikieditor-toolbar-dialog-hint' )
- .data( 'tooltip-mode', false );
+ var target = $( '#wikieditor-toolbar-link-int-target' ).val();
+ var cache = $( '#wikieditor-toolbar-link-int-target-status' ).data( 'existencecache' );
+ if ( cache[target] ) {
+ updateWidget( cache[target] );
+ return;
}
- })
- .bind( 'blur', function() {
- if ( $( this ).val() == '' ) {
- $( this )
- .addClass( 'wikieditor-toolbar-dialog-hint' )
- .val( $( this ).data( 'tooltip' ) )
- .data( 'tooltip-mode', true );
+ if ( target.replace( /^\s+$/,'' ) === '' ) {
+ // Hide the widget when the textbox is empty
+ updateWidget( false );
+ return;
}
- });
-
- // Automatically copy the value of the internal link page title field to the link text field unless the
- // user has changed the link text field - this is a convenience thing since most link texts are going to
- // be the the same as the page title - Also change the internal/external radio button accordingly
- $( '#wikieditor-toolbar-link-int-target' ).bind( 'change keydown paste cut', function() {
- // $(this).val() is the old value, before the keypress - Defer this until $(this).val() has
- // been updated
- setTimeout( function() {
- if ( isExternalLink( $( '#wikieditor-toolbar-link-int-target' ).val() ) ) {
- $( '#wikieditor-toolbar-link-type-ext' ).attr( 'checked', 'checked' );
+ // If the forced internal paremter was not true, check if the target is an external link
+ if ( !internal && isExternalLink( target ) ) {
updateWidget( 'external' );
- } else {
- $( '#wikieditor-toolbar-link-type-int' ).attr( 'checked', 'checked' );
- updateExistence();
+ return;
}
- if ( $( '#wikieditor-toolbar-link-int-text' ).data( 'untouched' ) )
- if ( $( '#wikieditor-toolbar-link-int-target' ).val() ==
- $( '#wikieditor-toolbar-link-int-target' ).data( 'tooltip' ) ) {
- $( '#wikieditor-toolbar-link-int-text' )
- .addClass( 'wikieditor-toolbar-dialog-hint' )
- .val( $( '#wikieditor-toolbar-link-int-text' ).data( 'tooltip' ) )
- .change();
- } else {
- $( '#wikieditor-toolbar-link-int-text' )
- .val( $( '#wikieditor-toolbar-link-int-target' ).val() )
- .change();
- }
- }, 0 );
- });
- $( '#wikieditor-toolbar-link-int-text' ).bind( 'change keydown paste cut', function() {
- var oldVal = $(this).val();
- var that = this;
- setTimeout( function() {
- if ( $(that).val() != oldVal )
- $(that).data( 'untouched', false );
- }, 0 );
- });
- // Add images to the page existence widget, which will be shown mutually exclusively to communicate if
- // the page exists, does not exist or the title is invalid (like if it contains a | character)
- var existsMsg = mediaWiki.msg( 'wikieditor-toolbar-tool-link-int-target-status-exists' );
- var notexistsMsg = mediaWiki.msg( 'wikieditor-toolbar-tool-link-int-target-status-notexists' );
- var invalidMsg = mediaWiki.msg( 'wikieditor-toolbar-tool-link-int-target-status-invalid' );
- var externalMsg = mediaWiki.msg( 'wikieditor-toolbar-tool-link-int-target-status-external' );
- var loadingMsg = mediaWiki.msg( 'wikieditor-toolbar-tool-link-int-target-status-loading' );
- $( '#wikieditor-toolbar-link-int-target-status' )
- .append( $( '<div />' )
- .attr( 'id', 'wikieditor-toolbar-link-int-target-status-exists' )
- .append( existsMsg )
- )
- .append( $( '<div />' )
- .attr( 'id', 'wikieditor-toolbar-link-int-target-status-notexists' )
- .append( notexistsMsg )
- )
- .append( $( '<div />' )
- .attr( 'id', 'wikieditor-toolbar-link-int-target-status-invalid' )
- .append( invalidMsg )
- )
- .append( $( '<div />' )
- .attr( 'id', 'wikieditor-toolbar-link-int-target-status-external' )
- .append( externalMsg )
- )
- .append( $( '<div />' )
- .attr( 'id', 'wikieditor-toolbar-link-int-target-status-loading' )
- .append( $( '<img />' ).attr( {
- 'src': $.wikiEditor.imgPath + 'dialogs/' + 'loading-small.gif',
- 'alt': loadingMsg,
- 'title': loadingMsg
- } ) )
- )
- .data( 'existencecache', {} )
- .children().hide();
-
- $( '#wikieditor-toolbar-link-int-target' )
- .bind( 'keyup paste cut', function() {
- // Cancel the running timer if applicable
- if ( typeof $(this).data( 'timerID' ) != 'undefined' ) {
- clearTimeout( $(this).data( 'timerID' ) );
+ if ( target.indexOf( '|' ) !== -1 ) {
+ // Title contains | , which means it's invalid
+ // but confuses the API. Show invalid and bypass API
+ updateWidget( 'invalid' );
+ return;
}
- // Delay fetch for a while
- // FIXME: Make 120 configurable elsewhere
- var timerID = setTimeout( updateExistence, 120 );
- $(this).data( 'timerID', timerID );
- } )
- .change( function() {
- // Cancel the running timer if applicable
- if ( typeof $(this).data( 'timerID' ) != 'undefined' ) {
- clearTimeout( $(this).data( 'timerID' ) );
+ // Show loading spinner while waiting for the API to respond
+ updateWidget( 'loading' );
+ // Call the API to check page status, saving the request object so it can be aborted if
+ // necessary
+ $( '#wikieditor-toolbar-link-int-target-status' ).data(
+ 'request',
+ $.ajax( {
+ url: mw.util.wikiScript( 'api' ),
+ dataType: 'json',
+ data: {
+ action: 'query',
+ indexpageids: '',
+ titles: target,
+ converttitles: '',
+ format: 'json'
+ },
+ success: function ( data ) {
+ var status;
+ if ( !data || !data.query ) {
+ // This happens in some weird cases
+ status = false;
+ } else {
+ var page = data.query.pages[data.query.pageids[0]];
+ status = 'exists';
+ if ( page.missing !== undefined ) {
+ status = 'notexists';
+ } else if ( page.invalid !== undefined ) {
+ status = 'invalid';
+ }
+ }
+ // Cache the status of the link target if the force internal
+ // parameter was not passed
+ if ( !internal ) {
+ cache[target] = status;
+ }
+ updateWidget( status );
+ }
+ } )
+ );
+ }
+ $( '#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext' ).click( function () {
+ if ( $( '#wikieditor-toolbar-link-type-ext' ).is( ':checked' ) ) {
+ // Abort previous request
+ var request = $( '#wikieditor-toolbar-link-int-target-status' ).data( 'request' );
+ if ( request ) {
+ request.abort();
+ }
+ updateWidget( 'external' );
}
- // Fetch right now
- updateExistence();
- } );
+ if ( $( '#wikieditor-toolbar-link-type-int' ).is( ':checked' ) )
+ updateExistence( true );
+ });
+ // Set labels of tabs based on rel values
+ $(this).find( '[rel]' ).each( function () {
+ $(this).text( mw.msg( $(this).attr( 'rel' ) ) );
+ });
+ // Set tabindexes on form fields
+ $.wikiEditor.modules.dialogs.fn.setTabindexes( $(this).find( 'input' ).not( '[tabindex]' ) );
+ // Setup the tooltips in the textboxes
+ $( '#wikieditor-toolbar-link-int-target' )
+ .data( 'tooltip', mw.msg( 'wikieditor-toolbar-tool-link-int-target-tooltip' ) );
+ $( '#wikieditor-toolbar-link-int-text' )
+ .data( 'tooltip', mw.msg( 'wikieditor-toolbar-tool-link-int-text-tooltip' ) );
+ $( '#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text' )
+ .each( function () {
+ var tooltip = mw.msg( $( this ).attr( 'id' ) + '-tooltip' );
+ if ( $( this ).val() === '' )
+ $( this )
+ .addClass( 'wikieditor-toolbar-dialog-hint' )
+ .val( $( this ).data( 'tooltip' ) )
+ .data( 'tooltip-mode', true );
+ } )
+ .focus( function () {
+ if ( $( this ).val() === $( this ).data( 'tooltip' ) ) {
+ $( this )
+ .val( '' )
+ .removeClass( 'wikieditor-toolbar-dialog-hint' )
+ .data( 'tooltip-mode', false );
+ }
+ })
+ .bind( 'change', function () {
+ if ( $( this ).val() !== $( this ).data( 'tooltip' ) ) {
+ $( this )
+ .removeClass( 'wikieditor-toolbar-dialog-hint' )
+ .data( 'tooltip-mode', false );
+ }
+ })
+ .bind( 'blur', function () {
+ if ( $( this ).val() === '' ) {
+ $( this )
+ .addClass( 'wikieditor-toolbar-dialog-hint' )
+ .val( $( this ).data( 'tooltip' ) )
+ .data( 'tooltip-mode', true );
+ }
+ });
- // Title suggestions
- $( '#wikieditor-toolbar-link-int-target' ).data( 'suggcache', {} ).suggestions( {
- fetch: function( query ) {
+ // Automatically copy the value of the internal link page title field to the link text field unless the
+ // user has changed the link text field - this is a convenience thing since most link texts are going to
+ // be the the same as the page title - Also change the internal/external radio button accordingly
+ $( '#wikieditor-toolbar-link-int-target' ).bind( 'change keydown paste cut', function () {
+ // $(this).val() is the old value, before the keypress - Defer this until $(this).val() has
+ // been updated
+ setTimeout( function () {
+ if ( isExternalLink( $( '#wikieditor-toolbar-link-int-target' ).val() ) ) {
+ $( '#wikieditor-toolbar-link-type-ext' ).prop( 'checked', true );
+ updateWidget( 'external' );
+ } else {
+ $( '#wikieditor-toolbar-link-type-int' ).prop( 'checked', true );
+ updateExistence();
+ }
+ if ( $( '#wikieditor-toolbar-link-int-text' ).data( 'untouched' ) )
+ if ( $( '#wikieditor-toolbar-link-int-target' ).val() ==
+ $( '#wikieditor-toolbar-link-int-target' ).data( 'tooltip' ) ) {
+ $( '#wikieditor-toolbar-link-int-text' )
+ .addClass( 'wikieditor-toolbar-dialog-hint' )
+ .val( $( '#wikieditor-toolbar-link-int-text' ).data( 'tooltip' ) )
+ .change();
+ } else {
+ $( '#wikieditor-toolbar-link-int-text' )
+ .val( $( '#wikieditor-toolbar-link-int-target' ).val() )
+ .change();
+ }
+ }, 0 );
+ });
+ $( '#wikieditor-toolbar-link-int-text' ).bind( 'change keydown paste cut', function () {
+ var oldVal = $(this).val();
var that = this;
- var title = $(this).val();
+ setTimeout( function () {
+ if ( $(that).val() !== oldVal )
+ $(that).data( 'untouched', false );
+ }, 0 );
+ });
+ // Add images to the page existence widget, which will be shown mutually exclusively to communicate if
+ // the page exists, does not exist or the title is invalid (like if it contains a | character)
+ var existsMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-exists' );
+ var notexistsMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-notexists' );
+ var invalidMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-invalid' );
+ var externalMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-external' );
+ var loadingMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-loading' );
+ $( '#wikieditor-toolbar-link-int-target-status' )
+ .append( $( '<div>' )
+ .attr( 'id', 'wikieditor-toolbar-link-int-target-status-exists' )
+ .append( existsMsg )
+ )
+ .append( $( '<div>' )
+ .attr( 'id', 'wikieditor-toolbar-link-int-target-status-notexists' )
+ .append( notexistsMsg )
+ )
+ .append( $( '<div>' )
+ .attr( 'id', 'wikieditor-toolbar-link-int-target-status-invalid' )
+ .append( invalidMsg )
+ )
+ .append( $( '<div>' )
+ .attr( 'id', 'wikieditor-toolbar-link-int-target-status-external' )
+ .append( externalMsg )
+ )
+ .append( $( '<div>' )
+ .attr( 'id', 'wikieditor-toolbar-link-int-target-status-loading' )
+ .append( $( '<img>' ).attr( {
+ 'src': $.wikiEditor.imgPath + 'dialogs/' + 'loading-small.gif',
+ 'alt': loadingMsg,
+ 'title': loadingMsg
+ } ) )
+ )
+ .data( 'existencecache', {} )
+ .children().hide();
- if ( isExternalLink( title ) || title.indexOf( '|' ) != -1 || title == '') {
- $(this).suggestions( 'suggestions', [] );
- return;
- }
+ $( '#wikieditor-toolbar-link-int-target' )
+ .bind( 'keyup paste cut', function () {
+ // Cancel the running timer if applicable
+ if ( typeof $(this).data( 'timerID' ) !== 'undefined' ) {
+ clearTimeout( $(this).data( 'timerID' ) );
+ }
+ // Delay fetch for a while
+ // FIXME: Make 120 configurable elsewhere
+ var timerID = setTimeout( updateExistence, 120 );
+ $(this).data( 'timerID', timerID );
+ } )
+ .change( function () {
+ // Cancel the running timer if applicable
+ if ( typeof $(this).data( 'timerID' ) !== 'undefined' ) {
+ clearTimeout( $(this).data( 'timerID' ) );
+ }
+ // Fetch right now
+ updateExistence();
+ } );
- var cache = $(this).data( 'suggcache' );
- if ( typeof cache[title] != 'undefined' ) {
- $(this).suggestions( 'suggestions', cache[title] );
- return;
- }
+ // Title suggestions
+ $( '#wikieditor-toolbar-link-int-target' ).data( 'suggcache', {} ).suggestions( {
+ fetch: function ( query ) {
+ var that = this;
+ var title = $(this).val();
- var request = $.ajax( {
- url: mw.util.wikiScript( 'api' ),
- data: {
- 'action': 'opensearch',
- 'search': title,
- 'namespace': 0,
- 'suggest': '',
- 'format': 'json'
- },
- dataType: 'json',
- success: function( data ) {
- cache[title] = data[1];
- $(that).suggestions( 'suggestions', data[1] );
- }
- });
- $(this).data( 'request', request );
- },
- cancel: function() {
- var request = $(this).data( 'request' );
- if ( request )
- request.abort();
- }
- });
- },
- dialog: {
- width: 500,
- dialogClass: 'wikiEditor-toolbar-dialog',
- buttons: {
- 'wikieditor-toolbar-tool-link-insert': function() {
- function escapeInternalText( s ) {
- // FIXME: Should this escape [[ too? Seems to work without that
- return s.replace( /(]{2,})/g, '<nowiki>$1</nowiki>' );
- }
- function escapeExternalTarget( s ) {
- return s.replace( / /g, '%20' )
- .replace( /\[/g, '%5B' )
- .replace( /]/g, '%5D' );
- }
- function escapeExternalText( s ) {
- // FIXME: Should this escape [ too? Seems to work without that
- return s.replace( /(]+)/g, '<nowiki>$1</nowiki>' );
- }
- var insertText = '';
- var whitespace = $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace' );
- var target = $( '#wikieditor-toolbar-link-int-target' ).val();
- var text = $( '#wikieditor-toolbar-link-int-text' ).val();
- // check if the tooltips were passed as target or text
- if ( $( '#wikieditor-toolbar-link-int-target' ).data( 'tooltip-mode' ) )
- target = "";
- if ( $( '#wikieditor-toolbar-link-int-text' ).data( 'tooltip-mode' ) )
- text = "";
- if ( target == '' ) {
- alert( mediaWiki.msg( 'wikieditor-toolbar-tool-link-empty' ) );
- return;
- }
- if ( $.trim( text ) == '' ) {
- // [[Foo| ]] creates an invisible link
- // Instead, generate [[Foo|]]
- text = '';
- }
- if ( $( '#wikieditor-toolbar-link-type-int' ).is( ':checked' ) ) {
- // FIXME: Exactly how fragile is this?
- if ( $( '#wikieditor-toolbar-link-int-target-status-invalid' ).is( ':visible' ) ) {
- // Refuse to add links to invalid titles
- alert( mediaWiki.msg( 'wikieditor-toolbar-tool-link-int-invalid' ) );
+ if ( isExternalLink( title ) || title.indexOf( '|' ) !== -1 || title === '') {
+ $(this).suggestions( 'suggestions', [] );
return;
}
- if ( target == text || !text.length )
- insertText = '[[' + target + ']]';
- else
- insertText = '[[' + target + '|' + escapeInternalText( text ) + ']]';
- } else {
- // Prepend http:// if there is no protocol
- if ( !target.match( /^[a-z]+:\/\/./ ) )
- target = 'http://' + target;
+ var cache = $(this).data( 'suggcache' );
+ if ( typeof cache[title] !== 'undefined' ) {
+ $(this).suggestions( 'suggestions', cache[title] );
+ return;
+ }
- // Detect if this is really an internal link in disguise
- var match = target.match( $(this).data( 'articlePathRegex' ) );
- if ( match && !$(this).data( 'ignoreLooksInternal' ) ) {
- var buttons = { };
- var that = this;
- buttons[ mediaWiki.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal-int' ) ] =
- function() {
- $( '#wikieditor-toolbar-link-int-target' ).val( match[1] ).change();
- $(this).dialog( 'close' );
- };
- buttons[ mediaWiki.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal-ext' ) ] =
- function() {
- $(that).data( 'ignoreLooksInternal', true );
- $(that).closest( '.ui-dialog' ).find( 'button:first' ).click();
- $(that).data( 'ignoreLooksInternal', false );
- $(this).dialog( 'close' );
- };
- $.wikiEditor.modules.dialogs.quickDialog(
- mediaWiki.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal', match[1] ),
- { buttons: buttons }
- );
+ var request = $.ajax( {
+ url: mw.util.wikiScript( 'api' ),
+ data: {
+ action: 'opensearch',
+ search: title,
+ namespace: 0,
+ suggest: '',
+ format: 'json'
+ },
+ dataType: 'json',
+ success: function ( data ) {
+ cache[title] = data[1];
+ $(that).suggestions( 'suggestions', data[1] );
+ }
+ });
+ $(this).data( 'request', request );
+ },
+ cancel: function () {
+ var request = $(this).data( 'request' );
+ if ( request )
+ request.abort();
+ }
+ });
+ },
+ dialog: {
+ width: 500,
+ dialogClass: 'wikiEditor-toolbar-dialog',
+ buttons: {
+ 'wikieditor-toolbar-tool-link-insert': function () {
+ function escapeInternalText( s ) {
+ return s.replace( /(\]{2,})/g, '<nowiki>$1</nowiki>' );
+ }
+ function escapeExternalTarget( s ) {
+ return s.replace( / /g, '%20' )
+ .replace( /\[/g, '%5B' )
+ .replace( /\]/g, '%5D' );
+ }
+ function escapeExternalText( s ) {
+ return s.replace( /(\]+)/g, '<nowiki>$1</nowiki>' );
+ }
+ var insertText = '';
+ var whitespace = $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace' );
+ var target = $( '#wikieditor-toolbar-link-int-target' ).val();
+ var text = $( '#wikieditor-toolbar-link-int-text' ).val();
+ // check if the tooltips were passed as target or text
+ if ( $( '#wikieditor-toolbar-link-int-target' ).data( 'tooltip-mode' ) )
+ target = "";
+ if ( $( '#wikieditor-toolbar-link-int-text' ).data( 'tooltip-mode' ) )
+ text = "";
+ if ( target === '' ) {
+ alert( mw.msg( 'wikieditor-toolbar-tool-link-empty' ) );
return;
}
+ if ( $.trim( text ) === '' ) {
+ // [[Foo| ]] creates an invisible link
+ // Instead, generate [[Foo|]]
+ text = '';
+ }
+ if ( $( '#wikieditor-toolbar-link-type-int' ).is( ':checked' ) ) {
+ // FIXME: Exactly how fragile is this?
+ if ( $( '#wikieditor-toolbar-link-int-target-status-invalid' ).is( ':visible' ) ) {
+ // Refuse to add links to invalid titles
+ alert( mw.msg( 'wikieditor-toolbar-tool-link-int-invalid' ) );
+ return;
+ }
- var escTarget = escapeExternalTarget( target );
- var escText = escapeExternalText( text );
+ if ( target === text || !text.length )
+ insertText = '[[' + target + ']]';
+ else
+ insertText = '[[' + target + '|' + escapeInternalText( text ) + ']]';
+ } else {
+ // Prepend http:// if there is no protocol
+ if ( !target.match( /^[a-z]+:\/\/./ ) )
+ target = 'http://' + target;
- if ( escTarget == escText )
- insertText = escTarget;
- else if ( text == '' )
- insertText = '[' + escTarget + ']';
- else
- insertText = '[' + escTarget + ' ' + escText + ']';
- }
- // Preserve whitespace in selection when replacing
- if ( whitespace ) insertText = whitespace[0] + insertText + whitespace[1];
- $(this).dialog( 'close' );
- $.wikiEditor.modules.toolbar.fn.doAction( $(this).data( 'context' ), {
- type: 'replace',
- options: {
- pre: insertText
+ // Detect if this is really an internal link in disguise
+ var match = target.match( $(this).data( 'articlePathRegex' ) );
+ if ( match && !$(this).data( 'ignoreLooksInternal' ) ) {
+ var buttons = { };
+ var that = this;
+ buttons[ mw.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal-int' ) ] =
+ function () {
+ $( '#wikieditor-toolbar-link-int-target' ).val( match[1] ).change();
+ $(this).dialog( 'close' );
+ };
+ buttons[ mw.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal-ext' ) ] =
+ function () {
+ $(that).data( 'ignoreLooksInternal', true );
+ $(that).closest( '.ui-dialog' ).find( 'button:first' ).click();
+ $(that).data( 'ignoreLooksInternal', false );
+ $(this).dialog( 'close' );
+ };
+ $.wikiEditor.modules.dialogs.quickDialog(
+ mw.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal', match[1] ),
+ { buttons: buttons }
+ );
+ return;
+ }
+
+ var escTarget = escapeExternalTarget( target );
+ var escText = escapeExternalText( text );
+
+ if ( escTarget === escText )
+ insertText = escTarget;
+ else if ( text === '' )
+ insertText = '[' + escTarget + ']';
+ else
+ insertText = '[' + escTarget + ' ' + escText + ']';
+ }
+ // Preserve whitespace in selection when replacing
+ if ( whitespace ) {
+ insertText = whitespace[0] + insertText + whitespace[1];
}
- }, $(this) );
+ $(this).dialog( 'close' );
+ $.wikiEditor.modules.toolbar.fn.doAction( $(this).data( 'context' ), {
+ type: 'replace',
+ options: {
+ pre: insertText
+ }
+ }, $(this) );
- // Blank form
- $( '#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text' ).val( '' );
- $( '#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext' )
- .attr( 'checked', '' );
+ // Blank form
+ $( '#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text' ).val( '' );
+ $( '#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext' )
+ .attr( 'checked', '' );
+ },
+ 'wikieditor-toolbar-tool-link-cancel': function () {
+ // Clear any saved selection state
+ var context = $(this).data( 'context' );
+ context.fn.restoreCursorAndScrollTop();
+ $(this).dialog( 'close' );
+ }
},
- 'wikieditor-toolbar-tool-link-cancel': function() {
- // Clear any saved selection state
+ open: function () {
+ var target, text, type, matches;
+
+ // Obtain the server name without the protocol. wgServer may be protocol-relative
+ var serverName = mw.config.get( 'wgServer' ).replace( /^(https?:)?\/\//, '' );
+ // Cache the articlepath regex
+ $(this).data( 'articlePathRegex', new RegExp(
+ '^https?://' + $.escapeRE( serverName + mw.config.get( 'wgArticlePath' ) )
+ .replace( /\\\$1/g, '(.*)' ) + '$'
+ ) );
+ // Pre-fill the text fields based on the current selection
var context = $(this).data( 'context' );
+ // Restore and immediately save selection state, needed for inserting stuff later
context.fn.restoreCursorAndScrollTop();
- $(this).dialog( 'close' );
- }
- },
- open: function() {
- // Obtain the server name without the protocol. wgServer may be protocol-relative
- var serverName = mw.config.get( 'wgServer' ).replace( /^(https?:)?\/\//, '' );
- // Cache the articlepath regex
- $(this).data( 'articlePathRegex', new RegExp(
- '^https?://' + $.escapeRE( serverName + mw.config.get( 'wgArticlePath' ) )
- .replace( /\\\$1/g, '(.*)' ) + '$'
- ) );
- // Pre-fill the text fields based on the current selection
- var context = $(this).data( 'context' );
- // Restore and immediately save selection state, needed for inserting stuff later
- context.fn.restoreCursorAndScrollTop();
- context.fn.saveCursorAndScrollTop();
- var selection = context.$textarea.textSelection( 'getSelection' );
- $( '#wikieditor-toolbar-link-int-target' ).focus();
- // Trigger the change event, so the link status indicator is up to date
- $( '#wikieditor-toolbar-link-int-target' ).change();
- $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [ '', '' ] );
- if ( selection != '' ) {
- var target, text, type;
- var matches;
- if ( ( matches = selection.match( /^(\s*)\[\[([^\]\|]+)(\|([^\]\|]*))?\]\](\s*)$/ ) ) ) {
- // [[foo|bar]] or [[foo]]
- target = matches[2];
- text = ( matches[4] ? matches[4] : matches[2] );
- type = 'int';
- // Preserve whitespace when replacing
- $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [ matches[1], matches[5] ] );
- } else if ( ( matches = selection.match( /^(\s*)\[([^\] ]+)( ([^\]]+))?\](\s*)$/ ) ) ) {
- // [http://www.example.com foo] or [http://www.example.com]
- target = matches[2];
- text = ( matches[4] ? matches[4] : '' );
- type = 'ext';
- // Preserve whitespace when replacing
- $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [ matches[1], matches[5] ] );
- } else {
- // Trim any leading and trailing whitespace from the selection,
- // but preserve it when replacing
- target = text = $.trim( selection );
- if ( target.length < selection.length ) {
- $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [
- selection.substr( 0, selection.indexOf( target.charAt( 0 ) ) ),
- selection.substr(
- selection.lastIndexOf( target.charAt( target.length - 1 ) ) + 1
- ) ]
- );
+ context.fn.saveCursorAndScrollTop();
+ var selection = context.$textarea.textSelection( 'getSelection' );
+ $( '#wikieditor-toolbar-link-int-target' ).focus();
+ // Trigger the change event, so the link status indicator is up to date
+ $( '#wikieditor-toolbar-link-int-target' ).change();
+ $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [ '', '' ] );
+ if ( selection !== '' ) {
+ if ( ( matches = selection.match( /^(\s*)\[\[([^\]\|]+)(\|([^\]\|]*))?\]\](\s*)$/ ) ) ) {
+ // [[foo|bar]] or [[foo]]
+ target = matches[2];
+ text = ( matches[4] ? matches[4] : matches[2] );
+ type = 'int';
+ // Preserve whitespace when replacing
+ $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [ matches[1], matches[5] ] );
+ } else if ( ( matches = selection.match( /^(\s*)\[([^\] ]+)( ([^\]]+))?\](\s*)$/ ) ) ) {
+ // [http://www.example.com foo] or [http://www.example.com]
+ target = matches[2];
+ text = ( matches[4] || '' );
+ type = 'ext';
+ // Preserve whitespace when replacing
+ $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [ matches[1], matches[5] ] );
+ } else {
+ // Trim any leading and trailing whitespace from the selection,
+ // but preserve it when replacing
+ target = text = $.trim( selection );
+ if ( target.length < selection.length ) {
+ $( '#wikieditor-toolbar-link-dialog' ).data( 'whitespace', [
+ selection.substr( 0, selection.indexOf( target.charAt( 0 ) ) ),
+ selection.substr(
+ selection.lastIndexOf( target.charAt( target.length - 1 ) ) + 1
+ ) ]
+ );
+ }
}
- }
- // Change the value by calling val() doesn't trigger the change event, so let's do that
- // ourselves
- if ( typeof text != 'undefined' )
- $( '#wikieditor-toolbar-link-int-text' ).val( text ).change();
- if ( typeof target != 'undefined' )
- $( '#wikieditor-toolbar-link-int-target' ).val( target ).change();
- if ( typeof type != 'undefined' )
- $( '#wikieditor-toolbar-link-' + type ).attr( 'checked', 'checked' );
- }
- $( '#wikieditor-toolbar-link-int-text' ).data( 'untouched',
- $( '#wikieditor-toolbar-link-int-text' ).val() ==
- $( '#wikieditor-toolbar-link-int-target' ).val() ||
- $( '#wikieditor-toolbar-link-int-text' ).hasClass( 'wikieditor-toolbar-dialog-hint' )
- );
- $( '#wikieditor-toolbar-link-int-target' ).suggestions();
+ // Change the value by calling val() doesn't trigger the change event, so let's do that
+ // ourselves
+ if ( typeof text !== 'undefined' )
+ $( '#wikieditor-toolbar-link-int-text' ).val( text ).change();
+ if ( typeof target !== 'undefined' )
+ $( '#wikieditor-toolbar-link-int-target' ).val( target ).change();
+ if ( typeof type !== 'undefined' )
+ $( '#wikieditor-toolbar-link-' + type ).prop( 'checked', true );
+ }
+ $( '#wikieditor-toolbar-link-int-text' ).data( 'untouched',
+ $( '#wikieditor-toolbar-link-int-text' ).val() ===
+ $( '#wikieditor-toolbar-link-int-target' ).val() ||
+ $( '#wikieditor-toolbar-link-int-text' ).hasClass( 'wikieditor-toolbar-dialog-hint' )
+ );
+ $( '#wikieditor-toolbar-link-int-target' ).suggestions();
- //don't overwrite user's text
- if( selection != '' ){
- $( '#wikieditor-toolbar-link-int-text' ).data( 'untouched', false );
- }
+ // don't overwrite user's text
+ if ( selection !== '' ){
+ $( '#wikieditor-toolbar-link-int-text' ).data( 'untouched', false );
+ }
- $( '#wikieditor-toolbar-link-int-text, #wikiedit-toolbar-link-int-target' )
- .each( function() {
- if ( $(this).val() == '' )
- $(this).parent().find( 'label' ).show();
- });
+ $( '#wikieditor-toolbar-link-int-text, #wikiedit-toolbar-link-int-target' )
+ .each( function () {
+ if ( $(this).val() === '' )
+ $(this).parent().find( 'label' ).show();
+ });
- if ( !( $(this).data( 'dialogkeypressset' ) ) ) {
- $(this).data( 'dialogkeypressset', true );
- // Execute the action associated with the first button
- // when the user presses Enter
- $(this).closest( '.ui-dialog' ).keypress( function( e ) {
- if ( ( e.keyCode || e.which ) == 13 ) {
- var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' );
- button.click();
- e.preventDefault();
- }
- });
+ if ( !$(this).data( 'dialogkeypressset' ) ) {
+ $(this).data( 'dialogkeypressset', true );
+ // Execute the action associated with the first button
+ // when the user presses Enter
+ $(this).closest( '.ui-dialog' ).keypress( function ( e ) {
+ if ( ( e.keyCode || e.which ) == 13 ) {
+ var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' );
+ button.click();
+ e.preventDefault();
+ }
+ });
- // Make tabbing to a button and pressing
- // Enter do what people expect
- $(this).closest( '.ui-dialog' ).find( 'button' ).focus( function() {
- $(this).closest( '.ui-dialog' ).data( 'dialogaction', this );
- });
+ // Make tabbing to a button and pressing
+ // Enter do what people expect
+ $(this).closest( '.ui-dialog' ).find( 'button' ).focus( function () {
+ $(this).closest( '.ui-dialog' ).data( 'dialogaction', this );
+ });
+ }
}
}
- }
- },
- 'insert-reference': {
- titleMsg: 'wikieditor-toolbar-tool-reference-title',
- id: 'wikieditor-toolbar-reference-dialog',
- html: '\
- <div class="wikieditor-toolbar-dialog-wrapper">\
- <fieldset><div class="wikieditor-toolbar-table-form">\
- <div class="wikieditor-toolbar-field-wrapper">\
- <label for="wikieditor-toolbar-reference-text"\
- rel="wikieditor-toolbar-tool-reference-text"></label>\
- <input type="text" id="wikieditor-toolbar-reference-text" />\
- </div>\
- </div></fieldset>\
- </div>',
- init: function() {
- // Insert translated strings into labels
- $( this ).find( '[rel]' ).each( function() {
- $( this ).text( mediaWiki.msg( $( this ).attr( 'rel' ) ) );
- } );
-
},
- dialog: {
- dialogClass: 'wikiEditor-toolbar-dialog',
- width: 590,
- buttons: {
- 'wikieditor-toolbar-tool-reference-insert': function() {
- var insertText = $( '#wikieditor-toolbar-reference-text' ).val();
- var whitespace = $( '#wikieditor-toolbar-reference-dialog' ).data( 'whitespace' );
- var attributes = $( '#wikieditor-toolbar-reference-dialog' ).data( 'attributes' );
- // Close the dialog
- $( this ).dialog( 'close' );
- $.wikiEditor.modules.toolbar.fn.doAction(
- $( this ).data( 'context' ),
- {
- type: 'replace',
- options: {
- pre: whitespace[0] + '<ref' + attributes + '>',
- peri: insertText,
- post: '</ref>' + whitespace[1]
- }
- },
- $( this )
- );
- // Restore form state
- $( '#wikieditor-toolbar-reference-text' ).val( "" );
+ 'insert-reference': {
+ titleMsg: 'wikieditor-toolbar-tool-reference-title',
+ id: 'wikieditor-toolbar-reference-dialog',
+ html: '\
+ <div class="wikieditor-toolbar-dialog-wrapper">\
+ <fieldset><div class="wikieditor-toolbar-table-form">\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-reference-text"\
+ rel="wikieditor-toolbar-tool-reference-text"></label>\
+ <input type="text" id="wikieditor-toolbar-reference-text"/>\
+ </div>\
+ </div></fieldset>\
+ </div>',
+ init: function () {
+ // Insert translated strings into labels
+ $( this ).find( '[rel]' ).each( function () {
+ $( this ).text( mw.msg( $( this ).attr( 'rel' ) ) );
+ } );
+
+ },
+ dialog: {
+ dialogClass: 'wikiEditor-toolbar-dialog',
+ width: 590,
+ buttons: {
+ 'wikieditor-toolbar-tool-reference-insert': function () {
+ var insertText = $( '#wikieditor-toolbar-reference-text' ).val();
+ var whitespace = $( '#wikieditor-toolbar-reference-dialog' ).data( 'whitespace' );
+ var attributes = $( '#wikieditor-toolbar-reference-dialog' ).data( 'attributes' );
+ // Close the dialog
+ $( this ).dialog( 'close' );
+ $.wikiEditor.modules.toolbar.fn.doAction(
+ $( this ).data( 'context' ),
+ {
+ type: 'replace',
+ options: {
+ pre: whitespace[0] + '<ref' + attributes + '>',
+ peri: insertText,
+ post: '</ref>' + whitespace[1]
+ }
+ },
+ $( this )
+ );
+ // Restore form state
+ $( '#wikieditor-toolbar-reference-text' ).val( '' );
+ },
+ 'wikieditor-toolbar-tool-reference-cancel': function () {
+ // Clear any saved selection state
+ var context = $( this ).data( 'context' );
+ context.fn.restoreCursorAndScrollTop();
+ $( this ).dialog( 'close' );
+ }
},
- 'wikieditor-toolbar-tool-reference-cancel': function() {
- // Clear any saved selection state
- var context = $( this ).data( 'context' );
+ open: function () {
+ // Pre-fill the text fields based on the current selection
+ var context = $(this).data( 'context' );
+ // Restore and immediately save selection state, needed for inserting stuff later
context.fn.restoreCursorAndScrollTop();
- $( this ).dialog( 'close' );
- }
- },
- open: function() {
- // Pre-fill the text fields based on the current selection
- var context = $(this).data( 'context' );
- // Restore and immediately save selection state, needed for inserting stuff later
- context.fn.restoreCursorAndScrollTop();
- context.fn.saveCursorAndScrollTop();
- var selection = context.$textarea.textSelection( 'getSelection' );
- // set focus
- $( '#wikieditor-toolbar-reference-text' ).focus();
- $( '#wikieditor-toolbar-reference-dialog' )
- .data( 'whitespace', [ '', '' ] )
- .data( 'attributes', '' );
- if ( selection != '' ) {
- var matches, text;
- if ( ( matches = selection.match( /^(\s*)<ref([^\>]*)>([^\<]*)<\/ref\>(\s*)$/ ) ) ) {
- text = matches[3];
- // Preserve whitespace when replacing
- $( '#wikieditor-toolbar-reference-dialog' )
- .data( 'whitespace', [ matches[1], matches[4] ] );
- $( '#wikieditor-toolbar-reference-dialog' ).data( 'attributes', matches[2] );
- } else {
- text = selection;
+ context.fn.saveCursorAndScrollTop();
+ var selection = context.$textarea.textSelection( 'getSelection' );
+ // set focus
+ $( '#wikieditor-toolbar-reference-text' ).focus();
+ $( '#wikieditor-toolbar-reference-dialog' )
+ .data( 'whitespace', [ '', '' ] )
+ .data( 'attributes', '' );
+ if ( selection !== '' ) {
+ var matches, text;
+ if ( ( matches = selection.match( /^(\s*)<ref([^\>]*)>([^<]*)<\/ref\>(\s*)$/ ) ) ) {
+ text = matches[3];
+ // Preserve whitespace when replacing
+ $( '#wikieditor-toolbar-reference-dialog' )
+ .data( 'whitespace', [ matches[1], matches[4] ] );
+ $( '#wikieditor-toolbar-reference-dialog' ).data( 'attributes', matches[2] );
+ } else {
+ text = selection;
+ }
+ $( '#wikieditor-toolbar-reference-text' ).val( text );
+ }
+ if ( !( $( this ).data( 'dialogkeypressset' ) ) ) {
+ $( this ).data( 'dialogkeypressset', true );
+ // Execute the action associated with the first button
+ // when the user presses Enter
+ $( this ).closest( '.ui-dialog' ).keypress( function ( e ) {
+ if ( ( e.keyCode || e.which ) == 13 ) {
+ var button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button:first' );
+ button.click();
+ e.preventDefault();
+ }
+ } );
+ // Make tabbing to a button and pressing
+ // Enter do what people expect
+ $( this ).closest( '.ui-dialog' ).find( 'button' ).focus( function () {
+ $( this ).closest( '.ui-dialog' ).data( 'dialogaction', this );
+ } );
}
- $( '#wikieditor-toolbar-reference-text' ).val( text );
}
- if ( !( $( this ).data( 'dialogkeypressset' ) ) ) {
- $( this ).data( 'dialogkeypressset', true );
- // Execute the action associated with the first button
- // when the user presses Enter
- $( this ).closest( '.ui-dialog' ).keypress( function( e ) {
- if ( ( e.keyCode || e.which ) == 13 ) {
- var button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button:first' );
- button.click();
- e.preventDefault();
+ }
+ },
+ 'insert-file': {
+ titleMsg: 'wikieditor-toolbar-tool-file-title',
+ id: 'wikieditor-toolbar-file-dialog',
+ html: '\
+ <fieldset>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-file-target" rel="wikieditor-toolbar-file-target" id="wikieditor-toolbar-tool-file-target-label"></label>\
+ <input type="text" id="wikieditor-toolbar-file-target"/>\
+ </div>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-file-caption" rel="wikieditor-toolbar-file-caption"></label>\
+ <input type="text" id="wikieditor-toolbar-file-caption"/>\
+ </div>\
+ <div class="wikieditor-toolbar-file-options">\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-file-size" rel="wikieditor-toolbar-file-size"></label><br/>\
+ <input type="text" id="wikieditor-toolbar-file-size" size="5"/>\
+ </div>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-file-float" rel="wikieditor-toolbar-file-float"></label><br/>\
+ <select type="text" id="wikieditor-toolbar-file-float">\
+ <option value="default" selected="selected" rel="wikieditor-toolbar-file-default"></option>\
+ <option data-i18n-magic="img_none"></option>\
+ <option data-i18n-magic="img_center"></option>\
+ <option data-i18n-magic="img_left"></option>\
+ <option data-i18n-magic="img_right"></option>\
+ </select>\
+ </div>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-file-format" rel="wikieditor-toolbar-file-format"></label><br/>\
+ <select type="text" id="wikieditor-toolbar-file-format">\
+ <option selected="selected" data-i18n-magic="img_thumbnail">thumb</option>\
+ <option data-i18n-magic="img_framed"></option>\
+ <option data-i18n-magic="img_frameless"></option>\
+ <option value="default" rel="wikieditor-toolbar-file-format-none"></option>\
+ </select>\
+ </div>\
+ </div>\
+ </fieldset>',
+ init: function () {
+ var magicWordsI18N = mw.config.get( 'wgWikiEditorMagicWords' );
+ var defaultMsg = mw.msg( 'wikieditor-toolbar-file-default' );
+ $( this )
+ .find( '[data-i18n-magic]' )
+ .text( function () {
+ return magicWordsI18N[ $( this ).attr( 'data-i18n-magic' ) ];
+ })
+ .removeAttr( 'data-i18n-magic' )
+ .end()
+ .find( '#wikieditor-toolbar-file-size' )
+ .attr( 'placeholder', defaultMsg )
+ // The message may be long in some languages
+ .attr( 'size', defaultMsg.length )
+ .end()
+ .find( '[rel]' )
+ .text( function () {
+ return mw.msg( $( this ).attr( 'rel' ) );
+ })
+ .removeAttr( 'rel' )
+ .end();
+ },
+ dialog: {
+ resizable: false,
+ dialogClass: 'wikiEditor-toolbar-dialog',
+ width: 590,
+ buttons: {
+ 'wikieditor-toolbar-tool-file-insert': function () {
+ var fileName, caption, fileFloat, fileFormat, fileSize, fileTitle,
+ options, fileUse,
+ hasPxRgx = /.+px$/;
+ fileName = $( '#wikieditor-toolbar-file-target' ).val();
+ caption = $( '#wikieditor-toolbar-file-caption' ).val();
+ fileFloat = $( '#wikieditor-toolbar-file-float' ).val();
+ fileFormat = $( '#wikieditor-toolbar-file-format' ).val();
+ fileSize = $( '#wikieditor-toolbar-file-size' ).val();
+ // Append px to end to size if not already contains it
+ if ( fileSize !== '' && !hasPxRgx.test( fileSize ) ) {
+ fileSize += 'px';
}
- } );
- // Make tabbing to a button and pressing
- // Enter do what people expect
- $( this ).closest( '.ui-dialog' ).find( 'button' ).focus( function() {
- $( this ).closest( '.ui-dialog' ).data( 'dialogaction', this );
- } );
+ if ( fileName !== '' ) {
+ fileTitle = new mw.Title( fileName );
+ // Append file namespace prefix to filename if not already contains it
+ if ( fileTitle.getNamespaceId() !== 6 ){
+ fileTitle = new mw.Title( fileName, 6 );
+ }
+ fileName = fileTitle.toText();
+ }
+ options = [ fileSize, fileFormat, fileFloat ];
+ // Filter empty values
+ options = $.grep( options, function ( val ) {
+ return val.length && val !== 'default';
+ } );
+ if ( caption.length ) {
+ options.push( caption );
+ }
+ fileUse = options.length === 0 ? fileName : ( fileName + '|' + options.join( '|' ) );
+ $( this ).dialog( 'close' );
+ $.wikiEditor.modules.toolbar.fn.doAction(
+ $( this ).data( 'context' ),
+ {
+ type: 'replace',
+ options: {
+ pre: '[[',
+ peri: fileUse,
+ post: ']]',
+ ownline: true
+ }
+ },
+ $( this )
+ );
+
+ // Restore form state
+ $( ['#wikieditor-toolbar-file-target',
+ '#wikieditor-toolbar-file-caption',
+ '#wikieditor-toolbar-file-size',
+ '#wikieditor-toolbar-file-float',
+ '#wikieditor-toolbar-file-format'].join( ',' )
+ ).val( '' );
+ },
+ 'wikieditor-toolbar-tool-file-cancel': function () {
+ $( this ).dialog( 'close' );
+ }
+ },
+ open: function () {
+ $( '#wikieditor-toolbar-file-target' ).focus();
+ if ( !( $( this ).data( 'dialogkeypressset' ) ) ) {
+ $( this ).data( 'dialogkeypressset', true );
+ // Execute the action associated with the first button
+ // when the user presses Enter
+ $( this ).closest( '.ui-dialog' ).keypress( function( e ) {
+ if ( e.which === 13 ) {
+ var button = $( this ).data( 'dialogaction' ) ||
+ $( this ).find( 'button:first' );
+ button.click();
+ e.preventDefault();
+ }
+ });
+
+ // Make tabbing to a button and pressing
+ // Enter do what people expect
+ $( this ).closest( '.ui-dialog' ).find( 'button' ).focus( function() {
+ $( this ).closest( '.ui-dialog' ).data( 'dialogaction', this );
+ });
+ }
}
}
- }
- },
- 'insert-table': {
- titleMsg: 'wikieditor-toolbar-tool-table-title',
- id: 'wikieditor-toolbar-table-dialog',
- // FIXME: Localize 'x'?
- html: '\
- <div class="wikieditor-toolbar-dialog-wrapper">\
- <fieldset><div class="wikieditor-toolbar-table-form">\
- <div class="wikieditor-toolbar-field-wrapper">\
- <input type="checkbox" id="wikieditor-toolbar-table-dimensions-header" checked />\
- <label for="wikieditor-toolbar-table-dimensions-header"\
- rel="wikieditor-toolbar-tool-table-dimensions-header"></label>\
- </div>\
- <div class="wikieditor-toolbar-field-wrapper">\
- <input type="checkbox" id="wikieditor-toolbar-table-wikitable" checked />\
- <label for="wikieditor-toolbar-table-wikitable" rel="wikieditor-toolbar-tool-table-wikitable"></label>\
- </div>\
- <div class="wikieditor-toolbar-field-wrapper">\
- <input type="checkbox" id="wikieditor-toolbar-table-sortable" />\
- <label for="wikieditor-toolbar-table-sortable" rel="wikieditor-toolbar-tool-table-sortable"></label>\
- </div>\
- <div class="wikieditor-toolbar-table-dimension-fields">\
+ },
+ 'insert-table': {
+ titleMsg: 'wikieditor-toolbar-tool-table-title',
+ id: 'wikieditor-toolbar-table-dialog',
+ // FIXME: Localize 'x'?
+ html: '\
+ <div class="wikieditor-toolbar-dialog-wrapper">\
+ <fieldset><div class="wikieditor-toolbar-table-form">\
<div class="wikieditor-toolbar-field-wrapper">\
- <label for="wikieditor-toolbar-table-dimensions-rows"\
- rel="wikieditor-toolbar-tool-table-dimensions-rows"></label><br />\
- <input type="text" id="wikieditor-toolbar-table-dimensions-rows" size="4" />\
+ <input type="checkbox" id="wikieditor-toolbar-table-dimensions-header" checked/>\
+ <label for="wikieditor-toolbar-table-dimensions-header"\
+ rel="wikieditor-toolbar-tool-table-dimensions-header"></label>\
</div>\
<div class="wikieditor-toolbar-field-wrapper">\
- <label for="wikieditor-toolbar-table-dimensions-columns"\
- rel="wikieditor-toolbar-tool-table-dimensions-columns"></label><br />\
- <input type="text" id="wikieditor-toolbar-table-dimensions-columns" size="4" />\
+ <input type="checkbox" id="wikieditor-toolbar-table-wikitable" checked/>\
+ <label for="wikieditor-toolbar-table-wikitable" rel="wikieditor-toolbar-tool-table-wikitable"></label>\
</div>\
- </div>\
- </div></fieldset>\
- <div class="wikieditor-toolbar-table-preview-wrapper" >\
- <span rel="wikieditor-toolbar-tool-table-example"></span>\
- <div class="wikieditor-toolbar-table-preview-content">\
- <table id="wikieditor-toolbar-table-preview" class="wikieditor-toolbar-table-preview wikitable">\
- <thead>\
- <tr class="wikieditor-toolbar-table-preview-header">\
- <th rel="wikieditor-toolbar-tool-table-example-header"></th>\
- <th rel="wikieditor-toolbar-tool-table-example-header"></th>\
- <th rel="wikieditor-toolbar-tool-table-example-header"></th>\
- </tr>\
- </thead><tbody>\
- <tr class="wikieditor-toolbar-table-preview-hidden" style="display: none;">\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- </tr><tr>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- </tr><tr>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- </tr><tr>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
- </tr>\
- </tbody>\
- </table>\
- </div>\
- </div></div>',
- init: function() {
- $(this).find( '[rel]' ).each( function() {
- $(this).text( mediaWiki.msg( $(this).attr( 'rel' ) ) );
- });
- // Set tabindexes on form fields
- $.wikiEditor.modules.dialogs.fn.setTabindexes( $(this).find( 'input' ).not( '[tabindex]' ) );
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <input type="checkbox" id="wikieditor-toolbar-table-sortable"/>\
+ <label for="wikieditor-toolbar-table-sortable" rel="wikieditor-toolbar-tool-table-sortable"></label>\
+ </div>\
+ <div class="wikieditor-toolbar-table-dimension-fields">\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-table-dimensions-rows"\
+ rel="wikieditor-toolbar-tool-table-dimensions-rows"></label><br/>\
+ <input type="number" min="1" max="1000" id="wikieditor-toolbar-table-dimensions-rows" size="4"/>\
+ </div>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-table-dimensions-columns"\
+ rel="wikieditor-toolbar-tool-table-dimensions-columns"></label><br/>\
+ <input type="number" min="1" max="1000" id="wikieditor-toolbar-table-dimensions-columns" size="4"/>\
+ </div>\
+ </div>\
+ </div></fieldset>\
+ <div class="wikieditor-toolbar-table-preview-wrapper" >\
+ <span rel="wikieditor-toolbar-tool-table-example"></span>\
+ <div class="wikieditor-toolbar-table-preview-content">\
+ <table id="wikieditor-toolbar-table-preview" class="wikieditor-toolbar-table-preview wikitable">\
+ <thead>\
+ <tr class="wikieditor-toolbar-table-preview-header">\
+ <th rel="wikieditor-toolbar-tool-table-example-header"></th>\
+ <th rel="wikieditor-toolbar-tool-table-example-header"></th>\
+ <th rel="wikieditor-toolbar-tool-table-example-header"></th>\
+ </tr>\
+ </thead><tbody>\
+ <tr class="wikieditor-toolbar-table-preview-hidden" style="display: none;">\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ </tr><tr>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ </tr><tr>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ </tr><tr>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ <td rel="wikieditor-toolbar-tool-table-example-cell-text"></td>\
+ </tr>\
+ </tbody>\
+ </table>\
+ </div>\
+ </div></div>',
+ init: function () {
+ $(this).find( '[rel]' ).each( function () {
+ $(this).text( mw.msg( $(this).attr( 'rel' ) ) );
+ });
+ // Set tabindexes on form fields
+ $.wikiEditor.modules.dialogs.fn.setTabindexes( $(this).find( 'input' ).not( '[tabindex]' ) );
- $( '#wikieditor-toolbar-table-dimensions-rows' ).val( 3 );
- $( '#wikieditor-toolbar-table-dimensions-columns' ).val( 3 );
- $( '#wikieditor-toolbar-table-wikitable' ).click( function() {
- $( '.wikieditor-toolbar-table-preview' ).toggleClass( 'wikitable' );
- });
+ $( '#wikieditor-toolbar-table-dimensions-rows' ).val( 3 );
+ $( '#wikieditor-toolbar-table-dimensions-columns' ).val( 3 );
+ $( '#wikieditor-toolbar-table-wikitable' ).click( function () {
+ $( '.wikieditor-toolbar-table-preview' ).toggleClass( 'wikitable' );
+ });
- // Hack for sortable preview: dynamically adding
- // sortable class doesn't work, so we use a clone
- $( '#wikieditor-toolbar-table-preview' )
- .clone()
- .attr( 'id', 'wikieditor-toolbar-table-preview2' )
- .addClass( 'sortable' )
- .insertAfter( $( '#wikieditor-toolbar-table-preview' ) )
- .hide();
+ // Hack for sortable preview: dynamically adding
+ // sortable class doesn't work, so we use a clone
+ $( '#wikieditor-toolbar-table-preview' )
+ .clone()
+ .attr( 'id', 'wikieditor-toolbar-table-preview2' )
+ .addClass( 'sortable' )
+ .insertAfter( $( '#wikieditor-toolbar-table-preview' ) )
+ .hide();
- mw.loader.using( 'jquery.tablesorter', function() {
- $( '#wikieditor-toolbar-table-preview2' ).tablesorter();
- });
+ mw.loader.using( 'jquery.tablesorter', function () {
+ $( '#wikieditor-toolbar-table-preview2' ).tablesorter();
+ });
- $( '#wikieditor-toolbar-table-sortable' ).click( function() {
- // Swap the currently shown one clone with the other one
- $( '#wikieditor-toolbar-table-preview' )
- .hide()
- .attr( 'id', 'wikieditor-toolbar-table-preview3' );
- $( '#wikieditor-toolbar-table-preview2' )
- .attr( 'id', 'wikieditor-toolbar-table-preview' )
- .show();
- $( '#wikieditor-toolbar-table-preview3' ).attr( 'id', 'wikieditor-toolbar-table-preview2' );
- });
+ $( '#wikieditor-toolbar-table-sortable' ).click( function () {
+ // Swap the currently shown one clone with the other one
+ $( '#wikieditor-toolbar-table-preview' )
+ .hide()
+ .attr( 'id', 'wikieditor-toolbar-table-preview3' );
+ $( '#wikieditor-toolbar-table-preview2' )
+ .attr( 'id', 'wikieditor-toolbar-table-preview' )
+ .show();
+ $( '#wikieditor-toolbar-table-preview3' ).attr( 'id', 'wikieditor-toolbar-table-preview2' );
+ });
- $( '#wikieditor-toolbar-table-dimensions-header' ).click( function() {
- // Instead of show/hiding, switch the HTML around
- // We do this because the sortable tables script styles the first row,
- // visible or not
- var headerHTML = $( '.wikieditor-toolbar-table-preview-header' ).html();
- var hiddenHTML = $( '.wikieditor-toolbar-table-preview-hidden' ).html();
- $( '.wikieditor-toolbar-table-preview-header' ).html( hiddenHTML );
- $( '.wikieditor-toolbar-table-preview-hidden' ).html( headerHTML );
- if ( typeof jQuery.fn.tablesorter == 'function' ) {
- $( '#wikieditor-toolbar-table-preview, #wikieditor-toolbar-table-preview2' )
- .filter( '.sortable' )
- .tablesorter();
- }
- });
- },
- dialog: {
- resizable: false,
- dialogClass: 'wikiEditor-toolbar-dialog',
- width: 590,
- buttons: {
- 'wikieditor-toolbar-tool-table-insert': function() {
- var rowsVal = $( '#wikieditor-toolbar-table-dimensions-rows' ).val();
- var colsVal = $( '#wikieditor-toolbar-table-dimensions-columns' ).val();
- var rows = parseInt( rowsVal, 10 );
- var cols = parseInt( colsVal, 10 );
- var header = $( '#wikieditor-toolbar-table-dimensions-header' ).is( ':checked' ) ? 1 : 0;
- if ( isNaN( rows ) || isNaN( cols ) || rows != rowsVal || cols != colsVal ) {
- alert( mediaWiki.msg( 'wikieditor-toolbar-tool-table-invalidnumber' ) );
- return;
- }
- if ( rows + header == 0 || cols == 0 ) {
- alert( mediaWiki.msg( 'wikieditor-toolbar-tool-table-zero' ) );
- return;
- }
- if ( rows * cols > 1000 ) {
- alert( mediaWiki.msg( 'wikieditor-toolbar-tool-table-toomany', 1000 ) );
- return;
+ $( '#wikieditor-toolbar-table-dimensions-header' ).click( function () {
+ // Instead of show/hiding, switch the HTML around
+ // We do this because the sortable tables script styles the first row,
+ // visible or not
+ var headerHTML = $( '.wikieditor-toolbar-table-preview-header' ).html();
+ var hiddenHTML = $( '.wikieditor-toolbar-table-preview-hidden' ).html();
+ $( '.wikieditor-toolbar-table-preview-header' ).html( hiddenHTML );
+ $( '.wikieditor-toolbar-table-preview-hidden' ).html( headerHTML );
+ if ( typeof jQuery.fn.tablesorter == 'function' ) {
+ $( '#wikieditor-toolbar-table-preview, #wikieditor-toolbar-table-preview2' )
+ .filter( '.sortable' )
+ .tablesorter();
}
- var headerText = mediaWiki.msg( 'wikieditor-toolbar-tool-table-example-header' );
- var normalText = mediaWiki.msg( 'wikieditor-toolbar-tool-table-example' );
- var table = "";
- for ( var r = 0; r < rows + header; r++ ) {
- table += "|-\n";
- for ( var c = 0; c < cols; c++ ) {
- var isHeader = ( header && r == 0 );
- var delim = isHeader ? '!' : '|';
- if ( c > 0 ) {
- delim += delim;
- }
- table += delim + ' ' + ( isHeader ? headerText : normalText ) + ' ';
+ });
+ },
+ dialog: {
+ resizable: false,
+ dialogClass: 'wikiEditor-toolbar-dialog',
+ width: 590,
+ buttons: {
+ 'wikieditor-toolbar-tool-table-insert': function () {
+ var rowsVal = $( '#wikieditor-toolbar-table-dimensions-rows' ).val();
+ var colsVal = $( '#wikieditor-toolbar-table-dimensions-columns' ).val();
+ var rows = parseInt( rowsVal, 10 );
+ var cols = parseInt( colsVal, 10 );
+ var header = $( '#wikieditor-toolbar-table-dimensions-header' ).prop( 'checked' ) ? 1 : 0;
+ if ( isNaN( rows ) || isNaN( cols ) || String( rows ) !== rowsVal || String( cols ) !== colsVal || rowsVal < 0 || colsVal < 0 ) {
+ alert( mw.msg( 'wikieditor-toolbar-tool-table-invalidnumber' ) );
+ return;
}
- // Replace trailing space by newline
- // table[table.length - 1] is read-only
- table = table.substr( 0, table.length - 1 ) + "\n";
- }
- var classes = [];
- if ( $( '#wikieditor-toolbar-table-wikitable' ).is( ':checked' ) )
- classes.push( 'wikitable' );
- if ( $( '#wikieditor-toolbar-table-sortable' ).is( ':checked' ) )
- classes.push( 'sortable' );
- var classStr = classes.length > 0 ? ' class="' + classes.join( ' ' ) + '"' : '';
- $(this).dialog( 'close' );
- $.wikiEditor.modules.toolbar.fn.doAction(
- $(this).data( 'context' ),
- {
- type: 'replace',
- options: {
- pre: '{|' + classStr + "\n",
- peri: table,
- post: '|}',
- ownline: true
+ if ( rows + header === 0 || cols === 0 ) {
+ alert( mw.msg( 'wikieditor-toolbar-tool-table-zero' ) );
+ return;
+ }
+ if ( ( rows * cols ) > 1000 ) {
+ alert( mw.msg( 'wikieditor-toolbar-tool-table-toomany', 1000 ) );
+ return;
+ }
+ var headerText = mw.msg( 'wikieditor-toolbar-tool-table-example-header' );
+ var normalText = mw.msg( 'wikieditor-toolbar-tool-table-example' );
+ var table = "";
+ for ( var r = 0; r < rows + header; r++ ) {
+ table += "|-\n";
+ for ( var c = 0; c < cols; c++ ) {
+ var isHeader = ( header && r === 0 );
+ var delim = isHeader ? '!' : '|';
+ if ( c > 0 ) {
+ delim += delim;
+ }
+ table += delim + ' ' + ( isHeader ? headerText : normalText ) + ' ';
}
- },
- $(this)
- );
-
- // Restore form state
- $( '#wikieditor-toolbar-table-dimensions-rows' ).val( 3 );
- $( '#wikieditor-toolbar-table-dimensions-columns' ).val( 3 );
- // Simulate clicks instead of setting values, so the according
- // actions are performed
- if ( !$( '#wikieditor-toolbar-table-dimensions-header' ).is( ':checked' ) )
- $( '#wikieditor-toolbar-table-dimensions-header' ).click();
- if ( !$( '#wikieditor-toolbar-table-wikitable' ).is( ':checked' ) )
- $( '#wikieditor-toolbar-table-wikitable' ).click();
+ // Replace trailing space by newline
+ // table[table.length - 1] is read-only
+ table = table.substr( 0, table.length - 1 ) + "\n";
+ }
+ var classes = [];
+ if ( $( '#wikieditor-toolbar-table-wikitable' ).is( ':checked' ) )
+ classes.push( 'wikitable' );
if ( $( '#wikieditor-toolbar-table-sortable' ).is( ':checked' ) )
- $( '#wikieditor-toolbar-table-sortable' ).click();
+ classes.push( 'sortable' );
+ var classStr = classes.length > 0 ? ' class="' + classes.join( ' ' ) + '"' : '';
+ $(this).dialog( 'close' );
+ $.wikiEditor.modules.toolbar.fn.doAction(
+ $(this).data( 'context' ),
+ {
+ type: 'replace',
+ options: {
+ pre: '{|' + classStr + "\n",
+ peri: table,
+ post: '|}',
+ ownline: true
+ }
+ },
+ $(this)
+ );
+
+ // Restore form state
+ $( '#wikieditor-toolbar-table-dimensions-rows' ).val( 3 );
+ $( '#wikieditor-toolbar-table-dimensions-columns' ).val( 3 );
+ // Simulate clicks instead of setting values, so the according
+ // actions are performed
+ if ( !$( '#wikieditor-toolbar-table-dimensions-header' ).is( ':checked' ) )
+ $( '#wikieditor-toolbar-table-dimensions-header' ).click();
+ if ( !$( '#wikieditor-toolbar-table-wikitable' ).is( ':checked' ) )
+ $( '#wikieditor-toolbar-table-wikitable' ).click();
+ if ( $( '#wikieditor-toolbar-table-sortable' ).is( ':checked' ) )
+ $( '#wikieditor-toolbar-table-sortable' ).click();
+ },
+ 'wikieditor-toolbar-tool-table-cancel': function () {
+ $(this).dialog( 'close' );
+ }
},
- 'wikieditor-toolbar-tool-table-cancel': function() {
- $(this).dialog( 'close' );
- }
- },
- open: function() {
- $( '#wikieditor-toolbar-table-dimensions-rows' ).focus();
- if ( !( $(this).data( 'dialogkeypressset' ) ) ) {
- $(this).data( 'dialogkeypressset', true );
- // Execute the action associated with the first button
- // when the user presses Enter
- $(this).closest( '.ui-dialog' ).keypress( function( e ) {
- if ( ( e.keyCode || e.which ) == 13 ) {
- var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' );
- button.click();
- e.preventDefault();
- }
- });
+ open: function () {
+ $( '#wikieditor-toolbar-table-dimensions-rows' ).focus();
+ if ( !( $(this).data( 'dialogkeypressset' ) ) ) {
+ $(this).data( 'dialogkeypressset', true );
+ // Execute the action associated with the first button
+ // when the user presses Enter
+ $(this).closest( '.ui-dialog' ).keypress( function ( e ) {
+ if ( ( e.keyCode || e.which ) == 13 ) {
+ var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' );
+ button.click();
+ e.preventDefault();
+ }
+ });
- // Make tabbing to a button and pressing
- // Enter do what people expect
- $(this).closest( '.ui-dialog' ).find( 'button' ).focus( function() {
- $(this).closest( '.ui-dialog' ).data( 'dialogaction', this );
- });
+ // Make tabbing to a button and pressing
+ // Enter do what people expect
+ $(this).closest( '.ui-dialog' ).find( 'button' ).focus( function () {
+ $(this).closest( '.ui-dialog' ).data( 'dialogaction', this );
+ });
+ }
}
}
- }
- },
- 'search-and-replace': {
- 'browsers': {
- // Left-to-right languages
- 'ltr': {
- 'msie': false,
- 'firefox': [['>=', 2]],
- 'opera': false,
- 'safari': [['>=', 3]],
- 'chrome': [['>=', 3]]
- },
- // Right-to-left languages
- 'rtl': {
- 'msie': false,
- 'firefox': [['>=', 2]],
- 'opera': false,
- 'safari': [['>=', 3]],
- 'chrome': [['>=', 3]]
- }
},
- titleMsg: 'wikieditor-toolbar-tool-replace-title',
- id: 'wikieditor-toolbar-replace-dialog',
- html: '\
- <div id="wikieditor-toolbar-replace-message">\
- <div id="wikieditor-toolbar-replace-nomatch" rel="wikieditor-toolbar-tool-replace-nomatch"></div>\
- <div id="wikieditor-toolbar-replace-success"></div>\
- <div id="wikieditor-toolbar-replace-emptysearch" rel="wikieditor-toolbar-tool-replace-emptysearch"></div>\
- <div id="wikieditor-toolbar-replace-invalidregex"></div>\
- </div>\
- <fieldset>\
- <div class="wikieditor-toolbar-field-wrapper">\
- <label for="wikieditor-toolbar-replace-search" rel="wikieditor-toolbar-tool-replace-search"></label>\
- <input type="text" id="wikieditor-toolbar-replace-search" style="width: 100%;" />\
- </div>\
- <div class="wikieditor-toolbar-field-wrapper">\
- <label for="wikieditor-toolbar-replace-replace" rel="wikieditor-toolbar-tool-replace-replace"></label>\
- <input type="text" id="wikieditor-toolbar-replace-replace" style="width: 100%;" />\
- </div>\
- <div class="wikieditor-toolbar-field-wrapper">\
- <input type="checkbox" id="wikieditor-toolbar-replace-case" />\
- <label for="wikieditor-toolbar-replace-case" rel="wikieditor-toolbar-tool-replace-case"></label>\
- </div>\
- <div class="wikieditor-toolbar-field-wrapper">\
- <input type="checkbox" id="wikieditor-toolbar-replace-regex" />\
- <label for="wikieditor-toolbar-replace-regex" rel="wikieditor-toolbar-tool-replace-regex"></label>\
+ 'search-and-replace': {
+ 'browsers': {
+ // Left-to-right languages
+ 'ltr': {
+ 'msie': false,
+ 'firefox': [['>=', 2]],
+ 'opera': false,
+ 'safari': [['>=', 3]],
+ 'chrome': [['>=', 3]]
+ },
+ // Right-to-left languages
+ 'rtl': {
+ 'msie': false,
+ 'firefox': [['>=', 2]],
+ 'opera': false,
+ 'safari': [['>=', 3]],
+ 'chrome': [['>=', 3]]
+ }
+ },
+ titleMsg: 'wikieditor-toolbar-tool-replace-title',
+ id: 'wikieditor-toolbar-replace-dialog',
+ html: '\
+ <div id="wikieditor-toolbar-replace-message">\
+ <div id="wikieditor-toolbar-replace-nomatch" rel="wikieditor-toolbar-tool-replace-nomatch"></div>\
+ <div id="wikieditor-toolbar-replace-success"></div>\
+ <div id="wikieditor-toolbar-replace-emptysearch" rel="wikieditor-toolbar-tool-replace-emptysearch"></div>\
+ <div id="wikieditor-toolbar-replace-invalidregex"></div>\
</div>\
- </fieldset>',
- init: function() {
- $(this).find( '[rel]' ).each( function() {
- $(this).text( mediaWiki.msg( $(this).attr( 'rel' ) ) );
- });
- // Set tabindexes on form fields
- $.wikiEditor.modules.dialogs.fn.setTabindexes( $(this).find( 'input' ).not( '[tabindex]' ) );
+ <fieldset>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-replace-search" rel="wikieditor-toolbar-tool-replace-search"></label>\
+ <input type="text" id="wikieditor-toolbar-replace-search" style="width: 100%;"/>\
+ </div>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <label for="wikieditor-toolbar-replace-replace" rel="wikieditor-toolbar-tool-replace-replace"></label>\
+ <input type="text" id="wikieditor-toolbar-replace-replace" style="width: 100%;"/>\
+ </div>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <input type="checkbox" id="wikieditor-toolbar-replace-case"/>\
+ <label for="wikieditor-toolbar-replace-case" rel="wikieditor-toolbar-tool-replace-case"></label>\
+ </div>\
+ <div class="wikieditor-toolbar-field-wrapper">\
+ <input type="checkbox" id="wikieditor-toolbar-replace-regex"/>\
+ <label for="wikieditor-toolbar-replace-regex" rel="wikieditor-toolbar-tool-replace-regex"></label>\
+ </div>\
+ </fieldset>',
+ init: function () {
+ $(this).find( '[rel]' ).each( function () {
+ $(this).text( mw.msg( $(this).attr( 'rel' ) ) );
+ });
+ // Set tabindexes on form fields
+ $.wikiEditor.modules.dialogs.fn.setTabindexes( $(this).find( 'input' ).not( '[tabindex]' ) );
- // TODO: Find a cleaner way to share this function
- $(this).data( 'replaceCallback', function( mode ) {
- $( '#wikieditor-toolbar-replace-nomatch, #wikieditor-toolbar-replace-success, #wikieditor-toolbar-replace-emptysearch, #wikieditor-toolbar-replace-invalidregex' ).hide();
+ // TODO: Find a cleaner way to share this function
+ $(this).data( 'replaceCallback', function ( mode ) {
+ var offset, textRemainder, regex, index, i,
+ start, end;
- // Search string cannot be empty
- var searchStr = $( '#wikieditor-toolbar-replace-search' ).val();
- if ( searchStr == '' ) {
- $( '#wikieditor-toolbar-replace-emptysearch' ).show();
- return;
- }
+ $( '#wikieditor-toolbar-replace-nomatch, #wikieditor-toolbar-replace-success, #wikieditor-toolbar-replace-emptysearch, #wikieditor-toolbar-replace-invalidregex' ).hide();
- // Replace string can be empty
- var replaceStr = $( '#wikieditor-toolbar-replace-replace' ).val();
+ // Search string cannot be empty
+ var searchStr = $( '#wikieditor-toolbar-replace-search' ).val();
+ if ( searchStr === '' ) {
+ $( '#wikieditor-toolbar-replace-emptysearch' ).show();
+ return;
+ }
- // Prepare the regular expression flags
- var flags = 'm';
- var matchCase = $( '#wikieditor-toolbar-replace-case' ).is( ':checked' );
- if ( !matchCase ) {
- flags += 'i';
- }
- var isRegex = $( '#wikieditor-toolbar-replace-regex' ).is( ':checked' );
- if ( !isRegex ) {
- searchStr = $.escapeRE( searchStr );
- }
- if ( mode == 'replaceAll' ) {
- flags += 'g';
- }
+ // Replace string can be empty
+ var replaceStr = $( '#wikieditor-toolbar-replace-replace' ).val();
- try {
- var regex = new RegExp( searchStr, flags );
- } catch( e ) {
- $( '#wikieditor-toolbar-replace-invalidregex' )
- .text( mediaWiki.msg( 'wikieditor-toolbar-tool-replace-invalidregex',
- e.message ) )
- .show();
- return;
- }
+ // Prepare the regular expression flags
+ var flags = 'm';
+ var matchCase = $( '#wikieditor-toolbar-replace-case' ).is( ':checked' );
+ if ( !matchCase ) {
+ flags += 'i';
+ }
+ var isRegex = $( '#wikieditor-toolbar-replace-regex' ).is( ':checked' );
+ if ( !isRegex ) {
+ searchStr = $.escapeRE( searchStr );
+ }
+ if ( mode === 'replaceAll' ) {
+ flags += 'g';
+ }
- var $textarea = $(this).data( 'context' ).$textarea;
- var text = $textarea.textSelection( 'getContents' );
- var match = false;
- var offset, textRemainder;
- if ( mode != 'replaceAll' ) {
- if (mode == 'replace') {
- offset = $(this).data( 'matchIndex' );
- } else {
- offset = $(this).data( 'offset' );
+ try {
+ regex = new RegExp( searchStr, flags );
+ } catch ( e ) {
+ $( '#wikieditor-toolbar-replace-invalidregex' )
+ .text( mw.msg( 'wikieditor-toolbar-tool-replace-invalidregex',
+ e.message ) )
+ .show();
+ return;
}
- textRemainder = text.substr( offset );
- match = textRemainder.match( regex );
- }
- if ( !match ) {
- // Search hit BOTTOM, continuing at TOP
- // TODO: Add a "Wrap around" option.
- offset = 0;
- textRemainder = text;
- match = textRemainder.match( regex );
- }
- if ( !match ) {
- $( '#wikieditor-toolbar-replace-nomatch' ).show();
- } else if ( mode == 'replaceAll' ) {
- // Instead of using repetitive .match() calls, we use one .match() call with /g
- // and indexOf() followed by substr() to find the offsets. This is actually
- // faster because our indexOf+substr loop is faster than a match loop, and the
- // /g match is so ridiculously fast that it's negligible.
- // FIXME: Repetitively calling encapsulateSelection() is probably the best strategy
- // in Firefox/Webkit, but in IE replacing the entire content once is better.
- var index;
- for ( var i = 0; i < match.length; i++ ) {
- index = textRemainder.indexOf( match[i] );
- if ( index == -1 ) {
- // This shouldn't happen
- break;
+ var $textarea = $(this).data( 'context' ).$textarea;
+ var text = $textarea.textSelection( 'getContents' );
+ var match = false;
+ if ( mode !== 'replaceAll' ) {
+ if ( mode === 'replace' ) {
+ offset = $(this).data( 'matchIndex' );
+ } else {
+ offset = $(this).data( 'offset' );
}
- var matchedText = textRemainder.substr( index, match[i].length );
- textRemainder = textRemainder.substr( index + match[i].length );
-
- var start = index + offset;
- var end = start + match[i].length;
- // Make regex placeholder substitution ($1) work
- var replace = isRegex ? matchedText.replace( regex, replaceStr ) : replaceStr;
- var newEnd = start + replace.length;
- $textarea
- .textSelection( 'setSelection', { 'start': start, 'end': end } )
- .textSelection( 'encapsulateSelection', {
- 'peri': replace,
- 'replace': true } )
- .textSelection( 'setSelection', { 'start': start, 'end': newEnd } );
- offset = newEnd;
+ textRemainder = text.substr( offset );
+ match = textRemainder.match( regex );
+ }
+ if ( !match ) {
+ // Search hit BOTTOM, continuing at TOP
+ // TODO: Add a "Wrap around" option.
+ offset = 0;
+ textRemainder = text;
+ match = textRemainder.match( regex );
}
- $( '#wikieditor-toolbar-replace-success' )
- .text( mediaWiki.msg( 'wikieditor-toolbar-tool-replace-success', match.length ) )
- .show();
- $(this).data( 'offset', 0 );
- } else {
- var start, end;
- if ( mode == 'replace' ) {
- var actualReplacement;
+ if ( !match ) {
+ $( '#wikieditor-toolbar-replace-nomatch' ).show();
+ } else if ( mode == 'replaceAll' ) {
+ // Instead of using repetitive .match() calls, we use one .match() call with /g
+ // and indexOf() followed by substr() to find the offsets. This is actually
+ // faster because our indexOf+substr loop is faster than a match loop, and the
+ // /g match is so ridiculously fast that it's negligible.
+ // FIXME: Repetitively calling encapsulateSelection() is probably the best strategy
+ // in Firefox/Webkit, but in IE replacing the entire content once is better.
+ for ( i = 0; i < match.length; i++ ) {
+ index = textRemainder.indexOf( match[i] );
+ if ( index === -1 ) {
+ // This shouldn't happen
+ break;
+ }
+ var matchedText = textRemainder.substr( index, match[i].length );
+ textRemainder = textRemainder.substr( index + match[i].length );
- if (isRegex) {
- // If backreferences (like $1) are used, the actual actual replacement string will be different
- actualReplacement = match[0].replace( regex, replaceStr );
- } else {
- actualReplacement = replaceStr;
+ start = index + offset;
+ end = start + match[i].length;
+ // Make regex placeholder substitution ($1) work
+ var replace = isRegex ? matchedText.replace( regex, replaceStr ) : replaceStr;
+ var newEnd = start + replace.length;
+ $textarea
+ .textSelection( 'setSelection', { 'start': start, 'end': end } )
+ .textSelection( 'encapsulateSelection', {
+ 'peri': replace,
+ 'replace': true } )
+ .textSelection( 'setSelection', { 'start': start, 'end': newEnd } );
+ offset = newEnd;
}
+ $( '#wikieditor-toolbar-replace-success' )
+ .text( mw.msg( 'wikieditor-toolbar-tool-replace-success', match.length ) )
+ .show();
+ $(this).data( 'offset', 0 );
+ } else {
- if (match) {
- // Do the replacement
- $textarea.textSelection( 'encapsulateSelection', {
- 'peri': actualReplacement,
- 'replace': true } );
- // Reload the text after replacement
- text = $textarea.textSelection( 'getContents' );
- }
+ if ( mode == 'replace' ) {
+ var actualReplacement;
- // Find the next instance
- offset = offset + match[0].length + actualReplacement.length;
- textRemainder = text.substr( offset );
- match = textRemainder.match( regex );
+ if (isRegex) {
+ // If backreferences (like $1) are used, the actual actual replacement string will be different
+ actualReplacement = match[0].replace( regex, replaceStr );
+ } else {
+ actualReplacement = replaceStr;
+ }
- if (match) {
- start = offset + match.index;
- end = start + match[0].length;
- } else {
- // If no new string was found, try searching from the beginning.
- // TODO: Add a "Wrap around" option.
- textRemainder = text;
+ if (match) {
+ // Do the replacement
+ $textarea.textSelection( 'encapsulateSelection', {
+ 'peri': actualReplacement,
+ 'replace': true } );
+ // Reload the text after replacement
+ text = $textarea.textSelection( 'getContents' );
+ }
+
+ // Find the next instance
+ offset = offset + match[0].length + actualReplacement.length;
+ textRemainder = text.substr( offset );
match = textRemainder.match( regex );
+
if (match) {
- start = match.index;
+ start = offset + match.index;
end = start + match[0].length;
} else {
- // Give up
- start = 0;
- end = 0;
+ // If no new string was found, try searching from the beginning.
+ // TODO: Add a "Wrap around" option.
+ textRemainder = text;
+ match = textRemainder.match( regex );
+ if (match) {
+ start = match.index;
+ end = start + match[0].length;
+ } else {
+ // Give up
+ start = 0;
+ end = 0;
+ }
}
+ } else {
+ start = offset + match.index;
+ end = start + match[0].length;
}
- } else {
- start = offset + match.index;
- end = start + match[0].length;
- }
- $( this ).data( 'matchIndex', start);
+ $( this ).data( 'matchIndex', start);
- $textarea.textSelection( 'setSelection', {
- 'start': start,
- 'end': end
- } );
- $textarea.textSelection( 'scrollToCaretPosition' );
- $( this ).data( 'offset', end );
- var context = $( this ).data( 'context' );
- var textbox = typeof context.$iframe != 'undefined' ?
- context.$iframe[0].contentWindow : $textarea[0];
- textbox.focus();
- }
- });
- },
- dialog: {
- width: 500,
- dialogClass: 'wikiEditor-toolbar-dialog',
- buttons: {
- 'wikieditor-toolbar-tool-replace-button-findnext': function( e ) {
- $(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target );
- $(this).data( 'replaceCallback' ).call( this, 'find' );
- },
- 'wikieditor-toolbar-tool-replace-button-replace': function( e ) {
- $(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target );
- $(this).data( 'replaceCallback' ).call( this, 'replace' );
- },
- 'wikieditor-toolbar-tool-replace-button-replaceall': function( e ) {
- $(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target );
- $(this).data( 'replaceCallback' ).call( this, 'replaceAll' );
- },
- 'wikieditor-toolbar-tool-replace-close': function() {
- $(this).dialog( 'close' );
- }
+ $textarea.textSelection( 'setSelection', {
+ 'start': start,
+ 'end': end
+ } );
+ $textarea.textSelection( 'scrollToCaretPosition' );
+ $( this ).data( 'offset', end );
+ var context = $( this ).data( 'context' );
+ var textbox = typeof context.$iframe !== 'undefined' ?
+ context.$iframe[0].contentWindow : $textarea[0];
+ textbox.focus();
+ }
+ });
},
- open: function() {
- $(this).data( 'offset', 0 );
- $(this).data( 'matchIndex', 0 );
+ dialog: {
+ width: 500,
+ dialogClass: 'wikiEditor-toolbar-dialog',
+ modal: false,
+ buttons: {
+ 'wikieditor-toolbar-tool-replace-button-findnext': function ( e ) {
+ $(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target );
+ $(this).data( 'replaceCallback' ).call( this, 'find' );
+ },
+ 'wikieditor-toolbar-tool-replace-button-replace': function ( e ) {
+ $(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target );
+ $(this).data( 'replaceCallback' ).call( this, 'replace' );
+ },
+ 'wikieditor-toolbar-tool-replace-button-replaceall': function ( e ) {
+ $(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target );
+ $(this).data( 'replaceCallback' ).call( this, 'replaceAll' );
+ },
+ 'wikieditor-toolbar-tool-replace-close': function () {
+ $(this).dialog( 'close' );
+ }
+ },
+ open: function () {
+ $(this).data( 'offset', 0 );
+ $(this).data( 'matchIndex', 0 );
- $( '#wikieditor-toolbar-replace-search' ).focus();
- $( '#wikieditor-toolbar-replace-nomatch, #wikieditor-toolbar-replace-success, #wikieditor-toolbar-replace-emptysearch, #wikieditor-toolbar-replace-invalidregex' ).hide();
- if ( !( $(this).data( 'onetimeonlystuff' ) ) ) {
- $(this).data( 'onetimeonlystuff', true );
- // Execute the action associated with the first button
- // when the user presses Enter
- $(this).closest( '.ui-dialog' ).keypress( function( e ) {
- if ( ( e.keyCode || e.which ) == 13 ) {
- var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' );
- button.click();
- e.preventDefault();
- }
- });
- // Make tabbing to a button and pressing
- // Enter do what people expect
- $(this).closest( '.ui-dialog' ).find( 'button' ).focus( function() {
- $(this).closest( '.ui-dialog' ).data( 'dialogaction', this );
- });
- }
- var dialog = $(this).closest( '.ui-dialog' );
- var that = this;
- var context = $(this).data( 'context' );
- var textbox = typeof context.$iframe != 'undefined' ?
- context.$iframe[0].contentWindow.document : context.$textarea;
+ $( '#wikieditor-toolbar-replace-search' ).focus();
+ $( '#wikieditor-toolbar-replace-nomatch, #wikieditor-toolbar-replace-success, #wikieditor-toolbar-replace-emptysearch, #wikieditor-toolbar-replace-invalidregex' ).hide();
+ if ( !( $(this).data( 'onetimeonlystuff' ) ) ) {
+ $(this).data( 'onetimeonlystuff', true );
+ // Execute the action associated with the first button
+ // when the user presses Enter
+ $(this).closest( '.ui-dialog' ).keypress( function ( e ) {
+ if ( ( e.keyCode || e.which ) == 13 ) {
+ var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' );
+ button.click();
+ e.preventDefault();
+ }
+ });
+ // Make tabbing to a button and pressing
+ // Enter do what people expect
+ $(this).closest( '.ui-dialog' ).find( 'button' ).focus( function () {
+ $(this).closest( '.ui-dialog' ).data( 'dialogaction', this );
+ });
+ }
+ var dialog = $(this).closest( '.ui-dialog' );
+ var that = this;
+ var context = $(this).data( 'context' );
+ var textbox = typeof context.$iframe !== 'undefined' ?
+ context.$iframe[0].contentWindow.document : context.$textarea;
- $( textbox )
- .bind( 'keypress.srdialog', function( e ) {
- if ( ( e.keyCode || e.which ) == 13 ) {
- // Enter
- var button = dialog.data( 'dialogaction' ) || dialog.find( 'button:first' );
- button.click();
- e.preventDefault();
- } else if ( ( e.keyCode || e.which ) == 27 ) {
- // Escape
- $(that).dialog( 'close' );
- }
- });
- },
- close: function() {
- var context = $(this).data( 'context' );
- var textbox = typeof context.$iframe != 'undefined' ?
- context.$iframe[0].contentWindow.document : context.$textarea;
- $( textbox ).unbind( 'keypress.srdialog' );
- $(this).closest( '.ui-dialog' ).data( 'dialogaction', false );
+ $( textbox )
+ .bind( 'keypress.srdialog', function ( e ) {
+ if ( e.which == 13 ) {
+ // Enter
+ var button = dialog.data( 'dialogaction' ) || dialog.find( 'button:first' );
+ button.click();
+ e.preventDefault();
+ } else if ( e.which == 27 ) {
+ // Escape
+ $(that).dialog( 'close' );
+ }
+ });
+ },
+ close: function () {
+ var context = $(this).data( 'context' );
+ var textbox = typeof context.$iframe !== 'undefined' ?
+ context.$iframe[0].contentWindow.document : context.$textarea;
+ $( textbox ).unbind( 'keypress.srdialog' );
+ $(this).closest( '.ui-dialog' ).data( 'dialogaction', false );
+ }
}
}
- }
- } };
-}
+ } };
+ }
+
+};
-}; } ) ( jQuery );
+}( jQuery, mediaWiki ) );
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.css b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.css
index 2c3d36a6..b97ce7e3 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.css
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.css
@@ -1,56 +1,68 @@
-/*
+/**
* CSS for WikiEditor Dialogs jQuery plugin
*/
.wikiEditor-toolbar-dialog table {
margin-top: 0.75em;
}
+
.wikiEditor-toolbar-dialog table td {
padding: 0.5em;
height: 3em;
overflow: visible;
}
+
/* Put suggestions (default z-index 99) on top of dialogs (z-index 1002) */
div.suggestions {
z-index: 1099;
}
+
.wikiEditor-toolbar-dialog table td {
padding: 0 !important;
}
+
.wikiEditor-toolbar-dialog .ui-dialog-content fieldset {
border: none !important;
margin: 0 !important;
padding: 0 !important;
}
+
.wikiEditor-toolbar-dialog .ui-widget-header {
border-bottom:1px solid #6bc8f3 !important;
}
+
.wikiEditor-toolbar-dialog .ui-dialog-content input[type=text] {
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-webkit-box-sizing: border-box;
-khtml-box-sizing: border-box;
}
+
.wikiEditor-toolbar-dialog .ui-dialog-content input[type="radio"],
.wikiEditor-toolbar-dialog .ui-dialog-content input[type="checkbox"] {
margin-left: 0;
}
+
.wikiEditor-toolbar-dialog .ui-dialog-titlebar-close {
padding: 0;
}
body .wikiEditor-toolbar-dialog .ui-dialog-titlebar-close {
right: 0.9em;
}
+
.wikieditor-toolbar-field-wrapper {
padding: 0 0 25px 0;
}
+
.wikieditor-toolbar-floated-field-wrapper {
float: left;
margin-right: 2em;
}
+
.wikieditor-toolbar-dialog-hint {
color: #999999;
}
+
.wikiEditor-toolbar-dialog {
border: none;
} \ No newline at end of file
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js
index 6f5404f5..f6d86d78 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js
@@ -1,217 +1,234 @@
/**
* Dialog Module for wikiEditor
*/
-( function( $ ) { $.wikiEditor.modules.dialogs = {
+( function ( $, mw ) {
-/**
- * Compatability map
- */
-'browsers': {
- // Left-to-right languages
- 'ltr': {
- 'msie': [['>=', 7]],
- // jQuery UI appears to be broken in FF 2.0 - 2.0.0.4
- 'firefox': [
- ['>=', 2], ['!=', '2.0'], ['!=', '2.0.0.1'], ['!=', '2.0.0.2'], ['!=', '2.0.0.3'], ['!=', '2.0.0.4']
- ],
- 'opera': [['>=', 9.6]],
- 'safari': [['>=', 3]],
- 'chrome': [['>=', 3]]
- },
- // Right-to-left languages
- 'rtl': {
- 'msie': [['>=', 7]],
- // jQuery UI appears to be broken in FF 2.0 - 2.0.0.4
- 'firefox': [
- ['>=', 2], ['!=', '2.0'], ['!=', '2.0.0.1'], ['!=', '2.0.0.2'], ['!=', '2.0.0.3'], ['!=', '2.0.0.4']
- ],
- 'opera': [['>=', 9.6]],
- 'safari': [['>=', 3]],
- 'chrome': [['>=', 3]]
- }
-},
-/**
- * API accessible functions
- */
-api: {
- addDialog: function( context, data ) {
- $.wikiEditor.modules.dialogs.fn.create( context, data )
- },
- openDialog: function( context, module ) {
- if ( module in $.wikiEditor.modules.dialogs.modules ) {
- var mod = $.wikiEditor.modules.dialogs.modules[module];
- var $dialog = $( '#' + mod.id );
- if ( $dialog.length == 0 ) {
- $.wikiEditor.modules.dialogs.fn.reallyCreate( context, mod, module );
- $dialog = $( '#' + mod.id );
- }
-
- // Workaround for bug in jQuery UI: close button in top right retains focus
- $dialog.closest( '.ui-dialog' )
- .find( '.ui-dialog-titlebar-close' )
- .removeClass( 'ui-state-focus' );
+$.wikiEditor.modules.dialogs = {
- $dialog.dialog( 'open' );
+ /**
+ * Compatability map
+ */
+ browsers: {
+ // Left-to-right languages
+ ltr: {
+ msie: [['>=', 7]],
+ // jQuery UI appears to be broken in FF 2.0 - 2.0.0.4
+ firefox: [
+ ['>=', 2], ['!=', '2.0'], ['!=', '2.0.0.1'], ['!=', '2.0.0.2'], ['!=', '2.0.0.3'], ['!=', '2.0.0.4']
+ ],
+ opera: [['>=', 9.6]],
+ safari: [['>=', 3]],
+ chrome: [['>=', 3]]
+ },
+ // Right-to-left languages
+ rtl: {
+ msie: [['>=', 7]],
+ // jQuery UI appears to be broken in FF 2.0 - 2.0.0.4
+ firefox: [
+ ['>=', 2], ['!=', '2.0'], ['!=', '2.0.0.1'], ['!=', '2.0.0.2'], ['!=', '2.0.0.3'], ['!=', '2.0.0.4']
+ ],
+ opera: [['>=', 9.6]],
+ safari: [['>=', 3]],
+ chrome: [['>=', 3]]
}
},
- closeDialog: function( context, module ) {
- if ( module in $.wikiEditor.modules.dialogs.modules ) {
- $( '#' + $.wikiEditor.modules.dialogs.modules[module].id ).dialog( 'close' );
- }
- }
-},
-/**
- * Internally used functions
- */
-fn: {
+
/**
- * Creates a dialog module within a wikiEditor
- *
- * @param {Object} context Context object of editor to create module in
- * @param {Object} config Configuration object to create module from
+ * API accessible functions
*/
- create: function( context, config ) {
- // Defer building of modules, but do check whether they need the iframe rightaway
- for ( var mod in config ) {
- var module = config[mod];
- // Only create the dialog if it's supported, isn't filtered and doesn't exist yet
- var filtered = false;
- if ( typeof module.filters != 'undefined' ) {
- for ( var i = 0; i < module.filters.length; i++ ) {
- if ( $( module.filters[i] ).length == 0 ) {
- filtered = true;
- break;
- }
+ api: {
+ addDialog: function ( context, data ) {
+ $.wikiEditor.modules.dialogs.fn.create( context, data );
+ },
+ openDialog: function ( context, module ) {
+ if ( module in $.wikiEditor.modules.dialogs.modules ) {
+ var mod = $.wikiEditor.modules.dialogs.modules[module];
+ var $dialog = $( '#' + mod.id );
+ if ( $dialog.length === 0 ) {
+ $.wikiEditor.modules.dialogs.fn.reallyCreate( context, mod, module );
+ $dialog = $( '#' + mod.id );
}
+
+ // Workaround for bug in jQuery UI: close button in top right retains focus
+ $dialog.closest( '.ui-dialog' )
+ .find( '.ui-dialog-titlebar-close' )
+ .removeClass( 'ui-state-focus' );
+
+ $dialog.dialog( 'open' );
}
- // If the dialog already exists, but for another textarea, simply remove it
- var $existingDialog = $( '#' + module.id );
- if ( $existingDialog.length > 0 && $existingDialog.data( 'context' ).$textarea != context.$textarea ) {
- $existingDialog.remove();
- }
- // Re-select from the DOM, we might have removed the dialog just now
- $existingDialog = $( '#' + module.id );
- if ( !filtered && $.wikiEditor.isSupported( module ) && $existingDialog.size() === 0 ) {
- $.wikiEditor.modules.dialogs.modules[mod] = module;
- // If this dialog requires the iframe, set it up
- if ( typeof context.$iframe == 'undefined' && $.wikiEditor.isRequired( module, 'iframe' ) ) {
- context.fn.setupIframe();
- }
- context.$textarea.trigger( 'wikiEditor-dialogs-setup-' + mod );
- // If this dialog requires immediate creation, create it now
- if ( typeof module.immediateCreate !== 'undefined' && module.immediateCreate ) {
- $.wikiEditor.modules.dialogs.fn.reallyCreate( context, module, mod );
- }
+ },
+ closeDialog: function ( context, module ) {
+ if ( module in $.wikiEditor.modules.dialogs.modules ) {
+ $( '#' + $.wikiEditor.modules.dialogs.modules[module].id ).dialog( 'close' );
}
}
},
- /**
- * Build the actual dialog. This done on-demand rather than in create()
- * @param {Object} context Context object of editor dialog belongs to
- * @param {Object} module Dialog module object
- * @param {String} name Dialog name (key in $.wikiEditor.modules.dialogs.modules)
- */
- reallyCreate: function( context, module, name ) {
- var configuration = module.dialog;
- // Add some stuff to configuration
- configuration.bgiframe = true;
- configuration.autoOpen = false;
- configuration.modal = true;
- configuration.title = $.wikiEditor.autoMsg( module, 'title' );
- // Transform messages in keys
- // Stupid JS won't let us do stuff like
- // foo = { mediaWiki.msg( 'bar' ): baz }
- configuration.newButtons = {};
- for ( var msg in configuration.buttons )
- configuration.newButtons[mediaWiki.msg( msg )] = configuration.buttons[msg];
- configuration.buttons = configuration.newButtons;
- // Create the dialog <div>
- var dialogDiv = $( '<div />' )
- .attr( 'id', module.id )
- .html( module.html )
- .data( 'context', context )
- .appendTo( $( 'body' ) )
- .each( module.init )
- .dialog( configuration );
- // Set tabindexes on buttons added by .dialog()
- $.wikiEditor.modules.dialogs.fn.setTabindexes( dialogDiv.closest( '.ui-dialog' )
- .find( 'button' ).not( '[tabindex]' ) );
- if ( !( 'resizeme' in module ) || module.resizeme ) {
- dialogDiv
- .bind( 'dialogopen', $.wikiEditor.modules.dialogs.fn.resize )
- .find( '.ui-tabs' ).bind( 'tabsshow', function() {
- $(this).closest( '.ui-dialog-content' ).each(
- $.wikiEditor.modules.dialogs.fn.resize );
- });
- }
- dialogDiv.bind( 'dialogclose', function() {
- context.fn.restoreSelection();
- } );
- // Let the outside world know we set up this dialog
- context.$textarea.trigger( 'wikiEditor-dialogs-loaded-' + name );
- },
/**
- * Resize a dialog so its contents fit
- *
- * Usage: dialog.each( resize ); or dialog.bind( 'blah', resize );
- * NOTE: This function assumes $.ui.dialog has already been loaded
+ * Internally used functions
*/
- resize: function() {
- var wrapper = $(this).closest( '.ui-dialog' );
- var oldWidth = wrapper.width();
- // Make sure elements don't wrapped so we get an accurate idea of whether they really fit. Also temporarily show
- // hidden elements. Work around jQuery bug where <div style="display:inline;" /> inside a dialog is both
- // :visible and :hidden
- var oldHidden = $(this).find( '*' ).not( ':visible' );
- // Save the style attributes of the hidden elements to restore them later. Calling hide() after show() messes up
- // for elements hidden with a class
- oldHidden.each( function() {
- $(this).data( 'oldstyle', $(this).attr( 'style' ) );
- });
- oldHidden.show();
- var oldWS = $(this).css( 'white-space' );
- $(this).css( 'white-space', 'nowrap' );
- if ( wrapper.width() <= $(this).get(0).scrollWidth ) {
- var thisWidth = $(this).data( 'thisWidth' ) ? $(this).data( 'thisWidth' ) : 0;
- thisWidth = Math.max( $(this).get(0).width, thisWidth );
- $(this).width( thisWidth );
- $(this).data( 'thisWidth', thisWidth );
- var wrapperWidth = $(this).data( 'wrapperWidth' ) ? $(this).data( 'wrapperWidth' ) : 0;
- wrapperWidth = Math.max( wrapper.get(0).scrollWidth, wrapperWidth );
- wrapper.width( wrapperWidth );
- $(this).data( 'wrapperWidth', wrapperWidth );
- $(this).dialog( { 'width': wrapper.width() } );
- wrapper.css( 'left', parseInt( wrapper.css( 'left' ) ) - ( wrapper.width() - oldWidth ) / 2 );
+ fn: {
+ /**
+ * Creates a dialog module within a wikiEditor
+ *
+ * @param {Object} context Context object of editor to create module in
+ * @param {Object} config Configuration object to create module from
+ */
+ create: function ( context, config ) {
+ var mod, module, filtered, i, $existingDialog;
+
+ // Defer building of modules, but do check whether they need the iframe rightaway
+ for ( mod in config ) {
+ module = config[mod];
+ // Only create the dialog if it's supported, isn't filtered and doesn't exist yet
+ filtered = false;
+ if ( typeof module.filters != 'undefined' ) {
+ for ( i = 0; i < module.filters.length; i++ ) {
+ if ( $( module.filters[i] ).length === 0 ) {
+ filtered = true;
+ break;
+ }
+ }
+ }
+ // If the dialog already exists, but for another textarea, simply remove it
+ $existingDialog = $( '#' + module.id );
+ if ( $existingDialog.length > 0 && $existingDialog.data( 'context' ).$textarea != context.$textarea ) {
+ $existingDialog.remove();
+ }
+ // Re-select from the DOM, we might have removed the dialog just now
+ $existingDialog = $( '#' + module.id );
+ if ( !filtered && $.wikiEditor.isSupported( module ) && $existingDialog.length === 0 ) {
+ $.wikiEditor.modules.dialogs.modules[mod] = module;
+ // If this dialog requires the iframe, set it up
+ if ( typeof context.$iframe === 'undefined' && $.wikiEditor.isRequired( module, 'iframe' ) ) {
+ context.fn.setupIframe();
+ }
+ context.$textarea.trigger( 'wikiEditor-dialogs-setup-' + mod );
+ // If this dialog requires immediate creation, create it now
+ if ( typeof module.immediateCreate !== 'undefined' && module.immediateCreate ) {
+ $.wikiEditor.modules.dialogs.fn.reallyCreate( context, module, mod );
+ }
+ }
+ }
+ },
+
+ /**
+ * Build the actual dialog. This done on-demand rather than in create()
+ * @param {Object} context Context object of editor dialog belongs to
+ * @param {Object} module Dialog module object
+ * @param {String} name Dialog name (key in $.wikiEditor.modules.dialogs.modules)
+ */
+ reallyCreate: function ( context, module, name ) {
+ var msg,
+ configuration = module.dialog;
+ // Add some stuff to configuration
+ configuration.bgiframe = true;
+ configuration.autoOpen = false;
+ // By default our dialogs are modal, unless explicitely defined in their specific configuration.
+ if( typeof configuration.modal == "undefined" ) {
+ configuration.modal = true;
+ }
+ configuration.title = $.wikiEditor.autoMsg( module, 'title' );
+ // Transform messages in keys
+ // Stupid JS won't let us do stuff like
+ // foo = { mw.msg( 'bar' ): baz }
+ configuration.newButtons = {};
+ for ( msg in configuration.buttons ) {
+ configuration.newButtons[mw.msg( msg )] = configuration.buttons[msg];
+ }
+ configuration.buttons = configuration.newButtons;
+ // Create the dialog <div>
+ var dialogDiv = $( '<div>' )
+ .attr( 'id', module.id )
+ .html( module.html )
+ .data( 'context', context )
+ .appendTo( $( 'body' ) )
+ .each( module.init )
+ .dialog( configuration );
+ // Set tabindexes on buttons added by .dialog()
+ $.wikiEditor.modules.dialogs.fn.setTabindexes( dialogDiv.closest( '.ui-dialog' )
+ .find( 'button' ).not( '[tabindex]' ) );
+ if ( !( 'resizeme' in module ) || module.resizeme ) {
+ dialogDiv
+ .bind( 'dialogopen', $.wikiEditor.modules.dialogs.fn.resize )
+ .find( '.ui-tabs' ).bind( 'tabsshow', function () {
+ $(this).closest( '.ui-dialog-content' ).each(
+ $.wikiEditor.modules.dialogs.fn.resize );
+ });
+ }
+ dialogDiv.bind( 'dialogclose', function () {
+ context.fn.restoreSelection();
+ } );
+
+ // Let the outside world know we set up this dialog
+ context.$textarea.trigger( 'wikiEditor-dialogs-loaded-' + name );
+ },
+
+ /**
+ * Resize a dialog so its contents fit
+ *
+ * Usage: dialog.each( resize ); or dialog.bind( 'blah', resize );
+ * NOTE: This function assumes $.ui.dialog has already been loaded
+ */
+ resize: function () {
+ var wrapper = $(this).closest( '.ui-dialog' );
+ var oldWidth = wrapper.width();
+ // Make sure elements don't wrapped so we get an accurate idea of whether they really fit. Also temporarily show
+ // hidden elements. Work around jQuery bug where <div style="display: inline;"/> inside a dialog is both
+ // :visible and :hidden
+ var oldHidden = $(this).find( '*' ).not( ':visible' );
+ // Save the style attributes of the hidden elements to restore them later. Calling hide() after show() messes up
+ // for elements hidden with a class
+ oldHidden.each( function () {
+ $(this).data( 'oldstyle', $(this).attr( 'style' ) );
+ });
+ oldHidden.show();
+ var oldWS = $(this).css( 'white-space' );
+ $(this).css( 'white-space', 'nowrap' );
+ if ( wrapper.width() <= $(this).get(0).scrollWidth ) {
+ var thisWidth = $(this).data( 'thisWidth' ) ? $(this).data( 'thisWidth' ) : 0;
+ thisWidth = Math.max( $(this).get(0).width, thisWidth );
+ $(this).width( thisWidth );
+ $(this).data( 'thisWidth', thisWidth );
+ var wrapperWidth = $(this).data( 'wrapperWidth' ) ? $(this).data( 'wrapperWidth' ) : 0;
+ wrapperWidth = Math.max( wrapper.get(0).scrollWidth, wrapperWidth );
+ wrapper.width( wrapperWidth );
+ $(this).data( 'wrapperWidth', wrapperWidth );
+ $(this).dialog( { 'width': wrapper.width() } );
+ wrapper.css( 'left', parseInt( wrapper.css( 'left' ), 10 ) - ( wrapper.width() - oldWidth ) / 2 );
+ }
+ $(this).css( 'white-space', oldWS );
+ oldHidden.each( function () {
+ $(this).attr( 'style', $(this).data( 'oldstyle' ) );
+ });
+ },
+ /**
+ * Set the right tabindexes on elements in a dialog
+ * @param $elements Elements to set tabindexes on. If they already have tabindexes, this function can behave a bit weird
+ */
+ setTabindexes: function ( $elements ) {
+ // Get the highest tab index
+ var tabIndex = $( document ).lastTabIndex() + 1;
+ $elements.each( function () {
+ $(this).attr( 'tabindex', tabIndex++ );
+ } );
}
- $(this).css( 'white-space', oldWS );
- oldHidden.each( function() {
- $(this).attr( 'style', $(this).data( 'oldstyle' ) );
- });
},
- /**
- * Set the right tabindexes on elements in a dialog
- * @param $elements Elements to set tabindexes on. If they already have tabindexes, this function can behave a bit weird
- */
- setTabindexes: function( $elements ) {
- // Get the highest tab index
- var tabIndex = $( document ).lastTabIndex() + 1;
- $elements.each( function() {
- $(this).attr( 'tabindex', tabIndex++ );
- } );
+
+ // This stuff is just hanging here, perhaps we could come up with a better home for this stuff
+ modules: {},
+
+ quickDialog: function ( body, settings ) {
+ $( '<div>' )
+ .text( body )
+ .appendTo( $( 'body' ) )
+ .dialog( $.extend( {
+ bgiframe: true,
+ modal: true
+ }, settings ) )
+ .dialog( 'open' );
}
-},
-// This stuff is just hanging here, perhaps we could come up with a better home for this stuff
-modules: {},
-quickDialog: function( body, settings ) {
- $( '<div />' )
- .text( body )
- .appendTo( $( 'body' ) )
- .dialog( $.extend( {
- bgiframe: true,
- modal: true
- }, settings ) )
- .dialog( 'open' );
-}
-}; } ) ( jQuery );
+};
+
+}( jQuery, mediaWiki ) );
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.highlight.js b/extensions/WikiEditor/modules/jquery.wikiEditor.highlight.js
index 48140206..9d964fa7 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.highlight.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.highlight.js
@@ -1,357 +1,373 @@
/* Highlight module for wikiEditor */
-( function( $ ) { $.wikiEditor.modules.highlight = {
+( function ( $ ) {
+
+$.wikiEditor.modules.highlight = {
+
+ /**
+ * Core Requirements
+ */
+ req: [ 'iframe' ],
-/**
- * Core Requirements
- */
-'req': [ 'iframe' ],
-/**
- * Configuration
- */
-'cfg': {
- 'styleVersion': 3
-},
-/**
- * Internally used event handlers
- */
-'evt': {
- 'delayedChange': function( context, event ) {
- if ( event.data.scope == 'realchange' ) {
- $.wikiEditor.modules.highlight.fn.scan( context );
- $.wikiEditor.modules.highlight.fn.mark( context, event.data.scope );
- }
- },
- 'ready': function( context, event ) {
- $.wikiEditor.modules.highlight.fn.scan( context );
- $.wikiEditor.modules.highlight.fn.mark( context, 'ready' );
- }
-},
-/**
- * Internally used functions
- */
-'fn': {
/**
- * Creates a highlight module within a wikiEditor
- *
- * @param config Configuration object to create module from
+ * Configuration
*/
- 'create': function( context, config ) {
- context.modules.highlight.markersStr = '';
+ cfg: {
+ styleVersion: 3
},
+
/**
- * Scans text division for tokens
- *
- * @param division
+ * Internally used event handlers
*/
- 'scan': function( context, division ) {
- // Remove all existing tokens
- var tokenArray = context.modules.highlight.tokenArray = [];
- // Scan text for new tokens
- var text = context.fn.getContents();
- // Perform a scan for each module which provides any expressions to scan for
- // FIXME: This traverses the entire string once for every regex. Investigate
- // whether |-concatenating regexes then traversing once is faster.
- for ( var module in context.modules ) {
- if ( module in $.wikiEditor.modules && 'exp' in $.wikiEditor.modules[module] ) {
- for ( var exp in $.wikiEditor.modules[module].exp ) {
- // Prepare configuration
- var regex = $.wikiEditor.modules[module].exp[exp].regex;
- var label = $.wikiEditor.modules[module].exp[exp].label;
- var markAfter = $.wikiEditor.modules[module].exp[exp].markAfter || false;
- // Search for tokens
- var offset = 0, left, right, match;
- while ( ( match = text.substr( offset ).match( regex ) ) != null ) {
- right = ( left = offset + match.index ) + match[0].length;
- tokenArray[tokenArray.length] = {
- 'offset': markAfter ? right : left,
- 'label': label,
- 'tokenStart': left,
- 'match': match
- };
- // Move to the right of this match
- offset = right;
- }
- }
+ evt: {
+ delayedChange: function ( context, event ) {
+ if ( event.data.scope == 'realchange' ) {
+ $.wikiEditor.modules.highlight.fn.scan( context );
+ $.wikiEditor.modules.highlight.fn.mark( context, event.data.scope );
}
+ },
+ ready: function ( context, event ) {
+ $.wikiEditor.modules.highlight.fn.scan( context );
+ $.wikiEditor.modules.highlight.fn.mark( context, 'ready' );
}
- // Sort by start
- tokenArray.sort( function( a, b ) { return a.tokenStart - b.tokenStart; } );
- // Let the world know, a scan just happened!
- context.fn.trigger( 'scan' );
},
+
/**
- * Marks up text with HTML
- *
- * @param division
- * @param tokens
+ * Internally used functions
*/
- // FIXME: What do division and tokens do?
- // TODO: Document the scan() and mark() APIs somewhere
- 'mark': function( context, division, tokens ) {
- // Reset markers
- var markers = [];
+ fn: {
+ /**
+ * Creates a highlight module within a wikiEditor
+ *
+ * @param config Configuration object to create module from
+ */
+ create: function ( context, config ) {
+ context.modules.highlight.markersStr = '';
+ },
+ /**
+ * Scans text division for tokens
+ *
+ * @param division
+ */
+ scan: function ( context, division ) {
+ var tokenArray, text, module, exp,
+ left, right, match;
+ /*jshint eqnull: true */
- // Recycle markers that will be skipped in this run
- if ( context.modules.highlight.markers && division != '' ) {
- for ( var i = 0; i < context.modules.highlight.markers.length; i++ ) {
- if ( context.modules.highlight.markers[i].skipDivision == division ) {
- markers.push( context.modules.highlight.markers[i] );
+ // Remove all existing tokens
+ tokenArray = context.modules.highlight.tokenArray = [];
+ // Scan text for new tokens
+ text = context.fn.getContents();
+ // Perform a scan for each module which provides any expressions to scan for
+ // FIXME: This traverses the entire string once for every regex. Investigate
+ // whether |-concatenating regexes then traversing once is faster.
+ for ( module in context.modules ) {
+ if ( module in $.wikiEditor.modules && 'exp' in $.wikiEditor.modules[module] ) {
+ for ( exp in $.wikiEditor.modules[module].exp ) {
+ // Prepare configuration
+ var regex = $.wikiEditor.modules[module].exp[exp].regex;
+ var label = $.wikiEditor.modules[module].exp[exp].label;
+ var markAfter = $.wikiEditor.modules[module].exp[exp].markAfter || false;
+ // Search for tokens
+ var offset = 0;
+ while ( ( match = text.substr( offset ).match( regex ) ) != null ) {
+ right = ( left = offset + match.index ) + match[0].length;
+ tokenArray[tokenArray.length] = {
+ offset: markAfter ? right : left,
+ label: label,
+ tokenStart: left,
+ match: match
+ };
+ // Move to the right of this match
+ offset = right;
+ }
+ }
}
}
- }
- context.modules.highlight.markers = markers;
+ // Sort by start
+ tokenArray.sort( function ( a, b ) {
+ return a.tokenStart - b.tokenStart;
+ } );
+ // Let the world know, a scan just happened!
+ context.fn.trigger( 'scan' );
+ },
- // Get all markers
- context.fn.trigger( 'mark' );
- markers.sort( function( a, b ) { return a.start - b.start || a.end - b.end; } );
+ /**
+ * Marks up text with HTML
+ *
+ * @param division
+ * @param tokens
+ */
+ // FIXME: What do division and tokens do?
+ // TODO: Document the scan() and mark() APIs somewhere
+ mark: function ( context, division, tokens ) {
+ var i, subtracted, oldLength, j, o;
- // Serialize the markers array to a string and compare it with the one stored in the previous run - if they're
- // equal, there's no markers to change
- var markersStr = '';
- for ( var i = 0; i < markers.length; i++ ) {
- markersStr += markers[i].start + ',' + markers[i].end + ',' + markers[i].type + ',';
- }
- if ( context.modules.highlight.markersStr == markersStr ) {
- // No change, bail out
- return;
- }
- context.modules.highlight.markersStr = markersStr;
+ // Reset markers
+ var markers = [];
- // Traverse the iframe DOM, inserting markers where they're needed - store visited markers here so we know which
- // markers should be removed
- var visited = [], v = 0;
- for ( var i = 0; i < markers.length; i++ ) {
- if ( typeof markers[i].skipDivision !== 'undefined' && ( division == markers[i].skipDivision ) ) {
- continue;
+ // Recycle markers that will be skipped in this run
+ if ( context.modules.highlight.markers && division !== '' ) {
+ for ( i = 0; i < context.modules.highlight.markers.length; i++ ) {
+ if ( context.modules.highlight.markers[i].skipDivision == division ) {
+ markers.push( context.modules.highlight.markers[i] );
+ }
+ }
}
+ context.modules.highlight.markers = markers;
- // We want to isolate each marker, so we may need to split textNodes if a marker starts or ends halfway one.
- var start = markers[i].start;
- var s = context.fn.getOffset( start );
- if ( !s ) {
- // This shouldn't happen
- continue;
- }
- var startNode = s.node;
+ // Get all markers
+ context.fn.trigger( 'mark' );
+ markers.sort( function ( a, b ) {
+ return a.start - b.start || a.end - b.end;
+ } );
- // Don't wrap leading BRs, produces undesirable results
- // FIXME: It's also possible that the offset is a bit high because getOffset() has incremented .length to
- // fake the newline caused by startNode being in a P. In this case, prevent the textnode splitting below
- // from making startNode an empty textnode, IE barfs on that
- while ( startNode.nodeName == 'BR' || s.offset == startNode.nodeValue.length ) {
- start++;
- s = context.fn.getOffset( start );
- startNode = s.node;
+ // Serialize the markers array to a string and compare it with the one stored in the previous run - if they're
+ // equal, there's no markers to change
+ var markersStr = '';
+ for ( i = 0; i < markers.length; i++ ) {
+ markersStr += markers[i].start + ',' + markers[i].end + ',' + markers[i].type + ',';
+ }
+ if ( context.modules.highlight.markersStr == markersStr ) {
+ // No change, bail out
+ return;
}
+ context.modules.highlight.markersStr = markersStr;
- // The next marker starts somewhere in this textNode or at this BR
- if ( s.offset > 0 && s.node.nodeName == '#text' ) {
- // Split off the prefix - this leaves the prefix in the current node and puts the rest in a new node
- // which is our start node
- var newStartNode = startNode.splitText( s.offset < s.node.nodeValue.length ?
- s.offset : s.node.nodeValue.length - 1
- );
- var oldStartNode = startNode;
- startNode = newStartNode;
- // Update offset objects. We don't need purgeOffsets(), simply manipulating the existing offset objects
- // will suffice
- // FIXME: This manipulates context.offsets directly, which is ugly, but the performance improvement vs.
- // purgeOffsets() is worth it - this code doesn't set lastTextNode to newStartNode for offset objects
- // with lastTextNode == oldStartNode, but that doesn't really matter
- var subtracted = s.offset;
- var oldLength = s.length;
+ // Traverse the iframe DOM, inserting markers where they're needed - store visited markers here so we know which
+ // markers should be removed
+ var visited = [], v = 0;
+ for ( i = 0; i < markers.length; i++ ) {
+ if ( typeof markers[i].skipDivision !== 'undefined' && ( division == markers[i].skipDivision ) ) {
+ continue;
+ }
- var j, o;
- // Update offset objects referring to oldStartNode
- for ( j = start - subtracted; j < start; j++ ) {
- if ( j in context.offsets ) {
- o = context.offsets[j];
- o.node = oldStartNode;
- o.length = subtracted;
- }
+ // We want to isolate each marker, so we may need to split textNodes if a marker starts or ends halfway one.
+ var start = markers[i].start;
+ var s = context.fn.getOffset( start );
+ if ( !s ) {
+ // This shouldn't happen
+ continue;
}
- // Update offset objects referring to newStartNode
- for ( j = start; j < start - subtracted + oldLength; j++ ) {
- if ( j in context.offsets ) {
- o = context.offsets[j];
- o.node = newStartNode;
- o.offset -= subtracted;
- o.length -= subtracted;
- o.lastTextNode = oldStartNode;
- }
+ var startNode = s.node;
+
+ // Don't wrap leading BRs, produces undesirable results
+ // FIXME: It's also possible that the offset is a bit high because getOffset() has incremented .length to
+ // fake the newline caused by startNode being in a P. In this case, prevent the textnode splitting below
+ // from making startNode an empty textnode, IE barfs on that
+ while ( startNode.nodeName === 'BR' || s.offset === startNode.nodeValue.length ) {
+ start++;
+ s = context.fn.getOffset( start );
+ startNode = s.node;
}
- }
- var end = markers[i].end;
- // To avoid ending up at the first char of the next node, we grab the offset for end - 1 and add one to the
- // offset
- var e = context.fn.getOffset( end - 1 );
- if ( !e ) {
- // This shouldn't happen
- continue;
- }
- var endNode = e.node;
- if ( e.offset + 1 < e.length - 1 && endNode.nodeName == '#text' ) {
- // Split off the suffix. This puts the suffix in a new node and leaves the rest in endNode
- var oldEndNode = endNode;
- var newEndNode = endNode.splitText( e.offset + 1 );
- // Update offset objects
- var subtracted = e.offset + 1;
- var oldLength = e.length;
- var j, o;
- // Update offset objects referring to oldEndNode
- for ( j = end - subtracted; j < end; j++ ) {
- if ( j in context.offsets ) {
- o = context.offsets[j];
- o.node = oldEndNode;
- o.length = subtracted;
+
+ // The next marker starts somewhere in this textNode or at this BR
+ if ( s.offset > 0 && s.node.nodeName == '#text' ) {
+ // Split off the prefix - this leaves the prefix in the current node and puts the rest in a new node
+ // which is our start node
+ var newStartNode = startNode.splitText( s.offset < s.node.nodeValue.length ?
+ s.offset : s.node.nodeValue.length - 1
+ );
+ var oldStartNode = startNode;
+ startNode = newStartNode;
+ // Update offset objects. We don't need purgeOffsets(), simply manipulating the existing offset objects
+ // will suffice
+ // FIXME: This manipulates context.offsets directly, which is ugly, but the performance improvement vs.
+ // purgeOffsets() is worth it - this code doesn't set lastTextNode to newStartNode for offset objects
+ // with lastTextNode == oldStartNode, but that doesn't really matter
+ subtracted = s.offset;
+ oldLength = s.length;
+
+ // Update offset objects referring to oldStartNode
+ for ( j = start - subtracted; j < start; j++ ) {
+ if ( j in context.offsets ) {
+ o = context.offsets[j];
+ o.node = oldStartNode;
+ o.length = subtracted;
+ }
+ }
+ // Update offset objects referring to newStartNode
+ for ( j = start; j < start - subtracted + oldLength; j++ ) {
+ if ( j in context.offsets ) {
+ o = context.offsets[j];
+ o.node = newStartNode;
+ o.offset -= subtracted;
+ o.length -= subtracted;
+ o.lastTextNode = oldStartNode;
+ }
}
}
- // We have to insert this one, as it might not exist: we didn't call getOffset( end )
- context.offsets[end] = {
- 'node': newEndNode,
- 'offset': 0,
- 'length': oldLength - subtracted,
- 'lastTextNode': oldEndNode
- };
- // Update offset objects referring to newEndNode
- for ( j = end + 1; j < end - subtracted + oldLength; j++ ) {
- if ( j in context.offsets ) {
- o = context.offsets[j];
- o.node = newEndNode;
- o.offset -= subtracted;
- o.length -= subtracted;
- o.lastTextNode = oldEndNode;
+ var end = markers[i].end;
+ // To avoid ending up at the first char of the next node, we grab the offset for end - 1 and add one to the
+ // offset
+ var e = context.fn.getOffset( end - 1 );
+ if ( !e ) {
+ // This shouldn't happen
+ continue;
+ }
+ var endNode = e.node;
+ if ( e.offset + 1 < e.length - 1 && endNode.nodeName == '#text' ) {
+ // Split off the suffix. This puts the suffix in a new node and leaves the rest in endNode
+ var oldEndNode = endNode;
+ var newEndNode = endNode.splitText( e.offset + 1 );
+ // Update offset objects
+ subtracted = e.offset + 1;
+ oldLength = e.length;
+
+ // Update offset objects referring to oldEndNode
+ for ( j = end - subtracted; j < end; j++ ) {
+ if ( j in context.offsets ) {
+ o = context.offsets[j];
+ o.node = oldEndNode;
+ o.length = subtracted;
+ }
+ }
+ // We have to insert this one, as it might not exist: we didn't call getOffset( end )
+ context.offsets[end] = {
+ 'node': newEndNode,
+ 'offset': 0,
+ 'length': oldLength - subtracted,
+ 'lastTextNode': oldEndNode
+ };
+ // Update offset objects referring to newEndNode
+ for ( j = end + 1; j < end - subtracted + oldLength; j++ ) {
+ if ( j in context.offsets ) {
+ o = context.offsets[j];
+ o.node = newEndNode;
+ o.offset -= subtracted;
+ o.length -= subtracted;
+ o.lastTextNode = oldEndNode;
+ }
}
}
- }
- // Don't wrap trailing BRs, doing that causes weird issues
- if ( endNode.nodeName == 'BR' ) {
- endNode = e.lastTextNode;
- }
- // If startNode and endNode have different parents, we need to pull endNode and all textnodes in between
- // into startNode's parent and replace </p><p> with <br>
- if ( startNode.parentNode != endNode.parentNode ) {
- var startP = $( startNode ).closest( 'p' ).get( 0 );
- var t = new context.fn.rawTraverser( startNode, startP, context.$content.get( 0 ), false );
- var afterStart = startNode.nextSibling;
- var lastP = startP;
- var nextT = t.next();
- while ( nextT && t.node != endNode ) {
- t = nextT;
- nextT = t.next();
- // If t.node has a different parent, merge t.node.parentNode with startNode.parentNode
- if ( t.node.parentNode != startNode.parentNode ) {
- var oldParent = t.node.parentNode;
- if ( afterStart ) {
- if ( lastP != t.inP ) {
- // We're entering a new <p>, insert a <br>
- startNode.parentNode.insertBefore(
- startNode.ownerDocument.createElement( 'br' ),
- afterStart
- );
- }
- // A <p> with just a <br> in it is an empty line, so let's not bother with unwrapping it
- if ( !( oldParent.childNodes.length == 1 && oldParent.firstChild.nodeName == 'BR' ) ) {
- // Move all children of oldParent into startNode's parent
- while ( oldParent.firstChild ) {
- startNode.parentNode.insertBefore( oldParent.firstChild, afterStart );
+ // Don't wrap trailing BRs, doing that causes weird issues
+ if ( endNode.nodeName == 'BR' ) {
+ endNode = e.lastTextNode;
+ }
+ // If startNode and endNode have different parents, we need to pull endNode and all textnodes in between
+ // into startNode's parent and replace </p><p> with <br>
+ if ( startNode.parentNode !== endNode.parentNode ) {
+ var startP = $( startNode ).closest( 'p' ).get( 0 );
+ var t = new context.fn.rawTraverser( startNode, startP, context.$content.get( 0 ), false );
+ var afterStart = startNode.nextSibling;
+ var lastP = startP;
+ var nextT = t.next();
+ while ( nextT && t.node !== endNode ) {
+ t = nextT;
+ nextT = t.next();
+ // If t.node has a different parent, merge t.node.parentNode with startNode.parentNode
+ if ( t.node.parentNode !== startNode.parentNode ) {
+ var oldParent = t.node.parentNode;
+ if ( afterStart ) {
+ if ( lastP !== t.inP ) {
+ // We're entering a new <p>, insert a <br>
+ startNode.parentNode.insertBefore(
+ startNode.ownerDocument.createElement( 'br' ),
+ afterStart
+ );
}
- }
- } else {
- if ( lastP != t.inP ) {
- // We're entering a new <p>, insert a <br>
- startNode.parentNode.appendChild(
- startNode.ownerDocument.createElement( 'br' )
- );
- }
- // A <p> with just a <br> in it is an empty line, so let's not bother with unwrapping it
- if ( !( oldParent.childNodes.length == 1 && oldParent.firstChild.nodeName == 'BR' ) ) {
- // Move all children of oldParent into startNode's parent
- while ( oldParent.firstChild ) {
- startNode.parentNode.appendChild( oldParent.firstChild );
+ // A <p> with just a <br> in it is an empty line, so let's not bother with unwrapping it
+ if ( !( oldParent.childNodes.length == 1 && oldParent.firstChild.nodeName == 'BR' ) ) {
+ // Move all children of oldParent into startNode's parent
+ while ( oldParent.firstChild ) {
+ startNode.parentNode.insertBefore( oldParent.firstChild, afterStart );
+ }
+ }
+ } else {
+ if ( lastP !== t.inP ) {
+ // We're entering a new <p>, insert a <br>
+ startNode.parentNode.appendChild(
+ startNode.ownerDocument.createElement( 'br' )
+ );
+ }
+ // A <p> with just a <br> in it is an empty line, so let's not bother with unwrapping it
+ if ( !( oldParent.childNodes.length == 1 && oldParent.firstChild.nodeName == 'BR' ) ) {
+ // Move all children of oldParent into startNode's parent
+ while ( oldParent.firstChild ) {
+ startNode.parentNode.appendChild( oldParent.firstChild );
+ }
}
}
+ // Remove oldParent, which is now empty
+ oldParent.parentNode.removeChild( oldParent );
}
- // Remove oldParent, which is now empty
- oldParent.parentNode.removeChild( oldParent );
+ lastP = t.inP;
}
- lastP = t.inP;
+ // Moving nodes around like this invalidates offset objects
+ // TODO: Update offset objects ourselves for performance. Requires rewriting this code block to be
+ // offset-based rather than traverser-based
}
- // Moving nodes around like this invalidates offset objects
- // TODO: Update offset objects ourselves for performance. Requires rewriting this code block to be
- // offset-based rather than traverser-based
- }
- // Now wrap everything between startNode and endNode (may be equal).
- var ca1 = startNode, ca2 = endNode;
- if ( ca1 && ca2 && ca1.parentNode ) {
- var anchor = markers[i].getAnchor( ca1, ca2 );
- if ( !anchor ) {
- var commonAncestor = ca1.parentNode;
- if ( markers[i].anchor == 'wrap') {
- // We have to store things like .parentNode and .nextSibling because appendChild() changes these
- var newNode = ca1.ownerDocument.createElement( 'span' );
- var nextNode = ca2.nextSibling;
- // Append all nodes between ca1 and ca2 (inclusive) to newNode
- var n = ca1;
- while ( n != nextNode ) {
- var ns = n.nextSibling;
- newNode.appendChild( n );
- n = ns;
- }
- // Insert newNode in the right place
- if ( nextNode ) {
- commonAncestor.insertBefore( newNode, nextNode );
- } else {
- commonAncestor.appendChild( newNode );
+ // Now wrap everything between startNode and endNode (may be equal).
+ var ca1 = startNode, ca2 = endNode;
+ if ( ca1 && ca2 && ca1.parentNode ) {
+ var anchor = markers[i].getAnchor( ca1, ca2 );
+ if ( !anchor ) {
+ var commonAncestor = ca1.parentNode;
+ if ( markers[i].anchor == 'wrap') {
+ // We have to store things like .parentNode and .nextSibling because appendChild() changes these
+ var newNode = ca1.ownerDocument.createElement( 'span' );
+ var nextNode = ca2.nextSibling;
+ // Append all nodes between ca1 and ca2 (inclusive) to newNode
+ var n = ca1;
+ while ( n !== nextNode ) {
+ var ns = n.nextSibling;
+ newNode.appendChild( n );
+ n = ns;
+ }
+ // Insert newNode in the right place
+ if ( nextNode ) {
+ commonAncestor.insertBefore( newNode, nextNode );
+ } else {
+ commonAncestor.appendChild( newNode );
+ }
+ anchor = newNode;
+ } else if ( markers[i].anchor == 'tag' ) {
+ anchor = commonAncestor;
}
- anchor = newNode;
- } else if ( markers[i].anchor == 'tag' ) {
- anchor = commonAncestor;
- }
- $( anchor ).data( 'marker', markers[i] ).addClass( 'wikiEditor-highlight' );
- // Allow the module adding this marker to manipulate it
- markers[i].afterWrap( anchor, markers[i] );
+ $( anchor ).data( 'marker', markers[i] ).addClass( 'wikiEditor-highlight' );
+ // Allow the module adding this marker to manipulate it
+ markers[i].afterWrap( anchor, markers[i] );
- } else {
- // Update the marker object
- $( anchor ).data( 'marker', markers[i] );
- if ( typeof markers[i].onSkip == 'function' ) {
- markers[i].onSkip( anchor );
+ } else {
+ // Update the marker object
+ $( anchor ).data( 'marker', markers[i] );
+ if ( typeof markers[i].onSkip == 'function' ) {
+ markers[i].onSkip( anchor );
+ }
}
+ visited[v++] = anchor;
}
- visited[v++] = anchor;
- }
- }
- // Remove markers that were previously inserted but weren't passed to this function - visited[] contains the
- // visited elements in order and find() and each() preserve order
- var j = 0;
- context.$content.find( '.wikiEditor-highlight' ).each( function() {
- if ( visited[j] == this ) {
- // This marker is legit, leave it in
- j++;
- return true;
}
- // Remove this marker
- var marker = $(this).data( 'marker' );
- if ( marker && typeof marker.skipDivision != 'undefined' && ( division == marker.skipDivision ) ) {
- // Don't remove these either
- return true;
- }
- if ( marker && typeof marker.beforeUnwrap == 'function' )
- marker.beforeUnwrap( this );
- if ( ( marker && marker.anchor == 'tag' ) || $(this).is( 'p' ) ) {
- // Remove all classes
- $(this).removeAttr( 'class' );
- } else {
- // Assume anchor == 'wrap'
- $(this).replaceWith( this.childNodes );
- }
- context.fn.purgeOffsets();
- });
+ // Remove markers that were previously inserted but weren't passed to this function - visited[] contains the
+ // visited elements in order and find() and each() preserve order
+ j = 0;
+ context.$content.find( '.wikiEditor-highlight' ).each( function () {
+ if ( visited[j] == this ) {
+ // This marker is legit, leave it in
+ j++;
+ return true;
+ }
+ // Remove this marker
+ var marker = $(this).data( 'marker' );
+ if ( marker && typeof marker.skipDivision !== 'undefined' && ( division === marker.skipDivision ) ) {
+ // Don't remove these either
+ return true;
+ }
+ if ( marker && typeof marker.beforeUnwrap === 'function' )
+ marker.beforeUnwrap( this );
+ if ( ( marker && marker.anchor === 'tag' ) || $(this).is( 'p' ) ) {
+ // Remove all classes
+ $(this).removeAttr( 'class' );
+ } else {
+ // Assume anchor == 'wrap'
+ $(this).replaceWith( this.childNodes );
+ }
+ context.fn.purgeOffsets();
+ });
+ }
}
-}
+};
-}; })( jQuery );
+}( jQuery ) );
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 ) );
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.preview.css b/extensions/WikiEditor/modules/jquery.wikiEditor.preview.css
index 7eb455b5..6b026a1e 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.preview.css
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.preview.css
@@ -1,4 +1,4 @@
-/*
+/**
* CSS for WikiEditor Preview jQuery plugin
*/
@@ -6,21 +6,26 @@
padding: 1em;
background-color: white;
}
+
.wikiEditor-preview-loading span {
color: #666666;
}
+
.wikiEditor-preview-spinner {
padding-right: 1em;
}
+
.wikiEditor-preview-contents {
padding: 1em;
background-color: white;
}
+
/* FIXME: This only works for the first wikiEditor on the page! */
#wikiEditor-0-preview-dialog .wikiEditor-ui-loading {
overflow: hidden;
border: none;
}
+
.ui-dialog .ui-dialog-buttonpane {
margin: 0 !important;
-} \ No newline at end of file
+}
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js b/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js
index 22c6d89e..39907364 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js
@@ -1,25 +1,28 @@
/* Preview module for wikiEditor */
-( function( $ ) { $.wikiEditor.modules.preview = {
+( function ( $, mw ) {
+
+$.wikiEditor.modules.preview = {
/**
* Compatability map
*/
-'browsers': {
+browsers: {
// Left-to-right languages
- 'ltr': {
- 'msie': [['>=', 7]],
- 'firefox': [['>=', 3]],
- 'opera': [['>=', 9.6]],
- 'safari': [['>=', 4]]
+ ltr: {
+ msie: [['>=', 7]],
+ firefox: [['>=', 3]],
+ opera: [['>=', 9.6]],
+ safari: [['>=', 4]]
},
// Right-to-left languages
- 'rtl': {
- 'msie': [['>=', 8]],
- 'firefox': [['>=', 3]],
- 'opera': [['>=', 9.6]],
- 'safari': [['>=', 4]]
+ rtl: {
+ msie: [['>=', 8]],
+ firefox: [['>=', 3]],
+ opera: [['>=', 9.6]],
+ safari: [['>=', 4]]
}
},
+
/**
* Internally used functions
*/
@@ -29,7 +32,7 @@ fn: {
* @param context Context object of editor to create module in
* @param config Configuration object to create module from
*/
- create: function( context, config ) {
+ create: function ( context, config ) {
if ( 'initialized' in context.modules.preview ) {
return;
}
@@ -41,11 +44,11 @@ fn: {
context.modules.preview.$preview = context.fn.addView( {
'name': 'preview',
'titleMsg': 'wikieditor-preview-tab',
- 'init': function( context ) {
+ 'init': function ( context ) {
// Gets the latest copy of the wikitext
var wikitext = context.$textarea.textSelection( 'getContents' );
// Aborts when nothing has changed since the last preview
- if ( context.modules.preview.previewText == wikitext ) {
+ if ( context.modules.preview.previewText === wikitext ) {
return;
}
context.modules.preview.$preview.find( '.wikiEditor-preview-contents' ).empty();
@@ -53,14 +56,14 @@ fn: {
$.post(
mw.util.wikiScript( 'api' ),
{
- 'action': 'parse',
- 'title': mw.config.get( 'wgPageName' ),
- 'text': wikitext,
- 'prop': 'text',
- 'pst': '',
- 'format': 'json'
+ format: 'json',
+ action: 'parse',
+ title: mw.config.get( 'wgPageName' ),
+ text: wikitext,
+ prop: 'text',
+ pst: ''
},
- function( data ) {
+ function ( data ) {
if (
typeof data.parse == 'undefined' ||
typeof data.parse.text == 'undefined' ||
@@ -72,7 +75,7 @@ fn: {
context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).hide();
context.modules.preview.$preview.find( '.wikiEditor-preview-contents' )
.html( data.parse.text['*'] )
- .find( 'a:not([href^=#])' ).click( function() { return false; } );
+ .find( 'a:not([href^=#])' ).click( false );
},
'json'
);
@@ -82,7 +85,7 @@ fn: {
context.$changesTab = context.fn.addView( {
'name': 'changes',
'titleMsg': 'wikieditor-preview-changes-tab',
- 'init': function( context ) {
+ 'init': function ( context ) {
// Gets the latest copy of the wikitext
var wikitext = context.$textarea.textSelection( 'getContents' );
// Aborts when nothing has changed since the last time
@@ -94,28 +97,28 @@ fn: {
// Call the API. First PST the input, then diff it
var postdata = {
- 'action': 'parse',
- 'onlypst': '',
- 'text': wikitext,
- 'format': 'json'
+ format: 'json',
+ action: 'parse',
+ onlypst: '',
+ text: wikitext
};
- $.post( mw.util.wikiScript( 'api' ), postdata, function( data ) {
+ $.post( mw.util.wikiScript( 'api' ), postdata, function ( data ) {
try {
var postdata2 = {
- 'action': 'query',
- 'indexpageids': '',
- 'prop': 'revisions',
- 'titles': mw.config.get( 'wgPageName' ),
- 'rvdifftotext': data.parse.text['*'],
- 'rvprop': '',
- 'format': 'json'
+ format: 'json',
+ action: 'query',
+ indexpageids: '',
+ prop: 'revisions',
+ titles: mw.config.get( 'wgPageName' ),
+ rvdifftotext: data.parse.text['*'],
+ rvprop: ''
};
- var section = $( '[name=wpSection]' ).val();
- if ( section != '' )
- postdata2['rvsection'] = section;
+ var section = $( '[name="wpSection"]' ).val();
+ if ( section !== '' )
+ postdata2.rvsection = section;
- $.post( mw.util.wikiScript( 'api' ), postdata2, function( data ) {
+ $.post( mw.util.wikiScript( 'api' ), postdata2, function ( data ) {
// Add diff CSS
mw.loader.load( 'mediawiki.action.history.diff' );
try {
@@ -129,17 +132,17 @@ fn: {
} catch ( e ) { } // "blah is undefined" error, ignore
}, 'json'
);
- } catch( e ) { } // "blah is undefined" error, ignore
+ } catch ( e ) { } // "blah is undefined" error, ignore
}, 'json' );
}
} );
- var loadingMsg = mediaWiki.msg( 'wikieditor-preview-loading' );
+ var loadingMsg = mw.msg( 'wikieditor-preview-loading' );
context.modules.preview.$preview
.add( context.$changesTab )
- .append( $( '<div />' )
+ .append( $( '<div>' )
.addClass( 'wikiEditor-preview-loading' )
- .append( $( '<img />' )
+ .append( $( '<img>' )
.addClass( 'wikiEditor-preview-spinner' )
.attr( {
'src': $.wikiEditor.imgPath + 'dialogs/loading.gif',
@@ -149,16 +152,18 @@ fn: {
} )
)
.append(
- $( '<span></span>' ).text( loadingMsg )
+ $( '<span>' ).text( loadingMsg )
)
)
- .append( $( '<div />' )
+ .append( $( '<div>' )
.addClass( 'wikiEditor-preview-contents' )
);
context.$changesTab.find( '.wikiEditor-preview-contents' )
- .html( '<table class="diff"><col class="diff-marker" /><col class="diff-content" />' +
- '<col class="diff-marker" /><col class="diff-content" /><tbody /></table>' );
+ .html( '<table class="diff"><col class="diff-marker"/><col class="diff-content"/>' +
+ '<col class="diff-marker"/><col class="diff-content"/><tbody/></table>' );
}
}
-}; } )( jQuery );
+};
+
+}( jQuery, mediaWiki ) );
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.previewDialog.css b/extensions/WikiEditor/modules/jquery.wikiEditor.previewDialog.css
index 7a27f594..f66773b0 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.previewDialog.css
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.previewDialog.css
@@ -1,4 +1,4 @@
-/*
+/**
* CSS for WikiEditor Preview Dialog jQuery plugin
*/
@@ -14,6 +14,7 @@
overflow: hidden;
border: none;
}
+
/* FIXME: This only works for the first wikiEditor on the page! */
#wikiEditor-0-preview-dialog .wikiEditor-ui-loading span {
display: block;
@@ -24,12 +25,15 @@
text-indent: -9999px;
margin: 50px auto;
}
+
.ui-dialog .ui-dialog-buttonpane {
margin: 0 !important;
}
+
.wikiEditor-preview-dialog-contents {
font-size: 0.9em !important;
}
+
.wikiEditor-preview-dialog-contents #firstHeading {
font-size: 2.1em;
-} \ No newline at end of file
+}
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.publish.js b/extensions/WikiEditor/modules/jquery.wikiEditor.publish.js
index 5a3b6cd6..bb631cf2 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.publish.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.publish.js
@@ -1,23 +1,25 @@
/* Publish module for wikiEditor */
-( function( $ ) { $.wikiEditor.modules.publish = {
+( function ( $ ) {
+
+$.wikiEditor.modules.publish = {
/**
* Compatability map
*/
-'browsers': {
+browsers: {
// Left-to-right languages
- 'ltr': {
- 'msie': [['>=', 7]],
- 'firefox': [['>=', 3]],
- 'opera': [['>=', 9.6]],
- 'safari': [['>=', 4]]
+ ltr: {
+ msie: [['>=', 7]],
+ firefox: [['>=', 3]],
+ opera: [['>=', 9.6]],
+ safari: [['>=', 4]]
},
// Right-to-left languages
- 'rtl': {
- 'msie': [['>=', 8]],
- 'firefox': [['>=', 3]],
- 'opera': [['>=', 9.6]],
- 'safari': [['>=', 4]]
+ rtl: {
+ msie: [['>=', 8]],
+ firefox: [['>=', 3]],
+ opera: [['>=', 9.6]],
+ safari: [['>=', 4]]
}
},
/**
@@ -29,7 +31,7 @@ fn: {
* @param context Context object of editor to create module in
* @param config Configuration object to create module from
*/
- create: function( context, config ) {
+ create: function ( context, config ) {
// Build the dialog behind the Publish button
var dialogID = 'wikiEditor-' + context.instance + '-dialog';
$.wikiEditor.modules.dialogs.fn.create(
@@ -61,8 +63,10 @@ fn: {
</div>\
</form>\
</div>',
- init: function() {
- $(this).find( '[rel]' ).each( function() {
+ init: function () {
+ var i;
+
+ $(this).find( '[rel]' ).each( function () {
$(this).text( mediaWiki.msg( $(this).attr( 'rel' ) ) );
});
@@ -72,8 +76,8 @@ fn: {
// TODO: internationalize by splitting on other characters that end statements
var copyWarnStatements = copyWarnHTML.split( '. ' );
var newCopyWarnHTML = '<ul>';
- for ( var i = 0; i < copyWarnStatements.length; i++ ) {
- if ( copyWarnStatements[i] != '' ) {
+ for ( i = 0; i < copyWarnStatements.length; i++ ) {
+ if ( copyWarnStatements[i] !== '' ) {
var copyWarnStatement = $.trim( copyWarnStatements[i] ).replace( /\.*$/, '' );
newCopyWarnHTML += '<li>' + copyWarnStatement + '.</li>';
}
@@ -85,42 +89,42 @@ fn: {
);
/* END OF REALLY DIRTY HACK */
- if ( $( '#wpMinoredit' ).size() == 0 )
+ if ( $( '#wpMinoredit' ).length === 0 )
$( '#wikiEditor-' + context.instance + '-dialog-minor' ).hide();
else if ( $( '#wpMinoredit' ).is( ':checked' ) )
$( '#wikiEditor-' + context.instance + '-dialog-minor' )
- .attr( 'checked', 'checked' );
- if ( $( '#wpWatchthis' ).size() == 0 )
+ .prop( 'checked', true );
+ if ( $( '#wpWatchthis' ).length === 0 )
$( '#wikiEditor-' + context.instance + '-dialog-watch' ).hide();
else if ( $( '#wpWatchthis' ).is( ':checked' ) )
$( '#wikiEditor-' + context.instance + '-dialog-watch' )
- .attr( 'checked', 'checked' );
+ .prop( 'checked', true );
- $(this).find( 'form' ).submit( function( e ) {
+ $(this).find( 'form' ).submit( function ( e ) {
$(this).closest( '.ui-dialog' ).find( 'button:first' ).click();
e.preventDefault();
});
},
dialog: {
buttons: {
- 'wikieditor-publish-dialog-publish': function() {
+ 'wikieditor-publish-dialog-publish': function () {
var minorChecked = $( '#wikiEditor-' + context.instance +
'-dialog-minor' ).is( ':checked' ) ?
'checked' : '';
var watchChecked = $( '#wikiEditor-' + context.instance +
'-dialog-watch' ).is( ':checked' ) ?
'checked' : '';
- $( '#wpMinoredit' ).attr( 'checked', minorChecked );
- $( '#wpWatchthis' ).attr( 'checked', watchChecked );
+ $( '#wpMinoredit' ).prop( 'checked', minorChecked );
+ $( '#wpWatchthis' ).prop( 'checked', watchChecked );
$( '#wpSummary' ).val( $( '#wikiEditor-' + context.instance +
'-dialog-summary' ).val() );
$( '#editform' ).submit();
},
- 'wikieditor-publish-dialog-goback': function() {
+ 'wikieditor-publish-dialog-goback': function () {
$(this).dialog( 'close' );
}
},
- open: function() {
+ open: function () {
$( '#wikiEditor-' + context.instance + '-dialog-summary' ).focus();
},
width: 500
@@ -129,18 +133,22 @@ fn: {
}
}
);
+
context.fn.addButton( {
'captionMsg': 'wikieditor-publish-button-publish',
- 'action': function() {
+ 'action': function () {
$( '#' + dialogID ).dialog( 'open' );
return false;
}
} );
+
context.fn.addButton( {
'captionMsg': 'wikieditor-publish-button-cancel',
- 'action': function() { }
+ 'action': function () { }
} );
}
}
-}; } )( jQuery );
+};
+
+}( jQuery ) );
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.templateEditor.js b/extensions/WikiEditor/modules/jquery.wikiEditor.templateEditor.js
index 9857b9e8..bd00325f 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.templateEditor.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.templateEditor.js
@@ -416,7 +416,7 @@ fn: {
} )
.appendTo( $paramRow );
$paramRow
- .append( '<div style="clear:both"></div>' )
+ .append( '<div style="clear: both;"></div>' )
.appendTo( $fields );
}
}
@@ -566,7 +566,7 @@ fn: {
ranges[params[rangeIndex].valueIndex].newVal = value;
}
return retVal;
- };
+ }
/* Public Functions */
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.toc.css b/extensions/WikiEditor/modules/jquery.wikiEditor.toc.css
index bb1e8775..d870e3ed 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.toc.css
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.toc.css
@@ -9,9 +9,11 @@
overflow: auto;
overflow-x: hidden;
}
+
.wikiEditor-ui-toc {
border-left: solid silver 1px;
}
+
.wikiEditor-ui-toc ul {
padding: 0;
margin: 0;
@@ -22,6 +24,7 @@
list-style-type: none;
width: 100%;
}
+
.tab-toc {
/* Should match the toolbar */
/* @embed */
@@ -36,13 +39,16 @@
white-space: nowrap;
overflow: hidden;
}
+
.tab-toc a {
outline: none;
}
+
.wikiEditor-ui-toc li {
padding: 0;
margin: 0;
}
+
.wikiEditor-ui-toc ul ul {
padding: 0;
margin: 0;
@@ -51,35 +57,44 @@
list-style: none;
background-image: none;
}
+
.wikiEditor-ui-toc ul li div {
display: block;
font-size: 0.9em;
cursor: pointer;
color: #0645ad;
}
+
.wikiEditor-ui-toc ul li div {
padding: 0.125em;
padding-left: 1em;
}
+
.wikiEditor-ui-toc ul ul li div {
padding-left: 2em;
}
+
.wikiEditor-ui-toc ul ul ul li div {
padding-left: 3em;
}
+
.wikiEditor-ui-toc ul ul ul ul li div {
padding-left: 4em;
}
+
.wikiEditor-ui-toc ul ul ul ul ul li div {
padding-left: 5em;
}
+
.wikiEditor-ui-toc ul ul ul ul ul ul li div {
padding-left: 6em;
}
+
.wikiEditor-ui-toc ul li div.current {
background-color: #FAFAFA;
color: #333333;
}
+
.wikiEditor-ui-toc ul li div.section-0 {
font-size: 1em;
padding-top: 0.5em;
@@ -91,13 +106,14 @@
overflow-y: hidden;
position: relative;
}
+
.wikiEditor-ui-toc ul {
overflow-y: auto;
overflow-x: hidden;
height: 100%;
margin-bottom: 0 !important;
-
}
+
.wikiEditor-ui-toc ul ul {
float: none;
height: auto;
@@ -109,15 +125,18 @@
top: 0;
left: 0;
}
+
.wikiEditor-ui-toc-collapse-open {
/* @embed */
background: #f3f3f3 url(images/toc/close.png) 4px 50% no-repeat;
border-left: 1px solid #DDDDDD;
}
+
.wikiEditor-ui-toc-collapse-closed {
/* @embed */
background: #f3f3f3 url(images/toc/open.png) 4px 50% no-repeat;
}
+
/* Resizing Changes */
.wikiEditor-ui-toc-resize-vertical,
.ui-resizable-w {
@@ -128,13 +147,16 @@
height: 100%;
cursor: ew-resize;
}
+
.wikiEditor-ui .wikiEditor-ui-right {
overflow: visible;
}
+
.wikiEditor-ui-right .ui-resizable-w {
- left: 0px !important;
+ left: 0 !important;
z-index: 0;
}
+
.wikiEditor-ui-right .wikiEditor-ui-toc-resize-grip {
width: 5px;
height: 12px;
@@ -147,15 +169,17 @@
background: url(images/toc/grip.png) 50% 50% no-repeat;
z-index: 0;
}
+
.wikiEditor-ui-toolbar .tab-toc {
float: right;
margin: 3px 16px 3px 3px;
line-height: 26px;
}
+
.wikiEditor-ui-toc-expandControl {
position: absolute;
z-index: 2;
- top: 0px;
+ top: 0;
right: 10px;
height: 26px;
padding: 3px 0;
@@ -164,14 +188,17 @@
white-space: nowrap;
overflow: hidden;
}
+
.wikiEditor-ui-text textarea {
resize: none;
}
+
.wikiEditor-ui-text textarea:focus {
outline: none;
}
+
/* Self Clearing for the wikiText view */
.wikiEditor-ui-view-wikiText {
overflow: auto;
width: 100%;
-} \ No newline at end of file
+}
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.toc.js b/extensions/WikiEditor/modules/jquery.wikiEditor.toc.js
index a714d253..5cfa900c 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.toc.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.toc.js
@@ -182,7 +182,7 @@ fn: {
$.wikiEditor.modules.toc.cfg.rtl = $( 'body' ).is( '.rtl' );
$.wikiEditor.modules.toc.cfg.flexProperty = $.wikiEditor.modules.toc.cfg.rtl ? 'marginLeft' : 'marginRight';
var height = context.$ui.find( '.wikiEditor-ui-left' ).height();
- context.modules.toc.$toc = $( '<div />' )
+ context.modules.toc.$toc = $( '<div>' )
.addClass( 'wikiEditor-ui-toc' )
.data( 'context', context )
.data( 'positionMode', 'regular' )
@@ -195,7 +195,7 @@ fn: {
$.wikiEditor.modules.toc.fn.redraw( context, $.wikiEditor.modules.toc.cfg.defaultWidth );
},
redraw: function( context, fixedWidth ) {
- var fixedWidth = parseFloat( fixedWidth );
+ fixedWidth = parseFloat( fixedWidth );
if( context.modules.toc.$toc.data( 'positionMode' ) == 'regular' ) {
context.$ui.find( '.wikiEditor-ui-right' )
.css( 'width', fixedWidth + 'px' );
@@ -214,8 +214,9 @@ fn: {
switchLayout: function( context ) {
var width,
height = context.$ui.find( '.wikiEditor-ui-right' ).height();
- if( context.modules.toc.$toc.data( 'positionMode' ) == 'regular'
- && !context.modules.toc.$toc.data( 'collapsed' ) ) {
+ if ( context.modules.toc.$toc.data( 'positionMode' ) == 'regular'
+ && !context.modules.toc.$toc.data( 'collapsed' )
+ ) {
// store position mode
context.modules.toc.$toc.data( 'positionMode', 'goofy' );
// store the width of the TOC, to ensure we dont allow it to be larger than this when switching back
@@ -423,8 +424,12 @@ fn: {
* @param {Object} outline Array of objects with level fields
*/
function buildStructure( outline, offset, level ) {
- if ( offset == undefined ) offset = 0;
- if ( level == undefined ) level = 1;
+ if ( offset === undefined ) {
+ offset = 0;
+ }
+ if ( level === undefined ) {
+ level = 1;
+ }
var sections = [];
for ( var i = offset; i < outline.length; i++ ) {
if ( outline[i].nLevel == level ) {
@@ -445,9 +450,9 @@ fn: {
* @param {Object} structure Structured outline
*/
function buildList( structure ) {
- var list = $( '<ul />' );
+ var list = $( '<ul>' );
for ( var i = 0; i < structure.length; i++ ) {
- var div = $( '<div />' )
+ var div = $( '<div>' )
.addClass( 'section-' + structure[i].index )
.data( 'index', structure[i].index )
.mousedown( function() {
@@ -457,7 +462,7 @@ fn: {
.click( function( event ) {
var wrapper = context.$content.find(
'.wikiEditor-toc-section-' + $( this ).data( 'index' ) );
- if ( wrapper.size() == 0 )
+ if ( wrapper.length === 0 )
wrapper = context.$content;
context.fn.scrollToTop( wrapper, true );
context.$textarea.textSelection( 'setSelection', {
@@ -471,16 +476,16 @@ fn: {
//$.wikiEditor.modules.toc.fn.unhighlight( context );
$( this ).addClass( 'current' );
//$( this ).removeClass( 'current' );
- setTimeout( function() { $.wikiEditor.modules.toc.fn.unhighlight( context ) }, 1000 );
+ setTimeout( function() { $.wikiEditor.modules.toc.fn.unhighlight( context ); }, 1000 );
if ( typeof $.trackAction != 'undefined' )
$.trackAction( 'ntoc.heading' );
event.preventDefault();
} )
.text( structure[i].text );
- if ( structure[i].text == '' )
+ if ( structure[i].text === '' )
div.html( '&nbsp;' );
- var item = $( '<li />' ).append( div );
+ var item = $( '<li>' ).append( div );
if ( structure[i].sections !== undefined ) {
item.append( buildList( structure[i].sections ) );
}
@@ -493,11 +498,11 @@ fn: {
*
*/
function buildCollapseControls( ) {
- var $collapseControl = $( '<div />' ), $expandControl = $( '<div />' );
+ var $collapseControl = $( '<div>' ), $expandControl = $( '<div>' );
$collapseControl
.addClass( 'tab' )
.addClass( 'tab-toc' )
- .append( '<a href="#" />' )
+ .append( '<a href="#"></a>' )
.mousedown( function( e ) {
// No dragging!
e.preventDefault();
@@ -513,7 +518,7 @@ fn: {
.text( mediaWiki.msg( 'wikieditor-toc-hide' ) );
$expandControl
.addClass( 'wikiEditor-ui-toc-expandControl' )
- .append( '<a href="#" />' )
+ .append( '<a href="#"></a>' )
.mousedown( function( e ) {
// No dragging!
e.preventDefault();
@@ -546,7 +551,7 @@ fn: {
start: function( e, ui ) {
var $this = $( this );
// Toss a transparent cover over our iframe
- $( '<div />' )
+ $( '<div>' )
.addClass( 'wikiEditor-ui-resize-mask' )
.css( {
'position': 'absolute',
@@ -636,8 +641,12 @@ fn: {
// Recursively build the structure and add special item for
// section 0, if needed
var structure = buildStructure( outline );
- if ( $( 'input[name=wpSection]' ).val() == '' ) {
- structure.unshift( { 'text': mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ), 'level': 1, 'index': 0 } );
+ if ( $( 'input[name="wpSection"]' ).val() === '' ) {
+ structure.unshift( {
+ 'text': mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ),
+ 'level': 1,
+ 'index': 0
+ } );
}
context.modules.toc.$toc.html( buildList( structure ) );
@@ -645,18 +654,20 @@ fn: {
buildResizeControls();
buildCollapseControls();
}
- context.modules.toc.$toc.find( 'div' ).autoEllipsis(
- { 'position': 'right', 'tooltip': true, 'restoreText': true }
- );
+ context.modules.toc.$toc.find( 'div' ).autoEllipsis( {
+ 'position': 'right',
+ 'tooltip': true,
+ 'restoreText': true
+ } );
}
},
improveUI: function() {
/*
* Extending resizable to allow west resizing without altering the left position attribute
*/
- $.ui.plugin.add( "resizable", "preventPositionLeftChange", {
+ $.ui.plugin.add( 'resizable', 'preventPositionLeftChange', {
resize: function( event, ui ) {
- $( this ).data( "resizable" ).position.left = 0;
+ $( this ).data( 'resizable' ).position.left = 0;
}
} );
}
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.config.js b/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.config.js
index e4928b29..52b7498f 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.config.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.config.js
@@ -149,7 +149,7 @@ getDefaultConfig: function() {
'options': {
'pre': '[[' + fileNamespace + ':',
'periMsg': 'wikieditor-toolbar-tool-file-example',
- 'post': "]]"
+ 'post': "|" + mw.config.get( 'wgWikiEditorMagicWords' ).img_thumbnail + "]]"
}
}
},
@@ -462,7 +462,7 @@ getDefaultConfig: function() {
'action': {
'type': 'encapsulate',
'options': {
- 'pre': "#REDIRECT [[",
+ 'pre': mw.config.get( 'wgWikiEditorMagicWords' ).redirect + ' [[',
'periMsg': 'wikieditor-toolbar-tool-redirect-example',
'post': "]]",
'ownline': true
@@ -1271,7 +1271,7 @@ getDefaultConfig: function() {
{
'description': { 'htmlMsg': 'wikieditor-toolbar-help-content-file-description' },
'syntax': { 'htmlMsg': [ 'wikieditor-toolbar-help-content-file-syntax', fileNamespace ] },
- 'result': { 'htmlMsg': [ 'wikieditor-toolbar-help-content-file-result', mw.config.get( 'stylepath' ) ] }
+ 'result': { 'htmlMsg': [ 'wikieditor-toolbar-help-content-file-result', mw.config.get( 'stylepath' ), mw.config.get( 'wgExtensionAssetsPath' ) ] }
}
]
},
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.css b/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.css
index a5903a63..6b3fc625 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.css
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.css
@@ -1,4 +1,4 @@
-/*
+/**
* CSS for WikiEditor Toolbar jQuery plugin
*/
@@ -119,7 +119,7 @@
/* Toolbar */
.wikiEditor-ui-toolbar .group .label {
float: left;
- border: 0px;
+ border: 0;
height: 22px;
line-height: 22px;
margin: 2px;
@@ -130,7 +130,7 @@
}
.wikiEditor-ui-toolbar .group img.tool {
float: left;
- border: 0px;
+ border: 0;
height: 22px;
width: 22px;
padding: 2px;
@@ -237,7 +237,7 @@
.wikiEditor-ui-toolbar .page-table td {
text-align: left;
padding: 5px;
- margin: 0px;
+ margin: 0;
}
.wikiEditor-ui-toolbar .section-help .page-table td.cell-syntax,
.wikiEditor-ui-toolbar .section-help .page-table td.syntax {
@@ -279,7 +279,7 @@
border-color: #a8d7f9;
}
.ui-widget table td.wikieditor-toolbar-table-preview-wrapper span {
- padding: 4px 6px 0px;
+ padding: 4px 6px 0;
display: block;
}
.ui-widget table .wikieditor-toolbar-table-preview-frame {
diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js b/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js
index 57dd3240..e7d2213a 100644
--- a/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js
+++ b/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js
@@ -157,7 +157,7 @@ api : {
// Save for later checking if empty
group = target;
// Tool
- target += ' span[rel="' + data.tool + '"].tool';
+ target += ' a[rel="' + data.tool + '"].tool';
}
} else if ( typeof data.page == 'string' ) {
// Booklet page