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