From 4a87ffb3364db69bd2c0f2fb07b32d264c2c4e61 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Tue, 28 Jan 2020 22:28:57 +1100 Subject: [PATCH] MDL-67675 atto_h5p: No need to manually clear the H5P placeholder --- .../moodle-atto_h5p-button-debug.js | 21 ------------------- .../moodle-atto_h5p-button-min.js | 4 ++-- .../moodle-atto_h5p-button.js | 21 ------------------- .../plugins/h5p/yui/src/button/js/button.js | 21 ------------------- 4 files changed, 2 insertions(+), 65 deletions(-) diff --git a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-debug.js b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-debug.js index 836a2bf81cb..29ed69b26e7 100644 --- a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-debug.js +++ b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-debug.js @@ -188,32 +188,11 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito tagMatchRequiresAll: false }); - this.editor.on(['keyup', 'cut'], this._clearH5P, this); this.editor.all('.h5p-placeholder').setAttribute('contenteditable', 'false'); this.editor.delegate('dblclick', this._handleDblClick, '.h5p-placeholder', this); this.editor.delegate('click', this._handleClick, '.h5p-placeholder', this); }, - /** - * Deletes elements with class .h5p-placeholder on backspace and delete. - * - * @method _clearH5P - * @param {EventFacade} e - * @private - */ - _clearH5P: function(e) { - if (e.keyCode === 8 || e.keyCode === 46) { - var parentNodes = this.get('host').getSelectedNodes().get('parentNode'); - if (parentNodes.hasOwnProperty('_nodes')) { - var placeholder = parentNodes.filter('.h5p-placeholder'); - if (!placeholder.isEmpty()) { - placeholder.remove(); - } - } - } - e.preventDefault(); - }, - /** * Handle a double click on a H5P Placeholder. * diff --git a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-min.js b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-min.js index f18c330390e..41c5f75d7f6 100644 --- a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-min.js +++ b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-atto_h5p-button",function(e,t){var n={CONTENTWARNING:"att_h5p_contentwarning",H5PBROWSER:"openh5pbrowser",INPUTALT:"atto_h5p_altentry",INPUTH5PFILE:"atto_h5p_file",INPUTH5PURL:"atto_h5p_url",INPUTSUBMIT:"atto_h5p_urlentrysubmit",OPTION_DOWNLOAD_BUTTON:"atto_h5p_option_download_button",OPTION_COPYRIGHT_BUTTON:"atto_h5p_option_copyright_button",OPTION_EMBED_BUTTON:"atto_h5p_option_embed_button",URLWARNING:"atto_h5p_warning"},r={CONTENTWARNING:"."+n.CONTENTWARNING,H5PBROWSER:"."+n.H5PBROWSER,INPUTH5PFILE:"."+n.INPUTH5PFILE,INPUTH5PURL:"."+n.INPUTH5PURL,INPUTSUBMIT:"."+n.INPUTSUBMIT,OPTION_DOWNLOAD_BUTTON:"."+n.OPTION_DOWNLOAD_BUTTON,OPTION_COPYRIGHT_BUTTON:"."+n.OPTION_COPYRIGHT_BUTTON,OPTION_EMBED_BUTTON:"."+n.OPTION_EMBED_BUTTON,URLWARNING:"."+n.URLWARNING},i="atto_h5p",s='
{{#if canUploadAndEmbed}}
{{{get_string "instructions" component}}}
{{get_string "either" component}}
{{/if}}{{#if canEmbed}}
{{/if}}{{#if canUploadAndEmbed}}
{{get_string "or" component}}
{{/if}}{{#if canUpload}}
{{get_string "h5poptions" component}}
{{/if}}
',o='{{#if addParagraphs}}


{{/if}}
{{{url}}}
{{#if addParagraphs}}


{{/if}}';e.namespace("M.atto_h5p").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_form:null,_H5PDiv:null,_allowedmethods:"none",initializer:function(){this._allowedmethods=this.get("allowedmethods");if(this._allowedmethods==="none")return;this.addButton({icon:"icon",iconComponent:"atto_h5p",callback:this._displayDialogue,tags:".h5p-placeholder",tagMatchRequiresAll:!1}),this.editor.on(["keyup","cut"],this._clearH5P,this),this.editor.all(".h5p-placeholder").setAttribute("contenteditable","false"),this.editor.delegate("dblclick",this._handleDblClick,".h5p-placeholder",this),this.editor.delegate("click",this._handleClick,".h5p-placeholder",this)},_clearH5P:function(e){if(e.keyCode===8||e.keyCode===46){var t=this.get("host").getSelectedNodes().get("parentNode");if(t.hasOwnProperty("_nodes")){var n=t.filter(".h5p-placeholder");n.isEmpty()||n.remove()}}e.preventDefault()},_handleDblClick:function(){this._displayDialogue()},_handleClick:function(e){var t=this.get("host").getSelectionFromNode(e.target);this.get("host").getSelection()!==t&&this.get("host").setSelection(t)},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection===!1)return;this._getH5PDiv();var e=this.getDialogue({headerContent:M.util.get_string("pluginname",i),width:"auto",focusAfterHide:!0});e.set("bodyContent",this._getDialogueContent()).show(),M.form.shortforms({formid:this.get("host").get("elementid")+"_atto_h5p_form"})},_getH5PDiv:function(){var e=this.get("host").getSelectedNodes(),t=null;e.each(function(e){e.hasClass("h5p-placeholder")&&(t=e)}),this._H5PDiv=t},_getPermissions:function(){var e={canUpload:!1,canUploadAndEbmed:!1,canEmbed:!1};this.get("host").canShowFilepicker("h5p")&&(this._allowedmethods==="both"?(e.canUploadAndEmbed=!0,e.canUpload=!0):this._allowedmethods==="upload"&&(e.canUpload=!0));if(this._allowedmethods==="both"||this._allowedmethods==="embed")e.canEmbed=!0;return e},_getDialogueContent:function(){var t=this._getPermissions(),r,o,u,a,f,l=!0;if(this._H5PDiv){var c=this._H5PDiv.get("innerHTML"),h=M.cfg.wwwroot+"/draftfile.php";if(h==c.substring(0,h.length)){r=c.split("?")[0];var p=c.split("?")[1];p&&(p.match(/export=1/)&&(u="checked",l=!1),p.match(/embed=1/)&&(a="checked",l=!1),p.match(/copyright=1/)&&(f="checked",l=!1))}else o=c}var d=e.Handlebars.compile -(s),v=e.Node.create(d({elementid:this.get("host").get("elementid"),CSS:n,component:i,canUpload:t.canUpload,canEmbed:t.canEmbed,fileURL:r,embedURL:o,canUploadAndEmbed:t.canUploadAndEmbed,collapseOptions:l,optionDownloadButton:u,optionEmbedButton:a,optionCopyrightButton:f}));return this._form=v,this._setEventListeners(),v},_filepickerCallback:function(e){if(e.url!==""){var t=this._form.one(r.INPUTH5PFILE);t.set("value",e.url),this._form.one(r.INPUTH5PURL).set("value",""),this._removeWarnings()}},_setEventListeners:function(){var e=this._form,t=this._getPermissions();e.one(r.INPUTSUBMIT).on("click",this._setH5P,this),t.canUpload&&e.one(r.H5PBROWSER).on("click",function(){this.get("host").showFilepicker("h5p",this._filepickerCallback,this)},this),t.canUploadAndEmbed&&(e.one(r.INPUTH5PFILE).on("change",function(){e.one(r.INPUTH5PURL).set("value",""),this._removeWarnings()},this),e.one(r.INPUTH5PURL).on("change",function(){e.one(r.INPUTH5PFILE).set("value",""),this._removeWarnings()},this))},_removeWarnings:function(){var e=this._form;e.one(r.URLWARNING).setStyle("display","none"),e.one(r.CONTENTWARNING).setStyle("display","none")},_setH5P:function(t){var n=this._form,i=n.one(r.INPUTH5PURL).get("value"),s,u=this.get("host"),a,f=this._getPermissions();f.canEmbed&&(i=n.one(r.INPUTH5PURL).get("value")),f.canUpload&&(a=n.one(r.INPUTH5PFILE).get("value")),t.preventDefault();if(this._updateWarning())return;u.focus();var l=!0;this._H5PDiv&&(this._H5PDiv.remove(),l=!1);if(i!==""){u.setSelection(this._currentSelection);if(this._validEmbed(i)){var c=e.Handlebars.compile(o),h=//,p=i.match(h)[1];p.startsWith(M.cfg.wwwroot+"/h5p/embed.php")&&(p=decodeURIComponent(p.split("url=")[1])),s=c({url:p})}else{var d=e.Handlebars.compile(o);s=d({url:i})}this.get("host").insertContentAtFocusPoint(s),this.markUpdated()}else if(a!==""){u.setSelection(this._currentSelection);var v={};n.one(r.OPTION_DOWNLOAD_BUTTON).get("checked")&&(v["export"]="1"),n.one(r.OPTION_EMBED_BUTTON).get("checked")&&(v.embed="1"),n.one(r.OPTION_COPYRIGHT_BUTTON).get("checked")&&(v.copyright="1");var m="";for(var g in v)m===""&&a.indexOf("?")===-1?m+="?":m+="&",m+=g+"="+v[g];var y=e.Handlebars.compile(o);s=y({url:a+m,addParagraphs:l}),this.get("host").insertContentAtFocusPoint(s),this.markUpdated()}this.getDialogue({focusAfterHide:null}).hide()},_validEmbed:function(e){var t=new RegExp("^()");return!!t.test(e)},_validURL:function(e){var t=new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*");return!!t.test(e)},_updateWarning:function(){var e=this._form,t=!0,n,i,s=this._getPermissions();if(s.canEmbed){n=e.one(r.INPUTH5PURL).get("value");if(n!=="")return this._validURL(n)||this._validEmbed(n)?(e.one(r.URLWARNING).setStyle("display","none"),t=!1):(e.one(r.URLWARNING).setStyle("display","block"),t=!0),t}return s.canUpload&&(i=e.one(r.INPUTH5PFILE).get("value"),i!==""?(e.one(r.CONTENTWARNING).setStyle("display","none"),t=!1):(e.one(r.CONTENTWARNING).setStyle("display","block"),t=!0)),t}},{ATTRS:{allowedmethods:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); +YUI.add("moodle-atto_h5p-button",function(e,t){var n={CONTENTWARNING:"att_h5p_contentwarning",H5PBROWSER:"openh5pbrowser",INPUTALT:"atto_h5p_altentry",INPUTH5PFILE:"atto_h5p_file",INPUTH5PURL:"atto_h5p_url",INPUTSUBMIT:"atto_h5p_urlentrysubmit",OPTION_DOWNLOAD_BUTTON:"atto_h5p_option_download_button",OPTION_COPYRIGHT_BUTTON:"atto_h5p_option_copyright_button",OPTION_EMBED_BUTTON:"atto_h5p_option_embed_button",URLWARNING:"atto_h5p_warning"},r={CONTENTWARNING:"."+n.CONTENTWARNING,H5PBROWSER:"."+n.H5PBROWSER,INPUTH5PFILE:"."+n.INPUTH5PFILE,INPUTH5PURL:"."+n.INPUTH5PURL,INPUTSUBMIT:"."+n.INPUTSUBMIT,OPTION_DOWNLOAD_BUTTON:"."+n.OPTION_DOWNLOAD_BUTTON,OPTION_COPYRIGHT_BUTTON:"."+n.OPTION_COPYRIGHT_BUTTON,OPTION_EMBED_BUTTON:"."+n.OPTION_EMBED_BUTTON,URLWARNING:"."+n.URLWARNING},i="atto_h5p",s='
{{#if canUploadAndEmbed}}
{{{get_string "instructions" component}}}
{{get_string "either" component}}
{{/if}}{{#if canEmbed}}
{{/if}}{{#if canUploadAndEmbed}}
{{get_string "or" component}}
{{/if}}{{#if canUpload}}
{{get_string "h5poptions" component}}
{{/if}}
',o='{{#if addParagraphs}}


{{/if}}
{{{url}}}
{{#if addParagraphs}}


{{/if}}';e.namespace("M.atto_h5p").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_form:null,_H5PDiv:null,_allowedmethods:"none",initializer:function(){this._allowedmethods=this.get("allowedmethods");if(this._allowedmethods==="none")return;this.addButton({icon:"icon",iconComponent:"atto_h5p",callback:this._displayDialogue,tags:".h5p-placeholder",tagMatchRequiresAll:!1}),this.editor.all(".h5p-placeholder").setAttribute("contenteditable","false"),this.editor.delegate("dblclick",this._handleDblClick,".h5p-placeholder",this),this.editor.delegate("click",this._handleClick,".h5p-placeholder",this)},_handleDblClick:function(){this._displayDialogue()},_handleClick:function(e){var t=this.get("host").getSelectionFromNode(e.target);this.get("host").getSelection()!==t&&this.get("host").setSelection(t)},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection===!1)return;this._getH5PDiv();var e=this.getDialogue({headerContent:M.util.get_string("pluginname",i),width:"auto",focusAfterHide:!0});e.set("bodyContent",this._getDialogueContent()).show(),M.form.shortforms({formid:this.get("host").get("elementid")+"_atto_h5p_form"})},_getH5PDiv:function(){var e=this.get("host").getSelectedNodes(),t=null;e.each(function(e){e.hasClass("h5p-placeholder")&&(t=e)}),this._H5PDiv=t},_getPermissions:function(){var e={canUpload:!1,canUploadAndEbmed:!1,canEmbed:!1};this.get("host").canShowFilepicker("h5p")&&(this._allowedmethods==="both"?(e.canUploadAndEmbed=!0,e.canUpload=!0):this._allowedmethods==="upload"&&(e.canUpload=!0));if(this._allowedmethods==="both"||this._allowedmethods==="embed")e.canEmbed=!0;return e},_getDialogueContent:function(){var t=this._getPermissions(),r,o,u,a,f,l=!0;if(this._H5PDiv){var c=this._H5PDiv.get("innerHTML"),h=M.cfg.wwwroot+"/draftfile.php";if(h==c.substring(0,h.length)){r=c.split("?")[0];var p=c.split("?")[1];p&&(p.match(/export=1/)&&(u="checked",l=!1),p.match(/embed=1/)&&(a="checked",l=!1),p.match(/copyright=1/)&&(f="checked",l=!1))}else o=c}var d=e.Handlebars.compile(s),v=e.Node.create(d({elementid:this.get("host").get("elementid"),CSS:n,component:i,canUpload:t.canUpload,canEmbed:t.canEmbed,fileURL:r,embedURL:o,canUploadAndEmbed:t.canUploadAndEmbed,collapseOptions:l,optionDownloadButton:u,optionEmbedButton:a,optionCopyrightButton:f}));return this +._form=v,this._setEventListeners(),v},_filepickerCallback:function(e){if(e.url!==""){var t=this._form.one(r.INPUTH5PFILE);t.set("value",e.url),this._form.one(r.INPUTH5PURL).set("value",""),this._removeWarnings()}},_setEventListeners:function(){var e=this._form,t=this._getPermissions();e.one(r.INPUTSUBMIT).on("click",this._setH5P,this),t.canUpload&&e.one(r.H5PBROWSER).on("click",function(){this.get("host").showFilepicker("h5p",this._filepickerCallback,this)},this),t.canUploadAndEmbed&&(e.one(r.INPUTH5PFILE).on("change",function(){e.one(r.INPUTH5PURL).set("value",""),this._removeWarnings()},this),e.one(r.INPUTH5PURL).on("change",function(){e.one(r.INPUTH5PFILE).set("value",""),this._removeWarnings()},this))},_removeWarnings:function(){var e=this._form;e.one(r.URLWARNING).setStyle("display","none"),e.one(r.CONTENTWARNING).setStyle("display","none")},_setH5P:function(t){var n=this._form,i=n.one(r.INPUTH5PURL).get("value"),s,u=this.get("host"),a,f=this._getPermissions();f.canEmbed&&(i=n.one(r.INPUTH5PURL).get("value")),f.canUpload&&(a=n.one(r.INPUTH5PFILE).get("value")),t.preventDefault();if(this._updateWarning())return;u.focus();var l=!0;this._H5PDiv&&(this._H5PDiv.remove(),l=!1);if(i!==""){u.setSelection(this._currentSelection);if(this._validEmbed(i)){var c=e.Handlebars.compile(o),h=//,p=i.match(h)[1];p.startsWith(M.cfg.wwwroot+"/h5p/embed.php")&&(p=decodeURIComponent(p.split("url=")[1])),s=c({url:p})}else{var d=e.Handlebars.compile(o);s=d({url:i})}this.get("host").insertContentAtFocusPoint(s),this.markUpdated()}else if(a!==""){u.setSelection(this._currentSelection);var v={};n.one(r.OPTION_DOWNLOAD_BUTTON).get("checked")&&(v["export"]="1"),n.one(r.OPTION_EMBED_BUTTON).get("checked")&&(v.embed="1"),n.one(r.OPTION_COPYRIGHT_BUTTON).get("checked")&&(v.copyright="1");var m="";for(var g in v)m===""&&a.indexOf("?")===-1?m+="?":m+="&",m+=g+"="+v[g];var y=e.Handlebars.compile(o);s=y({url:a+m,addParagraphs:l}),this.get("host").insertContentAtFocusPoint(s),this.markUpdated()}this.getDialogue({focusAfterHide:null}).hide()},_validEmbed:function(e){var t=new RegExp("^()");return!!t.test(e)},_validURL:function(e){var t=new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*");return!!t.test(e)},_updateWarning:function(){var e=this._form,t=!0,n,i,s=this._getPermissions();if(s.canEmbed){n=e.one(r.INPUTH5PURL).get("value");if(n!=="")return this._validURL(n)||this._validEmbed(n)?(e.one(r.URLWARNING).setStyle("display","none"),t=!1):(e.one(r.URLWARNING).setStyle("display","block"),t=!0),t}return s.canUpload&&(i=e.one(r.INPUTH5PFILE).get("value"),i!==""?(e.one(r.CONTENTWARNING).setStyle("display","none"),t=!1):(e.one(r.CONTENTWARNING).setStyle("display","block"),t=!0)),t}},{ATTRS:{allowedmethods:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); diff --git a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button.js b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button.js index 836a2bf81cb..29ed69b26e7 100644 --- a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button.js +++ b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button.js @@ -188,32 +188,11 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito tagMatchRequiresAll: false }); - this.editor.on(['keyup', 'cut'], this._clearH5P, this); this.editor.all('.h5p-placeholder').setAttribute('contenteditable', 'false'); this.editor.delegate('dblclick', this._handleDblClick, '.h5p-placeholder', this); this.editor.delegate('click', this._handleClick, '.h5p-placeholder', this); }, - /** - * Deletes elements with class .h5p-placeholder on backspace and delete. - * - * @method _clearH5P - * @param {EventFacade} e - * @private - */ - _clearH5P: function(e) { - if (e.keyCode === 8 || e.keyCode === 46) { - var parentNodes = this.get('host').getSelectedNodes().get('parentNode'); - if (parentNodes.hasOwnProperty('_nodes')) { - var placeholder = parentNodes.filter('.h5p-placeholder'); - if (!placeholder.isEmpty()) { - placeholder.remove(); - } - } - } - e.preventDefault(); - }, - /** * Handle a double click on a H5P Placeholder. * diff --git a/lib/editor/atto/plugins/h5p/yui/src/button/js/button.js b/lib/editor/atto/plugins/h5p/yui/src/button/js/button.js index 66971a80966..4b753baf780 100644 --- a/lib/editor/atto/plugins/h5p/yui/src/button/js/button.js +++ b/lib/editor/atto/plugins/h5p/yui/src/button/js/button.js @@ -186,32 +186,11 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito tagMatchRequiresAll: false }); - this.editor.on(['keyup', 'cut'], this._clearH5P, this); this.editor.all('.h5p-placeholder').setAttribute('contenteditable', 'false'); this.editor.delegate('dblclick', this._handleDblClick, '.h5p-placeholder', this); this.editor.delegate('click', this._handleClick, '.h5p-placeholder', this); }, - /** - * Deletes elements with class .h5p-placeholder on backspace and delete. - * - * @method _clearH5P - * @param {EventFacade} e - * @private - */ - _clearH5P: function(e) { - if (e.keyCode === 8 || e.keyCode === 46) { - var parentNodes = this.get('host').getSelectedNodes().get('parentNode'); - if (parentNodes.hasOwnProperty('_nodes')) { - var placeholder = parentNodes.filter('.h5p-placeholder'); - if (!placeholder.isEmpty()) { - placeholder.remove(); - } - } - } - e.preventDefault(); - }, - /** * Handle a double click on a H5P Placeholder. *