ext.ux.infopanel.js
来自「anewssystem新闻发布系统集成使用了spring hibernate f」· JavaScript 代码 · 共 1,438 行 · 第 1/3 页
JS
1,438 行
*/ , setResizable: function(enable) { if(true !== this.resizable) { return this; } // {{{ // lazy create resizer if(!this.resizer) { // {{{ // create resizer this.resizer = new Ext.Resizable(this.el, { handles: 's w e sw se' , minWidth: this.minWidth || this.tm.getWidth(this.getTitle()) + 56 || 48 , maxWidth: this.maxWidth , minHeight: this.minHeight , maxHeight: this.maxHeight , transparent: true , draggable: false }); // }}} // {{{ // install event handlers this.resizer.on({ beforeresize: { scope:this , fn: function(resizer, e) { var viewport = this.getViewport(); var box = this.getBox(); var pos = resizer.activeHandle.position; // left constraint if(pos.match(/west/)) { resizer.minX = viewport.x + (this.dragPadding.left || 8); } // down constraint var maxH; if(pos.match(/south/)) { resizer.oldMaxHeight = resizer.maxHeight; maxH = viewport.y + viewport.height - box.y - (this.dragPadding.bottom || 8); resizer.maxHeight = maxH < resizer.maxHeight ? maxH : resizer.maxHeight; } // right constraint var maxW; if(pos.match(/east/)) { resizer.oldMaxWidth = resizer.maxWidth; maxW = viewport.x + viewport.width - box.x - (this.dragPadding.right || 10); resizer.maxWidth = maxW < resizer.maxWidth ? maxW : resizer.maxWidth; } }} , resize: { scope: this , fn: function(resizer, width, height, e) { resizer.maxHeight = resizer.oldMaxHeight || resizer.maxHeight; resizer.maxWidth = resizer.oldMaxWidth || resizer.maxWidth; this.setSize(width, height); this.constrainToDesktop(); this.fireEvent('boxchange', this, this.el.getBox()); this.fireEvent('resize', this, width, height); this.lastHeight = height; this.lastWidth = width; }} }); // }}} } // }}} this.resizer.enabled = enable; // this is custom override of Ext.Resizer this.resizer.showHandles(enable); return this; } // }}} // {{{ /** * Called internally to clip passed width and height to viewport * @param {Integer} w width * @param {Integer} h height * @return {Object} {width:safeWidth, height:safeHeight} */ , safeSize: function(w, h) { var viewport = this.getViewport(); var box = this.getBox(); var gap = 0; var safeSize = {width:w, height:h}; safeSize.height = box.y + h + this.dragPadding.bottom + gap > viewport.height + viewport.y ? viewport.height - box.y + viewport.y - this.dragPadding.bottom - gap : safeSize.height ; safeSize.width = box.x + w + this.dragPadding.right + gap > viewport.width + viewport.x ? viewport.width - box.x + viewport.x - this.dragPadding.right - gap : safeSize.width ; return safeSize; } // }}} // {{{ /** * Called internally to get current viewport * @param {Element/HTMLElement/String} desktop Element to get size and position of * @return {Object} viewport {x:x, y:y, width:width, height:height} x and y are page coords */ , getViewport: function(desktop) { desktop = desktop || this.desktop || document.body; var viewport = Ext.get(desktop).getViewSize(); var xy; if(document.body === desktop.dom) { viewport.x = 0; viewport.y = 0; } else { xy = desktop.getXY(); viewport.x = isNaN(xy[0]) ? 0 : xy[0]; viewport.y = isNaN(xy[1]) ? 0 : xy[1]; } return viewport; } // }}} // {{{ /** * Sets the size of the panel. Demanded size is clipped to the viewport * * @param {Integer} w width to set * @param {Integer} h height to set * @return {Ext.ux.InfoPanel} this */ , setSize: function(w, h) { var safeSize = this.safeSize(w, h); this.setWidth(safeSize.width); this.setHeight(safeSize.height); if(Ext.isIE) { this.body.setWidth(safeSize.width); } if(!this.docked) { this.setShadow(true); } } // }}} // {{{ /** * Sets the width of the panel. Demanded width is clipped to the viewport * * @param {Integer} w width to set * @return {Ext.ux.InfoPanel} this */ , setWidth: function(w) { this.el.setWidth(w); this.body.setStyle('width',''); if(!this.docked) { this.setShadow(true); } this.lastWidth = w; return this; } // }}} // {{{ /** * Sets the height of the panel. Demanded height is clipped to the viewport * * @param {Integer} h height to set * @return {Ext.ux.InfoPanel} this */ , setHeight: function(h) { var newH = h - this.getTitleHeight(); var scrollH = newH; if(1 < newH) { if(this.scrollEl !== this.body) { scrollH -= this.toolbar ? this.toolbar.getEl().getHeight() : 0;// scrollH -= 27; scrollH -= this.adjustments[1] || 0; this.scrollEl.setHeight(scrollH); } this.body.setHeight(newH); } else { this.body.setStyle('height',''); } if(!this.docked) { this.setShadow(true); }// this.lastHeight = h; this.el.setStyle('height',''); return this; } // }}} // {{{ /** * Called internally to set x, y, width and height of the panel * * @param {Object} box * @return {Ext.ux.InfoPanel} this */ , setBox: function(box) { this.el.setBox(box); this.moveToViewport(); this.setSize(box.width, box.height); return this; } // }}} // {{{ /** * Called internally to get the box of the panel * * @return {Object} box */ , getBox: function() { return this.el.getBox(); } // }}} // {{{ , autoSize: function() { var width = 0; var height = this.fixedHeight || 0; var dock = this.dock; // docked if(this.docked && this.dock) { if(dock.fitHeight) { height = dock.getPanelBodyHeight() + this.getTitleHeight(); } } // undocked else { // height logic height = this.lastHeight || this.fixedHeight || 0; height = height < this.maxHeight ? height : (this.maxHeight < 9999 ? this.maxHeight : 0); height = (height && height < this.minHeight ) ? this.minHeight : height; this.lastHeight = height ? height : this.lastHeight; } this.setHeight(height); } // }}} // {{{ /** * Turns shadow on/off * Uses lazy creation of the shadow object * @param {Boolean} shadow pass false to hide, true to show the shadow * @return {Ext.ux.InfoPanel} this */ , setShadow: function(shadow) { // if I have shadow but shouldn't use it if(this.shadow && true !== this.useShadow) { this.shadow.hide(); return this; } // if I shouldn't use shadow if(true !== this.useShadow) { return this; } // if I don't have shadow if(!this.shadow) { this.shadow = new Ext.Shadow({mode:this.shadowMode}); } // show or hide var zindex; if(shadow) { this.shadow.show(this.el); // fix the Ext shadow z-index bug zindex = parseInt(this.el.getStyle('z-index'), 10); zindex = isNaN(zindex) ? '' : zindex - 1; this.shadow.el.setStyle('z-index', zindex); } else { this.shadow.hide(); } return this; } // }}} // {{{ /** * Show the panel * @param {Boolean} show (optional) if false hides the panel instead of show * @param {Boolean} alsoUndocked show/hide also undocked panel (defaults to false) * @return {Ext.ux.InfoPanel} this */ , show: function(show, alsoUndocked) { // ignore undocked panels if not forced to if(!this.docked && true !== alsoUndocked) { return this; } show = (false === show ? false : true); if(!this.docked) { this.setShadow(show); } this.el.setStyle('display', show ? '' : 'none'); return this; } // }}} // {{{ /** * Hide the panel * @param {Boolean} alsoUndocked show/hide also undocked panel (defaults to false) * @return {Ext.ux.InfoPanel} this */ , hide: function(alsoUndocked) { this.show(false, alsoUndocked); } // }}} // {{{ /** * Constrains dragging of this panel to desktop boundaries * @param {Element} desktop the panel is to be constrained to * @return {Ext.ux.InfoPanel} this */ , constrainToDesktop: function(desktop) { desktop = desktop || this.desktop; if(desktop && this.dd) { this.dd.constrainTo(desktop, this.dragPadding, false); } return this; } // }}} // {{{ /** * Called internally to move the panel to the viewport. * Also constrains the dragging to the desktop * * @param {Object} viewport (optional) object {x:x, y:y, width:width, height:height} * @return {Ext.ux.InfoPanel} this */ , moveToViewport: function(viewport) { viewport = viewport && !isNaN(viewport.x) ? viewport : this.getViewport(); var box = this.getBox(); var moved = false; var gap = 10; // horizontal if(box.x + box.width + this.dragPadding.right > viewport.x + viewport.width) { moved = true; box.x = viewport.width + viewport.x - box.width - this.dragPadding.right - gap; } if(box.x - this.dragPadding.left < viewport.x) { moved = true; box.x = viewport.x + this.dragPadding.left + gap; } // vertical if(box.y + box.height + this.dragPadding.bottom > viewport.y + viewport.height) { moved = true; box.y = viewport.height + viewport.y - box.height - this.dragPadding.bottom - gap; } if(box.y - this.dragPadding.top < viewport.y) { moved = true; box.y = viewport.y + this.dragPadding.top + gap; } var oldOverflow; if(moved) { // sanity clip box.x = box.x < viewport.x ? viewport.x : box.x; box.y = box.y < viewport.y ? viewport.y : box.y; // prevent scrollbars from appearing this.desktop.oldOverflow = this.desktop.oldOverflow || this.desktop.getStyle('overflow'); this.desktop.setStyle('overflow', 'hidden'); // set position this.el.setXY([box.x, box.y]); // restore overflow this.desktop.setStyle.defer(100, this.desktop, ['overflow', this.desktop.oldOverflow]); if(!this.docked) { this.setShadow(true); } } this.constrainToDesktop(); return this; } // }}} // {{{ /** * destroys the panel */ , destroy: function() { if(this.shadow) { this.shadow.hide(); } if(this.collapsible) { this.collapseBtn.removeAllListeners(); this.titleEl.removeAllListeners(); } if(this.resizer) { this.resizer.destroy(); } if(this.dd) { if(this.proxy) { this.proxy.removeAllListeners(); this.proxy.remove(); } this.dd.unreg(); this.dd = null; } if(this.dock) { this.dock.detach(this); } this.body.removeAllListeners(); // call parent destroy Ext.ux.InfoPanel.superclass.destroy.call(this); this.fireEvent('destroy', this); } // }}}}); // end of extend// {{{// show/hide resizer handles overrideExt.override(Ext.Resizable, { /** * Hide resizer handles */ hideHandles: function() { this.showHandles(false); } // end of function hideHandles /** * Show resizer handles * * @param {Boolean} show (true = show, false = hide) */ , showHandles: function(show) { show = (false === show ? false : true); var pos; for(var p in Ext.Resizable.positions) { pos = Ext.Resizable.positions[p]; if(this[pos]) { this[pos].el.setStyle('display', show ? '' : 'none'); } } } // end of function showHandles// }}}});// end of file
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?