MDL-41241 Atto: Make searching for the anchor tag more reliable
authorDamyon Wiese <damyon@moodle.com>
Wed, 2 Oct 2013 07:21:11 +0000 (15:21 +0800)
committerDamyon Wiese <damyon@moodle.com>
Wed, 2 Oct 2013 07:21:11 +0000 (15:21 +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

index 2a4d90b..1f95b38 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 cf87a38..3598441 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 2a4d90b..1f95b38 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 24f7594..3aecac9 100644 (file)
@@ -103,7 +103,7 @@ M.atto_link = M.atto_link || {
             return;
         }
 
-        anchornode = Y.one(selectednode).ancestor('a');
+        anchornode = M.atto_link.find_nearest_anchor(Y.one(selectednode));
 
         if (anchornode) {
             M.atto_link.selection = M.editor_atto.get_selection_from_node(anchornode);
@@ -165,7 +165,6 @@ M.atto_link = M.atto_link || {
         M.atto_link.dialogue.hide();
 
         input = e.currentTarget.get('parentNode').one('input[type=url]');
-        target = e.currentTarget.get('parentNode').one('input[type=checkbox]');
 
         value = input.get('value');
         if (value !== '') {
@@ -181,7 +180,7 @@ M.atto_link = M.atto_link || {
                 return;
             }
 
-            anchornode = Y.one(selectednode).ancestor('a');
+            anchornode = M.atto_link.find_nearest_anchor(Y.one(selectednode));
             if (anchornode) {
                 target = e.currentTarget.get('parentNode').one('input[type=checkbox]');
                 if (target.get('checked')) {
@@ -193,6 +192,32 @@ M.atto_link = M.atto_link || {
         }
     },
 
+    /**
+     * Look up and down for the nearest anchor tag.
+     *
+     * @method find_nearest_anchor
+     * @param Node node
+     * @return Node|false
+     */
+    find_nearest_anchor : function(node) {
+        var tagname = node.get('tagName'), hit;
+        // Direct hit.
+        if (tagname && tagname.toLowerCase() === 'a') {
+            return node;
+        }
+        // Search down.
+        hit = node.one('a');
+        if (hit) {
+            return hit;
+        }
+        // Search up.
+        hit = node.ancestor('a');
+        if (hit) {
+            return hit;
+        }
+        return false;
+    },
+
     /**
      * Return the HTML of the form to show in the dialogue.
      *