forked from aui/artDialog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artDialog.min.js
9 lines (9 loc) · 13.3 KB
/
artDialog.min.js
1
2
3
4
5
6
7
8
9
/*!
* artDialog 5.0.2
* Date: 2012-11-11
* https://github.com/aui/artDialog
* (c) 2009-2012 TangBin, http://www.planeArt.cn
*
* This is licensed under the GNU LGPL, version 2.1 or later.
* For details, see: http://creativecommons.org/licenses/LGPL/2.1/
*/(function(e,t){function s(e,t,n){t=t||document,n=n||"*";var r=0,i=0,s=[],o=t.getElementsByTagName(n),u=o.length,a=new RegExp("(^|\\s)"+e+"(\\s|$)");for(;r<u;r++)a.test(o[r].className)&&(s[i]=o[r],i++);return s}function o(r){var i=n.expando,s=r===e?0:r[i];return s===t&&(r[i]=s=++n.uuid),s}function u(e){return n.isWindow(e)?e:e.nodeType===9?e.defaultView||e.parentWindow:!1}var n=e.art=function(e,t){return new n.fn.constructor(e,t)},r=/^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,i=/[\n\t]/g;return e.$===t&&(e.$=n),n.fn=n.prototype={constructor:function(e,t){var n,i;t=t||document;if(!e)return this;if(e.nodeType)return this[0]=e,this;if(typeof e=="string"){n=r.exec(e);if(n&&n[2])return i=t.getElementById(n[2]),i&&i.parentNode&&(this[0]=i),this}return this[0]=e,this},hasClass:function(e){var t=" "+e+" ";return(" "+this[0].className+" ").replace(i," ").indexOf(t)>-1?!0:!1},addClass:function(e){return this.hasClass(e)||(this[0].className+=" "+e),this},removeClass:function(e){var t=this[0];return e?this.hasClass(e)&&(t.className=t.className.replace(e," ")):t.className="",this},css:function(e,r){var i,s=this[0],o=arguments[0];if(typeof e=="string"){if(r===t)return n.css(s,e);s.style[e]=r}else for(i in o)s.style[i]=o[i];return this},show:function(){return this.css("display","block")},hide:function(){return this.css("display","none")},offset:function(){var e=this[0],t=e.getBoundingClientRect(),n=e.ownerDocument,r=n.body,i=n.documentElement,s=i.clientTop||r.clientTop||0,o=i.clientLeft||r.clientLeft||0,u=t.top+(self.pageYOffset||i.scrollTop)-s,a=t.left+(self.pageXOffset||i.scrollLeft)-o;return{left:a,top:u}},html:function(e){var r=this[0];return e===t?r.innerHTML:(n.cleanData(r.getElementsByTagName("*")),r.innerHTML=e,this)},remove:function(){var e=this[0];return n.cleanData(e.getElementsByTagName("*")),n.cleanData([e]),e.parentNode.removeChild(e),this},bind:function(e,t){return n.event.add(this[0],e,t),this},unbind:function(e,t){return n.event.remove(this[0],e,t),this}},n.fn.constructor.prototype=n.fn,n.isWindow=function(e){return e&&typeof e=="object"&&"setInterval"in e},n.fn.find=function(e){var t,r=this[0],i=e.split(".")[1];return i?document.getElementsByClassName?t=r.getElementsByClassName(i):t=s(i,r):t=r.getElementsByTagName(e),n(t[0])},n.each=function(e,n){var r,i=0,s=e.length,o=s===t;if(o){for(r in e)if(n.call(e[r],r,e[r])===!1)break}else for(var u=e[0];i<s&&n.call(u,i,u)!==!1;u=e[++i]);return e},n.data=function(e,r,i){var s=n.cache,u=o(e);return r===t?s[u]:(s[u]||(s[u]={}),i!==t&&(s[u][r]=i),s[u][r])},n.removeData=function(e,t){var r=!0,i=n.expando,s=n.cache,u=o(e),a=u&&s[u];if(!a)return;if(t){delete a[t];for(var f in a)r=!1;r&&delete n.cache[u]}else delete s[u],e.removeAttribute?e.removeAttribute(i):e[i]=null},n.uuid=0,n.cache={},n.expando="@cache"+ +(new Date),n.event={add:function(e,t,r){var i,s,o=n.event,u=n.data(e,"@events")||n.data(e,"@events",{});i=u[t]=u[t]||{},s=i.listeners=i.listeners||[],s.push(r),i.handler||(i.elem=e,i.handler=o.handler(i),e.addEventListener?e.addEventListener(t,i.handler,!1):e.attachEvent("on"+t,i.handler))},remove:function(e,t,r){var i,s,o,u=n.event,a=!0,f=n.data(e,"@events");if(!f)return;if(!t){for(i in f)u.remove(e,i);return}s=f[t];if(!s)return;o=s.listeners;if(r)for(i=0;i<o.length;i++)o[i]===r&&o.splice(i--,1);else s.listeners=[];if(s.listeners.length===0){e.removeEventListener?e.removeEventListener(t,s.handler,!1):e.detachEvent("on"+t,s.handler),delete f[t],s=n.data(e,"@events");for(var l in s)a=!1;a&&n.removeData(e,"@events")}},handler:function(t){return function(r){r=n.event.fix(r||e.event);for(var i=0,s=t.listeners,o;o=s[i++];)o.call(t.elem,r)===!1&&(r.preventDefault(),r.stopPropagation())}},fix:function(e){if(e.target)return e;var t={target:e.srcElement||document,preventDefault:function(){e.returnValue=!1},stopPropagation:function(){e.cancelBubble=!0}};for(var n in e)t[n]=e[n];return t}},n.cleanData=function(e){var t=0,r,i=e.length,s=n.event.remove,o=n.removeData;for(;t<i;t++)r=e[t],s(r),o(r)},n.css="defaultView"in document&&"getComputedStyle"in document.defaultView?function(e,t){return document.defaultView.getComputedStyle(e,!1)[t]}:function(e,t){return e.currentStyle[t]||""},n.each(["Left","Top"],function(e,t){var r="scroll"+t;n.fn[r]=function(){var t=this[0],n;return n=u(t),n?"pageXOffset"in n?n[e?"pageYOffset":"pageXOffset"]:n.document.documentElement[r]||n.document.body[r]:t[r]}}),n.each(["Height","Width"],function(e,t){var r=t.toLowerCase();n.fn[r]=function(e){var r=this[0];return r?n.isWindow(r)?r.document.documentElement["client"+t]||r.document.body["client"+t]:r.nodeType===9?Math.max(r.documentElement["client"+t],r.body["scroll"+t],r.documentElement["scroll"+t],r.body["offset"+t],r.documentElement["offset"+t]):null:e==null?null:this}}),n})(window),function(e,t,n){if(document.compatMode==="BackCompat")throw new Error("artDialog: Document types require more than xhtml1.0");var r,i=0,s=e(document.getElementsByTagName("html")[0]),o="artDialog"+ +(new Date),u=t.VBArray&&!t.XMLHttpRequest,a="createTouch"in document&&!("onmousemove"in document)||/(iPhone|iPad|iPod)/i.test(navigator.userAgent),f=!u&&!a,l=function(e,t,s){e=e||{};if(typeof e=="string"||e.nodeType===1)e={content:e,fixed:!a};var u,c=l.defaults,h=e.follow=this.nodeType===1&&this||e.follow;for(var p in c)e[p]===n&&(e[p]=c[p]);e.id=h&&h[o+"follow"]||e.id||o+i,u=l.list[e.id];if(u)return h&&u.follow(h),u.zIndex().focus(),u;f||(e.fixed=!1);if(!e.button||!e.button.push)e.button=[];return t!==n&&(e.ok=t),e.ok&&e.button.push({id:"ok",value:e.okValue,callback:e.ok,focus:!0}),s!==n&&(e.cancel=s),e.cancel&&e.button.push({id:"cancel",value:e.cancelValue,callback:e.cancel}),l.defaults.zIndex=e.zIndex,i++,l.list[e.id]=r?r.constructor(e):new l.fn.constructor(e)};l.version="5.0.2",l.fn=l.prototype={constructor:function(e){var t;return this.closed=!1,this.config=e,this.dom=t=this.dom||this._getDom(),e.skin&&t.wrap.addClass(e.skin),t.wrap.css("position",e.fixed?"fixed":"absolute"),t.close[e.cancel===!1?"hide":"show"](),t.content.css("padding",e.padding),this.button.apply(this,e.button),this.title(e.title).content(e.content).size(e.width,e.height).time(e.time),this._reset(),this.zIndex(),e.lock&&this.lock(),this._addEvent(),this[e.visible?"visible":"hidden"]().focus(),r=null,e.initialize&&e.initialize.call(this),this},content:function(t){var n,r,i,s,o=this,u=this.dom.content,a=u[0];return this._elemBack&&(this._elemBack(),delete this._elemBack),typeof t=="string"?u.html(t):t&&t.nodeType===1&&(s=t.style.display,n=t.previousSibling,r=t.nextSibling,i=t.parentNode,this._elemBack=function(){n&&n.parentNode?n.parentNode.insertBefore(t,n.nextSibling):r&&r.parentNode?r.parentNode.insertBefore(t,r):i&&i.appendChild(t),t.style.display=s,o._elemBack=null},u.html(""),a.appendChild(t),e(t).show()),this._reset(),this},title:function(e){var t=this.dom,n=t.outer,r=t.title,i="d-state-noTitle";return e===!1?(r.hide().html(""),n.addClass(i)):(r.show().html(e),n.removeClass(i)),this},position:function(){var e=this.dom,t=e.wrap[0],n=e.window,r=e.document,i=this.config.fixed,s=i?0:r.scrollLeft(),u=i?0:r.scrollTop(),a=n.width(),f=n.height(),l=t.offsetWidth,c=t.offsetHeight,h=(a-l)/2+s,p=(f-c)*382/1e3+u,d=t.style;return d.left=Math.max(parseInt(h),s)+"px",d.top=Math.max(parseInt(p),u)+"px",this._follow&&(this._follow.removeAttribute(o+"follow"),this._follow=null),this},size:function(e,t){var n=this.dom.main[0].style;return typeof e=="number"&&(e+="px"),typeof t=="number"&&(t+="px"),n.width=e,n.height=t,this},follow:function(t){var n=e(t),r=this.config;if(!t||!t.offsetWidth&&!t.offsetHeight)return this.position(this._left,this._top);var i=r.fixed,s=o+"follow",u=this.dom,a=u.window,f=u.document,l=a.width(),c=a.height(),h=f.scrollLeft(),p=f.scrollTop(),d=n.offset(),v=t.offsetWidth,m=t.offsetHeight,g=i?d.left-h:d.left,y=i?d.top-p:d.top,b=this.dom.wrap[0],w=b.style,E=b.offsetWidth,S=b.offsetHeight,x=g-(E-v)/2,T=y+m,N=i?0:h,C=i?0:p;return x=x<N?g:x+E>l&&g-E>N?g-E+v:x,T=T+S>c+C&&y-S>C?y-S:T,w.left=parseInt(x)+"px",w.top=parseInt(T)+"px",this._follow&&this._follow.removeAttribute(s),this._follow=t,t[s]=r.id,this},button:function(){var t=this.dom,n=t.buttons,r=n[0],i="d-state-highlight",s=this._listeners=this._listeners||{},u=[].slice.call(arguments),a=0,f,l,c,h,p;for(;a<u.length;a++)f=u[a],l=f.value,c=f.id||l,h=!s[c],p=h?document.createElement("input"):s[c].elem,p.type="button",p.className="d-button",s[c]||(s[c]={}),l&&(p.value=l),f.width&&(p.style.width=f.width),f.callback&&(s[c].callback=f.callback),f.focus&&(this._focus&&this._focus.removeClass(i),this._focus=e(p).addClass(i),this.focus()),p[o+"callback"]=c,p.disabled=!!f.disabled,h&&(s[c].elem=p,r.appendChild(p));return n[0].style.display=u.length?"":"none",this},visible:function(){return this.dom.wrap.css("visibility","visible"),this.dom.outer.addClass("d-state-visible"),this._isLock&&this._lockMask.show(),this},hidden:function(){return this.dom.wrap.css("visibility","hidden"),this.dom.outer.removeClass("d-state-visible"),this._isLock&&this._lockMask.hide(),this},close:function(){if(this.closed)return this;var e=this.dom,t=e.wrap,n=l.list,i=this.config.beforeunload;if(i&&i.call(this)===!1)return this;l.focus===this&&(l.focus=null),this._follow&&this._follow.removeAttribute(o+"follow"),this._elemBack&&this._elemBack(),this.time(),this.unlock(),this._removeEvent(),delete n[this.config.id];if(r)t.remove();else{r=this,e.title.html(""),e.content.html(""),e.buttons.html(""),t[0].className=t[0].style.cssText="",e.outer[0].className="d-outer",t.css({left:0,top:0,position:f?"fixed":"absolute"});for(var s in this)this.hasOwnProperty(s)&&s!=="dom"&&delete this[s];this.hidden()}return this.closed=!0,this},time:function(e){var t=this,n=this._timer;return n&&clearTimeout(n),e&&(this._timer=setTimeout(function(){t._click("cancel")},e)),this},focus:function(){if(this.config.focus)try{var e=this._focus&&this._focus[0]||this.dom.close[0];e&&e.focus()}catch(t){}return this},zIndex:function(){var e=this.dom,t=l.focus,n=l.defaults.zIndex++;return e.wrap.css("zIndex",n),this._lockMask&&this._lockMask.css("zIndex",n-1),t&&t.dom.outer.removeClass("d-state-focus"),l.focus=this,e.outer.addClass("d-state-focus"),this},lock:function(){if(this._isLock)return this;var n=this,r=this.config,i=this.dom,s=document.createElement("div"),o=e(s),u=l.defaults.zIndex-1;return this.zIndex(),i.outer.addClass("d-state-lock"),o.css({zIndex:u,position:"fixed",left:0,top:0,width:"100%",height:"100%",overflow:"hidden"}).addClass("d-mask"),f||o.css({position:"absolute",width:e(t).width()+"px",height:e(document).height()+"px"}),o.bind("dblclick",function(){n._click("cancel")}),document.body.appendChild(s),this._lockMask=o,this._isLock=!0,this},unlock:function(){return this._isLock?(this._lockMask.unbind(),this._lockMask.hide(),this._lockMask.remove(),this.dom.outer.removeClass("d-state-lock"),this._isLock=!1,this):this},_getDom:function(){var n=document.body;if(!n)throw new Error('artDialog: "documents.body" not ready');var r=document.createElement("div");r.style.cssText="position:absolute;left:0;top:0",r.innerHTML=l._templates,n.insertBefore(r,n.firstChild);var i,s=0,o={},u=r.getElementsByTagName("*"),a=u.length;for(;s<a;s++)i=u[s].className.split("d-")[1],i&&(o[i]=e(u[s]));return o.window=e(t),o.document=e(document),o.wrap=e(r),o},_click:function(e){var t=this._listeners[e]&&this._listeners[e].callback;return typeof t!="function"||t.call(this)!==!1?this.close():this},_reset:function(){var e=this.config.follow||this._follow;e?this.follow(e):this.position()},_addEvent:function(){var e=this,t=this.dom;t.wrap.bind("click",function(n){var r=n.target,i;if(r.disabled)return!1;if(r===t.close[0])return e._click("cancel"),!1;i=r[o+"callback"],i&&e._click(i)}).bind("mousedown",function(){e.zIndex()})},_removeEvent:function(){this.dom.wrap.unbind()}},l.fn.constructor.prototype=l.fn,e.fn.dialog=e.fn.artDialog=function(){var e=arguments;return this[this.live?"live":"bind"]("click",function(){return l.apply(this,e),!1}),this},l.focus=null,l.get=function(e){return e===n?l.list:l.list[e]},l.list={},e(document).bind("keydown",function(e){var t=e.target,n=t.nodeName,r=/^input|textarea$/i,i=l.focus,s=e.keyCode;if(!i||!i.config.esc||r.test(n)&&t.type!=="button")return;s===27&&i._click("cancel")}),e(t).bind("resize",function(){var e=l.list;for(var t in e)e[t]._reset()}),l._templates='<div class="d-outer"><table class="d-border"><tbody><tr><td class="d-nw"></td><td class="d-n"></td><td class="d-ne"></td></tr><tr><td class="d-w"></td><td class="d-c"><div class="d-inner"><table class="d-dialog"><tbody><tr><td class="d-header"><div class="d-titleBar"><div class="d-title"></div><a class="d-close" href="javascript:/*artDialog*/;">\u00d7</a></div></td></tr><tr><td class="d-main"><div class="d-content"></div></td></tr><tr><td class="d-footer"><div class="d-buttons"></div></td></tr></tbody></table></div></td><td class="d-e"></td></tr><tr><td class="d-sw"></td><td class="d-s"></td><td class="d-se"></td></tr></tbody></table></div>',l.defaults={content:'<div class="d-loading"><span>loading..</span></div>',title:"message",button:null,ok:null,cancel:null,initialize:null,beforeunload:null,okValue:"ok",cancelValue:"cancel",width:"auto",height:"auto",padding:"20px 25px",skin:null,time:null,esc:!0,focus:!0,visible:!0,follow:null,lock:!1,fixed:!1,zIndex:1987},this.artDialog=e.dialog=e.artDialog=l}(this.art||this.jQuery,this)