MDL-51177 atto_html: Check isHTML before hiding editor

This commit is contained in:
Andrew Nicols 2018-09-13 15:32:20 +08:00
parent 3951d50a89
commit 11cd7c89d4
4 changed files with 16 additions and 4 deletions

View File

@ -47,7 +47,11 @@ Y.namespace('M.atto_html').Button = Y.Base.create('button', Y.M.editor_atto.Edit
// This ensures that the codeMirror is converted back to the original text before form submission.
var form = this.get('host').textarea.ancestor('form');
if (form) {
form.on('submit', this._hideCodeMirror, this);
form.on('submit', function() {
if (this.get('isHTML')) {
this._hideCodeMirror();
}
}, this);
}
},

View File

@ -1 +1 @@
YUI.add("moodle-atto_html-button",function(e,t){e.namespace("M.atto_html").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_codeMirror:null,initializer:function(){this.addButton({icon:"e/source_code",callback:this._toggleHTML});var e=this.get("host").textarea.ancestor("form");e&&e.on("submit",this._hideCodeMirror,this)},_toggleHTML:function(){this.set("isHTML",!this.get("isHTML")),this.get("isHTML")?this._showCodeMirror():this._hideCodeMirror()},_showCodeMirror:function(){var t=this.get("host");t.disablePlugins(),t.enablePlugins(this.name),t.updateOriginal();var n={width:this.editor.getComputedStyle("width"),height:this.editor.getComputedStyle("height")},r=e.M.atto_html.beautify.html_beautify(t.textarea.get("value"),{indent_size:4,indent_inner_html:!0});t.textarea.set("value",r),this._codeMirror=e.M.atto_html.CodeMirror.fromTextArea(t.textarea.getDOMNode(),{lineNumbers:!0,mode:"htmlmixed",tabSize:2,lineWrapping:!0}),this._codeMirror.on("change",function(e){e.save()}),this.editor.hide(),this._codeMirror.setSize(n.width,n.height),this._codeMirror.focus()},_hideCodeMirror:function(){var t=this.get("host");t.enablePlugins(),t.updateFromTextArea(),this._codeMirror&&(e.one(this._codeMirror.getWrapperElement()).hide(),this._codeMirror.toTextArea(),e.Object.each(this._codeMirror._handlers,function(t,n){e.Array.each(t,function(e){this.off(n,e)},this)},this._codeMirror),delete this._codeMirror,this._codeMirror=null),t.textarea.hide(),this.editor.show(),t.focus(),this.markUpdated()}},{ATTRS:{isHTML:{value:!1}}})},"@VERSION@",{requires:["promise","moodle-editor_atto-plugin","moodle-atto_html-beautify","moodle-atto_html-codemirror","event-valuechange"]});
YUI.add("moodle-atto_html-button",function(e,t){e.namespace("M.atto_html").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_codeMirror:null,initializer:function(){this.addButton({icon:"e/source_code",callback:this._toggleHTML});var e=this.get("host").textarea.ancestor("form");e&&e.on("submit",function(){this.get("isHTML")&&this._hideCodeMirror()},this)},_toggleHTML:function(){this.set("isHTML",!this.get("isHTML")),this.get("isHTML")?this._showCodeMirror():this._hideCodeMirror()},_showCodeMirror:function(){var t=this.get("host");t.disablePlugins(),t.enablePlugins(this.name),t.updateOriginal();var n={width:this.editor.getComputedStyle("width"),height:this.editor.getComputedStyle("height")},r=e.M.atto_html.beautify.html_beautify(t.textarea.get("value"),{indent_size:4,indent_inner_html:!0});t.textarea.set("value",r),this._codeMirror=e.M.atto_html.CodeMirror.fromTextArea(t.textarea.getDOMNode(),{lineNumbers:!0,mode:"htmlmixed",tabSize:2,lineWrapping:!0}),this._codeMirror.on("change",function(e){e.save()}),this.editor.hide(),this._codeMirror.setSize(n.width,n.height),this._codeMirror.focus()},_hideCodeMirror:function(){var t=this.get("host");t.enablePlugins(),t.updateFromTextArea(),this._codeMirror&&(e.one(this._codeMirror.getWrapperElement()).hide(),this._codeMirror.toTextArea(),e.Object.each(this._codeMirror._handlers,function(t,n){e.Array.each(t,function(e){this.off(n,e)},this)},this._codeMirror),delete this._codeMirror,this._codeMirror=null),t.textarea.hide(),this.editor.show(),t.focus(),this.markUpdated()}},{ATTRS:{isHTML:{value:!1}}})},"@VERSION@",{requires:["promise","moodle-editor_atto-plugin","moodle-atto_html-beautify","moodle-atto_html-codemirror","event-valuechange"]});

View File

@ -47,7 +47,11 @@ Y.namespace('M.atto_html').Button = Y.Base.create('button', Y.M.editor_atto.Edit
// This ensures that the codeMirror is converted back to the original text before form submission.
var form = this.get('host').textarea.ancestor('form');
if (form) {
form.on('submit', this._hideCodeMirror, this);
form.on('submit', function() {
if (this.get('isHTML')) {
this._hideCodeMirror();
}
}, this);
}
},

View File

@ -45,7 +45,11 @@ Y.namespace('M.atto_html').Button = Y.Base.create('button', Y.M.editor_atto.Edit
// This ensures that the codeMirror is converted back to the original text before form submission.
var form = this.get('host').textarea.ancestor('form');
if (form) {
form.on('submit', this._hideCodeMirror, this);
form.on('submit', function() {
if (this.get('isHTML')) {
this._hideCodeMirror();
}
}, this);
}
},