📄 layout.js
字号:
/** * @property STR_CLOSE * @description String used for close button title * @type {String} */ STR_CLOSE: 'Click to close this pane.', /** * @property STR_COLLAPSE * @description String used for collapse button title * @type {String} */ STR_COLLAPSE: 'Click to collapse this pane.', /** * @property STR_EXPAND * @description String used for expand button title * @type {String} */ STR_EXPAND: 'Click to expand this pane.', /** * The class name applied to dynamic tabs while loading. * @property LOADING_CLASSNAME * @type String * @default "disabled" */ LOADING_CLASSNAME: 'loading', /** * @property browser * @description A modified version of the YAHOO.env.ua object * @type Object */ browser: null, /** * @private * @property _sizes * @description A collection of the current sizes of the contents of this Layout Unit * @type Object */ _sizes: null, /** * @private * @property _anim * @description A reference to the Animation instance used by this LayouUnit * @type YAHOO.util.Anim */ _anim: null, /** * @private * @property _resize * @description A reference to the Resize instance used by this LayoutUnit * @type YAHOO.util.Resize */ _resize: null, /** * @private * @property _clip * @description A reference to the clip element used when collapsing the unit * @type HTMLElement */ _clip: null, /** * @private * @property _gutter * @description A simple hash table used to store the gutter to apply to the Unit * @type Object */ _gutter: null, /** * @property header * @description A reference to the HTML element used for the Header * @type HTMLELement */ header: null, /** * @property body * @description A reference to the HTML element used for the body * @type HTMLElement */ body: null, /** * @property footer * @description A reference to the HTML element used for the footer * @type HTMLElement */ footer: null, /** * @private * @property _collapsed * @description Flag to determine if the unit is collapsed or not. * @type Boolean */ _collapsed: null, /** * @private * @property _collapsing * @description A flag set while the unit is being collapsed, used so we don't fire events while animating the size * @type Boolean */ _collapsing: null, /** * @private * @property _lastWidth * @description A holder for the last known width of the unit * @type Number */ _lastWidth: null, /** * @private * @property _lastHeight * @description A holder for the last known height of the unit * @type Number */ _lastHeight: null, /** * @private * @property _lastTop * @description A holder for the last known top of the unit * @type Number */ _lastTop: null, /** * @private * @property _lastLeft * @description A holder for the last known left of the unit * @type Number */ _lastLeft: null, /** * @private * @property _lastScroll * @description A holder for the last known scroll state of the unit * @type Boolean */ _lastScroll: null, /** * @private * @property _lastCenetrScroll * @description A holder for the last known scroll state of the center unit * @type Boolean */ _lastCenterScroll: null, /** * @private * @property _lastScrollTop * @description A holder for the last known scrollTop state of the unit * @type Number */ _lastScrollTop: null, /** * @method resize * @description Resize either the unit or it's clipped state, also updating the box inside * @param {Boolean} force This will force full calculations even when the unit is collapsed * @return {<a href="YAHOO.widget.LayoutUnit.html">YAHOO.widget.LayoutUnit</a>} The LayoutUnit instance */ resize: function(force) { var retVal = this.fireEvent('beforeResize'); if (retVal === false) { return this; } if (!this._collapsing || (force === true)) { var scroll = this.get('scroll'); this.set('scroll', false); var hd = this._getBoxSize(this.header), ft = this._getBoxSize(this.footer), box = [this.get('height'), this.get('width')]; var nh = (box[0] - hd[0] - ft[0]) - (this._gutter.top + this._gutter.bottom), nw = box[1] - (this._gutter.left + this._gutter.right); var wrapH = (nh + (hd[0] + ft[0])), wrapW = nw; if (this._collapsed && !this._collapsing) { this._setHeight(this._clip, wrapH); this._setWidth(this._clip, wrapW); Dom.setStyle(this._clip, 'top', this.get('top') + this._gutter.top + 'px'); Dom.setStyle(this._clip, 'left', this.get('left') + this._gutter.left + 'px'); } else if (!this._collapsed || (this._collapsed && this._collapsing)) { wrapH = this._setHeight(this.get('wrap'), wrapH); wrapW = this._setWidth(this.get('wrap'), wrapW); this._sizes.wrap.h = wrapH; this._sizes.wrap.w = wrapW; Dom.setStyle(this.get('wrap'), 'top', this._gutter.top + 'px'); Dom.setStyle(this.get('wrap'), 'left', this._gutter.left + 'px'); this._sizes.header.w = this._setWidth(this.header, wrapW); this._sizes.header.h = hd[0]; this._sizes.footer.w = this._setWidth(this.footer, wrapW); this._sizes.footer.h = ft[0]; Dom.setStyle(this.footer, 'bottom', '0px'); this._sizes.body.h = this._setHeight(this.body, (wrapH - (hd[0] + ft[0]))); this._sizes.body.w =this._setWidth(this.body, wrapW); Dom.setStyle(this.body, 'top', hd[0] + 'px'); this.set('scroll', scroll); this.fireEvent('resize'); } } return this; }, /** * @private * @method _setWidth * @description Sets the width of the element based on the border size of the element. * @param {HTMLElement} el The HTMLElement to have it's width set * @param {Number} w The width that you want it the element set to * @return {Number} The new width, fixed for borders and IE QuirksMode */ _setWidth: function(el, w) { if (el) { var b = this._getBorderSizes(el); w = (w - (b[1] + b[3])); w = this._fixQuirks(el, w, 'w'); Dom.setStyle(el, 'width', w + 'px'); } return w; }, /** * @private * @method _setHeight * @description Sets the height of the element based on the border size of the element. * @param {HTMLElement} el The HTMLElement to have it's height set * @param {Number} h The height that you want it the element set to * @return {Number} The new height, fixed for borders and IE QuirksMode */ _setHeight: function(el, h) { if (el) { var b = this._getBorderSizes(el); h = (h - (b[0] + b[2])); h = this._fixQuirks(el, h, 'h'); Dom.setStyle(el, 'height', h + 'px'); } return h; }, /** * @private * @method _fixQuirks * @description Fixes the box calculations for IE in QuirksMode * @param {HTMLElement} el The HTMLElement to set the dimension on * @param {Number} dim The number of the dimension to fix * @param {String} side The dimension (h or w) to fix. Defaults to h * @return {Number} The fixed dimension */ _fixQuirks: function(el, dim, side) { var i1 = 0, i2 = 2; if (side == 'w') { i1 = 1; i2 = 3; } if (this.browser.ie && !this.browser.standardsMode) { //Internet Explorer - Quirks Mode var b = this._getBorderSizes(el), bp = this._getBorderSizes(el.parentNode); if ((b[i1] === 0) && (b[i2] === 0)) { //No Borders, check parent if ((bp[i1] !== 0) && (bp[i2] !== 0)) { //Parent has Borders dim = (dim - (bp[i1] + bp[i2])); } } else { if ((bp[i1] === 0) && (bp[i2] === 0)) { dim = (dim + (b[i1] + b[i2])); } } } return dim; }, /** * @private * @method _getBoxSize * @description Get's the elements clientHeight and clientWidth plus the size of the borders * @param {HTMLElement} el The HTMLElement to get the size of * @return {Array} An array of height and width */ _getBoxSize: function(el) { var size = [0, 0]; if (el) { if (this.browser.ie && !this.browser.standardsMode) { el.style.zoom = 1; } var b = this._getBorderSizes(el); size[0] = el.clientHeight + (b[0] + b[2]); size[1] = el.clientWidth + (b[1] + b[3]); } return size; }, /** * @private * @method _getBorderSizes * @description Get the CSS border size of the element passed. * @param {HTMLElement} el The element to get the border size of * @return {Array} An array of the top, right, bottom, left borders. */ _getBorderSizes: function(el) { var s = []; el = el || this.get('element'); if (this.browser.ie && !this.browser.standardsMode) { el.style.zoom = 1; } s[0] = parseInt(Dom.getStyle(el, 'borderTopWidth'), 10); s[1] = parseInt(Dom.getStyle(el, 'borderRightWidth'), 10); s[2] = parseInt(Dom.getStyle(el, 'borderBottomWidth'), 10); s[3] = parseInt(Dom.getStyle(el, 'borderLeftWidth'), 10); //IE will return NaN on these if they are set to auto, we'll set them to 0 for (var i = 0; i < s.length; i++) { if (isNaN(s[i])) { s[i] = 0; } } return s; }, /** * @private * @method _createClip * @description Create the clip element used when the Unit is collapsed */ _createClip: function() { if (!this._clip) { this._clip = document.createElement('div'); this._clip.className = 'yui-layout-clip yui-layout-clip-' + this.get('position'); this._clip.innerHTML = '<div class="collapse"></div>'; var c = this._clip.firstChild; c.title = this.STR_EXPAND; Event.on(c, 'click', this.expand, this, true); this.get('element').parentNode.appendChild(this._clip); } }, /** * @private * @method _toggleClip * @description Toggle th current state of the Clip element and set it's height, width and position */ _toggleClip: function() { if (!this._collapsed) { //show var hd = this._getBoxSize(this.header), ft = this._getBoxSize(this.footer), box = [this.get('height'), this.get('width')]; var nh = (box[0] - hd[0] - ft[0]) - (this._gutter.top + this._gutter.bottom), nw = box[1] - (this._gutter.left + this._gutter.right), wrapH = (nh + (hd[0] + ft[0])); switch (this.get('position')) { case 'top': case 'bottom': this._setWidth(this._clip, nw); this._setHeight(this._clip, this.get('collapseSize')); Dom.setStyle(this._clip, 'left', (this._lastLeft + this._gutter.left) + 'px'); if (this.get('position') == 'bottom') { Dom.setStyle(this._clip, 'top', ((this._lastTop + this._lastHeight) - (this.get('collapseSize') - this._gutter.top)) + 'px'); } else { Dom.setStyle(this._clip, 'top', this.get('top') + this._gutter.top + 'px');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -