MDL-46240 atto_collapse: fix icon url
[moodle.git] / lib / editor / atto / plugins / collapse / yui / build / moodle-atto_collapse-button / moodle-atto_collapse-button.js
CommitLineData
fcb5b5c4
DW
1YUI.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
62467795
AN
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
fcb5b5c4 24/**
62467795 25 * @module moodle-atto_collapse-button
fcb5b5c4 26 */
fcb5b5c4
DW
27
28/**
29 * Atto text editor collapse plugin.
30 *
62467795
AN
31 * @namespace M.atto_collapse
32 * @class button
33 * @extends M.editor_atto.EditorPlugin
fcb5b5c4 34 */
fcb5b5c4 35
62467795
AN
36var PLUGINNAME = 'atto_collapse',
37 ATTRSHOWGROUPS = 'showgroups',
38 COLLAPSE = 'collapse',
39 COLLAPSED = 'collapsed',
40 GROUPS = '.atto_group';
fcb5b5c4 41
62467795
AN
42Y.namespace('M.atto_collapse').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
43 initializer: function() {
9ad87e79
AN
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
62467795 53 var button = this.addButton({
e1673b58
DP
54 icon: 'icon',
55 iconComponent: PLUGINNAME,
62467795
AN
56 callback: this._toggle
57 });
fcb5b5c4 58
62467795
AN
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);
fcb5b5c4 62
62467795
AN
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);
fcb5b5c4
DW
67 },
68
69 /**
62467795 70 * Toggle the visibility of the extra groups in the toolbar.
fcb5b5c4 71 *
62467795
AN
72 * @method _toggle
73 * @param {EventFacade} e
74 * @private
fcb5b5c4 75 */
62467795
AN
76 _toggle: function(e) {
77 e.preventDefault();
78 var button = this.buttons[COLLAPSE];
fcb5b5c4 79
62467795 80 if (button.getData(COLLAPSED)) {
ba4e81d2 81 this.highlightButtons(COLLAPSE);
62467795 82 this._setVisibility(button, true);
fcb5b5c4 83 } else {
ba4e81d2 84 this.unHighlightButtons(COLLAPSE);
62467795 85 this._setVisibility(button);
fcb5b5c4 86 }
040e1301
AN
87
88 this.buttons[this.name].focus();
fcb5b5c4
DW
89 },
90
91 /**
62467795 92 * Set the visibility of the toolbar groups.
fcb5b5c4 93 *
62467795
AN
94 * @method _setVisibility
95 * @param {Node} button The collapse button
96 * @param {Booelan} visibility Whether the groups should be made visible
97 * @private
fcb5b5c4 98 */
62467795
AN
99 _setVisibility: function(button, visibility) {
100 var groups = this.toolbar.all(GROUPS).slice(this.get(ATTRSHOWGROUPS));
fcb5b5c4 101
62467795
AN
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 }
fcb5b5c4 111
62467795
AN
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});
fcb5b5c4
DW
127
128
62467795 129}, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});