diff --git a/CodeEditor.php b/CodeEditor.php index 7949d5af..f2617767 100644 --- a/CodeEditor.php +++ b/CodeEditor.php @@ -49,7 +49,8 @@ $wgResourceModules['jquery.codeEditor'] = array( 'jquery.ui.resizable' ), 'messages' => array( - 'codeeditor-toolbar-toggle' + 'codeeditor-toolbar-toggle', + 'codeeditor-save-with-errors' ) ) + $tpl; diff --git a/i18n/en.json b/i18n/en.json index 3eb19db6..13eca133 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1,9 +1,11 @@ { "@metadata": { "authors": [ - "Brion Vibber" + "Brion Vibber", + "Derk-Jan Hartman" ] }, "codeeditor-desc": "Syntax-highlighted editing for JavaScript and CSS pages using [http://ace.ajax.org/ Ace editor]", - "codeeditor-toolbar-toggle": "Toggle code editor" -} \ No newline at end of file + "codeeditor-toolbar-toggle": "Toggle code editor", + "codeeditor-save-with-errors": "The document contains errors. Are you sure you want to save?" +} diff --git a/i18n/qqq.json b/i18n/qqq.json index 09940b59..368b6347 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -2,9 +2,11 @@ "@metadata": { "authors": [ "Purodha", - "Shirayuki" + "Shirayuki", + "Derk-Jan Hartman" ] }, "codeeditor-desc": "{{desc|name=Code Editor|url=http://www.mediawiki.org/wiki/Extension:CodeEditor}}", - "codeeditor-toolbar-toggle": "Used as label for toolbar button." -} \ No newline at end of file + "codeeditor-toolbar-toggle": "Used as label for toolbar button.", + "codeeditor-save-with-errors": "Used as message in a dialog before saving a document with errors." +} diff --git a/modules/jquery.codeEditor.js b/modules/jquery.codeEditor.js index 17f7141e..ede9eb61 100644 --- a/modules/jquery.codeEditor.js +++ b/modules/jquery.codeEditor.js @@ -1,5 +1,5 @@ /* Ace syntax-highlighting code editor extension for wikiEditor */ -/*global require, ace */ +/*global require, ace, confirm */ (function ( $, mw ) { $.wikiEditor.modules.codeEditor = { /** @@ -60,7 +60,23 @@ 'ready': function ( ) { }, 'codeEditorSubmit': function ( ) { + context.evt.codeEditorSync(); + var i, + hasError = false, + annotations = context.codeEditor.getSession().getAnnotations(); + for( i = 0; i < annotations.length; i++ ) { + if ( annotations[i].type === 'error' ) { + hasError = true; + break; + } + } + if ( hasError ) { + return confirm( mw.msg( 'codeeditor-save-with-errors' ) ); + } + }, + 'codeEditorSync': function ( ) { context.$textarea.val( context.$textarea.textSelection( 'getContents' ) ); + } } );