MDL-46240 atto_collapse: fix icon url
[moodle.git] / lib / editor / atto / plugins / collapse / yui / build / moodle-atto_collapse-button / moodle-atto_collapse-button-debug.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 Y.log("There are not enough groups to require toggling - not adding the button",
47 'debug','moodle-atto_collapse');
48 return;
49 }
50
51 if (this.toolbar.all(GROUPS).size() > this.get(ATTRSHOWGROUPS)) {
52 Y.log("The collapse plugin is shown after it's cut-off - not adding the button",
53 'debug','moodle-atto_collapse');
54 return;
55 }
56
62467795 57 var button = this.addButton({
e1673b58
DP
58 icon: 'icon',
59 iconComponent: PLUGINNAME,
62467795
AN
60 callback: this._toggle
61 });
fcb5b5c4 62
62467795
AN
63 // Perform a toggle after all plugins have been loaded for the first time.
64 this.get('host').on('pluginsloaded', function(e, button) {
65 this._setVisibility(button);
fcb5b5c4 66
62467795
AN
67 // Set the toolbar to break after the initial those displayed by default.
68 var firstGroup = this.toolbar.all(GROUPS).item(this.get(ATTRSHOWGROUPS));
69 firstGroup.insert('<div class="toolbarbreak"></div>', 'before');
70 }, this, button);
fcb5b5c4
DW
71 },
72
73 /**
62467795 74 * Toggle the visibility of the extra groups in the toolbar.
fcb5b5c4 75 *
62467795
AN
76 * @method _toggle
77 * @param {EventFacade} e
78 * @private
fcb5b5c4 79 */
62467795
AN
80 _toggle: function(e) {
81 e.preventDefault();
82 var button = this.buttons[COLLAPSE];
fcb5b5c4 83
62467795 84 if (button.getData(COLLAPSED)) {
ba4e81d2 85 this.highlightButtons(COLLAPSE);
62467795 86 this._setVisibility(button, true);
fcb5b5c4 87 } else {
ba4e81d2 88 this.unHighlightButtons(COLLAPSE);
62467795 89 this._setVisibility(button);
fcb5b5c4 90 }
040e1301
AN
91
92 this.buttons[this.name].focus();
fcb5b5c4
DW
93 },
94
95 /**
62467795 96 * Set the visibility of the toolbar groups.
fcb5b5c4 97 *
62467795
AN
98 * @method _setVisibility
99 * @param {Node} button The collapse button
100 * @param {Booelan} visibility Whether the groups should be made visible
101 * @private
fcb5b5c4 102 */
62467795
AN
103 _setVisibility: function(button, visibility) {
104 var groups = this.toolbar.all(GROUPS).slice(this.get(ATTRSHOWGROUPS));
fcb5b5c4 105
62467795
AN
106 if (visibility) {
107 button.set('title', M.util.get_string('showfewer', PLUGINNAME));
108 groups.show();
109 button.setData(COLLAPSED, false);
110 } else {
111 button.set('title', M.util.get_string('showmore', PLUGINNAME));
112 groups.hide();
113 button.setData(COLLAPSED, true);
114 }
fcb5b5c4 115
62467795
AN
116 }
117}, {
118 ATTRS: {
119 /**
120 * How many groups to show when collapsed.
121 *
122 * @attribute showgroups
123 * @type Number
124 * @default 3
125 */
126 showgroups: {
127 value: 3
128 }
129 }
130});
fcb5b5c4
DW
131
132
62467795 133}, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});