From 0759da9ecf4a38e9d42e6643516b50f9853ca452 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 7 Nov 2019 21:45:46 +0000 Subject: [PATCH] MDL-68995 atto_image: remove initial dialogue image src attribute. It caused a spurious request to be sent to the server on display. --- .../moodle-atto_image-button/moodle-atto_image-button-debug.js | 2 +- .../moodle-atto_image-button/moodle-atto_image-button-min.js | 2 +- .../build/moodle-atto_image-button/moodle-atto_image-button.js | 2 +- lib/editor/atto/plugins/image/yui/src/button/js/button.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button-debug.js b/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button-debug.js index 75f44a531fa..b8c15f2b78c 100644 --- a/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button-debug.js +++ b/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button-debug.js @@ -182,7 +182,7 @@ var CSS = { // Add the image preview. '
' + '
' + - '' + + '' + '
' + // Add the submit button and close the form. diff --git a/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button-min.js b/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button-min.js index 939f2d7a686..a65bd188d0b 100644 --- a/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button-min.js +++ b/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button-min.js @@ -1,3 +1,3 @@ YUI.add("moodle-atto_image-button",function(d,e){var u={RESPONSIVE:"img-responsive",INPUTALIGNMENT:"atto_image_alignment",INPUTALT:"atto_image_altentry",INPUTHEIGHT:"atto_image_heightentry",INPUTSUBMIT:"atto_image_urlentrysubmit",INPUTURL:"atto_image_urlentry",INPUTSIZE:"atto_image_size",INPUTWIDTH:"atto_image_widthentry",IMAGEALTWARNING:"atto_image_altwarning",IMAGEBROWSER:"openimagebrowser",IMAGEPRESENTATION:"atto_image_presentation",INPUTCONSTRAIN:"atto_image_constrain",INPUTCUSTOMSTYLE:"atto_image_customstyle",IMAGEPREVIEW:"atto_image_preview",IMAGEPREVIEWBOX:"atto_image_preview_box",ALIGNSETTINGS:"atto_image_button"},t={INPUTURL:"."+u.INPUTURL},a=[{name:"verticalAlign",str:"alignment_top",value:"text-top",margin:"0 0.5em"},{name:"verticalAlign",str:"alignment_middle",value:"middle",margin:"0 0.5em"},{name:"verticalAlign",str:"alignment_bottom",value:"text-bottom",margin:"0 0.5em",isDefault:!0},{name:"float",str:"alignment_left",value:"left",margin:"0 0.5em 0 0"},{name:"float",str:"alignment_right",value:"right",margin:"0 0 0 0.5em"}],I=/\d+%/,_="atto_image",p='{{alt}}';d.namespace("M.atto_image").Button=d.Base.create("button",d.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_selectedImage:null,_form:null,_rawImageDimensions:null,initializer:function(){this.addButton({icon:"e/insert_edit_image",callback:this._displayDialogue,tags:"img",tagMatchRequiresAll:!1}),this.editor.delegate("dblclick",this._displayDialogue,"img",this),this.editor.delegate("click",this._handleClick,"img",this),this.editor.on("paste",this._handlePaste,this),this.editor.on("drop",this._handleDragDrop,this),this.editor.on("dragover",function(e){e.preventDefault()},this),this.editor.on("dragenter",function(e){e.preventDefault()},this)},_handleDragDrop:function(e){return!e._event||!e._event.dataTransfer||this._handlePasteOrDropHelper(e,e._event.dataTransfer)},_handlePaste:function(e){return!e._event||!e._event.clipboardData||this._handlePasteOrDropHelper(e,e._event.clipboardData)},_handlePasteOrDropHelper:function(e,t){var i,n,s=t.items,a=!1;for(i=0;i{{#if showFilepicker}}
{{else}}
{{/if}}
0 / 125
x

'),t=this.get("host").canShowFilepicker("image"),i=d.Node.create(e({elementid:this.get("host").get("elementid"),CSS:u,component:_,showFilepicker:t,alignments:a}));return this._form=i,this._applyImageProperties(this._form),this._form.one("."+u.INPUTURL).on("blur",this._urlChanged,this),this._form.one("."+u.IMAGEPRESENTATION).on("change",this._updateWarning,this),this._form.one("."+u.INPUTALT).on("change",this._updateWarning,this),this._form.one("."+u.INPUTWIDTH).on("blur",this._autoAdjustSize,this),this._form.one("."+u.INPUTHEIGHT).on("blur",this._autoAdjustSize,this,!0),this._form.one("."+u.INPUTCONSTRAIN).on("change",function(e){e.target.get("checked")&&this._autoAdjustSize(e)},this),this._form.one("."+u.INPUTURL).on("blur",this._urlChanged,this),this._form.one("."+u.INPUTSUBMIT).on("click",this._setImage,this),t&&this._form.one("."+u.IMAGEBROWSER).on("click",function(){this.get("host").showFilepicker("image",this._filepickerCallback,this)},this),this._form.one("."+u.INPUTALT).on("keyup",this._handleKeyup,this),i},_autoAdjustSize:function(e,t){var i,n,s,a,o,l,r,h,g,c,m;t=t||!1,i=this._form.one("."+u.INPUTWIDTH),n="width",s=this._form.one("."+u.INPUTHEIGHT),a="height",o=this._form.one("."+u.INPUTCONSTRAIN),l=i.get("value"),r=s.get("value"),h=this._form.one("."+u.IMAGEPREVIEW),this._rawImageDimensions&&(""===l&&(l=this._rawImageDimensions[n],i.set("value",l),l=i.get("value")),h.setStyles({width:null,height:null}),o.get("checked")?(t&&(m=i,i=s,s=m,m=n,n=a,a=m,m=l,l=r,r=m),l.match(I)?(r=l,g=parseInt(l,10),c=this._rawImageDimensions.width/100*g,h.setStyle("width",c),c=this._rawImageDimensions.height/100*g,h.setStyle("height",c)):(r=Math.round(l/this._rawImageDimensions[n]*this._rawImageDimensions[a]),t?h.setStyles({width:r,height:l}):h.setStyles({width:l,height:r})),s.set("value",r)):(l.match(I)?(g=parseInt(l,10),c=this._rawImageDimensions.width/100*g,h.setStyle("width",c+"px")):h.setStyle("width",l+"px"),r.match(I)?(g=parseInt(r,10),c=this._rawImageDimensions.height/100*g,h.setStyle("height",c+"px")):h.setStyle("height",r+"px")))},_filepickerCallback:function(e){""!==e.url&&(this._form.one("."+u.INPUTURL).set("value",e.url),this._form.one("."+u.INPUTWIDTH).set("value",""),this._form.one("."+u.INPUTHEIGHT).set("value",""),this._loadPreviewImage(e.url))},_applyImageProperties:function(t){var e=this._getSelectedImageProperties(),i=t.one("."+u.IMAGEPREVIEW);if(!1===e)return i.setStyle("display","none"),void a.some(function(e){return!!e.isDefault&&(t.one("."+u.INPUTALIGNMENT).set("value",e.value),!0)},this);e.align&&t.one("."+u.INPUTALIGNMENT).set("value",e.align),e.customstyle&&t.one("."+u.INPUTCUSTOMSTYLE).set("value",e.customstyle),e.width&&t.one("."+u.INPUTWIDTH).set("value",e.width),e.height&&t.one("."+u.INPUTHEIGHT).set("value",e.height),e.alt&&t.one("."+u.INPUTALT).set("value",e.alt),e.src&&(t.one("."+u.INPUTURL).set("value",e.src), +'
{{#if showFilepicker}}
{{else}}
{{/if}}
0 / 125
x

'),t=this.get("host").canShowFilepicker("image"),i=d.Node.create(e({elementid:this.get("host").get("elementid"),CSS:u,component:_,showFilepicker:t,alignments:a}));return this._form=i,this._applyImageProperties(this._form),this._form.one("."+u.INPUTURL).on("blur",this._urlChanged,this),this._form.one("."+u.IMAGEPRESENTATION).on("change",this._updateWarning,this),this._form.one("."+u.INPUTALT).on("change",this._updateWarning,this),this._form.one("."+u.INPUTWIDTH).on("blur",this._autoAdjustSize,this),this._form.one("."+u.INPUTHEIGHT).on("blur",this._autoAdjustSize,this,!0),this._form.one("."+u.INPUTCONSTRAIN).on("change",function(e){e.target.get("checked")&&this._autoAdjustSize(e)},this),this._form.one("."+u.INPUTURL).on("blur",this._urlChanged,this),this._form.one("."+u.INPUTSUBMIT).on("click",this._setImage,this),t&&this._form.one("."+u.IMAGEBROWSER).on("click",function(){this.get("host").showFilepicker("image",this._filepickerCallback,this)},this),this._form.one("."+u.INPUTALT).on("keyup",this._handleKeyup,this),i},_autoAdjustSize:function(e,t){var i,n,s,a,o,l,r,h,g,c,m;t=t||!1,i=this._form.one("."+u.INPUTWIDTH),n="width",s=this._form.one("."+u.INPUTHEIGHT),a="height",o=this._form.one("."+u.INPUTCONSTRAIN),l=i.get("value"),r=s.get("value"),h=this._form.one("."+u.IMAGEPREVIEW),this._rawImageDimensions&&(""===l&&(l=this._rawImageDimensions[n],i.set("value",l),l=i.get("value")),h.setStyles({width:null,height:null}),o.get("checked")?(t&&(m=i,i=s,s=m,m=n,n=a,a=m,m=l,l=r,r=m),l.match(I)?(r=l,g=parseInt(l,10),c=this._rawImageDimensions.width/100*g,h.setStyle("width",c),c=this._rawImageDimensions.height/100*g,h.setStyle("height",c)):(r=Math.round(l/this._rawImageDimensions[n]*this._rawImageDimensions[a]),t?h.setStyles({width:r,height:l}):h.setStyles({width:l,height:r})),s.set("value",r)):(l.match(I)?(g=parseInt(l,10),c=this._rawImageDimensions.width/100*g,h.setStyle("width",c+"px")):h.setStyle("width",l+"px"),r.match(I)?(g=parseInt(r,10),c=this._rawImageDimensions.height/100*g,h.setStyle("height",c+"px")):h.setStyle("height",r+"px")))},_filepickerCallback:function(e){""!==e.url&&(this._form.one("."+u.INPUTURL).set("value",e.url),this._form.one("."+u.INPUTWIDTH).set("value",""),this._form.one("."+u.INPUTHEIGHT).set("value",""),this._loadPreviewImage(e.url))},_applyImageProperties:function(t){var e=this._getSelectedImageProperties(),i=t.one("."+u.IMAGEPREVIEW);if(!1===e)return i.setStyle("display","none"),void a.some(function(e){return!!e.isDefault&&(t.one("."+u.INPUTALIGNMENT).set("value",e.value),!0)},this);e.align&&t.one("."+u.INPUTALIGNMENT).set("value",e.align),e.customstyle&&t.one("."+u.INPUTCUSTOMSTYLE).set("value",e.customstyle),e.width&&t.one("."+u.INPUTWIDTH).set("value",e.width),e.height&&t.one("."+u.INPUTHEIGHT).set("value",e.height),e.alt&&t.one("."+u.INPUTALT).set("value",e.alt),e.src&&(t.one("."+u.INPUTURL).set("value",e.src), this._loadPreviewImage(e.src)),e.presentation&&t.one("."+u.IMAGEPRESENTATION).set("checked","checked"),this._autoAdjustSize()},_getSelectedImageProperties:function(){var e,t,i,n,s={src:null,alt:null,width:null,height:null,align:"",presentation:!1},a=this.get("host").getSelectedNodes();return(a=a&&a.filter("img"))&&a.size()?(n=this._removeLegacyAlignment(a.item(0)),i=(this._selectedImage=n).getAttribute("style"),s.customstyle=i,(e=n.getAttribute("width")).match(I)||(e=parseInt(e,10)),(t=n.getAttribute("height")).match(I)||(t=parseInt(t,10)),0!==e&&(s.width=e),0!==t&&(s.height=t),this._getAlignmentPropeties(n,s),s.src=n.getAttribute("src"),s.alt=n.getAttribute("alt")||"",s.presentation="presentation"===n.get("role"),s):(this._selectedImage=null,!1)},_getAlignmentPropeties:function(i,n){var s;!a.some(function(e){var t=this._getAlignmentClass(e.value);return i.hasClass(t)?(n.align=e.value,!0):(e.isDefault&&(s=e.value),!1)},this)&&s&&(n.align=s)},_urlChanged:function(){var e=this._form.one("."+u.INPUTURL);""!==e.get("value")&&this._loadPreviewImage(e.get("value"))},_setImage:function(e){var t,i=this._form,n=i.one("."+u.INPUTURL).get("value"),s=i.one("."+u.INPUTALT).get("value"),a=i.one("."+u.INPUTWIDTH).get("value"),o=i.one("."+u.INPUTHEIGHT).get("value"),l=this._getAlignmentClass(i.one("."+u.INPUTALIGNMENT).get("value")),r=i.one("."+u.IMAGEPRESENTATION).get("checked"),h=i.one("."+u.INPUTCONSTRAIN).get("checked"),g=i.one("."+u.INPUTCUSTOMSTYLE).get("value"),c=[],m=this.get("host");if(e.preventDefault(),!this._updateWarning()){if(m.focus(),""!==n){if(this._selectedImage?m.setSelection(m.getSelectionFromNode(this._selectedImage)):m.setSelection(this._currentSelection),h&&c.push(u.RESPONSIVE),c.push(l),!a.match(I)&&isNaN(parseInt(a,10)))return void i.one("."+u.INPUTWIDTH).focus();if(!o.match(I)&&isNaN(parseInt(o,10)))return void i.one("."+u.INPUTHEIGHT).focus();t=d.Handlebars.compile(p)({url:n,alt:s,width:a,height:o,presentation:r,customstyle:g,classlist:c.join(" ")}),this.get("host").insertContentAtFocusPoint(t),this.markUpdated()}this.getDialogue({focusAfterHide:null}).hide()}},_removeLegacyAlignment:function(i){return i.getStyle("margin")&&a.some(function(e){if(i.getStyle(e.name)!==e.value)return!1;var t=d.Node.create("
");return t.setStyle("margin",e.margin),i.getStyle("margin")===t.getStyle("margin")&&(i.addClass(this._getAlignmentClass(e.value)),i.setStyle(e.name,null),i.setStyle("margin",null),!0)},this),i},_getAlignmentClass:function(e){return u.ALIGNSETTINGS+"_"+e},_updateWarning:function(){var e=this._form,t=!0,i=e.one("."+u.INPUTALT).get("value"),n=e.one("."+u.IMAGEPRESENTATION).get("checked");return t=""!==i||n?(e.one("."+u.IMAGEALTWARNING).setStyle("display","none"),e.one("."+u.INPUTALT).setAttribute("aria-invalid",!1),e.one("."+u.IMAGEPRESENTATION).setAttribute("aria-invalid",!1),!1):(e.one("."+u.IMAGEALTWARNING).setStyle("display","block"),e.one("."+u.INPUTALT).setAttribute("aria-invalid",!0),e.one("."+u.IMAGEPRESENTATION).setAttribute("aria-invalid",!0),!0),this.getDialogue().centerDialogue(),t},_handleKeyup:function(){var e=this._form,t=e.one("."+u.INPUTALT).get("value").length;e.one("#currentcount").setHTML(t)}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); \ No newline at end of file diff --git a/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button.js b/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button.js index 4bb3907522f..07a268aee5f 100644 --- a/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button.js +++ b/lib/editor/atto/plugins/image/yui/build/moodle-atto_image-button/moodle-atto_image-button.js @@ -182,7 +182,7 @@ var CSS = { // Add the image preview. '
' + '
' + - '' + + '' + '
' + // Add the submit button and close the form. diff --git a/lib/editor/atto/plugins/image/yui/src/button/js/button.js b/lib/editor/atto/plugins/image/yui/src/button/js/button.js index 774d8b10d3a..75f0ec44524 100644 --- a/lib/editor/atto/plugins/image/yui/src/button/js/button.js +++ b/lib/editor/atto/plugins/image/yui/src/button/js/button.js @@ -180,7 +180,7 @@ var CSS = { // Add the image preview. '
' + '
' + - '' + + '' + '
' + // Add the submit button and close the form.