[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/yui/src/dock/js/ -> tabheightmanager.js (source)

   1  /**
   2   * Dock JS.
   3   *
   4   * This file contains the tab height manager.
   5   * The tab height manager is responsible for ensure all tabs are visible all the time.
   6   *
   7   * @module moodle-core-dock
   8   */
   9  
  10  /**
  11   * Tab height manager.
  12   *
  13   * @namespace M.core.dock
  14   * @class TabHeightManager
  15   * @constructor
  16   * @extends Base
  17   */
  18  TABHEIGHTMANAGER = function() {
  19      TABHEIGHTMANAGER.superclass.constructor.apply(this, arguments);
  20  };
  21  TABHEIGHTMANAGER.prototype = {
  22      /**
  23       * Initialises the dock sizer which then attaches itself to the required
  24       * events in order to monitor the dock
  25       * @method initializer
  26       */
  27      initializer : function() {
  28          var dock = this.get('dock');
  29          dock.on('dock:itemschanged', this.checkSizing, this);
  30          Y.on('windowresize', this.checkSizing, this);
  31      },
  32      /**
  33       * Check if the size dock items needs to be adjusted
  34       * @method checkSizing
  35       */
  36      checkSizing : function() {
  37          var dock = this.get('dock'),
  38              node = dock.get('dockNode'),
  39              items = dock.dockeditems,
  40              containermargin = parseInt(node.one('.dockeditem_container').getStyle('marginTop').replace('/[^0-9]+$/', ''), 10),
  41              dockheight = node.get('offsetHeight') - containermargin,
  42              controlheight = node.one('.controls').get('offsetHeight'),
  43              buffer = (dock.get('bufferPanel') * 3),
  44              possibleheight = dockheight - controlheight - buffer - (items.length*2),
  45              totalheight = 0,
  46              id, dockedtitle;
  47          if (items.length > 0) {
  48              for (id in items) {
  49                  if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) {
  50                      dockedtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle);
  51                      if (dockedtitle) {
  52                          if (this.get('enabled')) {
  53                              dockedtitle.setStyle('height', 'auto');
  54                          }
  55                          totalheight += dockedtitle.get('offsetHeight') || 0;
  56                      }
  57                  }
  58              }
  59              if (totalheight > possibleheight) {
  60                  this.enable(possibleheight);
  61              }
  62          }
  63      },
  64      /**
  65       * Enables the dock sizer and resizes where required.
  66       * @method enable
  67       * @param {Number} possibleheight
  68       */
  69      enable : function(possibleheight) {
  70          var dock = this.get('dock'),
  71              items = dock.dockeditems,
  72              count = dock.count,
  73              runningcount = 0,
  74              usedheight = 0,
  75              id, itemtitle, itemheight, offsetheight;
  76          Y.log('Enabling the dock tab sizer.', 'debug', LOGNS);
  77          this.set('enabled', true);
  78          for (id in items) {
  79              if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) {
  80                  itemtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle);
  81                  if (!itemtitle) {
  82                      continue;
  83                  }
  84                  itemheight = Math.floor((possibleheight-usedheight) / (count - runningcount));
  85                  offsetheight = itemtitle.get('offsetHeight');
  86                  itemtitle.setStyle('overflow', 'hidden');
  87                  if (offsetheight > itemheight) {
  88                      itemtitle.setStyle('height', itemheight+'px');
  89                      usedheight += itemheight;
  90                  } else {
  91                      usedheight += offsetheight;
  92                  }
  93                  runningcount++;
  94              }
  95          }
  96      }
  97  };
  98  Y.extend(TABHEIGHTMANAGER, Y.Base, TABHEIGHTMANAGER.prototype, {
  99      NAME : 'moodle-core-tabheightmanager',
 100      ATTRS : {
 101          /**
 102           * The dock.
 103           * @attribute dock
 104           * @type DOCK
 105           * @writeOnce
 106           */
 107          dock : {
 108              writeOnce : 'initOnly'
 109          },
 110          /**
 111           * True if the item_sizer is being used, false otherwise.
 112           * @attribute enabled
 113           * @type Bool
 114           */
 115          enabled : {
 116              value : false
 117          }
 118      }
 119  });


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1