4 * This file contains the panel class used by the dock to display the content of docked blocks.
6 * @module moodle-core-dock
12 * @namespace M.core.dock
18 DOCKPANEL = function() {
19 DOCKPANEL.superclass.constructor.apply(this, arguments);
21 DOCKPANEL.prototype = {
23 * True once the panel has been created.
30 * Called during the initialisation process of the object.
33 initializer : function() {
34 Y.log('Panel initialising', 'debug', LOGNS);
36 * Fired before the panel is shown.
37 * @event dockpane::beforeshow
39 this.publish('dockpanel:beforeshow', {prefix:'dockpanel'});
41 * Fired after the panel is shown.
42 * @event dockpanel:shown
44 this.publish('dockpanel:shown', {prefix:'dockpanel'});
46 * Fired before the panel is hidden.
47 * @event dockpane::beforehide
49 this.publish('dockpanel:beforehide', {prefix:'dockpanel'});
51 * Fired after the panel is hidden.
52 * @event dockpanel:hidden
54 this.publish('dockpanel:hidden', {prefix:'dockpanel'});
56 * Fired when ever the dock panel is either hidden or shown.
57 * Always fired after the shown or hidden events.
58 * @event dockpanel:visiblechange
60 this.publish('dockpanel:visiblechange', {prefix:'dockpanel'});
63 * Creates the Panel if it has not already been created.
72 var dock = this.get('dock'),
73 node = dock.get('dockNode');
74 this.set('node', Y.Node.create('<div id="dockeditempanel" class="dockitempanel_hidden"></div>'));
75 this.set('contentNode', Y.Node.create('<div class="dockeditempanel_content"></div>'));
76 this.set('headerNode', Y.Node.create('<div class="dockeditempanel_hd"></div>'));
77 this.set('bodyNode', Y.Node.create('<div class="dockeditempanel_bd"></div>'));
79 this.get('node').append(this.get('contentNode').append(this.get('headerNode')).append(this.get('bodyNode')))
88 this.fire('dockpanel:beforeshow');
89 this.set('visible', true);
90 this.get('node').removeClass('dockitempanel_hidden');
91 this.fire('dockpanel:shown');
92 this.fire('dockpanel:visiblechange');
99 this.fire('dockpanel:beforehide');
100 this.set('visible', false);
101 this.get('node').addClass('dockitempanel_hidden');
102 this.fire('dockpanel:hidden');
103 this.fire('dockpanel:visiblechange');
106 * Sets the panel header.
108 * @param {Node|String} content
110 setHeader : function(content) {
112 var header = this.get('headerNode'),
114 header.setContent(content);
115 if (arguments.length > 1) {
116 for (i = 1; i < arguments.length; i++) {
117 if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) {
118 header.append(arguments[i]);
124 * Sets the panel body.
126 * @param {Node|String} content
128 setBody : function(content) {
130 this.get('bodyNode').setContent(content);
133 * Sets the new top mark of the panel.
136 * @param {Number} newtop
138 setTop : function(newtop) {
139 if (Y.UA.ie > 0 && Y.UA.ie < 7) {
140 this.get('node').setY(newtop);
142 this.get('node').setStyle('top', newtop.toString()+'px');
146 * Corrects the width of the panel.
147 * @method correctWidth
149 correctWidth : function() {
150 var bodyNode = this.get('bodyNode'),
152 width = bodyNode.get('clientWidth'),
153 // Scrollable width of content.
154 scroll = bodyNode.get('scrollWidth'),
155 // Width of content container with overflow.
156 offsetWidth = bodyNode.get('offsetWidth'),
157 // The new width - defaults to the current width.
159 // The max width (80% of screen).
160 maxWidth = Math.round(bodyNode.get('winWidth') * 0.8);
162 // If the scrollable width is more than the visible width
163 if (scroll > width) {
166 // + any rendering difference (borders, padding)
167 // + 10px to make it look nice.
168 newWidth = width + (scroll - width) + ((offsetWidth - width)*2) + 10;
171 // Make sure its not more then the maxwidth
172 if (newWidth > maxWidth) {
176 // Set the new width if its more than the old width.
177 if (newWidth > offsetWidth) {
178 this.get('node').setStyle('width', newWidth+'px');
182 Y.extend(DOCKPANEL, Y.Base, DOCKPANEL.prototype, {
183 NAME : 'moodle-core-dock-panel',
192 writeOnce : 'initOnly'
195 * The node that contains the whole panel.
203 * The node that contains the header, body and footer.
204 * @attribute contentNode
211 * The node that contains the header
212 * @attribute headerNode
219 * The node that contains the body
220 * @attribute bodyNode
227 * True if the panel is currently visible.
236 Y.augment(DOCKPANEL, Y.EventTarget);