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

📄 window.js

📁 jive论坛使得不时地好的不好的jive论坛使得不时地好的不好的
💻 JS
📖 第 1 页 / 共 4 页
字号:

var Window=Class.create();
Window.keepMultiModalWindow=false;
Window.hasEffectLib=(typeof Effect!='undefined');
Window.resizeEffectDuration=0.4;
Window.prototype={
initialize:function(){
var id;
var optionIndex=0;
if(arguments.length>0){
if(typeof arguments[0]=="string"){
id=arguments[0];
optionIndex=1;}
else
id=arguments[0]?arguments[0].id:null;}
if(!id)
id="window_"+new Date().getTime();
if($(id))
alert("Window "+id+" is already registered in the DOM! Make sure you use setDestroyOnClose() or destroyOnClose: true in the constructor");
this.options=Object.extend({
className:"dialog",
blurClassName:null,
minWidth:100,
minHeight:20,
resizable:true,
closable:true,
minimizable:true,
maximizable:true,
draggable:true,
userData:null,
showEffect:(Window.hasEffectLib?Effect.Appear:Element.show),
hideEffect:(Window.hasEffectLib?Effect.Fade:Element.hide),
showEffectOptions:{},
hideEffectOptions:{},
effectOptions:null,
parent:document.body,
title:" ",
url:null,
onload:Prototype.emptyFunction,
width:200,
height:300,
opacity:1,
recenterAuto:true,
wiredDrag:false,
closeCallback:null,
destroyOnClose:false,
gridX:1,
gridY:1},arguments[optionIndex]||{});
if(this.options.blurClassName)
this.options.focusClassName=this.options.className;
if(typeof this.options.top=="undefined"&&typeof this.options.bottom=="undefined")
this.options.top=this._round(Math.random()*500,this.options.gridY);
if(typeof this.options.left=="undefined"&&typeof this.options.right=="undefined")
this.options.left=this._round(Math.random()*500,this.options.gridX);
if(this.options.effectOptions){
Object.extend(this.options.hideEffectOptions,this.options.effectOptions);
Object.extend(this.options.showEffectOptions,this.options.effectOptions);
if(this.options.showEffect==Element.Appear)
this.options.showEffectOptions.to=this.options.opacity;}
if(Window.hasEffectLib){
if(this.options.showEffect==Effect.Appear)
this.options.showEffectOptions.to=this.options.opacity;
if(this.options.hideEffect==Effect.Fade)
this.options.hideEffectOptions.from=this.options.opacity;}
if(this.options.hideEffect==Element.hide)
this.options.hideEffect=function(){Element.hide(this.element);if(this.options.destroyOnClose)this.destroy();}.bind(this)
if(this.options.parent!=document.body)
this.options.parent=$(this.options.parent);
this.element=this._createWindow(id);
this.element.win=this;
this.eventMouseDown=this._initDrag.bindAsEventListener(this);
this.eventMouseUp=this._endDrag.bindAsEventListener(this);
this.eventMouseMove=this._updateDrag.bindAsEventListener(this);
this.eventOnLoad=this._getWindowBorderSize.bindAsEventListener(this);
this.eventMouseDownContent=this.toFront.bindAsEventListener(this);
this.eventResize=this._recenter.bindAsEventListener(this);
this.topbar=$(this.element.id+"_top");
this.bottombar=$(this.element.id+"_bottom");
this.content=$(this.element.id+"_content");
Event.observe(this.topbar,"mousedown",this.eventMouseDown);
Event.observe(this.bottombar,"mousedown",this.eventMouseDown);
Event.observe(this.content,"mousedown",this.eventMouseDownContent);
Event.observe(window,"load",this.eventOnLoad);
Event.observe(window,"resize",this.eventResize);
Event.observe(window,"scroll",this.eventResize);
Event.observe(this.options.parent,"scroll",this.eventResize);
if(this.options.draggable){
var that=this;[this.topbar,this.topbar.up().previous(),this.topbar.up().next()].each(function(element){
element.observe("mousedown",that.eventMouseDown);
element.addClassName("top_draggable");});[this.bottombar.up(),this.bottombar.up().previous(),this.bottombar.up().next()].each(function(element){
element.observe("mousedown",that.eventMouseDown);
element.addClassName("bottom_draggable");});}
if(this.options.resizable){
this.sizer=$(this.element.id+"_sizer");
Event.observe(this.sizer,"mousedown",this.eventMouseDown);}
this.useLeft=null;
this.useTop=null;
if(typeof this.options.left!="undefined"){
this.element.setStyle({left:parseFloat(this.options.left)+'px'});
this.useLeft=true;}
else{
this.element.setStyle({right:parseFloat(this.options.right)+'px'});
this.useLeft=false;}
if(typeof this.options.top!="undefined"){
this.element.setStyle({top:parseFloat(this.options.top)+'px'});
this.useTop=true;}
else{
this.element.setStyle({bottom:parseFloat(this.options.bottom)+'px'});
this.useTop=false;}
this.storedLocation=null;
this.setOpacity(this.options.opacity);
if(this.options.zIndex)
this.setZIndex(this.options.zIndex)
if(this.options.destroyOnClose)
this.setDestroyOnClose(true);
this._getWindowBorderSize();
this.width=this.options.width;
this.height=this.options.height;
this.visible=false;
this.constraint=false;
this.constraintPad={top:0,left:0,bottom:0,right:0};
if(this.width&&this.height)
this.setSize(this.options.width,this.options.height);
this.setTitle(this.options.title)
Windows.register(this);},
destroy:function(){
this._notify("onDestroy");
Event.stopObserving(this.topbar,"mousedown",this.eventMouseDown);
Event.stopObserving(this.bottombar,"mousedown",this.eventMouseDown);
Event.stopObserving(this.content,"mousedown",this.eventMouseDownContent);
Event.stopObserving(window,"load",this.eventOnLoad);
Event.stopObserving(window,"resize",this.eventResize);
Event.stopObserving(window,"scroll",this.eventResize);
Event.stopObserving(this.content,"load",this.options.onload);
if(this._oldParent){
var content=this.getContent();
var originalContent=null;
for(var i=0;i<content.childNodes.length;i++){
originalContent=content.childNodes[i];
if(originalContent.nodeType==1)
break;
originalContent=null;}
if(originalContent)
this._oldParent.appendChild(originalContent);
this._oldParent=null;}
if(this.sizer)
Event.stopObserving(this.sizer,"mousedown",this.eventMouseDown);
if(this.options.url)
this.content.src=null
if(this.iefix)
Element.remove(this.iefix);
Element.remove(this.element);
Windows.unregister(this);},
setCloseCallback:function(callback){
this.options.closeCallback=callback;},
getContent:function(){
return this.content;},
setContent:function(id,autoresize,autoposition){
var element=$(id);
if(null==element)throw "Unable to find element '"+id+"' in DOM";
this._oldParent=element.parentNode;
var d=null;
var p=null;
if(autoresize)
d=Element.getDimensions(element);
if(autoposition)
p=Position.cumulativeOffset(element);
var content=this.getContent();
this.setHTMLContent("");
content=this.getContent();
content.appendChild(element);
element.show();
if(autoresize)
this.setSize(d.width,d.height);
if(autoposition)
this.setLocation(p[1]-this.heightN,p[0]-this.widthW);},
setHTMLContent:function(html){
if(this.options.url){
this.content.src=null;
this.options.url=null;
var content="<div id=\"" + this.getId() + "_content\" class=\"" + this.options.className + "_content\"> </div>";
$(this.getId()+"_table_content").innerHTML=content;
this.content=$(this.element.id+"_content");}
this.getContent().innerHTML=html;},
setAjaxContent:function(url,options,showCentered,showModal){
this.showFunction=showCentered?"showCenter":"show";
this.showModal=showModal||false;
options=options||{};
this.setHTMLContent("");
this.onComplete=options.onComplete;
if(!this._onCompleteHandler)
this._onCompleteHandler=this._setAjaxContent.bind(this);
options.onComplete=this._onCompleteHandler;
new Ajax.Request(url,options);
options.onComplete=this.onComplete;},
_setAjaxContent:function(originalRequest){
Element.update(this.getContent(),originalRequest.responseText);
if(this.onComplete)
this.onComplete(originalRequest);
this.onComplete=null;
this[this.showFunction](this.showModal)},
setURL:function(url){
if(this.options.url)
this.content.src=null;
this.options.url=url;
var content="<iframe frameborder='0' name='"+this.getId()+"_content'  id='"+this.getId()+"_content' src='"+url+"' width='"+this.width+"' height='"+this.height+"'> </iframe>";
$(this.getId()+"_table_content").innerHTML=content;
this.content=$(this.element.id+"_content");},
getURL:function(){
return this.options.url?this.options.url:null;},
refresh:function(){
if(this.options.url)
$(this.element.getAttribute('id')+'_content').src=this.options.url;},
setCookie:function(name,expires,path,domain,secure){
name=name||this.element.id;
this.cookie=[name,expires,path,domain,secure];
var value=WindowUtilities.getCookie(name)
if(value){
var values=value.split(',');
var x=values[0].split(':');
var y=values[1].split(':');
var w=parseFloat(values[2]),h=parseFloat(values[3]);
var mini=values[4];
var maxi=values[5];
this.setSize(w,h);
if(mini=="true")
this.doMinimize=true;
else if(maxi=="true")
this.doMaximize=true;
this.useLeft=x[0]=="l";
this.useTop=y[0]=="t";
this.element.setStyle(this.useLeft?{left:x[1]}:{right:x[1]});
this.element.setStyle(this.useTop?{top:y[1]}:{bottom:y[1]});}},
getId:function(){
return this.element.id;},
setDestroyOnClose:function(){
this.options.destroyOnClose=true;},
setConstraint:function(bool,padding){
this.constraint=bool;
this.constraintPad=Object.extend(this.constraintPad,padding||{});
if(this.useTop&&this.useLeft)
this.setLocation(parseFloat(this.element.style.top),parseFloat(this.element.style.left));},
_initDrag:function(event){
if(Event.element(event)==this.sizer&&this.isMinimized())
return;
if(Event.element(event)!=this.sizer&&this.isMaximized())
return;
if(Prototype.Browser.IE&&this.heightN==0)
this._getWindowBorderSize();
this.pointer=[this._round(Event.pointerX(event),this.options.gridX),this._round(Event.pointerY(event),this.options.gridY)];
if(this.options.wiredDrag)
this.currentDrag=this._createWiredElement();
else
this.currentDrag=this.element;
if(Event.element(event)==this.sizer){
this.doResize=true;
this.widthOrg=this.width;
this.heightOrg=this.height;
this.bottomOrg=parseFloat(this.element.getStyle('bottom'));
this.rightOrg=parseFloat(this.element.getStyle('right'));
this._notify("onStartResize");}
else{
this.doResize=false;
var closeButton=$(this.getId()+'_close');
if(closeButton&&Position.within(closeButton,this.pointer[0],this.pointer[1])){
this.currentDrag=null;
return;}
this.toFront();
if(!this.options.draggable)
return;
this._notify("onStartMove");}
Event.observe(document,"mouseup",this.eventMouseUp,false);
Event.observe(document,"mousemove",this.eventMouseMove,false);
WindowUtilities.disableScreen('__invisible__','__invisible__',this.overlayOpacity);
document.body.ondrag=function(){return false;};
document.body.onselectstart=function(){return false;};
this.currentDrag.show();
Event.stop(event);},
_round:function(val,round){
return round==1?val:val=Math.floor(val/round)*round;},
_updateDrag:function(event){
var pointer=[this._round(Event.pointerX(event),this.options.gridX),this._round(Event.pointerY(event),this.options.gridY)];
var dx=pointer[0]-this.pointer[0];
var dy=pointer[1]-this.pointer[1];
if(this.doResize){
var w=this.widthOrg+dx;
var h=this.heightOrg+dy;
dx=this.width-this.widthOrg
dy=this.height-this.heightOrg

⌨️ 快捷键说明

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