1 /* global TABHEIGHTMANAGER, LOGNS */
6 * This file contains the tab height manager.
7 * The tab height manager is responsible for ensure all tabs are visible all the time.
9 * @module moodle-core-dock
15 * @namespace M.core.dock
16 * @class TabHeightManager
20 TABHEIGHTMANAGER = function() {
21 TABHEIGHTMANAGER.superclass.constructor.apply(this, arguments);
23 TABHEIGHTMANAGER.prototype = {
25 * Initialises the dock sizer which then attaches itself to the required
26 * events in order to monitor the dock
29 initializer: function() {
30 var dock = this.get('dock');
31 dock.on('dock:itemschanged', this.checkSizing, this);
32 Y.on('windowresize', this.checkSizing, this);
35 * Check if the size dock items needs to be adjusted
38 checkSizing: function() {
39 var dock = this.get('dock'),
40 node = dock.get('dockNode'),
41 items = dock.dockeditems,
42 containermargin = parseInt(node.one('.dockeditem_container').getStyle('marginTop').replace('/[^0-9]+$/', ''), 10),
43 dockheight = node.get('offsetHeight') - containermargin,
44 controlheight = node.one('.controls').get('offsetHeight'),
45 buffer = (dock.get('bufferPanel') * 3),
46 possibleheight = dockheight - controlheight - buffer - (items.length * 2),
49 if (items.length > 0) {
51 if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) {
52 dockedtitle = Y.one(items[id].get('title')).ancestor('.' + CSS.dockedtitle);
54 if (this.get('enabled')) {
55 dockedtitle.setStyle('height', 'auto');
57 totalheight += dockedtitle.get('offsetHeight') || 0;
61 if (totalheight > possibleheight) {
62 this.enable(possibleheight);
67 * Enables the dock sizer and resizes where required.
69 * @param {Number} possibleheight
71 enable: function(possibleheight) {
72 var dock = this.get('dock'),
73 items = dock.dockeditems,
77 id, itemtitle, itemheight, offsetheight;
78 Y.log('Enabling the dock tab sizer.', 'debug', LOGNS);
79 this.set('enabled', true);
81 if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) {
82 itemtitle = Y.one(items[id].get('title')).ancestor('.' + CSS.dockedtitle);
86 itemheight = Math.floor((possibleheight - usedheight) / (count - runningcount));
87 offsetheight = itemtitle.get('offsetHeight');
88 itemtitle.setStyle('overflow', 'hidden');
89 if (offsetheight > itemheight) {
90 itemtitle.setStyle('height', itemheight + 'px');
91 usedheight += itemheight;
93 usedheight += offsetheight;
100 Y.extend(TABHEIGHTMANAGER, Y.Base, TABHEIGHTMANAGER.prototype, {
101 NAME: 'moodle-core-tabheightmanager',
110 writeOnce: 'initOnly'
113 * True if the item_sizer is being used, false otherwise.