📄 brocade.js
字号:
bc.w.Panel = Class.create();
bc.w.Panel.Base = function(){}; bc.w.Panel.Base.prototype=Object.extend(new bc.w.Component(),{ version: '0.1.000', type:"bc.w.Panel", initialize: function(id,options) { this.paint(id,options); this._cc(); this.dragListener = this.drag.bindAsEventListener(this); this.dropListener = this.drop.bindAsEventListener(this); this.moveListener = this.move.bindAsEventListener(this); this.dragMaskListener = this.dragMask.bindAsEventListener(this); if(options.dragable){ Position.absolutize(this._e); this._e.setAttribute('tabindex','-1'); this.fixIE(); if(this.mask)this._e.style.zIndex = this.mask.style.zIndex + 1; Event.observe(this._e,"focus",function(e){ this._cacheZIdx = this._e.style.zIndex; this._e.style.zIndex = 99999; if(this.mask)this.mask.style.zIndex = 99997; }.bindAsEventListener(this)); Event.observe(this._e,"blur",function(e){ this._e.style.zIndex=this._cacheZIdx; if(this.mask)this.mask.style.zIndex=this._cacheZIdx-1; }.bindAsEventListener(this)); Event.observe(this._titleBar._e,"mousedown",this.dragListener); } }, _cc:function(){ if(null!=this._e){ var _cacheCnt=new Array(); for(var i=0,length=this._e.childNodes.length;i < length;i++){ var _fe=this._e.childNodes[i]; if(_fe.nodeName=='#text') continue; _cacheCnt.push(_fe); } Element.cleanWhitespace(this._e); } this._titleBar = new bc.w.Container("pltbc:"+this.id,{parent:this._e}); this.content = new bc.w.Container("plcnt:"+this.id,{parent:this._e}); if(null!=_cacheCnt){ for(var i=0,length=_cacheCnt.length;i<length;i++){ this.content.addChild(_cacheCnt[i]); } } }, drag:function(evt){ Event.observe(document,"selectstart",this.dragMaskListener); evt = evt||event||window.event; this._dragObj = evt.target?evt.target : evt.srcElement; var bt = ":btx"; if(this._dragObj.id.lastIndexOf(bt)!=-1 || this._dragObj.parentNode.id.lastIndexOf(bt)!=-1) return; this._dragObj.style.cursor="move"; this.drag = true; if(this._e.focus) this._e.focus(); this.offsetX = Event.pointerX(evt) - parseInt(this.getStyle("left")||"0"); this.offsetY = Event.pointerY(evt) - parseInt(this.getStyle("top")||"0"); Event.observe(document,"mouseup",this.dropListener); Event.observe(document,"mousemove",this.moveListener); Event.stop(evt); }, dragMask:function(evt){ return false; }, drop:function(evt){ evt = evt||event||window.event; this._dragObj.style.cursor=""; this.drag = false; Event.stopObserving(document,"mouseup",this.dropListener); Event.stopObserving(document,"mousemove",this.moveListener); Event.stopObserving(document,"selectstart",this.dragMaskListener); if(this.onDrop) this.onDrop(evt); }, move:function(evt){ evt = evt||event||window.event; if(!this.drag) return; var l = Event.pointerX(evt) - this.offsetX; var t = Event.pointerY(evt) - this.offsetY; if(this.parent){ var ps = Element.getDimensions(this.parent); var real = Position.cumulativeOffset(this.parent); this.size = this.getDimensions(); if(l <= real[0]) l = real[0]; if(l >= real[0]+(ps.width-this.size.width)) l = real[0]+(ps.width-this.size.width); if(t <= real[1]) t = real[1]; if(t >= (real[1] + ps.height - this.size.height)) t = real[1] + ps.height - this.size.height; } this.setStyle({left:l+"px",top:t+"px"}); if(this.mask)Position.clone(this._e,this.mask); }, setContent:function(c){ this.content.setContent(c); }, addChild : function (child) { this.content.addChild(child); return child; }, setTitleBar : function (tbr) { if(typeof tbr == "object"){ if(tbr instanceof bc.w.TitleBar){ tbr.pContainer = this; this.titleBar = tbr; } this._titleBar.addChild(tbr); this.onResize(); }else{ this.setTitle(tbr); } }, setTitle: function(title){ if(this.titleBar) this.titleBar.setTitle(title); else this._titleBar.setContent(title); }, min:function(){ if(this.content.isShow()){ this.oldh=this.style.height; this.content.hide(); this.style.height=""; }else{ this.content.show(); } if(this.mask)Position.clone(this._e,this.mask); }, onResize:function(e){ if(!this.isMax){ this._csize=Element.getDimensions(this.content._e); }else{ this.content.setStyle({ height:this._csize['height']+"px" }); } var a=this._getBdr(this._e); var b=this._getPdg(this._e); var c=this._getWsp(this.content._e); var d=this._getWsp(this.titleBar._e); var s=this.getDimensions(this._e); var h=Element.getHeight(this.titleBar._e); var fixw=b[0]+b[0]+c[0]; var fixh=b[1]+c[1]+h+d[1]; if(!this.isFixIE){ fixw += a[0]; fixh += a[1]; } this.content.setStyle({ top:'0px', left:'0px', height:s["height"]-fixh +"px" }); if(this.mask)Position.clone(this._e,this.mask); } }); bc.w.Panel.prototype = Object.extend(bc.w.Panel.Base.prototype,{});
bc.w.TitleBar = Class.create(); bc.w.TitleBar.prototype=Object.extend(new bc.w.Component(),{ version: '0.1.000', type:"bc.w.TitleBar", initialize: function(t,o) { this.paint(this.type+":"+this.hashCode(t),o); var buttonBox = document.createElement("div"); buttonBox.id = this.id+":btx"; Element.setStyle(buttonBox,{cssFloat:'right',styleFloat:'right',padding:'0px 5px 0px 0px'}); this.addChild(buttonBox); var titleBox = document.createElement("div"); Element.setStyle(titleBox,{clear:'left',fontWeight:'bold',padding:'0px 5px 0px 5px'}); this.addChild(titleBox); if(o.icon){ var icon = document.createElement("img"); icon.src = o.icon; titleBox.appendChild(icon); } this.title = document.createElement("label"); this.title.style.marginLeft = '5px'; this.title.innerHTML = t; titleBox.appendChild(this.title); var btstyle = {marginLeft:'2px',cursor:'pointer'}; if(this.isFixIE) btstyle.cursor = "hand"; if(o.minIcon){ var minBt = document.createElement("img"); minBt.src = o.minIcon; Element.setStyle(minBt,btstyle); minBt.title = o.minTitle || 'minimize'; buttonBox.appendChild(minBt); Event.observe(minBt,"click",function(e){ if(this._mx)return; if(this._mi){ this._mi=false; minBt.title=o.minTitle || 'minimize'; minBt.src=o.minIcon; }else{ this._mi=true; minBt.title= o.restoreTitle || "restore"; if(o.restoreIcon) minBt.src=o.restoreIcon; } this.pContainer.min(); }.bindAsEventListener(this)); } if(o.maxIcon){ var maxBt = document.createElement("img"); maxBt.src = o.maxIcon; Element.setStyle(maxBt,btstyle); maxBt.title = o.maxTitle || "maximize"; buttonBox.appendChild(maxBt); Event.observe(maxBt,"click",function(e){ if(this._mi) return; if(this._mx){ this._mx=false; maxBt.title= o.maxTitle || "maximize"; maxBt.src=o.maxIcon; }else{ this._mx=true; maxBt.title = o.restoreTitle || "restore"; if(o.restoreIcon) maxBt.src=o.restoreIcon; } this.pContainer.max(); }.bindAsEventListener(this)); } if(o.closeIcon){ var closeBt = document.createElement("img"); closeBt.src = o.closeIcon; Element.setStyle(closeBt,btstyle); closeBt.title = o.closeTitle || "Close ..."; buttonBox.appendChild(closeBt); Event.observe(closeBt,"click",function(event){ if(this.pContainer.onClose) if(!this.pContainer.onClose())return; if(this.pContainer.stopAutoRefresh)this.pContainer.stopAutoRefresh(); this.pContainer.remove(); }.bindAsEventListener(this)); }
this.addBtxClass=function(c){Element.addClassName(this.buttonBox,c);};
this.addTitleClass=function(c){Element.addClassName(this.title,c);}; }, setTitle:function(t){ this.title.innerHTML=t; } });
bc.a.Panel = Class.create(); bc.a.Panel.prototype = Object.extend(Object.extend(new bc.w.Panel.Base(),bc.a.Base.prototype),{ version: '0.1.000', type:"bc.a.Panel", initialize: function(id,o) { this.paint(id,o); this._cc(); this.setOptions(o) }, catchFormSubmit:function(f){ if(f){ Event.observe($(f),"submit",this.onSubmit.bindAsEventListener(this),false); return; } var fs = (this.content._e).getElementsByTagName("FORM"); if(null == fs)return; for(var i=0;i<fs.length;i++){ Event.observe(fs[i],"submit",this.onSubmit.bindAsEventListener(this),false); } }, decatchFormSubmit:function(f){ if(f){ Event.stopObserving($(f),"submit",this.onSubmit.bindAsEventListener(this),false); return; } var fs = (this.content._e).getElementsByTagName("FORM"); if(null == fs)return; for(var i=0;i<fs.length;i++){ Event.stopObserving(fs[i],"submit",this.onSubmit.bindAsEventListener(this),false); } }, onSubmit:function(evt){ this.elem = evt.target?evt.target : evt.srcElement; this.url=this.elem.action; if(this._vl){ for(var i=0;i < this._vl.length;i++){ if(!this._vl[i](this.elem)){ Event.stop(evt); return false; } } } if(null != this.elem){ if(this.options.preFunction) if(!this.options.preFunction()) return ; this.reqType = 'text'; this.options.form = this.elem; this.sendUpdateRequest(this.elem.target||this.content._e); } Event.stop(evt); return false; }, handler:function(r){ if(this.options.postFunction) this.options.postFunction(r); this.catchFormSubmit(); this.ri(false); }, error:function(n,e) { this.content.setContent("<b>Error: </b>"+n+"<br>"+e); this.ri(false); }, addValidator:function(v){ if(!this._vl)this._vl = []; this._vl.push(v); }, removeValidator:function(){ this._vl.clear(); }, load:function(url,o){ this.url = url; Object.extend(this.options,o); this.sendUpdateRequest(this.content._e); }, indicator:function(b){ if(b && this.elem && typeof this.elem.target=="object"){ alert("All of the fields in the form do'nt named \"target\",the indicate failured."); return true; } if(this.options.indicator){ this.options.indicator(b,((this.elem!=null?this.elem.target:null)||this.content._e)); }else if(b){ ((this.elem!=null?this.elem.target:null)||this.content._e).innerHTML=" Lodding..."; } } });
bc.w.TabBase = function(){}; bc.w.TabBase.prototype = Object.extend(new bc.w.Component(),{ version: '0.1.000', type:"bc.w.Tab", create:function(id,o){ this.paint(id,o); if(!o.barPosition) o.barPosition = "top"; if(o.barPosition && o.barPosition =="bottom"){ this.view = new bc.w.Container(this.type + ":view:"+id,{parent:this._e}); this.bar = new bc.w.Container(this.type + ":bar:"+id,{parent:this._e}); }else{ this.bar = new bc.w.Container(this.type + ":bar:"+id,{parent:this._e}); this.view = new bc.w.Container(this.type + ":view:"+id,{parent:this._e}); } if(o.barPosition && (o.barPosition == "top" || o.barPosition =="bottom")){ this.bar.setStyle({width:'100%',bottom:0,paddingTop:'5px'}); this.view.setStyle({width:'100%',height:'100%'}); }else{ this.bar.setStyle({height:'100%'}); this.view.setStyle({height:'100%',width:'100%'}); } this.bar.setStyle({position:'relative',zIndex:1}); this.view.setStyle({position:'relative',border:'#C0D9FB solid 2px',overflow:'auto',zIndex:0}); this.items = []; this.curItem = null; }, addItem:function(i){ if(!i instanceof bc.w.TabItem) return;
i.onClick = function(e){ if(this.curItem.equals(i)) return false; this.setCurTab(e); }.bind(this); i._sts(0); this.items.push(i); i.fPanel.tabIndex = this.items.length; this.bar.addChild(i._btp); this.view.addChild(i.content); this.setCurTab(0); }, getCurTab:function(){ return this.curItem; }, getTabCount:function(){ return this.items.length; }, setCurTab:function(i){ if(null != this.curItem) this.curItem.inactive(); this.curItem = typeof i== "object"?this.items[this.items.indexOf(i)]:this.items[i]; this.curItem.active(); }, refresh:function(){ this.curItem.refresh(); } });
bc.w.TabItem = Class.create(); bc.w.TabItem.prototype = { version: '0.1.000', type:"bc.w.TabItem", initialize: function(n,o,uri) { this._o = o; this._t = n; if(uri) this.uri = uri; this.id=this.type + ":"+Brocade.hashCode(n); this.buttonPanel = this._btp = document.createElement("span"); Element.setStyle(this._btp,{ position:'relative', padding:0, marging:0 }); this.lPanel = document.createElement("span"); Element.setStyle(this.lPanel,{ width:(this._o.lCorner||5)+'px' }); this._btp.appendChild(this.lPanel); this.cPanel = document.createElement("span"); Element.setStyle(this.cPanel,{ width:'0px' }); this._btp.appendChild(this.cPanel); this.rPanel = document.createElement("span"); Element.setStyle(this.rPanel,{ width:(this._o.rCorner||5)+'px' }); this._btp.appendChild(this.rPanel); this.fPanel = document.createElement("a"); Element.setStyle(this.fPanel,{ textDecoration:"none" }); this.fPanel.href="javascript:void(0)"; var c=document.createElement("nobr"); c.appendChild(this.fPanel); this.cPanel.appendChild(c); this.button = document.createElement("nobr"); Element.setStyle(this.button,{ }); this.setText(n); if(o.icon){ this.icon = document.createElement("img"); this.icon.src = o.icon; this.icon.style.border="0px"; this.fPanel.appendChild(this.icon); }this.button.src=o.icon; this.fPanel.appendChild(this.button); this.content = new bc.a.Panel(this.type + ":c:"+Brocade.hashCode(n),Object.extend({ indicator:function(b,t){ if(b){ this.icon.src = this._o.loadingIcon; Element.update(t,'<p style="margin-left:15px;background:url('+ this._o.loadingIcon+') no-repeat top left;'+ 'color:#777;padding:0 0 0 32;">Loading ...</p>'); }else{ this.icon.src = this._o.icon; } }.bind(this)},o)); this.content.hide(); this.content.setStyle({overflow:'auto'}); Event.observe(this._btp,"mouseover",this.hot.bindAsEventListener(this)); Event.observe(this._btp,"mouseout",this.unHot.bindAsEventListener(this)); Event.observe(this._btp,"click",this.click.bindAsEventListener(this)); Event.observe(this._btp,"keypress",this.key.bindAsEventListener(this)); }, setAccessKey:function(k){ this._akey = k; this.button.accessKey=k; Element.update(this.button,this._t + " (<u>"+k+"</u>)"); }, setText:function(t){ Element.update(this.button,t); }, _sts:function(i){ switch(i){ case 1: if(window.innerWidth) Element.setStyle(this._btp,{ top:-2 }); else Element.setStyle(this._btp,{ bottom:-4 }); Element.setStyle(this.lPanel,{ padding:'4 0 8 5', background:"url("+this._o.curImg+") no-repeat left top" }); Element.setStyle(this.cPanel,{ padding:'4 2 8', background:"url("+this._o.curImg+") repeat-x center top" }); Element.setStyle(this.rPanel,{ padding:'4 5 8 0', background:"url("+this._o.curImg+") no-repeat right top" }); break; case 2: Element.setStyle(this.lPanel,{ background:"url("+this._o.hotImg+") no-repeat left top" }); Element.setStyle(this.cPanel,{ background:"url("+this._o.hotImg+") repeat-x center top" }); Element.setStyle(this.rPanel,{ background:"url("+this._o.hotImg+") no-repeat right top" }); break; default: if(window.innerWidth) Element.setStyle(this._btp,{top:0}); else Element.setStyle(this._btp,{bottom:0}); Element.setStyle(this.lPanel,{ padding:'4 0 0 5', background:"url("+this._o.defImg+") no-repeat left top" }); Element.setStyle(this.cPanel,{ padding:'4 2 0 2', background:"url("+this._o.defImg+") repeat-x center top" }); Element.setStyle(this.rPanel,{ padding:'4 5 0 0', background:"url("+this._o.defImg+") no-repeat right top" }); break; } }, setUri:function(u){ this.uri = u; }, load:function(){ if(this.uri) this.content.load(this.uri); }, add:function(c){ this.content.addChild(c); }, key:function(k){ if(k.keyCode == Event.KEY_RETURN) this.onClick(this); }, click:function(evt){ this.onClick(this); }, hot:function(evt){ if(this.isCur)return false; this._sts(2); }, unHot:function(evt){ if(this.isCur)return false; this._sts(0); }, isCurTab:function(){ return this.isCur; }, active:function(){ this.isCur = true; this._sts(1); this.content.show(); if(!this._o.noLoad || !this._fLoad){ this._fLoad = true; this.load(); } }, inactive:function(){ this.isCur = false; this._sts(0); this.content.hide(); }, refresh:function(){ this.load(); }, equals:function(t){ if(!t.type) return false; if(t.type!=this.type) return false; if(t.id!=this.id) return false; return true; } }
bc.w.Tab = Class.create(); bc.w.Tab.prototype = Object.extend(new bc.w.TabBase(),{ initialize: function(id,o) { this.create(id,o); } });
bc.w.PopupPanel = function(){}; bc.w.PopupPanel.prototype = Object.extend(new bc.w.Component(),{ version: "0.1.000", type: "bc.w.PopupPanel", create: function(id,o) { this.paint(id,o); this._e.style.position="absolute"; this.hide(); this.hideListener = this.hide.bindAsEventListener(this); this.mouseListener = this.ood.bindAsEventListener(this); }, _shadow:function(){ if(this.shadow)return; new Insertion.After(this._e, '<div id="'+this.type+':sdw:'+this.id+ '" style="background-color:#A5BFDA;position:absolute;' + '-moz-opacity:0.6;opacity:0.6;'+ 'filter:progid:DXImageTransform.Microsoft.Alpha(opacity=60);" ' + '</div>'); this.shadow = $(this.type+':sdw:'+this.id); }, _shadowShow:function(){ Element.show(this.shadow); Position.clone(this._e,this.shadow,{setHeight:true, setWidth:true,offsetTop:4,offsetLeft:4}); }, show:function(evt){ if(this.isShow()) return; this._tgt = evt.target?evt.target : evt.srcElement; Element.show(this._e); this.position(this._tgt); this._shadow(); this._shadowShow(); this.setStyle({zIndex:99999}); this.fixIE(); Event.observe(this._e, "click", this.hideListener); Event.observe(document, "mousedown", this.mouseListener); if(this.onShow) this.onShow(evt); }, hide:function(){ this.style.zIndex=2; if(this.mask){ this.mask.style.zIndex = 1; Position.clone(this._e,this.mask); } Element.hide(this._e); if(this.shadow) Element.hide(this.shadow); if(this.mask) Element.hide(this.mask); Event.stopObserving(document.body, "mousedown", this.mouseListener); Event.stopObserving(this._e, "click", this.hideListener); if(this.onHide) this.onHide(); }, position:function(t){ var wz = Scroll.view(); var tz = Element.getDimensions(t); var thz = this.getDimensions(); var fix=Scroll.position(); var tt=Position.cumulativeOffset(t); var tp=0,lt=0; if(wz[1]-(tt[1]-fix[1])-tz.height < thz.height) tp =-thz.height; else tp = tz.height; if(wz[0]-(tt[0]-fix[0]) < thz.width) lt = -(thz.width-(wz[0]-(tt[0]-fix[0]))); Position.clone(t,this._e,{setHeight:false, setWidth:false,offsetTop: tp,offsetLeft:lt}); }, ood:function(e){ var o = false; var fix=Scroll.position(); var clickX = e.clientX+fix[0]; var clickY = e.clientY+fix[1]; o =!Position.within(this._e,clickX,clickY); if(this._tgt &&Position.within(this._tgt,clickX,clickY)) o = false; if(o) this.hide(); }, remove:function(){ Element.remove(this.shadow); Element.remove(this._e); if(this.mask)Element.remove(this.mask); } });
bc.w.Popup = Class.create(); bc.w.Popup.prototype = Object.extend(new bc.w.PopupPanel(),{ version: '0.1.000', type:"bc.w.Popup", initialize: function(id,o) { this.create(id,o); this.showEventListener = this.popup.bindAsEventListener(this); if(this._p.classId){ var items = document.getElementsByClassName("pop"); for(var i=0,l=items.length;i<l;i++){ Event.observe(items[i],"mouseover",this.showEventListener); Event.observe(items[i],"mouseout",this.hideListener); } } }, popup:function(e){ this.show(e); } });
bc.a.Popup = Class.create(); bc.a.Popup.prototype = Object.extend(Object.extend(new bc.w.PopupPanel(),bc.a.Base.prototype),{ version: '0.1.000', type:"bc.a.Popup", initialize: function(id,u,o) { this.create(id,o); this.setOptions(o); this.url = u; }, popup:function(e){ this.show(e); this.sendUpdateRequest(this._e); }, indicator:function(b){ if(this.options.indicator){ this.options.indicator(b,this._e); }else if(b){ this._e.innerHTML=" Lodding ... "; } }, handler:function(r){ if(this.options.postFunction) this.options.postFunction(r); this.ri(false); }, error:function(n,e) { this.ri(false); setTimeout(this.ff(e),10); }, ff:function(e){ this.setContent(""); this.setContent('<iframe src="javascript:void(0);" width="100%" height="100%" frameborder="10" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" name="'+this.id+'#ep" id="'+this.id+'#ep"></iframe>'); setTimeout(function(){ var ep=frames[this.id+"#ep"]; ep.document.clear(); ep.document.write(e); ep.document.close(); }.bind(this),10); } });
bc.w.ActiveMenu = Class.create(); bc.w.ActiveMenu.prototype = Object.extend(new bc.w.PopupPanel(),{ version: "0.1.008", type: "bc.w.ActiveMenu", initialize: function(id,o) { this.create(id,o); this.mp = document.createElement("ul"); this.mp.id=this.type+":"+this.id; this.addChild(this.mp); this.entry = null; Element.setStyle(this.mp,{listStyle:'none',margin:0,padding:2}); new bc.u.c.Ul4Menu(this.mp,Object.extend({cursor:null},o)); }, addMenuItem:function(i){ if(!this.items)this.items=[]; if(typeof i == "object"){ this.mp.appendChild(i instanceof bc.w.MenuItems?i._e:i); this.items.push(i); }else{ new Insertion.Bottom(this.mp,i); } }, removeMenuItem:function(i){ this.items[i].remove(); } });
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -