📄 control.modal.js
字号:
if(modal_image) modal_image.hide(); Control.Modal.loading.style.zIndex = this.options.zIndex + 1; Control.Modal.loading.update('<img id="modal_loading" src="' + this.options.loading + '"/>'); Control.Modal.loading.show(); Control.Modal.center(Control.Modal.loading); }.bind(this),250); } }, hideLoadingIndicator: function(){ if(this.options.loading){ if(Control.Modal.loadingTimeout) window.clearTimeout(Control.Modal.loadingTimeout); var modal_image = $('modal_image'); if(modal_image) modal_image.show(); Control.Modal.loading.hide(); } }, open: function(force){ if(!force && this.notify('beforeOpen') === false) return; if(!Control.Modal.loaded) Control.Modal.load(); Control.Modal.close(); if(!this.options.hover) Event.observe($(document.getElementsByTagName('body')[0]),'keydown',Control.Modal.onKeyDown); Control.Modal.current = this; if(!this.options.hover) Control.Modal.overlay.setStyle({ zIndex: this.options.zIndex, opacity: this.options.opacity }); Control.Modal.container.setStyle({ zIndex: this.options.zIndex + 1, width: (this.options.width ? (typeof(this.options.width) == 'function' ? this.options.width() : this.options.width) + 'px' : ''), height: (this.options.height ? (typeof(this.options.height) == 'function' ? this.options.height() : this.options.height) + 'px' : '') }); if(Control.Modal.ie && !this.options.hover){ $A(document.getElementsByTagName('select')).each(function(select){ select.style.visibility = 'hidden'; }); } Control.Modal.overlay.addClassName(this.options.overlayClassName); Control.Modal.container.addClassName(this.options.containerClassName); switch(this.mode){ case 'image': this.imageLoaded = false; this.notify('beforeImageLoad'); this.update(this.options.imageTemplate.evaluate({ src: this.src, id: 'modal_image' })); this.showLoadingIndicator(); this.position(); var modal_image = $('modal_image'); if(this.options.imageAutoDisplay && !window.opera) modal_image.hide(); if(this.options.imageCloseOnClick) modal_image.observe('click',Control.Modal.close); modal_image.observe('load',this.afterImageLoad); modal_image.observe('readystatechange',this.afterImageLoad); break; case 'ajax': this.notify('beforeLoad'); var options = { method: 'get', onSuccess: function(request){ this.hideLoadingIndicator(); this.update(request.responseText); if(this.options.evalScripts) request.responseText.evalScripts(); this.notify('onSuccess',request); this.ajaxRequest = false; }.bind(this), onFailure: function(){ this.notify('onFailure'); }.bind(this), onException: function(){ this.notify('onException'); }.bind(this) }; Object.extend(options,this.options.requestOptions); this.showLoadingIndicator(); this.ajaxRequest = new Ajax.Request(this.href,options); break; case 'iframe': this.update(this.options.iframeTemplate.evaluate({href: this.href, id: 'modal_iframe'})); this.position(); break; case 'contents': this.update((typeof(this.options.contents) == 'function' ? this.options.contents() : this.options.contents)); break; case 'named': this.update(this.html); break; } if(!this.options.hover){ if(this.options.overlayCloseOnClick && this.options.overlayDisplay) Control.Modal.overlay.observe('click',Control.Modal.close); if(this.options.overlayDisplay){ if(this.options.fade){ Control.Modal.overlay.setStyle({ height: Control.Modal.getWindowHeight() + 'px', width: Control.Modal.getWindowWidth() + 'px' }); if(Control.Modal.effects.overlayFade) Control.Modal.effects.overlayFade.cancel(); Control.Modal.effects.overlayAppear = new Effect.Appear(Control.Modal.overlay,{ queue: { position: 'front', scope: 'Control.Modal' }, to: this.options.opacity, duration: this.options.fadeDuration / 2 }); }else Control.Modal.overlay.show(); } } this.notify('afterOpen'); }, update: function(html){ if(typeof(html) == 'string') Control.Modal.container.update(html); else{ Control.Modal.container.update(''); (html.each) ? html.each(function(node){ Control.Modal.container.appendChild(node); }) : Control.Modal.container.appendChild(node); } this.position(); if(this.options.fade){ if(Control.Modal.effects.containerFade) Control.Modal.effects.containerFade.cancel(); Control.Modal.effects.containerAppear = new Effect.Appear(Control.Modal.container,{ queue: { position: 'end', scope: 'Control.Modal' }, to: 1, duration: this.options.fadeDuration / 2 }); }else Control.Modal.container.show(); if(this.options.position == 'absolute'){ Event.stopObserving(window,'resize',this.position,false); Event.stopObserving(window,'scroll',this.position,false); Event.observe(window,'resize',this.position,false); Event.observe(window,'scroll',this.position,false); } }, close: function(force){ if(!force && this.notify('beforeClose') === false) return; if(this.ajaxRequest) this.ajaxRequest.transport.abort(); this.hideLoadingIndicator(); if(this.mode == 'image'){ var modal_image = $('modal_image'); if(this.options.imageCloseOnClick) modal_image.stopObserving('click',Control.Modal.close); modal_image.stopObserving('load',this.afterImageLoad); modal_image.stopObserving('readystatechange',this.afterImageLoad); } if(Control.Modal.ie && !this.options.hover){ $A(document.getElementsByTagName('select')).each(function(select){ select.style.visibility = 'visible'; }); } if(!this.options.hover) Event.stopObserving(window,'keyup',Control.Modal.onKeyDown); Control.Modal.current = false; Event.stopObserving(window,'resize',this.position,false); Event.stopObserving(window,'scroll',this.position,false); if(!this.options.hover){ if(this.options.overlayCloseOnClick && this.options.overlayDisplay) Control.Modal.overlay.stopObserving('click',Control.Modal.close); if(this.options.overlayDisplay){ if(this.options.fade){ if(Control.Modal.effects.overlayAppear) Control.Modal.effects.overlayAppear.cancel(); Control.Modal.effects.overlayFade = new Effect.Fade(Control.Modal.overlay,{ queue: { position: 'end', scope: 'Control.Modal' }, from: this.options.opacity, to: 0, duration: this.options.fadeDuration / 2 }); }else Control.Modal.overlay.hide(); } } if(this.options.fade){ if(Control.Modal.effects.containerAppear) Control.Modal.effects.containerAppear.cancel(); Control.Modal.effects.containerFade = new Effect.Fade(Control.Modal.container,{ queue: { position: 'front', scope: 'Control.Modal' }, from: 1, to: 0, duration: this.options.fadeDuration / 2, afterFinish: function(){ Control.Modal.container.update(''); this.resetClassNameAndStyles(); }.bind(this) }); }else{ Control.Modal.container.hide(); Control.Modal.container.update(''); this.resetClassNameAndStyles(); } this.notify('afterClose'); }, resetClassNameAndStyles: function(){ Control.Modal.overlay.removeClassName(this.options.overlayClassName); Control.Modal.container.removeClassName(this.options.containerClassName); Control.Modal.container.setStyle({ height: null, width: null, top: null, left: null }); }, notify: function(event_name){ try{ if(this.options[event_name]) return [this.options[event_name].apply(this.options[event_name],$A(arguments).slice(1))]; }catch(e){ if(e != $break) throw e; else return false; } }});if(typeof(Object.Event) != 'undefined') Object.Event.extend(Control.Modal);Control.Modal.attachEvents();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -