MDL-41241 atto: Add a checkbox for open in new window to links
authorDamyon Wiese <damyon@moodle.com>
Fri, 20 Sep 2013 06:57:25 +0000 (14:57 +0800)
committerDamyon Wiese <damyon@moodle.com>
Fri, 20 Sep 2013 07:23:02 +0000 (15:23 +0800)
lib/editor/atto/plugins/link/lang/en/atto_link.php
lib/editor/atto/plugins/link/lib.php
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 9735788..ec7a027 100644 (file)
@@ -27,4 +27,5 @@ $string['link'] = 'Link';
 $string['createlink'] = 'Create link';
 $string['enterurl'] = 'Enter a URL';
 $string['browserepositories'] = 'Browse repositories...';
+$string['openinnewwindow'] = 'Open in new window';
 $string['accessibilityhint'] = '<p>Web content accessibility guidelines (WCAG):<br/><ul><li><a href="http://www.w3.org/TR/WCAG20/#navigation-mechanisms-refs" target="_blank">2.4.4 Link Purpose (In Context)</a></li><li><a href="http://www.w3.org/TR/WCAG20/#navigation-mechanisms-link" target="_blank">2.4.9 Link Purpose (Link Only)</a></li></ul></p>';
index 56067e7..c3a5a5f 100644 (file)
@@ -39,6 +39,7 @@ function atto_link_init_editor($elementid) {
     $PAGE->requires->strings_for_js(array('createlink',
                                           'enterurl',
                                           'browserepositories',
+                                          'openinnewwindow',
                                           'accessibilityhint'),
                                     'atto_link');
 
index b41a1b1..454f1c7 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 06b6b58..cb3e57f 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 b41a1b1..454f1c7 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 9ed2eba..17be724 100644 (file)
@@ -106,11 +106,17 @@ M.atto_link = M.atto_link || {
         anchornode = Y.one(selectednode).ancestor('a');
 
         if (anchornode) {
+            M.atto_link.selection = M.editor_atto.get_selection_from_node(anchornode);
             url = anchornode.getAttribute('href');
+            target = anchornode.getAttribute('target');
             if (url !== '') {
-                M.atto_link.selection = M.editor_atto.get_selection_from_node(anchornode);
                 Y.one('#atto_link_urlentry').set('value', url);
             }
+            if (target === '_blank') {
+                Y.one('#atto_link_openinnewwindow').set('checked', 'checked');
+            } else {
+                Y.one('#atto_link_openinnewwindow').set('checked', '');
+            }
         }
     },
 
@@ -149,16 +155,41 @@ M.atto_link = M.atto_link || {
      * @param Event e
      */
     set_link : function(e) {
+        var input,
+            target,
+            selectednode,
+            anchornode,
+            value;
+
         e.preventDefault();
         M.atto_link.dialogue.hide();
 
-        var input = e.currentTarget.get('parentNode').one('input');
+        input = e.currentTarget.get('parentNode').one('input[type=url]');
+        target = e.currentTarget.get('parentNode').one('input[type=checkbox]');
 
-        var value = input.get('value');
+        value = input.get('value');
         if (value !== '') {
             M.editor_atto.set_selection(M.atto_link.selection);
             document.execCommand('unlink', false, null);
             document.execCommand('createLink', false, value);
+
+            // Now set the target.
+            selectednode = M.editor_atto.get_selection_parent_node();
+
+            // Note this is a document fragment and YUI doesn't like them.
+            if (!selectednode) {
+                return;
+            }
+
+            anchornode = Y.one(selectednode).ancestor('a');
+            if (anchornode) {
+                target = e.currentTarget.get('parentNode').one('input[type=checkbox]');
+                if (target.get('checked')) {
+                    anchornode.setAttribute('target', '_blank');
+                } else {
+                    anchornode.removeAttribute('target');
+                }
+            }
         }
     },
 
@@ -175,6 +206,10 @@ M.atto_link = M.atto_link || {
                              '</label><br/>' +
                              '<input type="url" value="" id="atto_link_urlentry" size="32"/>' +
                              '<br/>' +
+                             '<label for="atto_link_openinnewwindow">' + M.util.get_string('openinnewwindow', 'atto_link') +
+                             '</label><br/>' +
+                             '<input type="checkbox" id="atto_link_openinnewwindow"/>' +
+                             '<br/>' +
                              '<button id="openlinkbrowser" data-editor="' + Y.Escape.html(elementid) + '">' +
                              M.util.get_string('browserepositories', 'atto_link') +
                              '</button>' +