1 /* global DOCKPANEL, LOGNS */
6 * This file contains the panel class used by the dock to display the content of docked blocks.
8 * @module moodle-core-dock
14 * @namespace M.core.dock
20 DOCKPANEL = function() {
21 DOCKPANEL.superclass.constructor.apply(this, arguments);
23 DOCKPANEL.prototype = {
25 * True once the panel has been created.
32 * Called during the initialisation process of the object.
35 initializer: function() {
36 Y.log('Panel initialising', 'debug', LOGNS);
38 * Fired before the panel is shown.
39 * @event dockpane::beforeshow
41 this.publish('dockpanel:beforeshow', {prefix: 'dockpanel'});
43 * Fired after the panel is shown.
44 * @event dockpanel:shown
46 this.publish('dockpanel:shown', {prefix: 'dockpanel'});
48 * Fired before the panel is hidden.
49 * @event dockpane::beforehide
51 this.publish('dockpanel:beforehide', {prefix: 'dockpanel'});
53 * Fired after the panel is hidden.
54 * @event dockpanel:hidden
56 this.publish('dockpanel:hidden', {prefix: 'dockpanel'});
58 * Fired when ever the dock panel is either hidden or shown.
59 * Always fired after the shown or hidden events.
60 * @event dockpanel:visiblechange
62 this.publish('dockpanel:visiblechange', {prefix: 'dockpanel'});
65 * Creates the Panel if it has not already been created.
74 var dock = this.get('dock'),
75 node = dock.get('dockNode');
76 this.set('node', Y.Node.create('<div id="dockeditempanel" class="dockitempanel_hidden"></div>'));
77 this.set('contentNode', Y.Node.create('<div class="dockeditempanel_content"></div>'));
78 this.set('headerNode', Y.Node.create('<div class="dockeditempanel_hd"></div>'));
79 this.set('bodyNode', Y.Node.create('<div class="dockeditempanel_bd"></div>'));
81 this.get('node').append(this.get('contentNode').append(this.get('headerNode')).append(this.get('bodyNode')))
90 this.fire('dockpanel:beforeshow');
91 this.set('visible', true);
92 this.get('node').removeClass('dockitempanel_hidden');
93 this.fire('dockpanel:shown');
94 this.fire('dockpanel:visiblechange');
101 this.fire('dockpanel:beforehide');
102 this.set('visible', false);
103 this.get('node').addClass('dockitempanel_hidden');
104 this.fire('dockpanel:hidden');
105 this.fire('dockpanel:visiblechange');
108 * Sets the panel header.
110 * @param {Node|String} content
112 setHeader: function(content) {
114 var header = this.get('headerNode'),
116 header.setContent(content);
117 if (arguments.length > 1) {
118 for (i = 1; i < arguments.length; i++) {
119 if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) {
120 header.append(arguments[i]);
126 * Sets the panel body.
128 * @param {Node|String} content
130 setBody: function(content) {
132 this.get('bodyNode').setContent(content);
135 * Sets the new top mark of the panel.
138 * @param {Number} newtop
140 setTop: function(newtop) {
141 if (Y.UA.ie > 0 && Y.UA.ie < 7) {
142 this.get('node').setY(newtop);
144 this.get('node').setStyle('top', newtop.toString() + 'px');
148 * Corrects the width of the panel.
149 * @method correctWidth
151 correctWidth: function() {
152 var bodyNode = this.get('bodyNode'),
154 width = bodyNode.get('clientWidth'),
155 // Scrollable width of content.
156 scroll = bodyNode.get('scrollWidth'),
157 // Width of content container with overflow.
158 offsetWidth = bodyNode.get('offsetWidth'),
159 // The new width - defaults to the current width.
161 // The max width (80% of screen).
162 maxWidth = Math.round(bodyNode.get('winWidth') * 0.8);
164 // If the scrollable width is more than the visible width
165 if (scroll > width) {
168 // + any rendering difference (borders, padding)
169 // + 10px to make it look nice.
170 newWidth = width + (scroll - width) + ((offsetWidth - width) * 2) + 10;
173 // Make sure its not more then the maxwidth
174 if (newWidth > maxWidth) {
178 // Set the new width if its more than the old width.
179 if (newWidth > offsetWidth) {
180 this.get('node').setStyle('width', newWidth + 'px');
184 Y.extend(DOCKPANEL, Y.Base, DOCKPANEL.prototype, {
185 NAME: 'moodle-core-dock-panel',
194 writeOnce: 'initOnly'
197 * The node that contains the whole panel.
205 * The node that contains the header, body and footer.
206 * @attribute contentNode
213 * The node that contains the header
214 * @attribute headerNode
221 * The node that contains the body
222 * @attribute bodyNode
229 * True if the panel is currently visible.
238 Y.augment(DOCKPANEL, Y.EventTarget);