1 YUI.add('moodle-core-dock', function (Y, NAME) {
6 * This file contains the DOCK object and all dock related global namespace methods and properties.
8 * @module moodle-core-dock
11 var LOGNS = 'moodle-core-dock',
12 BODY = Y.one(Y.config.doc.body),
14 dock: 'dock', // CSS Class applied to the dock box
15 dockspacer: 'dockspacer', // CSS class applied to the dockspacer
16 controls: 'controls', // CSS class applied to the controls box
17 body: 'has_dock', // CSS class added to the body when there is a dock
18 buttonscontainer: 'buttons_container',
19 dockeditem: 'dockeditem', // CSS class added to each item in the dock
20 dockeditemcontainer: 'dockeditem_container',
21 dockedtitle: 'dockedtitle', // CSS class added to the item's title in each dock
22 activeitem: 'activeitem', // CSS class added to the active item
23 dockonload: 'dock_on_load'
26 dockableblock: '.block[data-instanceid][data-dockable]',
27 blockmoveto: '.block[data-instanceid][data-dockable] .moveto',
28 panelmoveto: '#dockeditempanel .commands a.moveto',
29 dockonload: '.block.' + CSS.dockonload,
30 blockregion: '[data-blockregion]'
36 DOCKEDITEM; // eslint-disable-line no-unused-vars
38 M.core = M.core || {};
39 M.core.dock = M.core.dock || {};
42 * The dock - once initialised.
48 M.core.dock._dock = null;
51 * An associative array of dockable blocks.
52 * @property _dockableblocks
53 * @type {Array} An array of BLOCK objects organised by instanceid.
56 M.core.dock._dockableblocks = {};
59 * Initialises the dock.
60 * This method registers dockable blocks, and creates delegations to dock them.
64 M.core.dock.init = function() {
65 Y.all(SELECTOR.dockableblock).each(M.core.dock.registerDockableBlock);
66 Y.Global.on(M.core.globalEvents.BLOCK_CONTENT_UPDATED, function(e) {
67 M.core.dock.notifyBlockChange(e.instanceid);
69 BODY.delegate('click', M.core.dock.dockBlock, SELECTOR.blockmoveto);
70 BODY.delegate('key', M.core.dock.dockBlock, SELECTOR.blockmoveto, 'enter');
74 * Returns an instance of the dock.
75 * Initialises one if one hasn't already being initialised.
81 M.core.dock.get = function() {
82 if (this._dock === null) {
83 this._dock = new DOCK();
89 * Registers a dockable block with the dock.
92 * @method registerDockableBlock
93 * @param {int} id The block instance ID.
96 M.core.dock.registerDockableBlock = function(id) {
97 if (typeof id === 'object' && typeof id.getData === 'function') {
98 id = id.getData('instanceid');
100 M.core.dock._dockableblocks[id] = new BLOCK({id: id});
104 * Docks a block given either its instanceid, its node, or an event fired from within the block.
106 * @method dockBlockByInstanceID
110 M.core.dock.dockBlock = function(id) {
111 if (typeof id === 'object' && id.target !== 'undefined') {
114 if (typeof id === "object") {
115 if (!id.test(SELECTOR.dockableblock)) {
116 id = id.ancestor(SELECTOR.dockableblock);
118 if (typeof id === 'object' && typeof id.getData === 'function' && !id.ancestor('.' + CSS.dock)) {
119 id = id.getData('instanceid');
121 Y.log('Invalid instanceid given to dockBlockByInstanceID', 'warn', LOGNS);
125 var block = M.core.dock._dockableblocks[id];
132 * Fixes the title orientation. Rotating it if required.
135 * @method fixTitleOrientation
136 * @param {Node} title The title node we are looking at.
137 * @param {String} text The string to use as the title.
138 * @return {Node} The title node to use.
140 M.core.dock.fixTitleOrientation = function(title, text) {
141 var dock = M.core.dock.get(),
143 transform = 'rotate(270deg)',
148 verticaldirection = M.util.get_string('thisdirectionvertical', 'langconfig');
149 title = Y.one(title);
151 if (dock.get('orientation') !== 'vertical') {
152 // If the dock isn't vertical don't adjust it!
153 title.set('innerHTML', text);
157 if (Y.UA.ie > 0 && Y.UA.ie < 8) {
158 // IE 6/7 can't rotate text so force ver
159 verticaldirection = 'ver';
162 switch (verticaldirection) {
165 return title.set('innerHTML', text.split('').join('<br />'));
167 transform = 'rotate(90deg)';
170 // Nothing to do here. transform default is good.
175 // IE8 can flip the text via CSS but not handle transform. IE9+ can handle the CSS3 transform attribute.
176 title.set('innerHTML', text);
177 title.setAttribute('style', 'writing-mode: tb-rl; filter: flipV flipH;display:inline;');
178 title.addClass('filterrotate');
182 // We need to fix a font-size - sorry theme designers.
183 test = Y.Node.create('<h2 class="transform-test-heading"><span class="transform-test-node" style="font-size:' +
184 fontsize + ';">' + text + '</span></h2>');
185 BODY.insert(test, 0);
186 width = test.one('span').get('offsetWidth') * 1.2;
187 height = test.one('span').get('offsetHeight');
190 title.set('innerHTML', text);
191 title.addClass('css3transform');
193 // Move the title into position
195 'position': 'relative',
196 'fontSize': fontsize,
198 'top': (width - height) / 2
201 // Positioning is different when in RTL mode.
202 if (window.right_to_left()) {
203 title.setStyle('left', width / 2 - height);
205 title.setStyle('right', width / 2 - height);
210 'transform': transform,
211 '-ms-transform': transform,
212 '-moz-transform': transform,
213 '-webkit-transform': transform,
214 '-o-transform': transform
217 container = Y.Node.create('<div></div>');
218 container.append(title);
219 container.setStyles({
220 height: width + (width / 4),
227 * Informs the dock that the content of the block has changed.
228 * This should be called by the blocks JS code if its content has been updated dynamically.
229 * This method ensure the dock resizes if need be.
232 * @method notifyBlockChange
233 * @param {Number} instanceid
236 M.core.dock.notifyBlockChange = function(instanceid) {
237 if (this._dock !== null) {
238 var dock = M.core.dock.get(),
239 activeitem = dock.getActiveItem();
240 if (activeitem && activeitem.get('blockinstanceid') === parseInt(instanceid, 10)) {
241 dock.resizePanelIfRequired();
249 * @namespace M.core.dock
256 DOCK.superclass.constructor.apply(this, arguments);
260 * Tab height manager used to ensure tabs are always visible.
262 * @property tabheightmanager
263 * @type TABHEIGHTMANAGER
265 tabheightmanager: null,
267 * Will be an eventtype if there is an eventype to prevent.
269 * @property preventevent
274 * Will be an object if there is a delayed event in effect.
276 * @property delayedevent
281 * An array of currently docked items.
283 * @property dockeditems
288 * Set to true once the dock has been drawn.
290 * @property dockdrawn
295 * The number of blocks that are currently docked.
302 * The total number of blocks that have been docked.
304 * @property totalcount
309 * A hidden node used as a holding area for DOM objects used by blocks that have been docked.
311 * @property holdingareanode
314 holdingareanode: null,
316 * Called during the initialisation process of the object.
317 * @method initializer
319 initializer: function() {
320 Y.log('Dock initialising', 'debug', LOGNS);
322 // Publish the events the dock has
324 * Fired when the dock first starts initialising.
325 * @event dock:starting
327 this.publish('dock:starting', {prefix: 'dock', broadcast: 2, emitFacade: true, fireOnce: true});
329 * Fired after the dock is initialised for the first time.
330 * @event dock:initialised
332 this.publish('dock:initialised', {prefix: 'dock', broadcast: 2, emitFacade: true, fireOnce: true});
334 * Fired before the dock structure and content is first created.
335 * @event dock:beforedraw
337 this.publish('dock:beforedraw', {prefix: 'dock', fireOnce: true});
339 * Fired before the dock is changed from hidden to visible.
340 * @event dock:beforeshow
342 this.publish('dock:beforeshow', {prefix: 'dock'});
344 * Fires after the dock has been changed from hidden to visible.
347 this.publish('dock:shown', {prefix: 'dock', broadcast: 2});
349 * Fired after the dock has been changed from visible to hidden.
352 this.publish('dock:hidden', {prefix: 'dock', broadcast: 2});
354 * Fires when an item is added to the dock.
355 * @event dock:itemadded
357 this.publish('dock:itemadded', {prefix: 'dock'});
359 * Fires when an item is removed from the dock.
360 * @event dock:itemremoved
362 this.publish('dock:itemremoved', {prefix: 'dock'});
364 * Fires when a block is added or removed from the dock.
365 * This happens after the itemadded and itemremoved events have been called.
366 * @event dock:itemschanged
368 this.publish('dock:itemschanged', {prefix: 'dock', broadcast: 2});
370 * Fires once when the docks panel is first initialised.
371 * @event dock:panelgenerated
373 this.publish('dock:panelgenerated', {prefix: 'dock', fireOnce: true});
375 * Fires when the dock panel is about to be resized.
376 * @event dock:panelresizestart
378 this.publish('dock:panelresizestart', {prefix: 'dock'});
380 * Fires after the dock panel has been resized.
381 * @event dock:resizepanelcomplete
383 this.publish('dock:resizepanelcomplete', {prefix: 'dock'});
385 // Apply theme customisations here before we do any real work.
386 this._applyThemeCustomisation();
387 // Inform everyone we are now about to initialise.
388 this.fire('dock:starting');
389 this._ensureDockDrawn();
390 // Inform everyone the dock has been initialised
391 this.fire('dock:initialised');
394 * Ensures that the dock has been drawn.
396 * @method _ensureDockDrawn
399 _ensureDockDrawn: function() {
400 if (this.dockdrawn === true) {
403 var dock = this._initialiseDockNode(),
405 cssselector: '.' + CSS.dockedtitle,
409 cssselector: '.' + CSS.dockedtitle,
412 preventevent: 'click',
415 if (Y.UA.ie > 0 && Y.UA.ie < 7) {
416 // Adjust for IE 6 (can't handle fixed pos)
417 dock.setStyle('height', dock.get('winHeight') + 'px');
420 this.fire('dock:beforedraw');
422 this._initialiseDockControls();
424 this.tabheightmanager = new TABHEIGHTMANAGER({dock: this});
426 // Attach the required event listeners
427 // We use delegate here as that way a handful of events are created for the dock
428 // and all items rather than the same number for the dock AND every item individually
429 Y.delegate('click', this.handleEvent, this.get('dockNode'), '.' + CSS.dockedtitle, this, clickargs);
430 Y.delegate('mouseenter', this.handleEvent, this.get('dockNode'), '.' + CSS.dockedtitle, this, mouseenterargs);
431 this.get('dockNode').on('mouseleave', this.handleEvent, this, {cssselector: '#dock', delay: 0.5, iscontained: false});
433 Y.delegate('click', this.handleReturnToBlock, this.get('dockNode'), SELECTOR.panelmoveto, this);
434 Y.delegate('dock:actionkey', this.handleDockedItemEvent, this.get('dockNode'), '.' + CSS.dockeditem, this);
436 BODY.on('click', this.handleEvent, this, {cssselector: 'body', delay: 0});
437 this.on('dock:itemschanged', this.resizeBlockSpace, this);
438 this.on('dock:itemschanged', this.checkDockVisibility, this);
439 this.on('dock:itemschanged', this.resetFirstItem, this);
440 this.dockdrawn = true;
444 * Handles an actionkey event on the dock.
445 * @param {EventFacade} e
446 * @method handleDockedItemEvent
449 handleDockedItemEvent: function(e) {
450 if (e.type !== 'dock:actionkey') {
453 var target = e.target,
454 dockeditem = '.' + CSS.dockeditem;
455 if (!target.test(dockeditem)) {
456 target = target.ancestor(dockeditem);
462 this.dockeditems[target.getAttribute('rel')].toggle(e.action);
465 * Call the theme customisation method "customise_dock_for_theme" if it exists.
467 * @method _applyThemeCustomisation
469 _applyThemeCustomisation: function() {
470 // Check if there is a customisation function
471 if (typeof (customise_dock_for_theme) === 'function') {
472 // First up pre the legacy object.
478 spacebeforefirstitem: null,
486 buttonscontainer: null,
488 dockeditemcontainer: null,
493 // Run the customisation function
494 window.customise_dock_for_theme(this);
495 } catch (exception) {
496 // Do nothing at the moment.
497 Y.log('Exception while attempting to apply theme customisations.', 'error', LOGNS);
499 // Now to work out what they did.
503 buffer: 'bufferPanel',
504 orientation: 'orientation',
505 position: 'position',
506 spacebeforefirstitem: 'bufferBeforeFirstItem',
507 removeallicon: 'undockAllIconUrl'
509 // Check for and apply any legacy configuration.
510 for (key in M.core_dock.cfg) {
511 if (Y.Lang.isString(key) && cfgmap[key]) {
512 value = M.core_dock.cfg[key];
513 if (value === null) {
517 Y.log('Warning: customise_dock_for_theme has changed. Please update your code.', 'warn', LOGNS);
520 // Damn, the've set something.
521 Y.log('Note for customise_dock_for_theme code: M.core_dock.cfg.' + key +
522 ' is now dock.set(\'' + key + '\', value)',
524 this.set(cfgmap[key], value);
527 // Check for and apply any legacy CSS changes..
528 for (key in M.core_dock.css) {
529 if (Y.Lang.isString(key)) {
530 value = M.core_dock.css[key];
531 if (value === null) {
535 Y.log('Warning: customise_dock_for_theme has changed. Please update your code.', 'warn', LOGNS);
538 // Damn, they've set something.
539 Y.log('Note for customise_dock_for_theme code: M.core_dock.css.' + key + ' is now CSS.' + key + ' = value',
547 * Initialises the dock node, creating it and its content if required.
550 * @method _initialiseDockNode
551 * @return {Node} The dockNode
553 _initialiseDockNode: function() {
554 var dock = this.get('dockNode'),
555 positionorientationclass = CSS.dock + '_' + this.get('position') + '_' + this.get('orientation'),
556 holdingarea = Y.Node.create('<div></div>').setStyles({display: 'none'}),
557 buttons = this.get('buttonsNode'),
558 container = this.get('itemContainerNode');
561 dock = Y.one('#' + CSS.dock);
564 dock = Y.Node.create('<div id="' + CSS.dock + '"></div>');
567 dock.setAttribute('role', 'menubar').addClass(positionorientationclass);
568 if (Y.all(SELECTOR.dockonload).size() === 0) {
569 // Nothing on the dock... hide it using CSS
570 dock.addClass('nothingdocked');
572 positionorientationclass = CSS.body + '_' + this.get('position') + '_' + this.get('orientation');
573 BODY.addClass(CSS.body).addClass();
577 buttons = dock.one('.' + CSS.buttonscontainer);
580 buttons = Y.Node.create('<div class="' + CSS.buttonscontainer + '"></div>');
581 dock.append(buttons);
585 container = dock.one('.' + CSS.dockeditemcontainer);
588 container = Y.Node.create('<div class="' + CSS.dockeditemcontainer + '"></div>');
589 buttons.append(container);
592 BODY.append(holdingarea);
593 this.holdingareanode = holdingarea;
595 this.set('dockNode', dock);
596 this.set('buttonsNode', buttons);
597 this.set('itemContainerNode', container);
602 * Initialises the dock controls.
605 * @method _initialiseDockControls
607 _initialiseDockControls: function() {
608 // Add a removeall button
609 // Must set the image src seperatly of we get an error with XML strict headers
611 var removeall = Y.Node.create('<img alt="' + M.util.get_string('undockall', 'block') + '" tabindex="0" />');
612 removeall.setAttribute('src', this.get('undockAllIconUrl'));
613 removeall.on('removeall|click', this.removeAll, this);
614 removeall.on('dock:actionkey', this.removeAll, this, {actions: {enter: true}});
615 this.get('buttonsNode').append(Y.Node.create('<div class="' + CSS.controls + '"></div>').append(removeall));
618 * Returns the dock panel. Initialising it if it hasn't already been initialised.
620 * @return {DOCKPANEL}
622 getPanel: function() {
623 var panel = this.get('panel');
625 panel = new DOCKPANEL({dock: this});
626 panel.on('panel:visiblechange', this.resize, this);
627 Y.on('windowresize', this.resize, this);
628 // Initialise the dockpanel .. should only happen once
629 this.set('panel', panel);
630 this.fire('dock:panelgenerated');
635 * Resizes the dock panel if required.
636 * @method resizePanelIfRequired
638 resizePanelIfRequired: function() {
640 var panel = this.get('panel');
642 panel.correctWidth();
646 * Handles a dock event sending it to the right place.
648 * @method handleEvent
649 * @param {EventFacade} e
650 * @param {Object} options
653 handleEvent: function(e, options) {
654 var item = this.getActiveItem(),
657 regex = /^dock_item_(\d+)_title$/,
659 if (options.cssselector === 'body') {
660 if (!this.get('dockNode').contains(e.target)) {
666 if (e.target.test(options.cssselector)) {
669 target = e.target.ancestor(options.cssselector);
674 if (this.preventevent !== null && e.type === this.preventevent) {
677 if (options.preventevent) {
678 this.preventevent = options.preventevent;
679 if (options.preventdelay) {
680 setTimeout(function() {
681 self.preventevent = null;
682 }, options.preventdelay * 1000);
685 if (this.delayedevent && this.delayedevent.timeout) {
686 clearTimeout(this.delayedevent.timeout);
687 this.delayedevent.event.detach();
688 this.delayedevent = null;
690 if (options.delay > 0) {
691 return this.delayEvent(e, options, target);
693 targetid = target.get('id');
694 if (targetid.match(regex)) {
695 item = this.dockeditems[targetid.replace(regex, '$1')];
711 * @param {EventFacade} event
712 * @param {Object} options
713 * @param {Node} target
716 delayEvent: function(event, options, target) {
718 self.delayedevent = (function() {
721 event: BODY.on('mousemove', function(e) {
722 self.delayedevent.target = e.target;
727 self.delayedevent.timeout = setTimeout(function() {
728 self.delayedevent.timeout = null;
729 self.delayedevent.event.detach();
730 if (options.iscontained === self.get('dockNode').contains(self.delayedevent.target)) {
731 self.handleEvent(event, {cssselector: options.cssselector, delay: 0, iscontained: options.iscontained});
733 }, options.delay * 1000);
737 * Resizes block spaces.
738 * @method resizeBlockSpace
740 resizeBlockSpace: function() {
741 if (Y.all(SELECTOR.dockonload).size() > 0) {
742 // Do not resize during initial load
746 var populatedRegionCount = 0,
747 populatedBlockRegions = [],
748 unpopulatedBlockRegions = [],
750 populatedLegacyRegions = [],
751 containsLegacyRegions = false,
753 classesToRemove = [];
755 // First look for understood regions.
756 Y.all(SELECTOR.blockregion).each(function(region) {
757 var regionname = region.getData('blockregion');
758 if (region.all('.block').size() > 0) {
759 populatedBlockRegions.push(regionname);
760 populatedRegionCount++;
761 } else if (region.all('.block_dock_placeholder').size() > 0) {
762 unpopulatedBlockRegions.push(regionname);
766 // Next check for legacy regions.
767 Y.all('.block-region').each(function(region) {
768 if (region.test(SELECTOR.blockregion)) {
769 // This is a new region, we've already processed it.
773 // Sigh - there are legacy regions.
774 containsLegacyRegions = true;
776 var regionname = region.get('id').replace(/^region\-/, 'side-'),
777 hasblocks = (region.all('.block').size() > 0);
780 populatedLegacyRegions.push(regionname);
781 populatedRegionCount++;
783 // This legacy region has no blocks so cannot have the -only body tag.
784 classesToRemove.push(
790 if (BODY.hasClass('blocks-moving')) {
791 // When we're moving blocks, we do not want to collapse.
795 Y.each(unpopulatedBlockRegions, function(regionname) {
797 // This block region is empty.
798 'empty-region-' + regionname,
800 // Which has the same effect as being docked.
801 'docked-region-' + regionname
803 classesToRemove.push(
804 // It is no-longer used.
805 'used-region-' + regionname,
807 // It cannot be the only region on screen if it is empty.
812 Y.each(populatedBlockRegions, function(regionname) {
814 // This block region is in use.
815 'used-region-' + regionname
817 classesToRemove.push(
819 'empty-region-' + regionname,
822 'docked-region-' + regionname
825 if (populatedRegionCount === 1 && isMoving === false) {
826 // There was only one populated region, and we are not moving blocks.
827 classesToAdd.push(regionname + '-only');
829 // There were multiple block regions visible - remove any 'only' classes.
830 classesToRemove.push(regionname + '-only');
834 if (containsLegacyRegions) {
835 // Handle the classing for legacy blocks. These have slightly different class names for the body.
836 if (isMoving || populatedRegionCount !== 1) {
837 Y.each(populatedLegacyRegions, function(regionname) {
838 classesToRemove.push(regionname + '-only');
841 Y.each(populatedLegacyRegions, function(regionname) {
842 classesToAdd.push(regionname + '-only');
847 if (!BODY.hasClass('has-region-content')) {
848 // This page does not have a content region, therefore content-only is implied when all block regions are docked.
849 if (populatedRegionCount === 0 && isMoving === false) {
850 // If all blocks are docked, ensure that the content-only class is added anyway.
851 classesToAdd.push('content-only');
853 // Otherwise remove it.
854 classesToRemove.push('content-only');
858 // Modify the body clases.
859 Y.each(classesToRemove, function(className) {
860 BODY.removeClass(className);
862 Y.each(classesToAdd, function(className) {
863 BODY.addClass(className);
867 * Adds an item to the dock.
869 * @param {DOCKEDITEM} item
871 add: function(item) {
872 // Set the dockitem id to the total count and then increment it.
873 item.set('id', this.totalcount);
874 Y.log('Adding block ' + item._getLogDescription() + ' to the dock.', 'debug', LOGNS);
877 this.dockeditems[item.get('id')] = item;
878 this.dockeditems[item.get('id')].draw();
879 this.fire('dock:itemadded', item);
880 this.fire('dock:itemschanged', item);
883 * Appends an item to the dock (putting it in the item container.
885 * @param {Node} docknode
887 append: function(docknode) {
888 this.get('itemContainerNode').append(docknode);
891 * Handles events that require a docked block to be returned to the page./
892 * @method handleReturnToBlock
893 * @param {EventFacade} e
895 handleReturnToBlock: function(e) {
897 this.remove(this.getActiveItem().get('id'));
900 * Removes a docked item from the dock.
902 * @param {Number} id The docked item id.
905 remove: function(id) {
906 if (!this.dockeditems[id]) {
909 Y.log('Removing block ' + this.dockeditems[id]._getLogDescription() + ' from the dock.', 'debug', LOGNS);
910 this.dockeditems[id].remove();
911 delete this.dockeditems[id];
913 this.fire('dock:itemremoved', id);
914 this.fire('dock:itemschanged', id);
918 * Ensures the the first item in the dock has the correct class.
919 * @method resetFirstItem
921 resetFirstItem: function() {
922 this.get('dockNode').all('.' + CSS.dockeditem + '.firstdockitem').removeClass('firstdockitem');
923 if (this.get('dockNode').one('.' + CSS.dockeditem)) {
924 this.get('dockNode').one('.' + CSS.dockeditem).addClass('firstdockitem');
928 * Removes all docked blocks returning them to the page.
932 removeAll: function() {
933 Y.log('Undocking all ' + this.dockeditems.length + ' blocks', 'debug', LOGNS);
935 for (i in this.dockeditems) {
936 if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) {
943 * Hides the active item.
946 hideActive: function() {
947 var item = this.getActiveItem();
953 * Checks wether the dock should be shown or hidden
954 * @method checkDockVisibility
956 checkDockVisibility: function() {
957 var bodyclass = CSS.body + '_' + this.get('position') + '_' + this.get('orientation');
959 this.get('dockNode').addClass('nothingdocked');
960 BODY.removeClass(CSS.body).removeClass();
961 this.fire('dock:hidden');
963 this.fire('dock:beforeshow');
964 this.get('dockNode').removeClass('nothingdocked');
965 BODY.addClass(CSS.body).addClass(bodyclass);
966 this.fire('dock:shown');
970 * This function checks the size and position of the panel and moves/resizes if
971 * required to keep it within the bounds of the window.
976 var panel = this.getPanel(),
977 item = this.getActiveItem(),
988 if (!panel.get('visible') || !item) {
992 this.fire('dock:panelresizestart');
993 if (this.get('orientation') === 'vertical') {
994 buffer = this.get('bufferPanel');
995 screenh = parseInt(BODY.get('winHeight'), 10) - (buffer * 2);
996 docky = this.get('dockNode').getY();
997 titletop = item.get('dockTitleNode').getY() - docky - buffer;
998 containery = this.get('itemContainerNode').getY();
999 containerheight = containery - docky + this.get('buttonsNode').get('offsetHeight');
1000 scrolltop = panel.get('bodyNode').get('scrollTop');
1001 panel.get('bodyNode').setStyle('height', 'auto');
1002 panel.get('node').removeClass('oversized_content');
1003 panelheight = panel.get('node').get('offsetHeight');
1005 if (Y.UA.ie > 0 && Y.UA.ie < 7) {
1006 panel.setTop(item.get('dockTitleNode').getY());
1007 } else if (panelheight > screenh) {
1008 panel.setTop(buffer - containerheight);
1009 panel.get('bodyNode').setStyle('height', (screenh - panel.get('headerNode').get('offsetHeight')) + 'px');
1010 panel.get('node').addClass('oversized_content');
1011 } else if (panelheight > (screenh - (titletop - buffer))) {
1012 panel.setTop(titletop - containerheight - (panelheight - (screenh - titletop)) + buffer);
1014 panel.setTop(titletop - containerheight + buffer);
1018 panel.get('bodyNode').set('scrollTop', scrolltop);
1022 if (this.get('position') === 'right') {
1023 panel.get('node').setStyle('left', '-' + panel.get('node').get('offsetWidth') + 'px');
1025 } else if (this.get('position') === 'top') {
1026 dockx = this.get('dockNode').getX();
1027 titleleft = item.get('dockTitleNode').getX() - dockx;
1028 panel.get('node').setStyle('left', titleleft + 'px');
1031 this.fire('dock:resizepanelcomplete');
1035 * Returns the currently active dock item or false
1036 * @method getActiveItem
1037 * @return {DOCKEDITEM}
1039 getActiveItem: function() {
1041 for (i in this.dockeditems) {
1042 if (this.dockeditems[i].active) {
1043 return this.dockeditems[i];
1049 * Adds an item to the holding area.
1050 * @method addToHoldingArea
1051 * @param {Node} node
1053 addToHoldingArea: function(node) {
1054 this.holdingareanode.append(node);
1058 Y.extend(DOCK, Y.Base, DOCK.prototype, {
1059 NAME: 'moodle-core-dock',
1062 * The dock itself. #dock.
1063 * @attribute dockNode
1080 * A container within the dock used for buttons.
1081 * @attribute buttonsNode
1089 * A container within the dock used for docked blocks.
1090 * @attribute itemContainerNode
1094 itemContainerNode: {
1099 * Buffer used when containing a panel.
1100 * @attribute bufferPanel
1106 validator: Y.Lang.isNumber
1110 * Position of the dock.
1111 * @attribute position
1117 validator: Y.Lang.isString
1121 * vertical || horizontal determines if we change the title
1122 * @attribute orientation
1128 validator: Y.Lang.isString,
1129 setter: function(value) {
1130 if (value.match(/^vertical$/i)) {
1133 return 'horizontal';
1138 * Space between the top of the dock and the first item.
1139 * @attribute bufferBeforeFirstItem
1143 bufferBeforeFirstItem: {
1145 validator: Y.Lang.isNumber
1149 * Icon URL for the icon to undock all blocks
1150 * @attribute undockAllIconUrl
1152 * @default t/dock_to_block
1155 value: M.util.image_url((window.right_to_left()) ? 't/dock_to_block_rtl' : 't/dock_to_block', 'moodle'),
1156 validator: Y.Lang.isString
1160 Y.augment(DOCK, Y.EventTarget);
1161 /* global DOCKPANEL, LOGNS */
1166 * This file contains the panel class used by the dock to display the content of docked blocks.
1168 * @module moodle-core-dock
1174 * @namespace M.core.dock
1180 DOCKPANEL = function() {
1181 DOCKPANEL.superclass.constructor.apply(this, arguments);
1183 DOCKPANEL.prototype = {
1185 * True once the panel has been created.
1192 * Called during the initialisation process of the object.
1193 * @method initializer
1195 initializer: function() {
1196 Y.log('Panel initialising', 'debug', LOGNS);
1198 * Fired before the panel is shown.
1199 * @event dockpane::beforeshow
1201 this.publish('dockpanel:beforeshow', {prefix: 'dockpanel'});
1203 * Fired after the panel is shown.
1204 * @event dockpanel:shown
1206 this.publish('dockpanel:shown', {prefix: 'dockpanel'});
1208 * Fired before the panel is hidden.
1209 * @event dockpane::beforehide
1211 this.publish('dockpanel:beforehide', {prefix: 'dockpanel'});
1213 * Fired after the panel is hidden.
1214 * @event dockpanel:hidden
1216 this.publish('dockpanel:hidden', {prefix: 'dockpanel'});
1218 * Fired when ever the dock panel is either hidden or shown.
1219 * Always fired after the shown or hidden events.
1220 * @event dockpanel:visiblechange
1222 this.publish('dockpanel:visiblechange', {prefix: 'dockpanel'});
1225 * Creates the Panel if it has not already been created.
1229 create: function() {
1233 this.created = true;
1234 var dock = this.get('dock'),
1235 node = dock.get('dockNode');
1236 this.set('node', Y.Node.create('<div id="dockeditempanel" class="dockitempanel_hidden"></div>'));
1237 this.set('contentNode', Y.Node.create('<div class="dockeditempanel_content"></div>'));
1238 this.set('headerNode', Y.Node.create('<div class="dockeditempanel_hd"></div>'));
1239 this.set('bodyNode', Y.Node.create('<div class="dockeditempanel_bd"></div>'));
1241 this.get('node').append(this.get('contentNode').append(this.get('headerNode')).append(this.get('bodyNode')))
1245 * Displays the panel.
1250 this.fire('dockpanel:beforeshow');
1251 this.set('visible', true);
1252 this.get('node').removeClass('dockitempanel_hidden');
1253 this.fire('dockpanel:shown');
1254 this.fire('dockpanel:visiblechange');
1261 this.fire('dockpanel:beforehide');
1262 this.set('visible', false);
1263 this.get('node').addClass('dockitempanel_hidden');
1264 this.fire('dockpanel:hidden');
1265 this.fire('dockpanel:visiblechange');
1268 * Sets the panel header.
1270 * @param {Node|String} content
1272 setHeader: function(content) {
1274 var header = this.get('headerNode'),
1276 header.setContent(content);
1277 if (arguments.length > 1) {
1278 for (i = 1; i < arguments.length; i++) {
1279 if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) {
1280 header.append(arguments[i]);
1286 * Sets the panel body.
1288 * @param {Node|String} content
1290 setBody: function(content) {
1292 this.get('bodyNode').setContent(content);
1295 * Sets the new top mark of the panel.
1298 * @param {Number} newtop
1300 setTop: function(newtop) {
1301 if (Y.UA.ie > 0 && Y.UA.ie < 7) {
1302 this.get('node').setY(newtop);
1304 this.get('node').setStyle('top', newtop.toString() + 'px');
1308 * Corrects the width of the panel.
1309 * @method correctWidth
1311 correctWidth: function() {
1312 var bodyNode = this.get('bodyNode'),
1313 // Width of content.
1314 width = bodyNode.get('clientWidth'),
1315 // Scrollable width of content.
1316 scroll = bodyNode.get('scrollWidth'),
1317 // Width of content container with overflow.
1318 offsetWidth = bodyNode.get('offsetWidth'),
1319 // The new width - defaults to the current width.
1321 // The max width (80% of screen).
1322 maxWidth = Math.round(bodyNode.get('winWidth') * 0.8);
1324 // If the scrollable width is more than the visible width
1325 if (scroll > width) {
1328 // + any rendering difference (borders, padding)
1329 // + 10px to make it look nice.
1330 newWidth = width + (scroll - width) + ((offsetWidth - width) * 2) + 10;
1333 // Make sure its not more then the maxwidth
1334 if (newWidth > maxWidth) {
1335 newWidth = maxWidth;
1338 // Set the new width if its more than the old width.
1339 if (newWidth > offsetWidth) {
1340 this.get('node').setStyle('width', newWidth + 'px');
1344 Y.extend(DOCKPANEL, Y.Base, DOCKPANEL.prototype, {
1345 NAME: 'moodle-core-dock-panel',
1354 writeOnce: 'initOnly'
1357 * The node that contains the whole panel.
1365 * The node that contains the header, body and footer.
1366 * @attribute contentNode
1373 * The node that contains the header
1374 * @attribute headerNode
1381 * The node that contains the body
1382 * @attribute bodyNode
1389 * True if the panel is currently visible.
1390 * @attribute visible
1398 Y.augment(DOCKPANEL, Y.EventTarget);
1399 /* global TABHEIGHTMANAGER, LOGNS */
1404 * This file contains the tab height manager.
1405 * The tab height manager is responsible for ensure all tabs are visible all the time.
1407 * @module moodle-core-dock
1411 * Tab height manager.
1413 * @namespace M.core.dock
1414 * @class TabHeightManager
1418 TABHEIGHTMANAGER = function() {
1419 TABHEIGHTMANAGER.superclass.constructor.apply(this, arguments);
1421 TABHEIGHTMANAGER.prototype = {
1423 * Initialises the dock sizer which then attaches itself to the required
1424 * events in order to monitor the dock
1425 * @method initializer
1427 initializer: function() {
1428 var dock = this.get('dock');
1429 dock.on('dock:itemschanged', this.checkSizing, this);
1430 Y.on('windowresize', this.checkSizing, this);
1433 * Check if the size dock items needs to be adjusted
1434 * @method checkSizing
1436 checkSizing: function() {
1437 var dock = this.get('dock'),
1438 node = dock.get('dockNode'),
1439 items = dock.dockeditems,
1440 containermargin = parseInt(node.one('.dockeditem_container').getStyle('marginTop').replace('/[^0-9]+$/', ''), 10),
1441 dockheight = node.get('offsetHeight') - containermargin,
1442 controlheight = node.one('.controls').get('offsetHeight'),
1443 buffer = (dock.get('bufferPanel') * 3),
1444 possibleheight = dockheight - controlheight - buffer - (items.length * 2),
1447 if (items.length > 0) {
1449 if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) {
1450 dockedtitle = Y.one(items[id].get('title')).ancestor('.' + CSS.dockedtitle);
1452 if (this.get('enabled')) {
1453 dockedtitle.setStyle('height', 'auto');
1455 totalheight += dockedtitle.get('offsetHeight') || 0;
1459 if (totalheight > possibleheight) {
1460 this.enable(possibleheight);
1465 * Enables the dock sizer and resizes where required.
1467 * @param {Number} possibleheight
1469 enable: function(possibleheight) {
1470 var dock = this.get('dock'),
1471 items = dock.dockeditems,
1475 id, itemtitle, itemheight, offsetheight;
1476 Y.log('Enabling the dock tab sizer.', 'debug', LOGNS);
1477 this.set('enabled', true);
1479 if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) {
1480 itemtitle = Y.one(items[id].get('title')).ancestor('.' + CSS.dockedtitle);
1484 itemheight = Math.floor((possibleheight - usedheight) / (count - runningcount));
1485 offsetheight = itemtitle.get('offsetHeight');
1486 itemtitle.setStyle('overflow', 'hidden');
1487 if (offsetheight > itemheight) {
1488 itemtitle.setStyle('height', itemheight + 'px');
1489 usedheight += itemheight;
1491 usedheight += offsetheight;
1498 Y.extend(TABHEIGHTMANAGER, Y.Base, TABHEIGHTMANAGER.prototype, {
1499 NAME: 'moodle-core-tabheightmanager',
1508 writeOnce: 'initOnly'
1511 * True if the item_sizer is being used, false otherwise.
1512 * @attribute enabled
1523 * This file contains the action key event definition that is used for accessibility handling within the Dock.
1525 * @module moodle-core-dock
1529 * A 'dock:actionkey' Event.
1530 * The event consists of the left arrow, right arrow, enter and space keys.
1531 * More keys can be mapped to action meanings.
1532 * actions: collapse , expand, toggle, enter.
1534 * This event is subscribed to by dockitems.
1535 * The on() method to subscribe allows specifying the desired trigger actions as JSON.
1537 * This event can also be delegated if needed.
1539 * @namespace M.core.dock
1542 Y.Event.define("dock:actionkey", {
1543 // Webkit and IE repeat keydown when you hold down arrow keys.
1544 // Opera links keypress to page scroll; others keydown.
1545 // Firefox prevents page scroll via preventDefault() on either
1546 // keydown or keypress.
1547 _event: (Y.UA.webkit || Y.UA.ie) ? 'keydown' : 'keypress',
1550 * The keys to trigger on.
1557 // (@todo: lrt/rtl/M.core_dock.cfg.orientation decision to assign arrow to meanings)
1563 * Handles key events
1564 * @method _keyHandler
1565 * @param {EventFacade} e
1566 * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
1567 * @param {Object} args
1569 _keyHandler: function(e, notifier, args) {
1571 if (!args.actions) {
1572 actObj = {collapse: true, expand: true, toggle: true, enter: true};
1574 actObj = args.actions;
1576 if (this._keys[e.keyCode] && actObj[this._keys[e.keyCode]]) {
1577 e.action = this._keys[e.keyCode];
1583 * Subscribes to events.
1585 * @param {Node} node The node this subscription was applied to.
1586 * @param {Subscription} sub The object tracking this subscription.
1587 * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
1589 on: function(node, sub, notifier) {
1590 // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions).
1591 if (sub.args === null) {
1593 sub._detacher = node.on(this._event, this._keyHandler, this, notifier, {actions: false});
1595 sub._detacher = node.on(this._event, this._keyHandler, this, notifier, sub.args[0]);
1600 * Detaches an event listener
1602 * @param {Node} node The node this subscription was applied to.
1603 * @param {Subscription} sub The object tracking this subscription.
1604 * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
1606 detach: function(node, sub) {
1607 // detach our _detacher handle of the subscription made in on()
1608 sub._detacher.detach();
1612 * Creates a delegated event listener.
1614 * @param {Node} node The node this subscription was applied to.
1615 * @param {Subscription} sub The object tracking this subscription.
1616 * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
1617 * @param {String|function} filter Selector string or function that accpets an event object and returns null.
1619 delegate: function(node, sub, notifier, filter) {
1620 // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions).
1621 if (sub.args === null) {
1623 sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, {actions: false});
1625 sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, sub.args[0]);
1630 * Detaches a delegated event listener.
1631 * @method detachDelegate
1632 * @param {Node} node The node this subscription was applied to.
1633 * @param {Subscription} sub The object tracking this subscription.
1634 * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers
1635 * @param {String|function} filter Selector string or function that accpets an event object and returns null.
1637 detachDelegate: function(node, sub) {
1638 sub._delegateDetacher.detach();
1641 /* global BLOCK, LOGNS, DOCKEDITEM */
1646 * This file contains the block class used to manage blocks (both docked and not) for the dock.
1648 * @module moodle-core-dock
1654 * @namespace M.core.dock
1659 BLOCK = function() {
1660 BLOCK.superclass.constructor.apply(this, arguments);
1664 * A content place holder used when the block has been docked.
1665 * @property contentplaceholder
1669 contentplaceholder: null,
1671 * The skip link associated with this block.
1672 * @property contentskipanchor
1676 contentskipanchor: null,
1678 * The cached content node for the actual block
1679 * @property cachedcontentnode
1683 cachedcontentnode: null,
1685 * If true the user preference isn't updated
1686 * @property skipsetposition
1690 skipsetposition: true,
1692 * The dock item associated with this block
1693 * @property dockitem
1699 * Called during the initialisation process of the object.
1700 * @method initializer
1702 initializer: function() {
1703 var node = Y.one('#inst' + this.get('id'));
1708 Y.log('Initialised block with instance id:' + this.get('id'), 'debug', LOGNS);
1710 M.core.dock.ensureMoveToIconExists(node);
1712 // Move the block straight to the dock if required
1713 if (node.hasClass(CSS.dockonload)) {
1714 node.removeClass(CSS.dockonload);
1717 this.skipsetposition = false;
1721 * Returns the class associated with this block.
1722 * @method _getBlockClass
1724 * @param {Node} node
1727 _getBlockClass: function(node) {
1728 var block = node.getData('block'),
1731 if (Y.Lang.isString(block) && block !== '') {
1734 classes = node.getAttribute('className').toString();
1735 matches = /(^| )block_([^ ]+)/.exec(classes);
1743 * This function is responsible for moving a block from the page structure onto the dock.
1744 * @method moveToDock
1745 * @param {EventFacade} e
1747 moveToDock: function(e) {
1752 var dock = M.core.dock.get(),
1753 id = this.get('id'),
1754 blockcontent = Y.one('#inst' + id).one('.content'),
1755 icon = (window.right_to_left()) ? 't/dock_to_block_rtl' : 't/dock_to_block',
1756 breakchar = (location.href.match(/\?/)) ? '&' : '?',
1762 if (!blockcontent) {
1766 Y.log('Moving block to the dock:' + this.get('id'), 'debug', LOGNS);
1768 this.recordBlockState();
1770 blocktitle = this.cachedcontentnode.one('.title h2').cloneNode(true);
1772 // Build up the block commands.
1773 // These should not actually added to the DOM.
1774 blockcommands = this.cachedcontentnode.one('.title .commands');
1775 if (blockcommands) {
1776 blockcommands = blockcommands.cloneNode(true);
1778 blockcommands = Y.Node.create('<div class="commands"></div>');
1780 movetoimg = Y.Node.create('<img />').setAttrs({
1781 alt: Y.Escape.html(M.util.get_string('undockitem', 'block')),
1782 title: Y.Escape.html(M.util.get_string('undockblock', 'block', blocktitle.get('innerHTML'))),
1783 src: M.util.image_url(icon, 'moodle')
1785 moveto = Y.Node.create('<a class="moveto customcommand requiresjs"></a>').setAttrs({
1786 href: Y.config.win.location.href + breakchar + 'dock=' + id
1788 moveto.append(movetoimg);
1789 blockcommands.append(moveto.append(movetoimg));
1791 // Create a new dock item for the block
1792 this.dockitem = new DOCKEDITEM({
1795 blockinstanceid: id,
1797 contents: blockcontent,
1798 commands: blockcommands,
1799 blockclass: this._getBlockClass(Y.one('#inst' + id))
1801 // Register an event so that when it is removed we can put it back as a block
1802 dock.add(this.dockitem);
1804 if (!this.skipsetposition) {
1805 // save the users preference
1806 M.util.set_user_preference('docked_block_instance_' + id, 1);
1809 this.set('isDocked', true);
1812 * Records the block state and adds it to the docks holding area.
1813 * @method recordBlockState
1815 recordBlockState: function() {
1816 var id = this.get('id'),
1817 dock = M.core.dock.get(),
1818 node = Y.one('#inst' + id),
1819 skipanchor = node.previous();
1820 // Disable the skip anchor when docking
1821 if (skipanchor.hasClass('skip-block')) {
1822 this.contentskipanchor = skipanchor;
1823 this.contentskipanchor.hide();
1825 this.cachedcontentnode = node;
1826 this.contentplaceholder = Y.Node.create('<div class="block_dock_placeholder"></div>');
1827 node.replace(this.contentplaceholder);
1828 dock.addToHoldingArea(node);
1833 * This function removes a block from the dock and puts it back into the page structure.
1834 * @method returnToPage
1837 returnToPage: function() {
1838 var id = this.get('id');
1840 Y.log('Moving block out of the dock:' + this.get('id'), 'debug', LOGNS);
1842 // Enable the skip anchor when going back to block mode
1843 if (this.contentskipanchor) {
1844 this.contentskipanchor.show();
1847 if (this.cachedcontentnode.one('.header')) {
1848 this.cachedcontentnode.one('.header').insert(this.dockitem.get('contents'), 'after');
1850 this.cachedcontentnode.insert(this.dockitem.get('contents'));
1853 this.contentplaceholder.replace(this.cachedcontentnode);
1854 this.cachedcontentnode = null;
1856 M.util.set_user_preference('docked_block_instance_' + id, 0);
1857 this.set('isDocked', false);
1861 Y.extend(BLOCK, Y.Base, BLOCK.prototype, {
1862 NAME: 'moodle-core-dock-block',
1865 * The block instance ID
1871 writeOnce: 'initOnly',
1872 setter: function(value) {
1873 return parseInt(value, 10);
1877 * True if the block has been docked.
1878 * @attribute isDocked
1887 /* global LOGNS, DOCKEDITEM */
1892 * This file contains the docked item class.
1894 * @module moodle-core-dock
1900 * @namespace M.core.dock
1906 DOCKEDITEM = function() {
1907 DOCKEDITEM.superclass.constructor.apply(this, arguments);
1909 DOCKEDITEM.prototype = {
1911 * Set to true if this item is currently being displayed.
1918 * Called during the initialisation process of the object.
1919 * @method initializer
1921 initializer: function() {
1922 var title = this.get('title'),
1926 * Fired before the docked item has been drawn.
1927 * @event dockeditem:drawstart
1929 this.publish('dockeditem:drawstart', {prefix: 'dockeditem'});
1931 * Fired after the docked item has been drawn.
1932 * @event dockeditem:drawcomplete
1934 this.publish('dockeditem:drawcomplete', {prefix: 'dockeditem'});
1936 * Fired before the docked item is to be shown.
1937 * @event dockeditem:showstart
1939 this.publish('dockeditem:showstart', {prefix: 'dockeditem'});
1941 * Fired after the docked item has been shown.
1942 * @event dockeditem:showcomplete
1944 this.publish('dockeditem:showcomplete', {prefix: 'dockeditem'});
1946 * Fired before the docked item has been hidden.
1947 * @event dockeditem:hidestart
1949 this.publish('dockeditem:hidestart', {prefix: 'dockeditem'});
1951 * Fired after the docked item has been hidden.
1952 * @event dockeditem:hidecomplete
1954 this.publish('dockeditem:hidecomplete', {prefix: 'dockeditem'});
1956 * Fired when the docked item is removed from the dock.
1957 * @event dockeditem:itemremoved
1959 this.publish('dockeditem:itemremoved', {prefix: 'dockeditem'});
1961 type = title.get('nodeName');
1962 titlestring = title.cloneNode(true);
1963 title = Y.Node.create('<' + type + '></' + type + '>');
1964 title = M.core.dock.fixTitleOrientation(title, titlestring.get('text'));
1965 this.set('title', title);
1966 this.set('titlestring', titlestring);
1968 Y.log('Initialised dockeditem for block with title "' + this._getLogDescription(), 'debug', LOGNS);
1971 * This function draws the item on the dock.
1976 var create = Y.Node.create,
1977 dock = this.get('dock'),
1983 id = this.get('id');
1985 this.fire('dockeditem:drawstart');
1987 docktitle = create('<div id="dock_item_' + id + '_title" role="menu" aria-haspopup="true" class="'
1988 + CSS.dockedtitle + '"></div>');
1989 docktitle.append(this.get('title'));
1990 dockitem = create('<div id="dock_item_' + id + '" class="' + CSS.dockeditem + '" tabindex="0" rel="' + id + '"></div>');
1992 dockitem.addClass('firstdockitem');
1994 dockitem.append(docktitle);
1995 dock.append(dockitem);
1997 closeiconimg = create('<img alt="' + M.util.get_string('hidepanel', 'block') +
1998 '" title="' + M.util.get_string('hidedockpanel', 'block') + '" />');
1999 closeiconimg.setAttribute('src', M.util.image_url('t/dockclose', 'moodle'));
2000 closeicon = create('<span class="hidepanelicon" tabindex="0"></span>').append(closeiconimg);
2001 closeicon.on('forceclose|click', this.hide, this);
2002 closeicon.on('dock:actionkey', this.hide, this, {actions: {enter: true, toggle: true}});
2003 this.get('commands').append(closeicon);
2005 this.set('dockTitleNode', docktitle);
2006 this.set('dockItemNode', dockitem);
2008 this.fire('dockeditem:drawcomplete');
2012 * This function toggles makes the item active and shows it.
2017 var dock = this.get('dock'),
2018 panel = dock.getPanel(),
2019 docktitle = this.get('dockTitleNode');
2022 this.fire('dockeditem:showstart');
2023 Y.log('Showing ' + this._getLogDescription(), 'debug', LOGNS);
2024 panel.setHeader(this.get('titlestring'), this.get('commands'));
2025 panel.setBody(Y.Node.create('<div class="block_' + this.get('blockclass') + ' block_docked"></div>')
2026 .append(this.get('contents')));
2027 if (M.core.actionmenu !== undefined) {
2028 M.core.actionmenu.newDOMNode(panel.get('node'));
2031 panel.correctWidth();
2034 // Add active item class first up
2035 docktitle.addClass(CSS.activeitem);
2036 // Set aria-exapanded property to true.
2037 docktitle.set('aria-expanded', "true");
2038 this.fire('dockeditem:showcomplete');
2043 * This function hides the item and makes it inactive.
2047 this.fire('dockeditem:hidestart');
2048 Y.log('Hiding "' + this._getLogDescription(), 'debug', LOGNS);
2051 this.active = false;
2053 this.get('dock').getPanel().hide();
2055 // Remove the active class
2056 // Set aria-exapanded property to false
2057 this.get('dockTitleNode').removeClass(CSS.activeitem).set('aria-expanded', "false");
2058 this.fire('dockeditem:hidecomplete');
2061 * A toggle between calling show and hide functions based on css.activeitem
2062 * Applies rules to key press events (dock:actionkey)
2064 * @param {String} action
2066 toggle: function(action) {
2067 var docktitle = this.get('dockTitleNode');
2068 if (docktitle.hasClass(CSS.activeitem) && action !== 'expand') {
2070 } else if (!docktitle.hasClass(CSS.activeitem) && action !== 'collapse') {
2075 * This function removes the node and destroys it's bits.
2078 remove: function() {
2080 // Return the block to its original position.
2081 this.get('block').returnToPage();
2082 // Remove the dock item node.
2083 this.get('dockItemNode').remove();
2084 this.fire('dockeditem:itemremoved');
2087 * Returns the description of this item to use for log calls.
2088 * @method _getLogDescription
2092 _getLogDescription: function() {
2093 return this.get('titlestring').get('innerHTML') + ' (' + this.get('blockinstanceid') + ')';
2096 Y.extend(DOCKEDITEM, Y.Base, DOCKEDITEM.prototype, {
2097 NAME: 'moodle-core-dock-dockeditem',
2100 * The block this docked item is associated with.
2107 writeOnce: 'initOnly'
2117 writeOnce: 'initOnly'
2120 * The docked item ID. This will be given by the dock.
2126 * Block instance id.Taken from the associated block.
2127 * @attribute blockinstanceid
2132 writeOnce: 'initOnly',
2133 setter: function(value) {
2134 return parseInt(value, 10);
2138 * The title nodeof the docked item.
2148 * @attribute titlestring
2155 * The contents of the docked item
2156 * @attribute contents
2162 writeOnce: 'initOnly'
2165 * Commands associated with the block.
2166 * @attribute commands
2172 writeOnce: 'initOnly'
2176 * @attribute blockclass
2182 writeOnce: 'initOnly'
2185 * The title node for the docked block.
2186 * @attribute dockTitleNode
2193 * The item node for the docked block.
2194 * @attribute dockItemNode
2201 * The container for the docked item (will contain the block contents when visible)
2202 * @attribute dockcontainerNode
2205 dockcontainerNode: {
2210 Y.augment(DOCKEDITEM, Y.EventTarget);
2221 "moodle-core-dock-loader",