Merge "Ask for confirmation when saving document with errors"

This commit is contained in:
jenkins-bot 2014-03-30 12:03:51 +00:00 committed by Gerrit Code Review
commit ecff4f5837
4 changed files with 29 additions and 8 deletions

View file

@ -49,7 +49,8 @@ $wgResourceModules['jquery.codeEditor'] = array(
'jquery.ui.resizable' 'jquery.ui.resizable'
), ),
'messages' => array( 'messages' => array(
'codeeditor-toolbar-toggle' 'codeeditor-toolbar-toggle',
'codeeditor-save-with-errors'
) )
) + $tpl; ) + $tpl;

View file

@ -1,9 +1,11 @@
{ {
"@metadata": { "@metadata": {
"authors": [ "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-desc": "Syntax-highlighted editing for JavaScript and CSS pages using [http://ace.ajax.org/ Ace editor]",
"codeeditor-toolbar-toggle": "Toggle code editor" "codeeditor-toolbar-toggle": "Toggle code editor",
"codeeditor-save-with-errors": "The document contains errors. Are you sure you want to save?"
} }

View file

@ -2,9 +2,11 @@
"@metadata": { "@metadata": {
"authors": [ "authors": [
"Purodha", "Purodha",
"Shirayuki" "Shirayuki",
"Derk-Jan Hartman"
] ]
}, },
"codeeditor-desc": "{{desc|name=Code Editor|url=http://www.mediawiki.org/wiki/Extension:CodeEditor}}", "codeeditor-desc": "{{desc|name=Code Editor|url=http://www.mediawiki.org/wiki/Extension:CodeEditor}}",
"codeeditor-toolbar-toggle": "Used as label for toolbar button." "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."
} }

View file

@ -1,5 +1,5 @@
/* Ace syntax-highlighting code editor extension for wikiEditor */ /* Ace syntax-highlighting code editor extension for wikiEditor */
/*global require, ace */ /*global require, ace, confirm */
(function ( $, mw ) { (function ( $, mw ) {
$.wikiEditor.modules.codeEditor = { $.wikiEditor.modules.codeEditor = {
/** /**
@ -60,7 +60,23 @@
'ready': function ( ) { 'ready': function ( ) {
}, },
'codeEditorSubmit': 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' ) ); context.$textarea.val( context.$textarea.textSelection( 'getContents' ) );
} }
} ); } );