ext.ux.accordion.js
来自「anewssystem新闻发布系统集成使用了spring hibernate f」· JavaScript 代码 · 共 1,863 行 · 第 1/3 页
JS
1,863 行
// position the panel panel.setBox(box); // reset docked flag panel.docked = false; // hide panel shadow (will be shown by raise) if(panel.shadow) { panel.shadow.hide(); } // raise panel above others this.raise(panel); panel.autoSize(); if(panel === this.expanded) { this.expanded = null; } // set the height of a docked expanded panel this.setPanelHeight(this.expanded); // enable resizing and scrolling panel.setResizable(!panel.collapsed); // remember size of the undocked panel panel.lastWidth = box.width;// panel.lastHeight = box.height; // fire panelundock event this.fireEvent('panelundock', panel, {x:box.x, y:box.y, width:box.width, height:box.height});// this.updateOrder(); } return this; } // }}} // {{{ /** * Called internally while dragging * @param {Ext.ux.InfoPanel/String} panel Panel object or id of the panel * @param {String} targetId id of panel after which this panel will be docked * @return {Ext.ux.Accordion} this */ , dock: function(panel, targetId) { // get panel if necessary panel = 'string' === typeof panel ? this.items.get(panel) : panel; // proceed only if we have a docked panel var dockWidth, newTargetId, panelHeight, idx, i, targetPanel; if(panel && !panel.docked) { // find correct target if order is forced if(this.forceOrder) { idx = this.items.indexOf(panel); for(i = idx + 1; i < this.items.getCount(); i++) { targetPanel = this.items.itemAt(i); if(targetPanel.docked) { newTargetId = targetPanel.id; break; } } targetId = newTargetId || this.id; } // remember width and height if(!panel.collapsed) {// panel.lastWidth = panel.el.getWidth();// panel.lastHeight = panel.el.getHeight(); if(!this.independent && this.expanded) { this.expanded.collapse(); } this.expanded = panel; } dockWidth = this.body.getWidth(true); // move the panel element in the dom if(targetId && (this.body.id !== targetId)) { panel.el.insertBefore(Ext.fly(targetId)); } else { panel.el.appendTo(this.body); } // set docked flag panel.docked = true; // adjust panel visuals panel.body.replaceClass('x-dock-panel-body-undocked', 'x-dock-panel-body-docked'); panel.el.applyStyles({ top:'' , left:'' , width:''// , height:'' , 'z-index':'' , position:'relative' , visibility:'' }); panel.body.applyStyles({width: Ext.isIE ? dockWidth + 'px' : '', height:''}); panel.autoSize();// if(!this.fitHeight) {// panelHeight = panel.fixedHeight || panel.maxHeight;// if(panelHeight) {// panel.setHeight(panelHeight);// }// } // disable resizing and shadow panel.setResizable(false); if(panel.shadow) { panel.shadow.hide(); } // set panel height (only if this.fitHeight = true) this.setPanelHeight(panel.collapsed ? this.expanded : panel); // fire paneldock event this.fireEvent('paneldock', panel);// this.updateOrder(); } return this; } // }}} // {{{ /** * Moves panel from this dock (accordion) to another * @param {Ext.ux.InfoPanel} panel Panel to move * @param {Ext.ux.Accordion} targetDock Dock to move to */ , moveToDock: function(panel, targetDock) { this.detach(panel); targetDock.attach(panel); panel.docked = false; targetDock.dock(panel); this.setPanelHeight(); this.updateOrder(); targetDock.updateOrder(); } // }}} // {{{ /** * Sets the independent mode * @param {Boolean} independent set to false for normal mode * @return {Ext.ux.Accordion} this */ , setIndependent: function(independent) { this.independent = independent ? true : false; this.fireEvent('independent', this, independent); return this; } // }}} // {{{ /** * Sets the undockable mode * If undockable === true all undocked panels are docked and collapsed (except pinned) * @param {Boolean} undockable set to true to not allow undocking * @return {Ext.ux.Accordion} this */ , setUndockable: function(undockable) { this.items.each(function(panel) { // dock and collapse (except pinned) all undocked panels if not undockable if(!undockable && !panel.docked) { this.dock(panel); if(!this.independent && !panel.collapsed && !panel.pinned) { panel.collapse(); } } // refresh dragging constraints if(panel.docked && panel.draggable) { panel.dd.constrainTo(this.body, 0, false); panel.dd.clearConstraints(); if(undockable) { panel.constrainToDesktop(); } else { panel.dd.setXConstraint(0,0); } } }, this); // set the flag and fire event this.undockable = undockable; this.fireEvent('undockable', this, undockable); return this; } // }}} // {{{ /** * Sets the shadows for all panels * @param {Boolean} shadow set to false to disable shadows * @return {Ext.ux.Accordion} this */ , setShadow: function(shadow) { this.items.each(function(panel) { panel.useShadow = shadow; panel.setShadow(false); if(!panel.docked) { panel.setShadow(shadow); } }); this.useShadow = shadow; this.fireEvent('useshadow', this, shadow); return this; } // }}}// {{{ /** * Called when user clicks the panel body * @param {Ext.ux.InfoPanel} panel */ , onClickPanelBody: function(panel) { if(!panel.docked) { this.raise(panel); } } // }}} // {{{ /** * Called internally for fixed height docks to get current height of panel(s) */ , getPanelBodyHeight: function() { var titleHeight = 0; this.items.each(function(panel) { titleHeight += panel.docked ? panel.titleEl.getHeight() : 0; }); this.panelBodyHeight = this.body.getHeight() - titleHeight - this.body.getFrameWidth('tb') + 1;// this.panelBodyHeight = this.body.getHeight() - titleHeight - this.body.getFrameWidth('tb'); return this.panelBodyHeight; } // }}} // {{{ /** * Sets the height of panel body * Used with fixed height (fitHeight:true) docs * @param {Ext.ux.InfoPanel} panel (defaults to this.expanded) * @return {Ext.ux.Accordion} this */ , setPanelHeight: function(panel) { panel = panel || this.expanded; if(this.fitHeight && panel && panel.docked) { panel.body.setHeight(this.getPanelBodyHeight()); panel.setHeight(panel.getHeight()); } return this; } // }}} // {{{ /** * Constrains the dragging of panels do the desktop * @return {Ext.ux.Accordion} this */ , constrainToDesktop: function() { this.items.each(function(panel) { panel.constrainToDesktop(); }, this); return this; } // }}} // {{{ /** * Clears dragging constraints of panels * @return {Ext.ux.Accordion} this */ , clearConstraints: function() { this.items.each(function(panel) { panel.dd.clearConstraints(); }); } // }}} // {{{ /** * Shows all panels * @param {Boolean} show (optional) if false hides the panels instead of showing * @param {Boolean} alsoUndocked show also undocked panels (defaults to false) * @return {Ext.ux.Accordion} this */ , showAll: function(show, alsoUndocked) { show = (false === show ? false : true); this.items.each(function(panel) { panel.show(show, alsoUndocked); }); return this; } // }}} , showOther: function(panel, show, alsoPinned) { show = (false === show ? false : true); this.items.each(function(p) { if(p === panel || (p.pinned && !alsoPinned)) { return; } if(show) { p.show(); } else { p.hide(); } }); } , hideOther: function(panel, alsoPinned) { this.showOther(panel, false, alsoPinned); } // {{{ /** * Hides all panels * @param {Boolean} alsoUndocked hide also undocked panels (defaults to false) * @return {Ext.ux.Accordion} this */ , hideAll: function(alsoUndocked) { return this.showAll(false, alsoUndocked); } // }}} // {{{ /** * Called internally to disable/enable scrolling of the dock while animating * @param {Boolean} enable true to enable, false to disable * @return {void} * @todo not used at present - revise */ , setDockScroll: function(enable) { if(enable && !this.fitHeight) { this.body.setStyle('overflow','auto'); } else { this.body.setStyle('overflow','hidden'); } } // }}} // {{{ /** * Set Accordion size * Overrides ContentPanel.setSize * * @param {Integer} w width * @param {Integer} h height * @return {Ext.ux.Accordion} this */ , setSize: function(w, h) { // call parent's setSize Ext.ux.Accordion.superclass.setSize.call(this, w, h);// this.body.setHeight(h); this.setPanelHeight(); return this; } // }}} // {{{ /** * Called as windowResize event handler * * @todo: review */ , adjustViewport: function() { var viewport = this.desktop.dom === document.body ? {} : Ext.get(this.desktop).getBox(); viewport.height = this.desktop === document.body ? window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight : viewport.height ; viewport.width = this.desktop === document.body ? window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth : viewport.width ; viewport.x = this.desktop === document.body ? 0 : viewport.x; viewport.y = this.desktop === document.body ? 0 : viewport.y; this.items.each(function(panel) { if(!panel.docked) { panel.moveToViewport(viewport); } }); } // }}} // {{{ /** * private - called internally to create relay event function * @param {String} ename event name to relay * @return {Function} relay event function */ , createRelay: function(ename) { return function() { return this.fireEvent.apply(this, Ext.combine(ename, Array.prototype.slice.call(arguments, 0))); }; } // }}} // {{{ /** * Array of event names to relay */ , relayedEvents: [ 'beforecollapse' , 'collapse' , 'beforeexpand' , 'expand' , 'animationcompleted' , 'pinned' , 'boxchange' , 'destroy' ] // }}} // {{{ /** * private - called internaly to install event relays on panel * @param {Ext.ux.InfoPanel} panel panel to install events on */ , installRelays: function(panel) { panel.relays = {}; var ename, fn; for(var i = 0; i < this.relayedEvents.length; i++) { ename = this.relayedEvents[i]; fn = this.createRelay(ename); panel.relays[ename] = fn; panel.on(ename, fn, this); } } // }}} // {{{ /** * private - called internaly to remove installed relays * @param {Ext.ux.InfoPanel} panel panel to remove relays from */ , removeRelays: function(panel) { for(var ename in panel.relays) { panel.un(ename, panel.relays[ename], this); } panel.relays = {}; } // }}} // {{{ /** * Removes and destroys panel * @param {String/InfoPanel} panel Panel object or id */ , remove: function(panel) { panel = this.items.get(panel.id || panel); if(panel) { this.detach(panel); panel.destroy(); } } // }}} // {{{ /** * Removes and destroys all panels */ , removeAll: function() { this.items.each(function(panel) { this.remove(panel); }, this); } // }}} // {{{ /** * Destroys Accrodion */ , destroy: function() { this.removeAll(); Ext.ux.Accordion.superclass.destroy.call(this); } // }}}}); // end of extend// {{{// {{{/** * @class Ext.ux.Accordion.DDDock * @constructor * @extends Ext.dd.DDProxy * @param {Ext.ux.InfoPanel} panel Panel the dragging object is created for * @param {String} group Only elements of same group interact * @param {Ext.ux.Accordion} dock Place where panels are docked/undocked */Ext.ux.Accordion.DDDock = function(panel, group, dock) { // call parent constructor Ext.ux.Accordion.DDDock.superclass.constructor.call(this, panel.el.dom, group); // save panel and dock references for use in methods this.panel = panel; this.dock = dock; // drag by grabbing the title only this.setHandleElId(panel.titleEl.id); // move only in the dock if undockable if(false === dock.undockable) { this.setXConstraint(0, 0); } // init internal variables this.lastY = 0; //this.DDM.mode = Ext.dd.DDM.INTERSECT; this.DDM.mode = Ext.dd.DDM.POINT;}; // end of constructor// }}}// extendExt.extend(Ext.ux.Accordion.DDDock, Ext.dd.DDProxy, { // {{{ /** * Default DDProxy startDrag override * Saves some variable for use by other methods * and creates nice dragging proxy (ghost) * * Passed x, y arguments are not used */ startDrag: function(x, y) { this.createIframeMasks(); this.lastMoveTarget = null; // create nice dragging ghost this.createGhost(); // get srcEl (the original) and dragEl (the ghost) var srcEl = Ext.get(this.getEl()); var dragEl = Ext.get(this.getDragEl()); // refresh constraints this.panel.constrainToDesktop(); var dragHeight, rightC, bottomC; if(this.panel.dock.undockable) { if(this.panel.collapsed) { dragHeight = this.panel.titleEl.getHeight(); } else { dragHeight = dragEl.getHeight(); dragHeight = dragHeight <= this.panel.titleEl.getHeight() ? srcEl.getHeight() : dragHeight; } rightC = this.rightConstraint + srcEl.getWidth() - dragEl.getWidth(); bottomC = this.bottomConstraint + srcEl.getHeight() - dragHeight; this.setXConstraint(this.leftConstraint, rightC); this.setYConstraint(this.topConstraint, bottomC); } else { if(this.panel.docked) { this.setXConstraint(0, 0); } } // hide dragEl (will be shown by onDrag) dragEl.hide(); // raise panel's "window" above others if(!this.panel.docked) { this.panel.dock.raise(this.panel); } // hide panel's shadow if any this.panel.setShadow(false); // clear visibility of panel's body (was setup by animations) this.panel.body.dom.style.visibility = ''; // hide source panel if undocked if(!this.panel.docked) {// srcEl.hide(); srcEl.setDisplayed(false); dragEl.show(); } } // end of function startDrag // }}} // {{{ /** * Called internally to create nice dragging proxy (ghost) */ , createGhost: function() { // get variables var srcEl = Ext.get(this.getEl()); var dragEl = Ext.get(this.getDragEl()); var panel = this.panel; var dock = panel.dock; // adjust look of ghost var am = Ext.ux.AccordionManager; dragEl.addClass('x-dock-panel-ghost'); dragEl.applyStyles({border:'1px solid #84a0c4','z-index': am.zindex + am.zindexInc}); // set size of ghost same as original dragEl.setBox(srcEl.getBox()); if(panel.docked) { if(panel.lastWidth && dock.undockable) { dragEl.setWidth(panel.lastWidth); } if(!panel.collapsed && dock.undockable && (panel.lastHeight > panel.titleEl.getHeight())) { dragEl.setHeight(panel.lastHeight); } } // remove unnecessary text nodes from srcEl srcEl.clean(); // setup title var dragTitleEl = Ext.DomHelper.append(dragEl, {tag:'div'}, true); dragTitleEl.update(srcEl.dom.firstChild.innerHTML); dragTitleEl.dom.className = srcEl.dom.firstChild.className;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?