Merge branch 'MDL-49107-master' of git://github.com/FMCorz/moodle
authorDavid Monllao <davidm@moodle.com>
Tue, 10 Mar 2015 03:42:58 +0000 (11:42 +0800)
committerDavid Monllao <davidm@moodle.com>
Tue, 10 Mar 2015 03:42:58 +0000 (11:42 +0800)
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
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js
lib/editor/atto/yui/src/editor/js/selection.js

index 838fe81..eeadd60 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 ba3cf0c..8d1e8f1 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 838fe81..eeadd60 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 0215e86..50e91fe 100644 (file)
@@ -109,7 +109,7 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
     _displayDialogue: function() {
         // Store the current selection.
         this._currentSelection = this.get('host').getSelection();
-        if (this._currentSelection === false || this._currentSelection.collapsed) {
+        if (this._currentSelection === false) {
             return;
         }
 
@@ -165,11 +165,11 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
     },
 
     /**
-     * Update the dialogue after an image was selected in the File Picker.
+     * Update the dialogue after a link was selected in the File Picker.
      *
      * @method _filepickerCallback
      * @param {object} params The parameters provided by the filepicker
-     * containing information about the image.
+     * containing information about the link.
      * @private
      */
     _filepickerCallback: function(params) {
@@ -178,9 +178,9 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
                 .hide();
 
         if (params.url !== '') {
-            this.get('host').setSelection(this._currentSelection);
-            document.execCommand('unlink', false, null);
-            document.execCommand('createLink', false, params.url);
+            // Add the link.
+            this._setLinkOnSelection(params.url);
+
             // And mark the text area as updated.
             this.markUpdated();
         }
@@ -200,8 +200,6 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
             anchornodes,
             value;
 
-        var host = this.get('host');
-
         e.preventDefault();
         this.getDialogue({
             focusAfterHide: null
@@ -211,8 +209,6 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
 
         value = input.get('value');
         if (value !== '') {
-            this.editor.focus();
-            host.setSelection(this._currentSelection);
 
             // We add a prefix if it is not already prefixed.
             value = value.trim();
@@ -221,11 +217,8 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
                 value = 'http://' + value;
             }
 
-            document.execCommand('unlink', false, null);
-            document.execCommand('createLink', false, value);
-
-            // Now set the target.
-            selectednode = host.getSelectionParentNode();
+            // Add the link.
+            selectednode = this._setLinkOnSelection(value);
 
             // Note this is a document fragment and YUI doesn't like them.
             if (!selectednode) {
@@ -246,6 +239,41 @@ Y.namespace('M.atto_link').Button = Y.Base.create('button', Y.M.editor_atto.Edit
         }
     },
 
+    /**
+     * Final step setting the anchor on the selection.
+     *
+     * @private
+     * @method _setLinkOnSelection
+     * @param  {String} url URL the link will point to.
+     * @return {Node} The added Node.
+     */
+    _setLinkOnSelection: function(url) {
+        var host = this.get('host'),
+            link,
+            selectednode;
+
+        this.editor.focus();
+        host.setSelection(this._currentSelection);
+
+        if (this._currentSelection[0].collapsed) {
+            // Firefox cannot add links when the selection is empty so we will add it manually.
+            link = Y.Node.create('<a>' + url + '</a>');
+            link.setAttribute('href', url);
+
+            // Add the node and select it to replicate the behaviour of execCommand.
+            selectednode = host.insertContentAtFocusPoint(link.get('outerHTML'));
+            host.setSelection(host.getSelectionFromNode(selectednode));
+        } else {
+            document.execCommand('unlink', false, null);
+            document.execCommand('createLink', false, url);
+
+            // Now set the target.
+            selectednode = host.getSelectionParentNode();
+        }
+
+        return selectednode;
+    },
+
     /**
      * Look up and down for the nearest anchor tags that are least partly contained in the selection.
      *
index fbd5c05..829d055 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js differ
index 17f3959..aa206ae 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js differ
index 2a54f7b..28a4cfb 100644 (file)
Binary files a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js and b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js differ
index 788692f..12086a3 100644 (file)
@@ -378,6 +378,7 @@ EditorSelection.prototype = {
      *
      * @method insertContentAtFocusPoint
      * @param {String} html
+     * @return {Node} The YUI Node object added to the DOM.
      */
     insertContentAtFocusPoint: function(html) {
         var selection = rangy.getSelection(),
@@ -390,6 +391,7 @@ EditorSelection.prototype = {
             range.deleteContents();
             range.insertNode(node.getDOMNode());
         }
+        return node;
     }
 
 };