/** * easydialog v2.2 * url : http://stylechen.com/easydialog-v2.0.html * author : chenmnkken@gmail.com * date : 2012-04-22 */ (function(o,v){var g=o.document,q=g.documentelement,j=function(){var p=g.body,w=!-[1,],r=w&&/msie 6/.test(navigator.useragent.tolowercase()),i=1,y="cache"+(+new date+"").slice(-8),u={},d=function(){};d.prototype={getoptions:function(a){var b,c={},e={container:null,overlay:true,drag:true,fixed:true,follow:null,followx:0,followy:0,autoclose:0,lock:false,callback:null};for(b in e)c[b]=a[b]!==v?a[b]:e[b];d.data("options",c);return c},setbodybg:function(){if(p.currentstyle.backgroundattachment!=="fixed"){p.style.backgroundimage= "url(about:blank)";p.style.backgroundattachment="fixed"}},appendiframe:function(a){a.innerhtml=''},setfollow:function(a,b,c,e){b=typeof b==="string"?g.getelementbyid(b):b;a=a.style;a.position="absolute";a.left=d.getoffset(b,"left")+c+"px";a.top=d.getoffset(b,"top")+e+"px"},setposition:function(a,b){var c=a.style;c.position=r?"absolute":b?"fixed":"absolute";if(b){if(r)c.setexpression("top", 'fuckie6=document.documentelement.scrolltop+document.documentelement.clientheight/2+"px"');else c.top="50%";c.left="50%"}else{r&&c.removeexpression("top");c.top=q.clientheight/2+d.getscroll("top")+"px";c.left=q.clientwidth/2+d.getscroll("left")+"px"}},createoverlay:function(){var a=g.createelement("div"),b=a.style;b.csstext="margin:0;padding:0;border:none;width:100%;height:100%;background:#333;opacity:0.6;filter:alpha(opacity=60);z-index:9999;position:fixed;top:0;left:0;";if(r){p.style.height="100%"; b.position="absolute";b.setexpression("top",'fuckie6=document.documentelement.scrolltop+"px"')}a.id="overlay";return a},createdialogbox:function(){var a=g.createelement("div");a.style.csstext="margin:0;padding:0;border:none;z-index:10000;";a.id="easydialogbox";return a},createdialogwrap:function(a){var b=typeof a.yesfn==="function"?'":"",c=typeof a.nofn==="function"||a.nofn===true? '":"";a=['
',a.header?'

×'+a.header+"

":"",'
'+a.content+"
",b===""&&c===""?"":'","
"].join("");b=g.getelementbyid("easydialogwrapper"); if(!b){b=g.createelement("div");b.id="easydialogwrapper";b.classname="easydialog_wrapper"}b.innerhtml=a.replace(/<[\/]*script[\s\s]*?>/ig,"");return b}};d.data=function(a,b,c){if(typeof a==="string"){if(b!==v)u[a]=b;return u[a]}else if(typeof a==="object"){a=a===o?0:a.nodetype===9?1:a[y]?a[y]:a[y]=++i;a=u[a]?u[a]:u[a]={};if(c!==v)a[b]=c;return a[b]}};d.removedata=function(a,b){if(typeof a==="string")delete u[a];else if(typeof a==="object"){var c=a===o?0:a.nodetype===9?1:a[y];if(c!==v){var e=function(m){for(var n in m)return false; return true},f=function(){delete u[c];if(!(c<=1))try{delete a[y]}catch(m){a.removeattribute(y)}};if(b){delete u[c][b];e(u[c])&&f()}else f()}}};d.event={bind:function(a,b,c){var e=d.data(a,"e"+b)||d.data(a,"e"+b,[]);e.push(c);if(e.length===1){c=this.eventhandler(a);d.data(a,b+"handler",c);if(a.addeventlistener)a.addeventlistener(b,c,false);else a.attachevent&&a.attachevent("on"+b,c)}},unbind:function(a,b,c){var e=d.data(a,"e"+b);if(e){if(c)for(var f=e.length-1,m=e[f];f>=0;f--)m===c&&e.splice(f,1); else e=v;if(!e||!e.length){c=d.data(a,b+"handler");if(a.addeventlistener)a.removeeventlistener(b,c,false);else a.attachevent&&a.detachevent("on"+b,c);d.removedata(a,b+"handler");d.removedata(a,"e"+b)}}},eventhandler:function(a){return function(b){b=d.event.fixevent(b||o.event);for(var c=d.data(a,"e"+b.type),e=0,f;f=c[e++];)if(f.call(a,b)===false){b.preventdefault();b.stoppropagation()}}},fixevent:function(a){if(a.target)return a;var b={},c;b.target=a.srcelement||document;b.preventdefault=function(){a.returnvalue= false};b.stoppropagation=function(){a.cancelbubble=true};for(c in a)b[c]=a[c];return b}};d.capitalize=function(a){var b=a.charat(0);return b.touppercase()+a.replace(b,"")};d.getscroll=function(a){a=this.capitalize(a);return q["scroll"+a]||p["scroll"+a]};d.getoffset=function(a,b){var c=this.capitalize(b);c=q["client"+c]||p["client"+c]||0;var e=this.getscroll(b),f=a.getboundingclientrect();return math.round(f[b])+e-c};d.drag=function(a,b){var c="getselection"in o?function(){o.getselection().removeallranges()}: function(){try{g.selection.empty()}catch(i){}},e=this,f=e.event,m=false,n=w?a:g,h=b.style.position==="fixed",j=d.data("options").fixed;f.bind(a,"mousedown",function(i){m=true;var k=e.getscroll("top"),s=e.getscroll("left"),z=h?0:s,b=h?0:k;d.data("dragdata",{x:i.clientx-e.getoffset(b,"left")+(h?s:0),y:i.clienty-e.getoffset(b,"top")+(h?k:0),el:z,et:b,er:z+q.clientwidth-b.offsetwidth,eb:b+q.clientheight-b.offsetheight});if(w){r&&j&&b.style.removeexpression("top");a.setcapture()}f.bind(n,"mousemove",l); f.bind(n,"mouseup",t);w&&f.bind(a,"losecapture",t);i.stoppropagation();i.preventdefault()});var l=function(i){if(m){c();var k=d.data("dragdata"),s=i.clientx-k.x,z=i.clienty-k.y,b=k.et,e=k.er,f=k.eb;k=k.el;var c=b.style;c.marginleft=c.margintop="0px";c.left=(s<=k?k:s>=e?e:s)+"px";c.top=(z<=b?b:z>=f?f:z)+"px";i.stoppropagation()}},t=function(i){m=false;w&&f.unbind(a,"losecapture",arguments.callee);f.unbind(n,"mousemove",l);f.unbind(n,"mouseup",arguments.callee);if(w){a.releasecapture();if(r&&j){var k= parseint(b.style.top)-e.getscroll("top");b.style.setexpression("top","fuckie6=document.documentelement.scrolltop+"+k+'+"px"')}}i.stoppropagation()}};var x,g=function(a){a.keycode===27&&d.close()},d={open:function(a){var b=new d,c=b.getoptions(a||{});a=d.event;var e=q.clientwidth,f=q.clientheight,m=this,n,h,j,l;if(x){cleartimeout(x);x=v}if(c.overlay){n=g.getelementbyid("overlay");if(!n){n=b.createoverlay();p.appendchild(n);r&&b.appendiframe(n)}n.style.display="block"}r&&b.setbodybg();h=g.getelementbyid("easydialogbox"); if(!h){h=b.createdialogbox();p.appendchild(h)}if(c.follow){l=function(){b.setfollow(h,c.follow,c.followx,c.followy)};l();a.bind(o,"resize",l);d.data("follow",l);if(n)n.style.display="none";c.fixed=false}else b.setposition(h,c.fixed);h.style.display="block";j=typeof c.container==="string"?g.getelementbyid(c.container):b.createdialogwrap(c.container);if(l=h.getelementsbytagname("*")[0]){if(l&&j!==l){l.style.display="none";p.appendchild(l);h.appendchild(j)}}else h.appendchild(j);j.style.display="block"; var t=j.offsetwidth,i=j.offsetheight;l=t>e;var k=i>f;j.style.margintop=j.style.marginright=j.style.marginbottom=j.style.marginleft="0px";if(c.follow)h.style.marginleft=h.style.margintop="0px";else{h.style.marginleft="-"+(l?e/2:t/2)+"px";h.style.margintop="-"+(k?f/2:i/2)+"px"}if(r&&!c.overlay){h.style.width=t+"px";h.style.height=i+"px"}e=g.getelementbyid("closebtn");f=g.getelementbyid("easydialogtitle");j=g.getelementbyid("easydialogyesbtn");t=g.getelementbyid("easydialognobtn");j&&a.bind(j,"click", function(s){c.container.yesfn.call(m,s)!==false&&m.close()});if(t){i=function(s){if(c.container.nofn===true||c.container.nofn.call(m,s)!==false)m.close()};a.bind(t,"click",i);e&&a.bind(e,"click",i)}else e&&a.bind(e,"click",m.close);c.lock||a.bind(g,"keyup",g);if(c.autoclose&&typeof c.autoclose==="number")x=settimeout(m.close,c.autoclose);if(c.drag&&f&&!l&&!k){f.style.cursor="move";d.drag(f,h)}if(!c.follow&&!c.fixed){i=function(){b.setposition(h,false)};!l&&!k&&a.bind(o,"resize",i);d.data("resize", i)}d.data("dialogelements",{overlay:n,dialogbox:h,closebtn:e,dialogtitle:f,dialogyesbtn:j,dialognobtn:t})},close:function(){var a=d.data("options"),b=d.data("dialogelements"),c=d.event;if(x){cleartimeout(x);x=v}if(a.overlay&&b.overlay)b.overlay.style.display="none";b.dialogbox.style.display="none";r&&b.dialogbox.style.removeexpression("top");b.closebtn&&c.unbind(b.closebtn,"click");b.dialogtitle&&c.unbind(b.dialogtitle,"mousedown");b.dialogyesbtn&&c.unbind(b.dialogyesbtn,"click");b.dialognobtn&&c.unbind(b.dialognobtn, "click");if(!a.follow&&!a.fixed){c.unbind(o,"resize",d.data("resize"));d.removedata("resize")}if(a.follow){c.unbind(o,"resize",d.data("follow"));d.removedata("follow")}a.lock||c.unbind(g,"keyup",g);typeof a.callback==="function"&&a.callback.call(d);d.removedata("options");d.removedata("dialogelements")}};return d},a=function(){o.easydialog=j()},h=function(){if(!g.body){try{q.doscroll("left")}catch(p){settimeout(h,1);return}a()}};(function(){if(g.body)a();else if(g.addeventlistener){g.addeventlistener("domcontentloaded", function(){g.removeeventlistener("domcontentloaded",arguments.callee,false);a()},false);o.addeventlistener("load",a,false)}else if(g.attachevent){g.attachevent("onreadystatechange",function(){if(g.readystate==="complete"){g.detachevent("onreadystatechange",arguments.callee);a()}});o.attachevent("onload",a);var p=false;try{p=o.frameelement==null}catch(w){}q.doscroll&&p&&h()}})()})(window,undefined);