MDL-43869 New Atto plugin switch language LTR/RTL
authorJerome Mouneyrac <jerome@mouneyrac.com>
Wed, 12 Feb 2014 05:37:24 +0000 (13:37 +0800)
committerDamyon Wiese <damyon@moodle.com>
Wed, 26 Mar 2014 02:00:05 +0000 (10:00 +0800)
14 files changed:
lib/editor/atto/plugins/rtl/lang/en/atto_rtl.php [new file with mode: 0755]
lib/editor/atto/plugins/rtl/lib.php [new file with mode: 0644]
lib/editor/atto/plugins/rtl/version.php [new file with mode: 0755]
lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-debug.js [new file with mode: 0644]
lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-min.js [new file with mode: 0644]
lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button.js [new file with mode: 0644]
lib/editor/atto/plugins/rtl/yui/src/button/build.json [new file with mode: 0755]
lib/editor/atto/plugins/rtl/yui/src/button/js/button.js [new file with mode: 0755]
lib/editor/atto/plugins/rtl/yui/src/button/meta/button.json [new file with mode: 0755]
lib/editor/atto/styles.css [changed mode: 0644->0755]
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 [changed mode: 0644->0755]

diff --git a/lib/editor/atto/plugins/rtl/lang/en/atto_rtl.php b/lib/editor/atto/plugins/rtl/lang/en/atto_rtl.php
new file mode 100755 (executable)
index 0000000..77d4889
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Strings for component 'atto_rtl', language 'en'.
+ *
+ * @package    atto_rtl
+ * @copyright  2014 Jerome Mouneyrac
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['pluginname'] = 'RTL/LTR';
+$string['rtl'] = 'Right to left';
+$string['ltr'] = 'Left to right';
diff --git a/lib/editor/atto/plugins/rtl/lib.php b/lib/editor/atto/plugins/rtl/lib.php
new file mode 100644 (file)
index 0000000..134cfa3
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Atto text editor rtl plugin lib.
+ *
+ * @package    atto_rtl
+ * @copyright  2014 Jerome Mouneyrac
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Initialise the strings required for JS.
+ *
+ * @return void
+ */
+function atto_rtl_strings_for_js() {
+    global $PAGE;
+
+    // In order to prevent extra strings to be imported, comment/uncomment the characters
+    // which are enabled in the JavaScript part of this plugin.
+    $PAGE->requires->strings_for_js(
+        array(
+            'rtl',
+            'ltr'
+        ),
+        'atto_rtl'
+    );
+}
diff --git a/lib/editor/atto/plugins/rtl/version.php b/lib/editor/atto/plugins/rtl/version.php
new file mode 100755 (executable)
index 0000000..7a5af0a
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Atto text editor integration version file.
+ *
+ * @package    atto_rtl
+ * @copyright  2014 Jerome Mouneyrac
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version   = 2014012800;        // The current plugin version (Date: YYYYMMDDXX).
+$plugin->requires  = 2013110500;        // Requires this Moodle version.
+$plugin->component = 'atto_rtl';  // Full name of the plugin (used for diagnostics).
diff --git a/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-debug.js b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-debug.js
new file mode 100644 (file)
index 0000000..d4ded0f
Binary files /dev/null and b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-debug.js differ
diff --git a/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-min.js b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-min.js
new file mode 100644 (file)
index 0000000..ebed822
Binary files /dev/null and b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button-min.js differ
diff --git a/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button.js b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button.js
new file mode 100644 (file)
index 0000000..d4ded0f
Binary files /dev/null and b/lib/editor/atto/plugins/rtl/yui/build/moodle-atto_rtl-button/moodle-atto_rtl-button.js differ
diff --git a/lib/editor/atto/plugins/rtl/yui/src/button/build.json b/lib/editor/atto/plugins/rtl/yui/src/button/build.json
new file mode 100755 (executable)
index 0000000..dd12c74
--- /dev/null
@@ -0,0 +1,10 @@
+{
+  "name": "moodle-atto_rtl-button",
+  "builds": {
+    "moodle-atto_rtl-button": {
+      "jsfiles": [
+        "button.js"
+      ]
+    }
+  }
+}
diff --git a/lib/editor/atto/plugins/rtl/yui/src/button/js/button.js b/lib/editor/atto/plugins/rtl/yui/src/button/js/button.js
new file mode 100755 (executable)
index 0000000..8f9d48e
--- /dev/null
@@ -0,0 +1,64 @@
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Atto text editor rtl plugin.
+ *
+ * @package    editor_atto
+ * @copyright  2014 Jerome Mouneyrac
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+M.atto_rtl = M.atto_rtl || {
+    init : function(params) {
+        var click = function(e, elementid, direction) {
+            e.preventDefault();
+            if (!M.editor_atto.is_active(elementid)) {
+                M.editor_atto.focus(elementid);
+            }
+
+            M.atto_rtl.selection = M.editor_atto.get_selection();
+            if (M.atto_rtl.selection !== false) {
+
+                // Format the selection to be sure it has a tag parent (not the contenteditable).
+                var parentnode = M.editor_atto.format_selection_block(elementid);
+                parentnodeelement = parentnode.getDOMNode();
+
+                var currentdirection = parentnodeelement.getAttribute("dir");
+                if (currentdirection === direction) {
+                    parentnodeelement.removeAttribute("dir");
+                } else {
+                    parentnodeelement.setAttribute("dir", direction);
+                }
+            }
+
+            // Clean the YUI ids from the HTML.
+            M.editor_atto.text_updated(elementid);
+        };
+
+        var rtlclick = function(e, elementid) {
+            click(e, elementid, 'rtl');
+        };
+
+        var ltrclick = function(e, elementid) {
+            click(e, elementid, 'ltr');
+        };
+
+        var iconurl = M.util.image_url('e/left_to_right', 'core');
+        M.editor_atto.add_toolbar_button(params.elementid, 'ltr', iconurl, params.group, ltrclick, M.util.get_string('ltr', 'atto_rtl'));
+
+        iconurl = M.util.image_url('e/right_to_left', 'core');
+        M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, rtlclick, M.util.get_string('rtl', 'atto_rtl'));
+    }
+};
diff --git a/lib/editor/atto/plugins/rtl/yui/src/button/meta/button.json b/lib/editor/atto/plugins/rtl/yui/src/button/meta/button.json
new file mode 100755 (executable)
index 0000000..8f95ca8
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "moodle-atto_rtl-button": {
+    "requires": ["node"]
+  }
+}
old mode 100644 (file)
new mode 100755 (executable)
index fe4af1c..c4c4e39 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 c9b21c8..fa09cd8 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 fe4af1c..c4c4e39 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
old mode 100644 (file)
new mode 100755 (executable)
index ce3a742..a26d81e
@@ -392,14 +392,19 @@ M.editor_atto = M.editor_atto || {
      * @param string plugin - the plugin defining the button.
      * @param string icon - the url to the image for the icon
      * @param string groupname - the group the button should be appended to.
+     * @param string title - button title. If null, then the title is the 'pluginname' string.
      * @handler function handler- A function to call when the button is clicked.
      */
-    add_toolbar_button : function(elementid, plugin, iconurl, groupname, handler) {
+    add_toolbar_button : function(elementid, plugin, iconurl, groupname, handler, title) {
         var toolbar = M.editor_atto.get_toolbar_node(elementid),
             group = toolbar.one('.atto_group.' + groupname + '_group'),
             button,
             currentfocus;
 
+        if (!title) {
+            title = M.util.get_string('pluginname', 'atto_' + plugin);
+        }
+
         if (!group) {
             group = Y.Node.create('<div class="atto_group ' + groupname +'_group"></div>');
             toolbar.append(group);
@@ -409,7 +414,7 @@ M.editor_atto = M.editor_atto || {
                                'data-plugin="' + Y.Escape.html(plugin) + '" ' +
                                'tabindex="-1" ' +
                                'data-handler="' + Y.Escape.html(plugin) + '" ' +
-                               'title="' + Y.Escape.html(M.util.get_string('pluginname', 'atto_' + plugin)) + '">' +
+                               'title="' + Y.Escape.html(title) + '">' +
                                     '<img class="icon" aria-hidden="true" role="presentation" width="16" height="16" src="' + iconurl + '"/>' +
                                '</button>');