Merge branch 'MDL-41241-master-fix3' of git://github.com/damyon/moodle
authorSam Hemelryk <sam@moodle.com>
Thu, 3 Oct 2013 03:03:22 +0000 (16:03 +1300)
committerSam Hemelryk <sam@moodle.com>
Thu, 3 Oct 2013 03:03:22 +0000 (16:03 +1300)
Conflicts:
lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js

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/editor.js

index 1f95b38..7f88586 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 3598441..1434aed 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 1f95b38..7f88586 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 3aecac9..71d74b9 100644 (file)
@@ -95,6 +95,7 @@ M.atto_link = M.atto_link || {
     resolve_anchors : function() {
         // Find the first anchor tag in the selection.
         var selectednode = M.editor_atto.get_selection_parent_node(),
+            anchornodes,
             anchornode,
             url;
 
@@ -103,9 +104,10 @@ M.atto_link = M.atto_link || {
             return;
         }
 
-        anchornode = M.atto_link.find_nearest_anchor(Y.one(selectednode));
+        anchornodes = M.atto_link.find_selected_anchors(Y.one(selectednode));
 
-        if (anchornode) {
+        if (anchornodes.length > 0) {
+            anchornode = anchornodes[0];
             M.atto_link.selection = M.editor_atto.get_selection_from_node(anchornode);
             url = anchornode.getAttribute('href');
             target = anchornode.getAttribute('target');
@@ -158,7 +160,7 @@ M.atto_link = M.atto_link || {
         var input,
             target,
             selectednode,
-            anchornode,
+            anchornodes,
             value;
 
         e.preventDefault();
@@ -180,42 +182,47 @@ M.atto_link = M.atto_link || {
                 return;
             }
 
-            anchornode = M.atto_link.find_nearest_anchor(Y.one(selectednode));
-            if (anchornode) {
+            anchornodes = M.atto_link.find_selected_anchors(Y.one(selectednode));
+            Y.Array.each(anchornodes, function(anchornode) {
                 target = e.currentTarget.get('parentNode').one('input[type=checkbox]');
                 if (target.get('checked')) {
                     anchornode.setAttribute('target', '_blank');
                 } else {
                     anchornode.removeAttribute('target');
                 }
-            }
+            });
         }
     },
 
     /**
-     * Look up and down for the nearest anchor tag.
+     * Look up and down for the nearest anchor tags that are least partly contained in the selection.
      *
-     * @method find_nearest_anchor
+     * @method find_selected_anchors
      * @param Node node
      * @return Node|false
      */
-    find_nearest_anchor : function(node) {
-        var tagname = node.get('tagName'), hit;
+    find_selected_anchors : function(node) {
+        var tagname = node.get('tagName'), hit, hits;
         // Direct hit.
         if (tagname && tagname.toLowerCase() === 'a') {
-            return node;
+            return [node];
         }
-        // Search down.
-        hit = node.one('a');
-        if (hit) {
-            return hit;
+        // Search down but check that each node is part of the selection.
+        hits = [];
+        node.all('a').each(function(n) {
+            if (!hit && M.editor_atto.selection_contains_node(n)) {
+                hits.push(n);
+            }
+        });
+        if (hits.length > 0) {
+            return hits;
         }
         // Search up.
         hit = node.ancestor('a');
         if (hit) {
-            return hit;
+            return [hit];
         }
-        return false;
+        return [];
     },
 
     /**
index b656e3f..cc95695 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 0a79882..b0057cb 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 b656e3f..cc95695 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 d6e0c6f..dce37f6 100644 (file)
@@ -483,6 +483,27 @@ M.editor_atto = M.editor_atto || {
         return false;
     },
 
+    /**
+     * Check that a YUI node it at least partly contained by the selection.
+     * @param Range selection
+     * @param Y.Node node
+     * @return boolean
+     */
+    selection_contains_node : function(node) {
+        var range, sel;
+        if (window.getSelection) {
+            sel = window.getSelection();
+
+            if (sel.containsNode) {
+                return sel.containsNode(node.getDOMNode(), true);
+            }
+        }
+        sel = document.selection.createRange();
+        range = sel.duplicate();
+        range.moveToElementText(node.getDOMNode());
+        return sel.inRange(range);
+    },
+
     /**
      * Get the dom node representing the common anscestor of the selection nodes.
      * @return DOMNode