⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 layout.js

📁 很棒的在线教学系统
💻 JS
📖 第 1 页 / 共 5 页
字号:
/*Copyright (c) 2008, Yahoo! Inc. All rights reserved.Code licensed under the BSD License:http://developer.yahoo.net/yui/license.txtversion: 2.6.0*//** * @description <p>Provides a fixed layout containing, top, bottom, left, right and center layout units. It can be applied to either the body or an element.</p> * @namespace YAHOO.widget * @requires yahoo, dom, element, event * @module layout * @beta */(function() {    var Dom = YAHOO.util.Dom,        Event = YAHOO.util.Event,        Lang = YAHOO.lang;    /**     * @constructor     * @class Layout     * @extends YAHOO.util.Element     * @description <p>Provides a fixed layout containing, top, bottom, left, right and center layout units. It can be applied to either the body or an element.</p>     * @param {String/HTMLElement} el The element to make contain a layout.     * @param {Object} attrs Object liternal containing configuration parameters.    */    var Layout = function(el, config) {        if (Lang.isObject(el) && !el.tagName) {            config = el;            el = null;        }        if (Lang.isString(el)) {            if (Dom.get(el)) {                el = Dom.get(el);            }        }        if (!el) {            el = document.body;        }        var oConfig = {            element: el,            attributes: config || {}        };        Layout.superclass.constructor.call(this, oConfig.element, oConfig.attributes);        };    /**    * @private    * @static    * @property _instances    * @description Internal hash table for all layout instances    * @type Object    */     Layout._instances = {};    /**    * @static    * @method getLayoutById     * @description Get's a layout object by the HTML id of the element associated with the Layout object.    * @return {Object} The Layout Object    */     Layout.getLayoutById = function(id) {        if (Layout._instances[id]) {            return Layout._instances[id];        }        return false;    };    YAHOO.extend(Layout, YAHOO.util.Element, {        /**        * @property browser        * @description A modified version of the YAHOO.env.ua object        * @type Object        */        browser: function() {            var b = YAHOO.env.ua;            b.standardsMode = false;            b.secure = false;            return b;        }(),        /**        * @private        * @property _units        * @description An object literal that contains a list of units in the layout        * @type Object        */        _rendered: null,        /**        * @private        * @property _rendered        * @description Set to true when the layout is rendered        * @type Boolean        */        _rendered: null,        /**        * @private        * @property _zIndex        * @description The zIndex to set all LayoutUnits to        * @type Number        */        _zIndex: null,        /**        * @private        * @property _sizes        * @description A collection of the current sizes of all usable LayoutUnits to be used for calculations        * @type Object        */        _sizes: null,        /**        * @private        * @method _setBodySize        * @param {Boolean} set If set to false, it will NOT set the size, just perform the calculations (used for collapsing units)        * @description Used to set the body size of the layout, sets the height and width of the parent container        */        _setBodySize: function(set) {            var h = 0, w = 0;            set = ((set === false) ? false : true);            if (this._isBody) {                h = Dom.getClientHeight();                w = Dom.getClientWidth();            } else {                h = parseInt(this.getStyle('height'), 10);                w = parseInt(this.getStyle('width'), 10);                if (isNaN(w)) {                    w = this.get('element').clientWidth;                }                if (isNaN(h)) {                    h = this.get('element').clientHeight;                }            }            if (this.get('minWidth')) {                if (w < this.get('minWidth')) {                    w = this.get('minWidth');                }            }            if (this.get('minHeight')) {                if (h < this.get('minHeight')) {                    h = this.get('minHeight');                }            }            if (set) {                Dom.setStyle(this._doc, 'height', h + 'px');                Dom.setStyle(this._doc, 'width', w + 'px');            }            this._sizes.doc = { h: h, w: w };            this._setSides(set);        },        /**        * @private        * @method _setSides        * @param {Boolean} set If set to false, it will NOT set the size, just perform the calculations (used for collapsing units)        * @description Used to set the size and position of the left, right, top and bottom units        */        _setSides: function(set) {            var h1 = ((this._units.top) ? this._units.top.get('height') : 0),                h2 = ((this._units.bottom) ? this._units.bottom.get('height') : 0),                h = this._sizes.doc.h,                w = this._sizes.doc.w;            set = ((set === false) ? false : true);            this._sizes.top = {                h: h1, w: ((this._units.top) ? w : 0),                t: 0            };            this._sizes.bottom = {                h: h2, w: ((this._units.bottom) ? w : 0)            };                        var newH = (h - (h1 + h2));            this._sizes.left = {                h: newH, w: ((this._units.left) ? this._units.left.get('width') : 0)            };            this._sizes.right = {                h: newH, w: ((this._units.right) ? this._units.right.get('width') : 0),                l: ((this._units.right) ? (w - this._units.right.get('width')) : 0),                t: ((this._units.top) ? this._sizes.top.h : 0)            };                        if (this._units.right && set) {                this._units.right.set('top', this._sizes.right.t);                if (!this._units.right._collapsing) {                     this._units.right.set('left', this._sizes.right.l);                }                this._units.right.set('height', this._sizes.right.h, true);            }            if (this._units.left) {                this._sizes.left.l = 0;                if (this._units.top) {                    this._sizes.left.t = this._sizes.top.h;                } else {                    this._sizes.left.t = 0;                }                if (set) {                    this._units.left.set('top', this._sizes.left.t);                    this._units.left.set('height', this._sizes.left.h, true);                    this._units.left.set('left', 0);                }            }            if (this._units.bottom) {                this._sizes.bottom.t = this._sizes.top.h + this._sizes.left.h;                if (set) {                    this._units.bottom.set('top', this._sizes.bottom.t);                    this._units.bottom.set('width', this._sizes.bottom.w, true);                }            }            if (this._units.top) {                if (set) {                    this._units.top.set('width', this._sizes.top.w, true);                }            }            this._setCenter(set);        },        /**        * @private        * @method _setCenter        * @param {Boolean} set If set to false, it will NOT set the size, just perform the calculations (used for collapsing units)        * @description Used to set the size and position of the center unit        */        _setCenter: function(set) {            set = ((set === false) ? false : true);            var h = this._sizes.left.h;            var w = (this._sizes.doc.w - (this._sizes.left.w + this._sizes.right.w));            if (set) {                this._units.center.set('height', h, true);                this._units.center.set('width', w, true);                this._units.center.set('top', this._sizes.top.h);                this._units.center.set('left', this._sizes.left.w);            }            this._sizes.center = { h: h, w: w, t: this._sizes.top.h, l: this._sizes.left.w };        },        /**        * @method getSizes        * @description Get a reference to the internal Layout Unit sizes object used to build the layout wireframe        * @return {Object} An object of the layout unit sizes        */        getSizes: function() {            return this._sizes;        },        /**        * @method getUnitById        * @param {String} id The HTML element id of the unit        * @description Get the LayoutUnit by it's HTML id        * @return {<a href="YAHOO.widget.LayoutUnit.html">YAHOO.widget.LayoutUnit</a>} The LayoutUnit instance        */        getUnitById: function(id) {            return YAHOO.widget.LayoutUnit.getLayoutUnitById(id);        },        /**        * @method getUnitByPosition        * @param {String} pos The position of the unit in this layout        * @description Get the LayoutUnit by it's position in this layout        * @return {<a href="YAHOO.widget.LayoutUnit.html">YAHOO.widget.LayoutUnit</a>} The LayoutUnit instance        */        getUnitByPosition: function(pos) {            if (pos) {                pos = pos.toLowerCase();                if (this._units[pos]) {                    return this._units[pos];                }                return false;            }            return false;        },        /**        * @method removeUnit        * @param {Object} unit The LayoutUnit that you want to remove        * @description Remove the unit from this layout and resize the layout.        */        removeUnit: function(unit) {            delete this._units[unit.get('position')];            this.resize();        },        /**        * @method addUnit        * @param {Object} cfg The config for the LayoutUnit that you want to add        * @description Add a unit to this layout and if the layout is rendered, resize the layout.         * @return {<a href="YAHOO.widget.LayoutUnit.html">YAHOO.widget.LayoutUnit</a>} The LayoutUnit instance        */        addUnit: function(cfg) {            if (!cfg.position) {                return false;            }            if (this._units[cfg.position]) {                return false;            }            var element = null,                el = null;            if (cfg.id) {                if (Dom.get(cfg.id)) {                    element = Dom.get(cfg.id);                    delete cfg.id;                }            }            if (cfg.element) {                element = cfg.element;            }            if (!el) {                el = document.createElement('div');                var id = Dom.generateId();                el.id = id;            }            if (!element) {                element = document.createElement('div');            }            Dom.addClass(element, 'yui-layout-wrap');            if (this.browser.ie && !this.browser.standardsMode) {                el.style.zoom = 1;                element.style.zoom = 1;            }            if (el.firstChild) {                el.insertBefore(element, el.firstChild);            } else {                el.appendChild(element);            }            this._doc.appendChild(el);            var h = false, w = false;            if (cfg.height) {                h = parseInt(cfg.height, 10);            }            if (cfg.width) {                w = parseInt(cfg.width, 10);            }            var unitConfig = {};            YAHOO.lang.augmentObject(unitConfig, cfg); // break obj ref            unitConfig.parent = this;            unitConfig.wrap = element;            unitConfig.height = h;            unitConfig.width = w;            var unit = new YAHOO.widget.LayoutUnit(el, unitConfig);            unit.on('heightChange', this.resize, this, true);            unit.on('widthChange', this.resize, this, true);            unit.on('gutterChange', this.resize, this, true);            this._units[cfg.position] = unit;            if (this._rendered) {                this.resize();            }            return unit;        },        /**        * @private        * @method _createUnits        * @description Private method to create units from the config that was passed in.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -