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 f20942dbce1..86270a2d495 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 @@ -92,7 +92,10 @@ var CSS = { margin: '0 0 0 0.5em' } ], - + DEFAULTS = { + WIDTH: 160, + HEIGHT: 160, + }, REGEX = { ISPERCENT: /\d+%/ }, @@ -550,22 +553,23 @@ Y.namespace('M.atto_image').Button = Y.Base.create('button', Y.M.editor_atto.Edi image.onload = function() { var input, currentwidth, currentheight, widthRatio, heightRatio; + // Store dimensions of the raw image, falling back to defaults for images without dimensions (e.g. SVG). self._rawImageDimensions = { - width: this.width, - height: this.height + width: this.width || DEFAULTS.WIDTH, + height: this.height || DEFAULTS.HEIGHT, }; input = self._form.one('.' + CSS.INPUTWIDTH); currentwidth = input.get('value'); if (currentwidth === '') { - input.set('value', this.width); - currentwidth = "" + this.width; + input.set('value', self._rawImageDimensions.width); + currentwidth = "" + self._rawImageDimensions.width; } input = self._form.one('.' + CSS.INPUTHEIGHT); currentheight = input.get('value'); if (currentheight === '') { - input.set('value', this.height); - currentheight = "" + this.height; + input.set('value', self._rawImageDimensions.height); + currentheight = "" + self._rawImageDimensions.height; } input = self._form.one('.' + CSS.IMAGEPREVIEW); input.setAttribute('src', this.src); @@ -576,13 +580,10 @@ Y.namespace('M.atto_image').Button = Y.Base.create('button', Y.M.editor_atto.Edi input = self._form.one('.' + CSS.INPUTCONSTRAIN); if (currentwidth.match(REGEX.ISPERCENT) && currentheight.match(REGEX.ISPERCENT)) { input.set('checked', currentwidth === currentheight); + } else if (this.width === 0 || this.height === 0) { + // If we don't have both dimensions of the image, we can't auto-size it, so disable control. + input.set('disabled', 'disabled'); } else { - if (this.width === 0) { - this.width = 1; - } - if (this.height === 0) { - this.height = 1; - } // This is the same as comparing to 3 decimal places. widthRatio = Math.round(1000 * parseInt(currentwidth, 10) / this.width); heightRatio = Math.round(1000 * parseInt(currentheight, 10) / this.height); 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 9a9522be60f..a3203a060b7 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(c,e){var u={RESPONSIVE:"img-fluid",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",IMAGEURLWARNING:"atto_image_urlwarning",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"},n={URL:"urlentry",ALT:"altentry"},t={INPUTURL:"."+u.INPUTURL},s=[{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}}';c.namespace("M.atto_image").Button=c.Base.create("button",c.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,a=t.items,s=!1;for(i=0;i{{#if showFilepicker}}
{{else}}
{{/if}}
0 / 125
x

'),t=this.get("host").canShowFilepicker("image"),i=c.Node.create(e({elementid:this.get("host").get("elementid"),CSS:u,FORMNAMES:n,component:_,showFilepicker:t,alignments:s}));return this._form=i,this._applyImageProperties(this._form),this._form.one("."+u.INPUTURL).on("blur",this._urlChanged,this),this._form.one("."+u.INPUTURL).on("change",this._hasErrorUrlField,this),this._form.one("."+u.IMAGEPRESENTATION).on("change",this._hasErrorAltField,this),this._form.one("."+u.INPUTALT).on("blur",this._hasErrorAltField,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.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,a,s,o,l,r,h,g,d,m;t=t||!1,i=this._form.one("."+u.INPUTWIDTH),n="width",a=this._form.one("."+u.INPUTHEIGHT),s="height",o=this._form.one("."+u.INPUTCONSTRAIN),l=i.get("value"),r=a.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=a,a=m,m=n,n=s,s=m,m=l,l=r,r=m),l.match(I)?(r=l,g=parseInt(l,10),d=this._rawImageDimensions.width/100*g,h.setStyle("width",d),d=this._rawImageDimensions.height/100*g,h.setStyle("height",d)):(r=Math.round(l/this._rawImageDimensions[n]*this._rawImageDimensions[s]),t?h.setStyles({width:r,height:l}):h.setStyles({width:l,height:r})),a.set("value",r)):(l.match(I)?(g=parseInt(l,10),d=this._rawImageDimensions.width/100*g,h.setStyle("width",d+"px")):h.setStyle("width",l+"px"),r.match(I)?(g=parseInt(r,10),d=this._rawImageDimensions.height/100*g,h.setStyle("height",d+"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 s.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,a={src:null,alt:null,width:null,height:null,align:"",presentation:!1},s=this.get("host").getSelectedNodes();return(s=s&&s.filter("img"))&&s.size()?(n=this._removeLegacyAlignment(s.item(0)),i=(this._selectedImage=n).getAttribute("style"),a.customstyle=i,(e=n.getAttribute("width")).match(I)||(e=parseInt(e,10)),(t=n.getAttribute("height")).match(I)||(t=parseInt(t,10)),0!==e&&(a.width=e),0!==t&&(a.height=t),this._getAlignmentPropeties(n,a),a.src=n.getAttribute("src"),a.alt=n.getAttribute("alt")||"",a.presentation="presentation"===n.get("role"),a):(this._selectedImage=null,!1)},_getAlignmentPropeties:function(i,n){var a;!s.some(function(e){var t=this._getAlignmentClass(e.value);return i.hasClass(t)?(n.align=e.value,!0):(e.isDefault&&(a=e.value),!1)},this)&&a&&(n.align=a)},_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"),a=i.one("."+u.INPUTALT).get("value"),s=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"),d=[],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&&d.push(u.RESPONSIVE),d.push(l),!s.match(I)&&isNaN(parseInt(s,10)))return void i.one("."+u.INPUTWIDTH).focus();if(!o.match(I)&&isNaN(parseInt(o,10)))return void i.one("."+u.INPUTHEIGHT).focus();t=c.Handlebars.compile(p)({url:n,alt:a,width:s,height:o,presentation:r,customstyle:g,classlist:d.join(" ")}),this.get("host").insertContentAtFocusPoint(t),this.markUpdated()}this.getDialogue({focusAfterHide:null}).hide()}},_removeLegacyAlignment:function(i){return i.getStyle("margin")&&s.some(function(e){if(i.getStyle(e.name)!==e.value)return!1;var t=c.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},_toggleVisibility:function(e,t){var i=this._form,n=i.all(e);n.setStyle("display",t?"block":"none")},_toggleAriaInvalid:function(e,t){var i=this._form;e.forEach(function(e){i.all(e).setAttribute("aria-invalid",t)})},_hasErrorUrlField:function(){var e=this._form,t=e.one("."+u.INPUTURL).get("value"),i=""===t;return this._toggleVisibility("."+u.IMAGEURLWARNING,i),this._toggleAriaInvalid(["."+u.INPUTURL],i),i},_hasErrorAltField:function(){var e=this._form,t=e.one("."+u.INPUTALT).get("value"),i=e.one("."+u.IMAGEPRESENTATION).get("checked"),n=""===t&&!i;return this._toggleVisibility("."+u.IMAGEALTWARNING,n),this._toggleAriaInvalid(["."+u.INPUTALT,"."+u.IMAGEPRESENTATION],n),n},_updateWarning:function(){var e=this._hasErrorUrlField(),t=this._hasErrorAltField(),i=e||t;return this.getDialogue().centerDialogue(),i},_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 +YUI.add("moodle-atto_image-button",function(c,e){var u={RESPONSIVE:"img-fluid",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",IMAGEURLWARNING:"atto_image_urlwarning",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"},n={URL:"urlentry",ALT:"altentry"},t={INPUTURL:"."+u.INPUTURL},s=[{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"}],o=160,l=160,I=/\d+%/,_="atto_image",p='{{alt}}';c.namespace("M.atto_image").Button=c.Base.create("button",c.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,a=t.items,s=!1;for(i=0;i{{#if showFilepicker}}
{{else}}
{{/if}}
0 / 125
x

'),t=this.get("host").canShowFilepicker("image"),i=c.Node.create(e({elementid:this.get("host").get("elementid"),CSS:u,FORMNAMES:n,component:_,showFilepicker:t,alignments:s}));return this._form=i,this._applyImageProperties(this._form),this._form.one("."+u.INPUTURL).on("blur",this._urlChanged,this),this._form.one("."+u.INPUTURL).on("change",this._hasErrorUrlField,this),this._form.one("."+u.IMAGEPRESENTATION).on("change",this._hasErrorAltField,this),this._form.one("."+u.INPUTALT).on("blur",this._hasErrorAltField,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.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,a,s,o,l,r,h,g,d,m;t=t||!1,i=this._form.one("."+u.INPUTWIDTH),n="width",a=this._form.one("."+u.INPUTHEIGHT),s="height",o=this._form.one("."+u.INPUTCONSTRAIN),l=i.get("value"),r=a.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=a,a=m,m=n,n=s,s=m,m=l,l=r,r=m),l.match(I)?(r=l,g=parseInt(l,10),d=this._rawImageDimensions.width/100*g,h.setStyle("width",d),d=this._rawImageDimensions.height/100*g,h.setStyle("height",d)):(r=Math.round(l/this._rawImageDimensions[n]*this._rawImageDimensions[s]),t?h.setStyles({width:r,height:l}):h.setStyles({width:l,height:r})),a.set("value",r)):(l.match(I)?(g=parseInt(l,10),d=this._rawImageDimensions.width/100*g,h.setStyle("width",d+"px")):h.setStyle("width",l+"px"),r.match(I)?(g=parseInt(r,10),d=this._rawImageDimensions.height/100*g,h.setStyle("height",d+"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 s.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,a={src:null,alt:null,width:null,height:null,align:"",presentation:!1},s=this.get("host").getSelectedNodes();return(s=s&&s.filter("img"))&&s.size()?(n=this._removeLegacyAlignment(s.item(0)),i=(this._selectedImage=n).getAttribute("style"),a.customstyle=i,(e=n.getAttribute("width")).match(I)||(e=parseInt(e,10)),(t=n.getAttribute("height")).match(I)||(t=parseInt(t,10)),0!==e&&(a.width=e),0!==t&&(a.height=t),this._getAlignmentPropeties(n,a),a.src=n.getAttribute("src"),a.alt=n.getAttribute("alt")||"",a.presentation="presentation"===n.get("role"),a):(this._selectedImage=null,!1)},_getAlignmentPropeties:function(i,n){var a;!s.some(function(e){var t=this._getAlignmentClass(e.value);return i.hasClass(t)?(n.align=e.value,!0):(e.isDefault&&(a=e.value),!1)},this)&&a&&(n.align=a)},_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"),a=i.one("."+u.INPUTALT).get("value"),s=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"),d=[],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&&d.push(u.RESPONSIVE),d.push(l),!s.match(I)&&isNaN(parseInt(s,10)))return void i.one("."+u.INPUTWIDTH).focus();if(!o.match(I)&&isNaN(parseInt(o,10)))return void i.one("."+u.INPUTHEIGHT).focus();t=c.Handlebars.compile(p)({url:n,alt:a,width:s,height:o,presentation:r,customstyle:g,classlist:d.join(" ")}),this.get("host").insertContentAtFocusPoint(t),this.markUpdated()}this.getDialogue({focusAfterHide:null}).hide()}},_removeLegacyAlignment:function(i){return i.getStyle("margin")&&s.some(function(e){if(i.getStyle(e.name)!==e.value)return!1;var t=c.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},_toggleVisibility:function(e,t){var i=this._form,n=i.all(e);n.setStyle("display",t?"block":"none")},_toggleAriaInvalid:function(e,t){var i=this._form;e.forEach(function(e){i.all(e).setAttribute("aria-invalid",t)})},_hasErrorUrlField:function(){var e=this._form,t=e.one("."+u.INPUTURL).get("value"),i=""===t;return this._toggleVisibility("."+u.IMAGEURLWARNING,i),this._toggleAriaInvalid(["."+u.INPUTURL],i),i},_hasErrorAltField:function(){var e=this._form,t=e.one("."+u.INPUTALT).get("value"),i=e.one("."+u.IMAGEPRESENTATION).get("checked"),n=""===t&&!i;return this._toggleVisibility("."+u.IMAGEALTWARNING,n),this._toggleAriaInvalid(["."+u.INPUTALT,"."+u.IMAGEPRESENTATION],n),n},_updateWarning:function(){var e=this._hasErrorUrlField(),t=this._hasErrorAltField(),i=e||t;return this.getDialogue().centerDialogue(),i},_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 418fc17aac7..19cf5db689d 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 @@ -92,7 +92,10 @@ var CSS = { margin: '0 0 0 0.5em' } ], - + DEFAULTS = { + WIDTH: 160, + HEIGHT: 160, + }, REGEX = { ISPERCENT: /\d+%/ }, @@ -550,22 +553,23 @@ Y.namespace('M.atto_image').Button = Y.Base.create('button', Y.M.editor_atto.Edi image.onload = function() { var input, currentwidth, currentheight, widthRatio, heightRatio; + // Store dimensions of the raw image, falling back to defaults for images without dimensions (e.g. SVG). self._rawImageDimensions = { - width: this.width, - height: this.height + width: this.width || DEFAULTS.WIDTH, + height: this.height || DEFAULTS.HEIGHT, }; input = self._form.one('.' + CSS.INPUTWIDTH); currentwidth = input.get('value'); if (currentwidth === '') { - input.set('value', this.width); - currentwidth = "" + this.width; + input.set('value', self._rawImageDimensions.width); + currentwidth = "" + self._rawImageDimensions.width; } input = self._form.one('.' + CSS.INPUTHEIGHT); currentheight = input.get('value'); if (currentheight === '') { - input.set('value', this.height); - currentheight = "" + this.height; + input.set('value', self._rawImageDimensions.height); + currentheight = "" + self._rawImageDimensions.height; } input = self._form.one('.' + CSS.IMAGEPREVIEW); input.setAttribute('src', this.src); @@ -576,13 +580,10 @@ Y.namespace('M.atto_image').Button = Y.Base.create('button', Y.M.editor_atto.Edi input = self._form.one('.' + CSS.INPUTCONSTRAIN); if (currentwidth.match(REGEX.ISPERCENT) && currentheight.match(REGEX.ISPERCENT)) { input.set('checked', currentwidth === currentheight); + } else if (this.width === 0 || this.height === 0) { + // If we don't have both dimensions of the image, we can't auto-size it, so disable control. + input.set('disabled', 'disabled'); } else { - if (this.width === 0) { - this.width = 1; - } - if (this.height === 0) { - this.height = 1; - } // This is the same as comparing to 3 decimal places. widthRatio = Math.round(1000 * parseInt(currentwidth, 10) / this.width); heightRatio = Math.round(1000 * parseInt(currentheight, 10) / this.height); 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 c41fcdfc67b..46aad7bce8d 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 @@ -90,7 +90,10 @@ var CSS = { margin: '0 0 0 0.5em' } ], - + DEFAULTS = { + WIDTH: 160, + HEIGHT: 160, + }, REGEX = { ISPERCENT: /\d+%/ }, @@ -548,22 +551,23 @@ Y.namespace('M.atto_image').Button = Y.Base.create('button', Y.M.editor_atto.Edi image.onload = function() { var input, currentwidth, currentheight, widthRatio, heightRatio; + // Store dimensions of the raw image, falling back to defaults for images without dimensions (e.g. SVG). self._rawImageDimensions = { - width: this.width, - height: this.height + width: this.width || DEFAULTS.WIDTH, + height: this.height || DEFAULTS.HEIGHT, }; input = self._form.one('.' + CSS.INPUTWIDTH); currentwidth = input.get('value'); if (currentwidth === '') { - input.set('value', this.width); - currentwidth = "" + this.width; + input.set('value', self._rawImageDimensions.width); + currentwidth = "" + self._rawImageDimensions.width; } input = self._form.one('.' + CSS.INPUTHEIGHT); currentheight = input.get('value'); if (currentheight === '') { - input.set('value', this.height); - currentheight = "" + this.height; + input.set('value', self._rawImageDimensions.height); + currentheight = "" + self._rawImageDimensions.height; } input = self._form.one('.' + CSS.IMAGEPREVIEW); input.setAttribute('src', this.src); @@ -574,13 +578,10 @@ Y.namespace('M.atto_image').Button = Y.Base.create('button', Y.M.editor_atto.Edi input = self._form.one('.' + CSS.INPUTCONSTRAIN); if (currentwidth.match(REGEX.ISPERCENT) && currentheight.match(REGEX.ISPERCENT)) { input.set('checked', currentwidth === currentheight); + } else if (this.width === 0 || this.height === 0) { + // If we don't have both dimensions of the image, we can't auto-size it, so disable control. + input.set('disabled', 'disabled'); } else { - if (this.width === 0) { - this.width = 1; - } - if (this.height === 0) { - this.height = 1; - } // This is the same as comparing to 3 decimal places. widthRatio = Math.round(1000 * parseInt(currentwidth, 10) / this.width); heightRatio = Math.round(1000 * parseInt(currentheight, 10) / this.height);