[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 // This file is part of Moodle - http://moodle.org/ 2 // 3 // Moodle is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // Moodle is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 15 16 /* 17 * @package atto_collapse 18 * @copyright 2013 Damyon Wiese <damyon@moodle.com> 19 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 20 */ 21 22 /** 23 * @module moodle-atto_collapse-button 24 */ 25 26 /** 27 * Atto text editor collapse plugin. 28 * 29 * @namespace M.atto_collapse 30 * @class button 31 * @extends M.editor_atto.EditorPlugin 32 */ 33 34 var PLUGINNAME = 'atto_collapse', 35 ATTRSHOWGROUPS = 'showgroups', 36 COLLAPSE = 'collapse', 37 COLLAPSED = 'collapsed', 38 GROUPS = '.atto_group'; 39 40 Y.namespace('M.atto_collapse').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], { 41 initializer: function() { 42 var toolbarGroupCount = Y.Object.size(this.get('host').get('plugins')); 43 if (toolbarGroupCount <= 1 + parseInt(this.get(ATTRSHOWGROUPS), 10)) { 44 Y.log("There are not enough groups to require toggling - not adding the button", 45 'debug', 'moodle-atto_collapse'); 46 return; 47 } 48 49 if (this.toolbar.all(GROUPS).size() > this.get(ATTRSHOWGROUPS)) { 50 Y.log("The collapse plugin is shown after it's cut-off - not adding the button", 51 'debug', 'moodle-atto_collapse'); 52 return; 53 } 54 55 var button = this.addButton({ 56 icon: 'icon', 57 iconComponent: PLUGINNAME, 58 callback: this._toggle 59 }); 60 61 // Perform a toggle after all plugins have been loaded for the first time. 62 this.get('host').on('pluginsloaded', function(e, button) { 63 this._setVisibility(button); 64 65 // Set the toolbar to break after the initial those displayed by default. 66 var firstGroup = this.toolbar.all(GROUPS).item(this.get(ATTRSHOWGROUPS)); 67 firstGroup.insert('<div class="toolbarbreak"></div>', 'before'); 68 }, this, button); 69 }, 70 71 /** 72 * Toggle the visibility of the extra groups in the toolbar. 73 * 74 * @method _toggle 75 * @param {EventFacade} e 76 * @private 77 */ 78 _toggle: function(e) { 79 e.preventDefault(); 80 var button = this.buttons[COLLAPSE]; 81 82 if (button.getData(COLLAPSED)) { 83 this.highlightButtons(COLLAPSE); 84 this._setVisibility(button, true); 85 } else { 86 this.unHighlightButtons(COLLAPSE); 87 this._setVisibility(button); 88 } 89 90 this.buttons[this.name].focus(); 91 }, 92 93 /** 94 * Set the visibility of the toolbar groups. 95 * 96 * @method _setVisibility 97 * @param {Node} button The collapse button 98 * @param {Booelan} visibility Whether the groups should be made visible 99 * @private 100 */ 101 _setVisibility: function(button, visibility) { 102 var groups = this.toolbar.all(GROUPS).slice(this.get(ATTRSHOWGROUPS)); 103 104 if (visibility) { 105 button.set('title', M.util.get_string('showfewer', PLUGINNAME)); 106 groups.show(); 107 button.setData(COLLAPSED, false); 108 } else { 109 button.set('title', M.util.get_string('showmore', PLUGINNAME)); 110 groups.hide(); 111 button.setData(COLLAPSED, true); 112 } 113 114 } 115 }, { 116 ATTRS: { 117 /** 118 * How many groups to show when collapsed. 119 * 120 * @attribute showgroups 121 * @type Number 122 * @default 3 123 */ 124 showgroups: { 125 value: 3 126 } 127 } 128 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |