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