Created
November 18, 2010 06:56
-
-
Save sofish/704707 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AP.widget.tipdone = new AP.Class( | |
| /** | |
| *@lends AP.widget.tipdone.prototype | |
| *@author xuning | |
| */ | |
| { | |
| /** | |
| *设置属性 | |
| *@returns {Object} | |
| */ | |
| setOptions : function(options){ | |
| return AP.hashExtend({ | |
| timeout : 5 | |
| },options || {}) | |
| }, | |
| /** | |
| *自定义tipdone的构造函数 | |
| *@constructs | |
| *@param options 初始化配置属性 | |
| *@param options.timeout 设置超时时间 | |
| *@returns {tipdone} 返回一个新创建的topdone对象 | |
| */ | |
| initialize : function(options){ | |
| this.options = this.setOptions(options); | |
| }, | |
| /** | |
| *移除tipdone的dom节点 | |
| *@returns {void} | |
| */ | |
| remove : function(){ | |
| var tip = D.query('.tip-done')[0]; | |
| if(tip){ | |
| tip.parentNode.removeChild(tip) | |
| } | |
| }, | |
| /** | |
| *显示tipdone | |
| *@returns {void} | |
| *@example | |
| *<pre><code> | |
| *var tipdone = new AP.widget.tipdone({timeout:5}); | |
| *tipdone.show('操作成功。') | |
| *</code></pre> | |
| *<div><input type="button" id="tipdone"/></div> | |
| *<script type="text/javascript"> | |
| *var tipdone = new AP.widget.tipdone({timeout:5}); | |
| *tipdone.show('操作成功。') | |
| *</script> | |
| */ | |
| show : function(info){ | |
| this.remove(); | |
| var tip = this.createDom(info); | |
| D.setStyle(tip,'left',(document.documentElement.clientWidth-tip.offsetWidth)/2+'px'); | |
| this.position(tip); | |
| this.scollChange(tip); | |
| if(this.timeout){ | |
| clearTimeout(this.timeout); | |
| } | |
| this.timeout = setTimeout(this.remove,5000); | |
| }, | |
| /** | |
| *显示tipdone | |
| *@returns {void} | |
| */ | |
| scollChange : function(tip){ | |
| E.on(window,'scroll',function(){ | |
| this.position(tip); | |
| },'',this); | |
| }, | |
| /** | |
| *将tipdone定位到浏览器顶部位置 | |
| *@returns {void} | |
| */ | |
| position : function(tip){ | |
| D.setStyle(tip,'top',document.documentElement.scrollTop + 'px'); | |
| }, | |
| /** | |
| *获取页面中是否存在tip-done | |
| *@returns {element} class为tip-done的dom对象 | |
| */ | |
| getTip : function(){ | |
| return D.query('.tip-done')[0]; | |
| }, | |
| /** | |
| *创建tipdone的dom | |
| *@returns {element} class为tip-done的dom对象 | |
| */ | |
| createDom : function(info){ | |
| html = '<div class="container">'+info+'</div>'; | |
| return Element.create("div", {innerHTML:html,appendTo:document.body,'class':'tip-done'}); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment