From 1670fc84a7eda9ada6952a8fa96c2121e0fe3fa8 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Fri, 9 Oct 2015 11:22:26 +0100 Subject: [PATCH] MDL-50079 atto_link: respect new window option when creating from repo Previously users had to go back and edit their link to set the new window option. --- .../moodle-atto_link-button-debug.js | 40 +++++++++---------- .../moodle-atto_link-button-min.js | 2 +- .../moodle-atto_link-button.js | 40 +++++++++---------- .../plugins/link/yui/src/button/js/button.js | 40 +++++++++---------- 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-debug.js b/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-debug.js index 935af770cd9..1599d12145e 100644 --- a/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-debug.js +++ b/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-debug.js @@ -197,9 +197,6 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit */ _setLink: function(e) { var input, - target, - selectednode, - anchornodes, value; e.preventDefault(); @@ -213,22 +210,7 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit if (value !== '') { // Add the link. - selectednode = this._setLinkOnSelection(value); - - // Note this is a document fragment and YUI doesn't like them. - if (!selectednode) { - return; - } - - anchornodes = this._findSelectedAnchors(Y.one(selectednode)); - Y.Array.each(anchornodes, function(anchornode) { - target = this._content.one('.newwindow'); - if (target.get('checked')) { - anchornode.setAttribute('target', '_blank'); - } else { - anchornode.removeAttribute('target'); - } - }, this); + this._setLinkOnSelection(value); this.markUpdated(); } @@ -245,7 +227,9 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit _setLinkOnSelection: function(url) { var host = this.get('host'), link, - selectednode; + selectednode, + target, + anchornodes; this.editor.focus(); host.setSelection(this._currentSelection); @@ -266,6 +250,22 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit selectednode = host.getSelectionParentNode(); } + // Note this is a document fragment and YUI doesn't like them. + if (!selectednode) { + return; + } + + anchornodes = this._findSelectedAnchors(Y.one(selectednode)); + // Add new window attributes if requested. + Y.Array.each(anchornodes, function(anchornode) { + target = this._content.one('.newwindow'); + if (target.get('checked')) { + anchornode.setAttribute('target', '_blank'); + } else { + anchornode.removeAttribute('target'); + } + }, this); + return selectednode; }, diff --git a/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-min.js b/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-min.js index 44aedf4cf33..63952a215a7 100644 --- a/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-min.js +++ b/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-min.js @@ -1 +1 @@ -YUI.add("moodle-atto_link-button",function(e,t){var n="atto_link",r={NEWWINDOW:"atto_link_openinnewwindow",URLINPUT:"atto_link_urlentry"},i={URLINPUT:".atto_link_urlentry"},s='

{{#if showFilepicker}}
{{/if}}

';e.namespace("M.atto_link").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_content:null,initializer:function(){this.addButton({icon:"e/insert_edit_link",callback:this._displayDialogue,tags:"a",tagMatchRequiresAll:!1}),this.addButton({buttonName:"unlink",callback:this._unlink,icon:"e/remove_link",title:"unlink",tags:"a",tagMatchRequiresAll:!1})},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection===!1)return;var e=this.getDialogue({headerContent:M.util.get_string("createlink",n),focusAfterHide:!0,focusOnShowSelector:i.URLINPUT});e.set("bodyContent",this._getDialogueContent()),this._resolveAnchors(),e.show()},_resolveAnchors:function(){var t=this.get("host").getSelectionParentNode(),n,r,i,s;if(!t)return;n=this._findSelectedAnchors(e.one(t)),n.length>0&&(r=n[0],this._currentSelection=this.get("host").getSelectionFromNode(r),i=r.getAttribute("href"),s=r.getAttribute("target"),i!==""&&this._content.one(".url").setAttribute("value",i),s==="_blank"?this._content.one(".newwindow").setAttribute("checked","checked"):this._content.one(".newwindow").removeAttribute("checked"))},_filepickerCallback:function(e){this.getDialogue().set("focusAfterHide",null).hide(),e.url!==""&&(this._setLinkOnSelection(e.url),this.markUpdated())},_setLink:function(t){var n,r,i,s,o;t.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),n=this._content.one(".url"),o=n.get("value");if(o!==""){i=this._setLinkOnSelection(o);if(!i)return;s=this._findSelectedAnchors(e.one(i)),e.Array.each(s,function(e){r=this._content.one(".newwindow"),r.get("checked")?e.setAttribute("target","_blank"):e.removeAttribute("target")},this),this.markUpdated()}},_setLinkOnSelection:function(t){var n=this.get("host"),r,i;return this.editor.focus(),n.setSelection(this._currentSelection),this._currentSelection[0].collapsed?(r=e.Node.create(""+t+""),r.setAttribute("href",t),i=n.insertContentAtFocusPoint(r.get("outerHTML")),n.setSelection(n.getSelectionFromNode(i))):(document.execCommand("unlink",!1,null),document.execCommand("createLink",!1,t),i=n.getSelectionParentNode()),i},_findSelectedAnchors:function(e){var t=e.get("tagName"),n,r;return t&&t.toLowerCase()==="a"?[e]:(r=[],e.all("a").each(function(e){!n&&this.get("host").selectionContainsNode(e)&&r.push(e)},this),r.length>0?r:(n=e.ancestor("a"),n?[n]:[]))},_getDialogueContent:function(){var t=this.get("host").canShowFilepicker("link"),i=e.Handlebars.compile(s);return this._content=e.Node.create(i({showFilepicker:t,component:n,CSS:r})),this._content.one(".submit").on("click",this._setLink,this),t&&this._content.one(".openlinkbrowser").on("click",function(e){e.preventDefault(),this.get("host").showFilepicker("link",this._filepickerCallback,this)},this),this._content},_unlink:function(){var e=this.get("host"),t=e.getSelection();if(t&&t.length)if(t[0].startOffset===t[0].endOffset){var n=e.getSelectedNodes();n&&(n.each(function(t){var n=t.ancestor("a",!0);n&&(e.setSelection(e.getSelectionFromNode(n)),document.execCommand("unlink",!1,null))},this),this.markUpdated())}else document.execCommand("unlink",!1,null),this.markUpdated()}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); +YUI.add("moodle-atto_link-button",function(e,t){var n="atto_link",r={NEWWINDOW:"atto_link_openinnewwindow",URLINPUT:"atto_link_urlentry"},i={URLINPUT:".atto_link_urlentry"},s='

{{#if showFilepicker}}
{{/if}}

';e.namespace("M.atto_link").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_content:null,initializer:function(){this.addButton({icon:"e/insert_edit_link",callback:this._displayDialogue,tags:"a",tagMatchRequiresAll:!1}),this.addButton({buttonName:"unlink",callback:this._unlink,icon:"e/remove_link",title:"unlink",tags:"a",tagMatchRequiresAll:!1})},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection===!1)return;var e=this.getDialogue({headerContent:M.util.get_string("createlink",n),focusAfterHide:!0,focusOnShowSelector:i.URLINPUT});e.set("bodyContent",this._getDialogueContent()),this._resolveAnchors(),e.show()},_resolveAnchors:function(){var t=this.get("host").getSelectionParentNode(),n,r,i,s;if(!t)return;n=this._findSelectedAnchors(e.one(t)),n.length>0&&(r=n[0],this._currentSelection=this.get("host").getSelectionFromNode(r),i=r.getAttribute("href"),s=r.getAttribute("target"),i!==""&&this._content.one(".url").setAttribute("value",i),s==="_blank"?this._content.one(".newwindow").setAttribute("checked","checked"):this._content.one(".newwindow").removeAttribute("checked"))},_filepickerCallback:function(e){this.getDialogue().set("focusAfterHide",null).hide(),e.url!==""&&(this._setLinkOnSelection(e.url),this.markUpdated())},_setLink:function(e){var t,n;e.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),t=this._content.one(".url"),n=t.get("value"),n!==""&&(this._setLinkOnSelection(n),this.markUpdated())},_setLinkOnSelection:function(t){var n=this.get("host"),r,i,s,o;this.editor.focus(),n.setSelection(this._currentSelection),this._currentSelection[0].collapsed?(r=e.Node.create(""+t+""),r.setAttribute("href",t),i=n.insertContentAtFocusPoint(r.get("outerHTML")),n.setSelection(n.getSelectionFromNode(i))):(document.execCommand("unlink",!1,null),document.execCommand("createLink",!1,t),i=n.getSelectionParentNode());if(!i)return;return o=this._findSelectedAnchors(e.one(i)),e.Array.each(o,function(e){s=this._content.one(".newwindow"),s.get("checked")?e.setAttribute("target","_blank"):e.removeAttribute("target")},this),i},_findSelectedAnchors:function(e){var t=e.get("tagName"),n,r;return t&&t.toLowerCase()==="a"?[e]:(r=[],e.all("a").each(function(e){!n&&this.get("host").selectionContainsNode(e)&&r.push(e)},this),r.length>0?r:(n=e.ancestor("a"),n?[n]:[]))},_getDialogueContent:function(){var t=this.get("host").canShowFilepicker("link"),i=e.Handlebars.compile(s);return this._content=e.Node.create(i({showFilepicker:t,component:n,CSS:r})),this._content.one(".submit").on("click",this._setLink,this),t&&this._content.one(".openlinkbrowser").on("click",function(e){e.preventDefault(),this.get("host").showFilepicker("link",this._filepickerCallback,this)},this),this._content},_unlink:function(){var e=this.get("host"),t=e.getSelection();if(t&&t.length)if(t[0].startOffset===t[0].endOffset){var n=e.getSelectedNodes();n&&(n.each(function(t){var n=t.ancestor("a",!0);n&&(e.setSelection(e.getSelectionFromNode(n)),document.execCommand("unlink",!1,null))},this),this.markUpdated())}else document.execCommand("unlink",!1,null),this.markUpdated()}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); diff --git a/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button.js b/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button.js index 935af770cd9..1599d12145e 100644 --- a/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button.js +++ b/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button.js @@ -197,9 +197,6 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit */ _setLink: function(e) { var input, - target, - selectednode, - anchornodes, value; e.preventDefault(); @@ -213,22 +210,7 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit if (value !== '') { // Add the link. - selectednode = this._setLinkOnSelection(value); - - // Note this is a document fragment and YUI doesn't like them. - if (!selectednode) { - return; - } - - anchornodes = this._findSelectedAnchors(Y.one(selectednode)); - Y.Array.each(anchornodes, function(anchornode) { - target = this._content.one('.newwindow'); - if (target.get('checked')) { - anchornode.setAttribute('target', '_blank'); - } else { - anchornode.removeAttribute('target'); - } - }, this); + this._setLinkOnSelection(value); this.markUpdated(); } @@ -245,7 +227,9 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit _setLinkOnSelection: function(url) { var host = this.get('host'), link, - selectednode; + selectednode, + target, + anchornodes; this.editor.focus(); host.setSelection(this._currentSelection); @@ -266,6 +250,22 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit selectednode = host.getSelectionParentNode(); } + // Note this is a document fragment and YUI doesn't like them. + if (!selectednode) { + return; + } + + anchornodes = this._findSelectedAnchors(Y.one(selectednode)); + // Add new window attributes if requested. + Y.Array.each(anchornodes, function(anchornode) { + target = this._content.one('.newwindow'); + if (target.get('checked')) { + anchornode.setAttribute('target', '_blank'); + } else { + anchornode.removeAttribute('target'); + } + }, this); + return selectednode; }, diff --git a/lib/editor/atto/plugins/link/yui/src/button/js/button.js b/lib/editor/atto/plugins/link/yui/src/button/js/button.js index 415fd0bbcbd..a15ac10d03d 100644 --- a/lib/editor/atto/plugins/link/yui/src/button/js/button.js +++ b/lib/editor/atto/plugins/link/yui/src/button/js/button.js @@ -195,9 +195,6 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit */ _setLink: function(e) { var input, - target, - selectednode, - anchornodes, value; e.preventDefault(); @@ -211,22 +208,7 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit if (value !== '') { // Add the link. - selectednode = this._setLinkOnSelection(value); - - // Note this is a document fragment and YUI doesn't like them. - if (!selectednode) { - return; - } - - anchornodes = this._findSelectedAnchors(Y.one(selectednode)); - Y.Array.each(anchornodes, function(anchornode) { - target = this._content.one('.newwindow'); - if (target.get('checked')) { - anchornode.setAttribute('target', '_blank'); - } else { - anchornode.removeAttribute('target'); - } - }, this); + this._setLinkOnSelection(value); this.markUpdated(); } @@ -243,7 +225,9 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit _setLinkOnSelection: function(url) { var host = this.get('host'), link, - selectednode; + selectednode, + target, + anchornodes; this.editor.focus(); host.setSelection(this._currentSelection); @@ -264,6 +248,22 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit selectednode = host.getSelectionParentNode(); } + // Note this is a document fragment and YUI doesn't like them. + if (!selectednode) { + return; + } + + anchornodes = this._findSelectedAnchors(Y.one(selectednode)); + // Add new window attributes if requested. + Y.Array.each(anchornodes, function(anchornode) { + target = this._content.one('.newwindow'); + if (target.get('checked')) { + anchornode.setAttribute('target', '_blank'); + } else { + anchornode.removeAttribute('target'); + } + }, this); + return selectednode; },