From fcb5b5c473ed4465fac364c281f0e2c7b0346dbd Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Mon, 3 Feb 2014 10:55:44 +0800 Subject: [PATCH] MDL-43854 Atto: Add collapse toolbar plugin --- lib/editor/atto/classes/plugininfo/atto.php | 41 +++++++ .../collapse/lang/en/atto_collapse.php | 30 +++++ lib/editor/atto/plugins/collapse/lib.php | 44 +++++++ lib/editor/atto/plugins/collapse/pix/icon.png | Bin 0 -> 2865 bytes lib/editor/atto/plugins/collapse/pix/icon.svg | 74 ++++++++++++ lib/editor/atto/plugins/collapse/settings.php | 43 +++++++ lib/editor/atto/plugins/collapse/version.php | 29 +++++ .../moodle-atto_collapse-button-debug.js | 110 ++++++++++++++++++ .../moodle-atto_collapse-button-min.js | 1 + .../moodle-atto_collapse-button.js | 110 ++++++++++++++++++ .../collapse/yui/src/button/build.json | 10 ++ .../collapse/yui/src/button/js/button.js | 105 +++++++++++++++++ .../collapse/yui/src/button/meta/button.json | 5 + lib/editor/atto/settings.php | 7 +- .../moodle-editor_atto-editor-debug.js | 48 +++++++- .../moodle-editor_atto-editor-min.js | 6 +- .../moodle-editor_atto-editor.js | 48 +++++++- lib/editor/atto/yui/src/editor/js/editor.js | 48 +++++++- 18 files changed, 739 insertions(+), 20 deletions(-) create mode 100644 lib/editor/atto/plugins/collapse/lang/en/atto_collapse.php create mode 100644 lib/editor/atto/plugins/collapse/lib.php create mode 100644 lib/editor/atto/plugins/collapse/pix/icon.png create mode 100644 lib/editor/atto/plugins/collapse/pix/icon.svg create mode 100644 lib/editor/atto/plugins/collapse/settings.php create mode 100644 lib/editor/atto/plugins/collapse/version.php create mode 100644 lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button-debug.js create mode 100644 lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button-min.js create mode 100644 lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button.js create mode 100644 lib/editor/atto/plugins/collapse/yui/src/button/build.json create mode 100644 lib/editor/atto/plugins/collapse/yui/src/button/js/button.js create mode 100644 lib/editor/atto/plugins/collapse/yui/src/button/meta/button.json diff --git a/lib/editor/atto/classes/plugininfo/atto.php b/lib/editor/atto/classes/plugininfo/atto.php index ed52dc48610..b3b742cc9c2 100644 --- a/lib/editor/atto/classes/plugininfo/atto.php +++ b/lib/editor/atto/classes/plugininfo/atto.php @@ -29,7 +29,48 @@ defined('MOODLE_INTERNAL') || die(); class atto extends base { + + /** + * Yes you can uninstall these plugins if you want. + * @return moodle_url + */ public function is_uninstall_allowed() { return true; } + + /** + * Return URL used for management of plugins of this type. + * @return moodle_url + */ + public static function get_manage_url() { + return new moodle_url('/admin/settings.php', array('section'=>'editorsettingsatto')); + } + + /** + * Include the settings.php file from sub plugins if they provide it. + * This is a copy of very similar implementations from various other subplugin areas. + * + * @return moodle_url + */ + public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them. + $ADMIN = $adminroot; // May be used in settings.php. + $plugininfo = $this; // Also can be used inside settings.php. + + if (!$this->is_installed_and_upgraded()) { + return; + } + + if (!$hassiteconfig or !file_exists($this->full_path('settings.php'))) { + return; + } + + $section = $this->get_settings_section_name(); + $settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // This may also set $settings to null. + + if ($settings) { + $ADMIN->add($parentnodename, $settings); + } + } } diff --git a/lib/editor/atto/plugins/collapse/lang/en/atto_collapse.php b/lib/editor/atto/plugins/collapse/lang/en/atto_collapse.php new file mode 100644 index 00000000000..b9f75ed72a7 --- /dev/null +++ b/lib/editor/atto/plugins/collapse/lang/en/atto_collapse.php @@ -0,0 +1,30 @@ +. + +/** + * Strings for component 'atto_collapse', language 'en'. + * + * @package atto_collapse + * @copyright 2013 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['pluginname'] = 'Show/hide advanced buttons'; +$string['showmore'] = 'Show more buttons'; +$string['showless'] = 'Show less buttons'; +$string['settings'] = 'Collapse toolbar settings'; +$string['showgroups'] = 'Show (n) groups when collapsed.'; +$string['showgroups_desc'] = 'When the toolbar is collapsed (it is by default) only this many groups will be displayed at once.'; diff --git a/lib/editor/atto/plugins/collapse/lib.php b/lib/editor/atto/plugins/collapse/lib.php new file mode 100644 index 00000000000..6b0987ccc57 --- /dev/null +++ b/lib/editor/atto/plugins/collapse/lib.php @@ -0,0 +1,44 @@ +. + +/** + * Atto text editor integration version file. + * + * @package atto_collapse + * @copyright 2013 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Initialise the js strings required for this module. + */ +function atto_collapse_strings_for_js() { + global $PAGE; + + $PAGE->requires->strings_for_js(array('showmore', 'showless'), 'atto_collapse'); +} + +/** + * Set params for this plugin + * @param string $elementid + */ +function atto_collapse_params_for_js($elementid, $options, $fpoptions) { + // Pass the number of visible groups as a param. + $params = array('showgroups' => get_config('atto_collapse', 'showgroups')); + return $params; +} diff --git a/lib/editor/atto/plugins/collapse/pix/icon.png b/lib/editor/atto/plugins/collapse/pix/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..db0be7cac30dae15110b038e478ee5583061a7dc GIT binary patch literal 2865 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 P00000NkvXXu0mjfUuRHI literal 0 HcmV?d00001 diff --git a/lib/editor/atto/plugins/collapse/pix/icon.svg b/lib/editor/atto/plugins/collapse/pix/icon.svg new file mode 100644 index 00000000000..4ec6f93031b --- /dev/null +++ b/lib/editor/atto/plugins/collapse/pix/icon.svg @@ -0,0 +1,74 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/lib/editor/atto/plugins/collapse/settings.php b/lib/editor/atto/plugins/collapse/settings.php new file mode 100644 index 00000000000..dac6a5d859f --- /dev/null +++ b/lib/editor/atto/plugins/collapse/settings.php @@ -0,0 +1,43 @@ +. + +/** + * Settings that allow configuration of the list of tex examples in the equation editor. + * + * @package atto_collapse + * @copyright 2013 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$ADMIN->add('editoratto', new admin_category('atto_collapse', new lang_string('pluginname', 'atto_collapse'))); + +$settings = new admin_settingpage('atto_collapse_settings', new lang_string('settings', 'atto_collapse')); +if ($ADMIN->fulltree) { + // Number of groups to show when collapsed. + $name = new lang_string('showgroups', 'atto_collapse'); + $desc = new lang_string('showgroups_desc', 'atto_collapse'); + $default = 3; + $options = array_combine(range(1, 10), range(1, 10)); + + $setting = new admin_setting_configselect('atto_collapse/showgroups', + $name, + $desc, + $default, + $options); + $settings->add($setting); +} diff --git a/lib/editor/atto/plugins/collapse/version.php b/lib/editor/atto/plugins/collapse/version.php new file mode 100644 index 00000000000..c454ddabb6d --- /dev/null +++ b/lib/editor/atto/plugins/collapse/version.php @@ -0,0 +1,29 @@ +. + +/** + * Atto text editor integration version file. + * + * @package atto_collapse + * @copyright 2013 Damyon Wiese + * @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_collapse'; // Full name of the plugin (used for diagnostics). diff --git a/lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button-debug.js b/lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button-debug.js new file mode 100644 index 00000000000..d99e8bc14fa --- /dev/null +++ b/lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button-debug.js @@ -0,0 +1,110 @@ +YUI.add('moodle-atto_collapse-button', function (Y, NAME) { + +// 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 . + +/** + * CSS Selectors + * + * @type {Object} + */ +var SELECTORS = { + GROUPS: '.atto_group', + BUTTON: '.atto_collapse_button' +}; + +/** + * Atto text editor collapse plugin. + * + * @package atto_collapse + * @copyright 2013 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +M.atto_collapse = M.atto_collapse || { + + /** + * How many groups to show when collapsed. + * + * @property showgroups + * @type {Integer} + * @default 3 + */ + showgroups : 3, + + /** + * Init. + * + * @param {Object} params + * + * @return {Void} + */ + init : function(params) { + var click = function(e, elementid) { + e.preventDefault(); + M.atto_collapse.toggle(elementid); + }; + + this.showgroups = params.showgroups; + + var iconurl = M.util.image_url('icon', 'atto_collapse'); + + // Add the button to the toolbar. + M.editor_atto.add_toolbar_button(params.elementid, 'collapse', iconurl, params.group, click); + }, + + /** + * Either hide or show the extra groups in the toolbar. + * + * @param {String} elementid + * + * @return {Void} + */ + toggle : function(elementid) { + var toolbar = M.editor_atto.get_toolbar_node(elementid); + var button = toolbar.one(SELECTORS.BUTTON); + var groups = toolbar.all(SELECTORS.GROUPS).slice(this.showgroups); + + if (button.getData('collapsed')) { + button.set('title', M.util.get_string('showmore', 'atto_collapse')); + groups.show(); + button.setData('collapsed', false); + } else { + button.set('title', M.util.get_string('showless', 'atto_collapse')); + groups.hide(); + button.setData('collapsed', true); + } + }, + + /** + * After init function called after all plugins init() has been run. + * + * @param {Object} params + * + * @return {Void} + */ + after_init : function(params) { + var toolbar = M.editor_atto.get_toolbar_node(params.elementid); + var button = toolbar.one(SELECTORS.BUTTON); + + // Set the state to "not collapsed" (which is the state when the page loads). + button.setData('collapsed', false); + // Call toggle to change the state when the page loads to "collapsed". + M.atto_collapse.toggle(params.elementid); + } + +}; + + +}, '@VERSION@', {"requires": ["node"]}); diff --git a/lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button-min.js b/lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button-min.js new file mode 100644 index 00000000000..6e9ef1224d2 --- /dev/null +++ b/lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button-min.js @@ -0,0 +1 @@ +YUI.add("moodle-atto_collapse-button",function(e,t){var n={GROUPS:".atto_group",BUTTON:".atto_collapse_button"};M.atto_collapse=M.atto_collapse||{showgroups:3,init:function(e){var t=function(e,t){e.preventDefault(),M.atto_collapse.toggle(t)};this.showgroups=e.showgroups;var n=M.util.image_url("icon","atto_collapse");M.editor_atto.add_toolbar_button(e.elementid,"collapse",n,e.group,t)},toggle:function(e){var t=M.editor_atto.get_toolbar_node(e),r=t.one(n.BUTTON),i=t.all(n.GROUPS).slice(this.showgroups);r.getData("collapsed")?(r.set("title",M.util.get_string("showmore","atto_collapse")),i.show(),r.setData("collapsed",!1)):(r.set("title",M.util.get_string("showless","atto_collapse")),i.hide(),r.setData("collapsed",!0))},after_init:function(e){var t=M.editor_atto.get_toolbar_node(e.elementid),r=t.one(n.BUTTON);r.setData("collapsed",!1),M.atto_collapse.toggle(e.elementid)}}},"@VERSION@",{requires:["node"]}); diff --git a/lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button.js b/lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button.js new file mode 100644 index 00000000000..d99e8bc14fa --- /dev/null +++ b/lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/moodle-atto_collapse-button.js @@ -0,0 +1,110 @@ +YUI.add('moodle-atto_collapse-button', function (Y, NAME) { + +// 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 . + +/** + * CSS Selectors + * + * @type {Object} + */ +var SELECTORS = { + GROUPS: '.atto_group', + BUTTON: '.atto_collapse_button' +}; + +/** + * Atto text editor collapse plugin. + * + * @package atto_collapse + * @copyright 2013 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +M.atto_collapse = M.atto_collapse || { + + /** + * How many groups to show when collapsed. + * + * @property showgroups + * @type {Integer} + * @default 3 + */ + showgroups : 3, + + /** + * Init. + * + * @param {Object} params + * + * @return {Void} + */ + init : function(params) { + var click = function(e, elementid) { + e.preventDefault(); + M.atto_collapse.toggle(elementid); + }; + + this.showgroups = params.showgroups; + + var iconurl = M.util.image_url('icon', 'atto_collapse'); + + // Add the button to the toolbar. + M.editor_atto.add_toolbar_button(params.elementid, 'collapse', iconurl, params.group, click); + }, + + /** + * Either hide or show the extra groups in the toolbar. + * + * @param {String} elementid + * + * @return {Void} + */ + toggle : function(elementid) { + var toolbar = M.editor_atto.get_toolbar_node(elementid); + var button = toolbar.one(SELECTORS.BUTTON); + var groups = toolbar.all(SELECTORS.GROUPS).slice(this.showgroups); + + if (button.getData('collapsed')) { + button.set('title', M.util.get_string('showmore', 'atto_collapse')); + groups.show(); + button.setData('collapsed', false); + } else { + button.set('title', M.util.get_string('showless', 'atto_collapse')); + groups.hide(); + button.setData('collapsed', true); + } + }, + + /** + * After init function called after all plugins init() has been run. + * + * @param {Object} params + * + * @return {Void} + */ + after_init : function(params) { + var toolbar = M.editor_atto.get_toolbar_node(params.elementid); + var button = toolbar.one(SELECTORS.BUTTON); + + // Set the state to "not collapsed" (which is the state when the page loads). + button.setData('collapsed', false); + // Call toggle to change the state when the page loads to "collapsed". + M.atto_collapse.toggle(params.elementid); + } + +}; + + +}, '@VERSION@', {"requires": ["node"]}); diff --git a/lib/editor/atto/plugins/collapse/yui/src/button/build.json b/lib/editor/atto/plugins/collapse/yui/src/button/build.json new file mode 100644 index 00000000000..c0f7f198ed0 --- /dev/null +++ b/lib/editor/atto/plugins/collapse/yui/src/button/build.json @@ -0,0 +1,10 @@ +{ + "name": "moodle-atto_collapse-button", + "builds": { + "moodle-atto_collapse-button": { + "jsfiles": [ + "button.js" + ] + } + } +} diff --git a/lib/editor/atto/plugins/collapse/yui/src/button/js/button.js b/lib/editor/atto/plugins/collapse/yui/src/button/js/button.js new file mode 100644 index 00000000000..2715e711f50 --- /dev/null +++ b/lib/editor/atto/plugins/collapse/yui/src/button/js/button.js @@ -0,0 +1,105 @@ +// 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 . + +/** + * CSS Selectors + * + * @type {Object} + */ +var SELECTORS = { + GROUPS: '.atto_group', + BUTTON: '.atto_collapse_button' +}; + +/** + * Atto text editor collapse plugin. + * + * @package atto_collapse + * @copyright 2013 Damyon Wiese + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +M.atto_collapse = M.atto_collapse || { + + /** + * How many groups to show when collapsed. + * + * @property showgroups + * @type {Integer} + * @default 3 + */ + showgroups : 3, + + /** + * Init. + * + * @param {Object} params + * + * @return {Void} + */ + init : function(params) { + var click = function(e, elementid) { + e.preventDefault(); + M.atto_collapse.toggle(elementid); + }; + + this.showgroups = params.showgroups; + + var iconurl = M.util.image_url('icon', 'atto_collapse'); + + // Add the button to the toolbar. + M.editor_atto.add_toolbar_button(params.elementid, 'collapse', iconurl, params.group, click); + }, + + /** + * Either hide or show the extra groups in the toolbar. + * + * @param {String} elementid + * + * @return {Void} + */ + toggle : function(elementid) { + var toolbar = M.editor_atto.get_toolbar_node(elementid); + var button = toolbar.one(SELECTORS.BUTTON); + var groups = toolbar.all(SELECTORS.GROUPS).slice(this.showgroups); + + if (button.getData('collapsed')) { + button.set('title', M.util.get_string('showmore', 'atto_collapse')); + groups.show(); + button.setData('collapsed', false); + } else { + button.set('title', M.util.get_string('showless', 'atto_collapse')); + groups.hide(); + button.setData('collapsed', true); + } + }, + + /** + * After init function called after all plugins init() has been run. + * + * @param {Object} params + * + * @return {Void} + */ + after_init : function(params) { + var toolbar = M.editor_atto.get_toolbar_node(params.elementid); + var button = toolbar.one(SELECTORS.BUTTON); + + // Set the state to "not collapsed" (which is the state when the page loads). + button.setData('collapsed', false); + // Call toggle to change the state when the page loads to "collapsed". + M.atto_collapse.toggle(params.elementid); + } + +}; diff --git a/lib/editor/atto/plugins/collapse/yui/src/button/meta/button.json b/lib/editor/atto/plugins/collapse/yui/src/button/meta/button.json new file mode 100644 index 00000000000..a88cdaa4727 --- /dev/null +++ b/lib/editor/atto/plugins/collapse/yui/src/button/meta/button.json @@ -0,0 +1,5 @@ +{ + "moodle-atto_collapse-button": { + "requires": ["node"] + } +} diff --git a/lib/editor/atto/settings.php b/lib/editor/atto/settings.php index c775dbb2e5c..c0b483fd01b 100644 --- a/lib/editor/atto/settings.php +++ b/lib/editor/atto/settings.php @@ -30,7 +30,8 @@ $settings = new admin_settingpage('editorsettingsatto', new lang_string('setting if ($ADMIN->fulltree) { $name = new lang_string('toolbarconfig', 'editor_atto'); $desc = new lang_string('toolbarconfig_desc', 'editor_atto'); - $default = 'style = bold, italic, underline, strike, clear, title' . "\n" . + $default = 'collapse = collapse' . "\n" . + 'style = bold, italic, underline, strike, clear, title' . "\n" . 'paragraph = subscript, superscript, indent, outdent, orderedlist, unorderedlist' . "\n" . 'links = link, unlink' . "\n" . 'insert = table, image, media, managefiles, charmap, emoticon' . "\n" . @@ -44,10 +45,12 @@ if ($ADMIN->fulltree) { } $ADMIN->add('editoratto', $settings); -unset($settings); foreach (core_plugin_manager::instance()->get_plugins_of_type('atto') as $plugin) { + /** @var \editor_atto\plugininfo\atto $plugin */ $plugin->load_settings($ADMIN, 'editoratto', $hassiteconfig); } +// Required or the editor plugininfo will add this section twice. +unset($settings); $settings = null; diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js index 04f6078a7e0..fe4af1c16cc 100644 --- a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js +++ b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js @@ -161,6 +161,18 @@ M.editor_atto = M.editor_atto || { var plugin = this.getAttribute('data-plugin'); var handler = this.getAttribute('data-handler'); var overlay = M.editor_atto.menus[plugin + '_' + elementid]; + var toolbar = M.editor_atto.get_toolbar_node(elementid); + var currentid = toolbar.getAttribute('aria-activedescendant'); + + // Right now, currentid is the id of the previously selected button. + if (currentid) { + current = Y.one('#' + currentid); + // We only ever want one button with a tabindex of 0 at any one time. + current.setAttribute('tabindex', '-1'); + } + this.setAttribute('tabindex', 0); + // And update the activedescendant to point at the currently selected button. + toolbar.setAttribute('aria-activedescendant', this.generateID()); if (overlay) { overlay.hide(); @@ -323,6 +335,7 @@ M.editor_atto = M.editor_atto || { currentfocus = toolbar.getAttribute('aria-activedescendant'); if (!currentfocus) { + // Initially set the first button in the toolbar to be the default on keyboard focus. button.setAttribute('tabindex', '0'); toolbar.setAttribute('aria-activedescendant', button.generateID()); } @@ -406,6 +419,7 @@ M.editor_atto = M.editor_atto || { currentfocus = toolbar.getAttribute('aria-activedescendant'); if (!currentfocus) { + // Initially set the first button in the toolbar to be the default on keyboard focus. button.setAttribute('tabindex', '0'); toolbar.setAttribute('aria-activedescendant', button.generateID()); } @@ -540,17 +554,31 @@ M.editor_atto = M.editor_atto || { M.editor_atto.filepickeroptions[params.elementid] = params.filepickeroptions; // Init each of the plugins - var i, j; + var i, j, group, plugin; for (i = 0; i < params.plugins.length; i++) { - var group = params.plugins[i].group; + group = params.plugins[i].group; for (j = 0; j < params.plugins[i].plugins.length; j++) { - var plugin = params.plugins[i].plugins[j]; + plugin = params.plugins[i].plugins[j]; plugin.params.elementid = params.elementid; plugin.params.group = group; M['atto_' + plugin.name].init(plugin.params); } } + + // Let the plugins run some init code once all plugins are in the page. + for (i = 0; i < params.plugins.length; i++) { + group = params.plugins[i].group; + for (j = 0; j < params.plugins[i].plugins.length; j++) { + plugin = params.plugins[i].plugins[j]; + plugin.params.elementid = params.elementid; + plugin.params.group = group; + + if (typeof M['atto_' + plugin.name].after_init !== 'undefined') { + M['atto_' + plugin.name].after_init(plugin.params); + } + } + } }, /** @@ -613,11 +641,21 @@ M.editor_atto = M.editor_atto || { e.preventDefault(); - buttons = toolbar.all('button'); + // This workaround is because we cannot do ".atto_group:not([hidden]) button" in ie8 (even with selector-css3). + // Create an empty NodeList. + buttons = toolbar.all('empty'); + toolbar.all('.atto_group').each(function(group) { + if (!group.hasAttribute('hidden')) { + // Append the visible buttons to the buttons list. + buttons = buttons.concat(group.all('button')); + } + }); + // The currentid is the id of the previously selected button. currentid = toolbar.getAttribute('aria-activedescendant'); if (!currentid) { return; } + // We only ever want one button with a tabindex of 0. current = Y.one('#' + currentid); current.setAttribute('tabindex', '-1'); @@ -636,7 +674,7 @@ M.editor_atto = M.editor_atto || { currentindex = 0; } } - + // Currentindex has been updated to point to the new button. current = buttons.item(currentindex); current.setAttribute('tabindex', '0'); current.focus(); diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js index 844b40b15e7..c9b21c868d0 100644 --- a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js +++ b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js @@ -1,3 +1,3 @@ -YUI.add("moodle-editor_atto-editor",function(e,t){function i(){var e=this.getHTML(),t=[{regex://gi,replace:""},{regex:/<\\?\?xml[^>]*>/gi,replace:""},{regex:/<\/?\w+:[^>]*>/gi,replace:""},{regex:/\s*MSO[-:][^;"']*;?/gi,replace:""},{regex:/]*>( |\s)*<\/span>/gi,replace:""},{regex:/class="Mso[^"]*"/gi,replace:""},{regex:/<(\/?title|\/?meta|\/?style|\/?st\d|\/?head|\/?font|\/?html|\/?body|!\[)[^>]*?>/gi,replace:""},{regex:new RegExp(String.fromCharCode(8220),"gi"),replace:'"'},{regex:new RegExp(String.fromCharCode(8216),"gi"),replace:"'"},{regex:new RegExp(String.fromCharCode(8217),"gi"),replace:"'"},{regex:new RegExp(String.fromCharCode(8211),"gi"),replace:"-"},{regex:new RegExp(String.fromCharCode(8212),"gi"),replace:"--"},{regex:new RegExp(String.fromCharCode(189),"gi"),replace:"1/2"},{regex:new RegExp(String.fromCharCode(188),"gi"),replace:"1/4"},{regex:new RegExp(String.fromCharCode(190),"gi"),replace:"3/4"},{regex:new RegExp(String.fromCharCode(169),"gi"),replace:"(c)"},{regex:new RegExp(String.fromCharCode(174),"gi"),replace:"(r)"},{regex:new RegExp(String.fromCharCode(8230),"gi"),replace:"..."}],n=0,r;for(n=0;n'),a.append(f)),h=M.util.image_url("t/expanded","moodle"),c=e.Node.create('"),f.append(c),l=a.getAttribute("aria-activedescendant"),l||(c.setAttribute("tabindex","0"),a.setAttribute("aria-activedescendant",c.generateID())),M.editor_atto.widgets[n]=n;var p=e.Node.create('
'),d=0,v={};for(d=0;d'+v.text+""+"")),M.editor_atto.buttonhandlers[n+"_action_"+d]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_action_"+d),e.one("body").delegate("key",M.editor_atto.buttonclicked_handler,"space,enter",".atto_"+n+"_action_"+d),M.editor_atto.buttonhandlers[n+"_action_"+d]=v.handler);M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.showhide_menu_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=!0);var m=new M.core.dialogue({bodyContent:p,visible:!1,width:o+"em",lightbox:!1,closeButton:!1,center:!1});M.editor_atto.menus[n+"_"+t]=m,m.align(c,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]),m.hide(),m.headerNode.hide(),m.render()},add_toolbar_button:function(t,n,r,i,s){var o=M.editor_atto.get_toolbar_node(t),u=o.one(".atto_group."+i+"_group"),a,f;u||(u=e.Node.create('
'),o.append(u)),a=e.Node.create('"),u.append(a),f=o.getAttribute("aria-activedescendant"),f||(a.setAttribute("tabindex","0"),o.setAttribute("aria-activedescendant",a.generateID())),M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=s),M.editor_atto.widgets[n]=n},is_active:function(t){var n=M.editor_atto.get_selection();n.length&&(n=n.pop());var r=null;n.parentElement?r=e.one(n.parentElement()):r=e.one(n.startContainer);var i=M.editor_atto.get_editable_node(t);return r&&i.contains(r)},focus:function(e){M.editor_atto.get_editable_node(e).focus()},init:function(t){var n=e.Node.create('
'),r=e.Node.create('
'),i=e.Node.create('")),M.editor_atto.buttonhandlers[n+"_action_"+d]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_action_"+d),e.one("body").delegate("key",M.editor_atto.buttonclicked_handler,"space,enter",".atto_"+n+"_action_"+d),M.editor_atto.buttonhandlers[n+"_action_"+d]=v.handler);M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.showhide_menu_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=!0);var m=new M.core.dialogue({bodyContent:p,visible:!1,width:o+"em",lightbox:!1,closeButton:!1,center:!1});M.editor_atto.menus[n+"_"+t]=m,m.align(c,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]),m.hide(),m.headerNode.hide(),m.render +()},add_toolbar_button:function(t,n,r,i,s){var o=M.editor_atto.get_toolbar_node(t),u=o.one(".atto_group."+i+"_group"),a,f;u||(u=e.Node.create('
'),o.append(u)),a=e.Node.create('"),u.append(a),f=o.getAttribute("aria-activedescendant"),f||(a.setAttribute("tabindex","0"),o.setAttribute("aria-activedescendant",a.generateID())),M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=s),M.editor_atto.widgets[n]=n},is_active:function(t){var n=M.editor_atto.get_selection();n.length&&(n=n.pop());var r=null;n.parentElement?r=e.one(n.parentElement()):r=e.one(n.startContainer);var i=M.editor_atto.get_editable_node(t);return r&&i.contains(r)},focus:function(e){M.editor_atto.get_editable_node(e).focus()},init:function(t){var n=e.Node.create('
'),r=e.Node.create('
'),i=e.Node.create('