MDL-50079 atto_link: respect new window option when creating from repo
authorDan Poltawski <dan@moodle.com>
Fri, 9 Oct 2015 10:22:26 +0000 (11:22 +0100)
committerDan Poltawski <dan@moodle.com>
Fri, 9 Oct 2015 10:23:32 +0000 (11:23 +0100)
Previously users had to go back and edit their link to set the new
window option.

lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-debug.js
lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-min.js
lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button.js
lib/editor/atto/plugins/link/yui/src/button/js/button.js

index 2059b15..7aa1907 100644 (file)
Binary files a/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-debug.js and b/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-debug.js differ
index 7c76227..f7b3aeb 100644 (file)
Binary files a/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-min.js and b/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button-min.js differ
index 2059b15..7aa1907 100644 (file)
Binary files a/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button.js and b/lib/editor/atto/plugins/link/yui/build/moodle-atto_link-button/moodle-atto_link-button.js differ
index 4f13053..8226483 100644 (file)
@@ -196,9 +196,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();
@@ -219,22 +216,7 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
             }
 
             // 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();
         }
@@ -251,7 +233,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);
@@ -272,6 +256,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;
     },