ext.ux.accordion.js
来自「anewssystem新闻发布系统集成使用了spring hibernate f」· JavaScript 代码 · 共 1,863 行 · 第 1/3 页
JS
1,863 行
if(panel.collapsed && Ext.isIE) { dragTitleEl.dom.style.borderBottom = "0"; } } // end of function createGhost // }}} // {{{ /** * Default DDProxy onDragOver override * It is called when dragging over a panel * or over the dock.body DropZone * * @param {Event} e not used * @param {String} targetId id of the target we're over * * Beware: While dragging over docked panels it's called * twice. Once for panel and once for DropZone */ , onDragOver: function(e, targetId) { // get panel element var srcEl = Ext.get(this.getEl()); // get target panel and dock var targetDock = Ext.ux.AccordionManager.get(targetId); var targetPanel = targetDock ? targetDock.items.get(targetId) : this.panel; // setup current target for endDrag if(targetPanel) { this.currentTarget = targetPanel.id; } if(targetDock && !this.currentTarget) { this.currentTarget = targetDock.id; } // landing indicators if(targetPanel && targetPanel.docked && !this.panel.dock.forceOrder) { targetPanel.titleEl.addClass('x-dock-panel-title-dragover'); } if(targetDock) { targetDock.body.addClass('x-dock-body-dragover'); } if(this.panel.docked) { this.panel.titleEl.addClass('x-dock-panel-title-dragover'); } // reorder panels in dock if we're docked too var targetEl; if(targetDock === this.panel.dock && targetPanel && targetPanel.docked && this.panel.docked && !this.panel.dock.forceOrder) { targetEl = targetPanel.el; if(targetPanel.collapsed || this.lastMoveTarget !== targetPanel) { if(this.movingUp) { srcEl.insertBefore(targetEl); this.lastMoveTarget = targetPanel; } else { srcEl.insertAfter(targetEl); this.lastMoveTarget = targetPanel; } } this.DDM.refreshCache(this.groups); } } // end of function onDragOver // }}} // {{{ /** * called internally to attach this.panel to accordion * @param {Ext.ux.Accordion} targetDock the dock to attach the panel to */ , attachToDock: function(targetDock) { if(targetDock && this.panel.dock !== targetDock) { // detach panel this.panel.dock.detach(this.panel); // attach panel targetDock.attach(this.panel); } } // }}} // {{{ /** * Called internally when cursor leaves a drop target * @param {Ext.Event} e * @param {String} targetId id of target we're leaving */ , onDragOut: function(e, targetId) { var targetDock = Ext.ux.AccordionManager.get(targetId); var targetPanel = targetDock ? targetDock.items.get(targetId) : this.panel; if(targetDock) { targetDock.body.removeClass('x-dock-body-dragover'); } if(targetPanel) { targetPanel.titleEl.removeClass('x-dock-panel-title-dragover'); } this.currentTarget = null; } // }}} // {{{ /** * Default DDProxy onDrag override * * It's called while dragging * @param {Event} e used to get coordinates */ , onDrag: function(e) { // get source (original) and proxy (ghost) elements var srcEl = Ext.get(this.getEl()); var dragEl = Ext.get(this.getDragEl()); if(!dragEl.isVisible()) { dragEl.show(); } var y = e.getPageY(); this.movingUp = this.lastY > y; this.lastY = y; } // end of function onDrag // }}} // {{{ /** * Default DDProxy endDrag override * * Called when dragging is finished */ , endDrag: function() { this.destroyIframeMasks(); // get the source (original) and proxy (ghost) elements var srcEl = Ext.get(this.getEl()); var dragEl = Ext.get(this.getDragEl()); srcEl.setDisplayed(true); // get box and hide the ghost var box = dragEl.getBox(); var sourceDock = this.panel.dock; var targetDock = Ext.ux.AccordionManager.get(this.currentTarget); var targetPanel = targetDock ? targetDock.items.get(this.currentTarget) : this.panel; var orderChanged = false; // remove any dragover classes from panel title and dock this.panel.titleEl.removeClass('x-dock-panel-title-dragover'); this.dock.body.removeClass('x-dock-body-dragover'); if(targetDock) { targetDock.items.each(function(panel) { panel.titleEl.removeClass('x-dock-panel-title-dragover'); }); } // undock (docked panel dropped out of dock) if(!this.panel.dock.catchPanels && (this.panel.docked && !this.currentTarget && !targetDock) || (targetPanel && !targetPanel.docked)) { this.dock.undock(this.panel, box); orderChanged = true; } // dock undocked panel else if(!this.panel.docked) { this.attachToDock(targetDock); this.panel.dock.dock(this.panel, this.currentTarget); orderChanged = true; } // do nothing for panel moved over it's own dock // handling has already been done by onDragOver else if(this.panel.docked && (this.panel.dock === targetDock)) { // do nothing on purpose - do not remove orderChanged = true; } // dock panel to another dock else if(this.currentTarget || targetDock) { this.attachToDock(targetDock); if(targetDock) { targetDock.body.removeClass('x-dock-body-dragover'); this.panel.docked = false; targetDock.dock(this.panel, this.currentTarget); } orderChanged = true; } // just free dragging if(!this.panel.docked) { this.panel.setBox(box); // let the state manager know the new panel position this.dock.fireEvent('panelbox', this.panel, {x:box.x, y:box.y, width:box.width, height:box.height}); } // clear the ghost content, hide id and move it off screen dragEl.hide(); dragEl.update(''); dragEl.applyStyles({ top:'-9999px' , left:'-9999px' , height:'0px' , width:'0px' }); if(orderChanged) { sourceDock.updateOrder(); if(targetDock && targetDock !== sourceDock) { targetDock.updateOrder(); } } this.DDM.refreshCache(this.groups); } // end of function endDrag // }}} // {{{ , createIframeMasks: function() { this.destroyIframeMasks(); var masks = []; var iframes = Ext.get(document.body).select('iframe'); iframes.each(function(iframe) { var mask = Ext.DomHelper.append(document.body, {tag:'div'}, true); mask.setBox(iframe.getBox()); masks.push(mask); }); this.iframeMasks = masks; } // }}} // {{{ , destroyIframeMasks: function() { if(!this.iframeMasks || ! this.iframeMasks.length) { return; } for(var i = 0; i < this.iframeMasks.length; i++) { this.iframeMasks[i].remove(); } this.iframeMasks = []; } // }}}});// }}}// {{{/** * Private class for keeping and restoring state of the Accordion */Ext.ux.AccordionStateManager = function() { this.state = { docks:{}, panels:{} };};Ext.ux.AccordionStateManager.prototype = { init: function(provider) { // save state provider this.provider = provider;// var state = provider.get('accjs-state');// if(state) {// this.state = state;// } state = this.state; var am = Ext.ux.AccordionManager; var dockState; // {{{ // docks loop am.each(function(dock) { if(false === dock.keepState) { return; } state.docks[dock.id] = provider.get('accjsd-' + dock.id); dockState = state.docks[dock.id]; if(dockState) { // {{{ // handle docks (accordions) if(dockState) { // {{{ // restore order of panels if(dockState.order) { dock.setOrder(dockState.order); } // }}} // {{{ // restore independent if(undefined !== dockState.independent) { dock.setIndependent(dockState.independent); } // }}} // {{{ // restore undockable if(undefined !== dockState.undockable) { dock.setUndockable(dockState.undockable); } // }}} // {{{ // restore useShadow if(undefined !== dockState.useShadow) { dock.setShadow(dockState.useShadow); } // }}} } // end of if(dockState) // }}} } // install event handlers on docks dock.on({ orderchange: {scope:this, fn:this.onOrderChange} , independent: {scope:this, fn:this.onIndependent} , undockable: {scope:this, fn:this.onUndockable} , useshadow: {scope: this, fn: this.onUseShadow} , panelexpand: {scope: this, fn: this.onPanelCollapse} , panelcollapse: {scope: this, fn: this.onPanelCollapse} , panelpinned: {scope: this, fn: this.onPanelPinned} , paneldock: {scope: this, fn: this.onPanelUnDock} , panelundock: {scope: this, fn: this.onPanelUnDock} , boxchange: {scope: this, fn: this.onPanelUnDock} , panelbox: {scope: this, fn: this.onPanelUnDock} }); }, this); // }}} // {{{ // panels loop am.each(function(dock) { if(!dock.keepState) { return; } // panels within dock loop var panelState; dock.items.each(function(panel) { state.panels[panel.id] = provider.get('accjsp-' + panel.id); panelState = state.panels[panel.id]; if(panelState) { // {{{ // restore docked/undocked state if(undefined !== panelState.docked) { if(!panelState.docked) { if('object' === typeof panelState.box) { panel.docked = true; panel.dock.undock(panel, panelState.box); } } } // }}} // {{{ // restore pinned state if(undefined !== panelState.pinned) { panel.pinned = panelState.pinned; if(panel.pinned) { panel.expand(true); } else { panel.updateVisuals(); } } // }}} // {{{ // restore collapsed/expanded state if(undefined !== panelState.collapsed) { if(panelState.collapsed) { panel.collapsed = false; panel.collapse(true); } else { panel.collapsed = true; panel.expand(true); } } // }}} } }, this); // end of panels within dock loop }, this); // end of docks loop // }}} } // event handlers // {{{ , onOrderChange: function(dock, order) { if(false !== dock.keepState) { this.state.docks[dock.id] = this.state.docks[dock.id] ? this.state.docks[dock.id] : {}; this.state.docks[dock.id].order = order; this.storeDockState(dock); } } // }}} // {{{ , onIndependent: function(dock, independent) { if(false !== dock.keepState) { this.state.docks[dock.id] = this.state.docks[dock.id] ? this.state.docks[dock.id] : {}; this.state.docks[dock.id].independent = independent; this.storeDockState(dock); } } // }}} // {{{ , onUndockable: function(dock, undockable) { if(false !== dock.keepState) { this.state.docks[dock.id] = this.state.docks[dock.id] ? this.state.docks[dock.id] : {}; this.state.docks[dock.id].undockable = undockable; this.storeDockState(dock); } } // }}} // {{{ , onUseShadow: function(dock, shadow) { if(false !== dock.keepState) { this.state.docks[dock.id] = this.state.docks[dock.id] ? this.state.docks[dock.id] : {}; this.state.docks[dock.id].useShadow = shadow; this.storeDockState(dock); } } // }}} // {{{ , onPanelCollapse: function(panel) { if(panel.dock.keepState) { this.state.panels[panel.id] = this.state.panels[panel.id] || {}; this.state.panels[panel.id].collapsed = panel.collapsed; } else { try {delete(this.state.panels[panel.id].collapsed);} catch(e){} } this.storePanelState(panel); } // }}} // {{{ , onPanelPinned: function(panel, pinned) { if(panel.dock.keepState) { this.state.panels[panel.id] = this.state.panels[panel.id] || {}; this.state.panels[panel.id].pinned = pinned; } else { try {delete(this.state.panels[panel.id].pinned);} catch(e){} } this.storePanelState(panel); } // }}} // {{{ , onPanelUnDock: function(panel, box) { if(panel.dock.keepState) { this.state.panels[panel.id] = this.state.panels[panel.id] || {}; this.state.panels[panel.id].docked = panel.docked ? true : false; this.state.panels[panel.id].box = box || null; } else { try {delete(this.state.panels[panel.id].docked);} catch(e){} try {delete(this.state.panels[panel.id].box);} catch(e){} }// console.log('onPanelUnDock: ', + panel.id); this.storePanelState(panel); } // }}} // {{{ , storeDockState: function(dock) { this.provider.set.defer(700, this, ['accjsd-' + dock.id, this.state.docks[dock.id]]); } // }}} // {{{ , storePanelState: function(panel) { this.provider.set.defer(700, this, ['accjsp-' + panel.id, this.state.panels[panel.id]]); } // }}}}; // end of Ext.ux.AccordionManager.prototype// }}}// {{{/** * Singleton to manage multiple accordions * @singleton */Ext.ux.AccordionManager = function() { // collection of accordions var items = new Ext.util.MixedCollection(); // public stuff return { // starting z-index for panels zindex: 9999 // z-index increment (2 as 1 is for shadow) , zindexInc: 2 // {{{ /** * increments (by this.zindexInc) this.zindex and returns new value * @return {Integer} next zindex value */ , getNextZindex: function() { this.zindex += this.zindexInc; return this.zindex; } // }}} // {{{ /** * raises panel above others (in the same desktop) * Maintains z-index stack * @param {Ext.ux.InfoPanel} panel panel to raise * @return {Ext.ux.InfoPanel} panel panel that has been raised */ , raise: function(panel) { items.each(function(dock) { dock.items.each(function(p) { if(p.zindex > panel.zindex) { p.zindex -= this.zindexInc; p.el.applyStyles({'z-index':p.zindex}); if(!p.docked) { p.setShadow(true); } } }, this); }, this); if(panel.zindex !== this.zindex) { panel.zindex = this.zindex; panel.el.applyStyles({'z-index':panel.zindex}); if(panel.desktop.lastChild !== panel.el.dom) { panel.dock.desktop.appendChild(panel.el.dom); } if(!panel.docked) { panel.setShadow(true); } } return panel; } // }}} // {{{ /** * Adds accordion to items * @param {Ext.ux.Accordion} acc accordion to add * @return {Ext.ux.Accordion} added accordion */ , add: function(acc) { items.add(acc.id, acc); return acc; } // }}} // {{{ /** * get accordion by it's id or by id of some ot it's panels * @param {String} key id of accordion or panel * @return {Ext.ux.Accordion} or undefined if not found */ , get: function(key) { var dock = items.get(key); if(!dock) { items.each(function(acc) { if(dock) { return; } var panel = acc.items.get(key); if(panel) { dock = panel.dock; } }); } return dock; } // }}} // {{{ /** * get panel by it's id * @param {String} key id of the panel to get * @return {Ext.ux.InfoPanel} panel found or null */ , getPanel: function(key) { var dock = this.get(key); return dock && dock.items ? this.get(key).items.get(key) : null; } // }}} // {{{ /** * Restores state of dock and panels * @param {Ext.state.Provider} provider (optional) An alternate state provider */ , restoreState: function(provider) { if(!provider) { provider = Ext.state.Manager; } var sm = new Ext.ux.AccordionStateManager(); sm.init(provider); } // }}} , each: function(fn, scope) { items.each(fn, scope); } }; // end of return}();// }}}// end of file
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?