1234567 |
- /*!
- * zeroModal.js
- * http://git.oschina.net/cylansad/zeroModal
- *
- * Copyright 2016, Sad
- */
- (function(a){if(typeof module!=="undefined"&&typeof exports==="object"&&define.cmd){module.exports=a}else{if(typeof define==="function"&&define.amd){define(function(){return a})}else{window.zeroModal=a}}}((function(e,f){var u={};var r={unique:"",title:"",content:"",url:false,iframe:false,width:"500px",height:"300px",transition:false,opacity:0.2,overlay:true,overlayClose:false,max:false,resize:false,resizeAfterFn:f,ok:false,okTitle:"确定",okFn:false,cancel:false,cancelTitle:"关闭",cancelFn:true,buttonTopLine:true,buttons:[],esc:false,onOpen:false,onLoad:false,onComplete:false,onCleanup:false,onClosed:false};var d=false;var q=1000;var k={};u.show=function(v){var w=m(v);h(w);d=true;e(window).resize(function(){if(d){g(w)}});return w.unique};u.close=function(v){a({unique:v});d=false;delete k[v]};u.closeAll=function(){e('[role="zeromodal-loading"]').remove();e(".zeromodal-overlay").remove();e(".zeromodal-container").each(function(){var x=e(this);var w=x.attr("zero-unique-container");if(w!==f&&k[w]!==f){var v=k[w];if(typeof v.onCleanup==="function"){v.onCleanup()}x.remove();if(typeof v.onClosed==="function"){v.onClosed()}delete k[w]}});d=false};u.loading=function(y){var B=m();t(B);q++;var A=e(window).scrollTop()+Math.ceil(e(window).height()/3);if(y===f){y=1}if(y===1||y===2){var z="zeromodal-loading"+y;e("body").append('<div role="zeromodal-loading" zero-unique-loading="'+B.unique+'" class="'+z+'" style="z-index:'+q+";top:"+A+'px;"></div>')}else{if(i([3,4,5,6],y)){var v={};switch(y){case 3:v.className="pacman";v.containerCount=5;break;case 4:v.className="line-scale-pulse-out";v.containerCount=5;break;case 5:v.className="line-spin-fade-loader";v.containerCount=8;break;case 6:v.className="square-spin";v.containerCount=1;break}var w='<div role="zeromodal-loading" zero-unique-loading="'+B.unique+'" class="'+v.className+'" style="z-index:'+q+";left:46%;top:"+A+'px;">';for(var x=0;x<v.containerCount;x++){w+=" <div></div>"}w+=" </div>";e("body").append(w)}}return B.unique};u.progress=function(B,v){var y=m();t(y);q++;if(B===f){B=3}var D=e(window).scrollTop()+Math.ceil(e(window).height()/3);var C={};switch(B){case 3:C.className="pacman";C.containerCount=5;break;case 4:C.className="line-scale-pulse-out";C.containerCount=5;break;case 5:C.className="line-spin-fade-loader";C.containerCount=8;break;case 6:C.className="square-spin";C.containerCount=1;break}var w='<div zero-unique-loading="'+y.unique+'" class="'+C.className+'" style="z-index:'+q+";left:46%;top:"+D+'px;">';for(var A=0;A<C.containerCount;A++){w+=" <div></div>"}w+=" </div>";w+=' <div zero-unique-loading="'+y.unique+'" class="zeromodal-progress-content" style="z-index:'+q+";top:"+(D+64)+'px;"><span id="progess_content_'+y.unique+'"></span></div>';w+="";e("body").append(w);var z=0;var x=setInterval(function(){e.ajax({url:v.getProgressUrl+"?_="+new Date().getTime(),dataType:"json",type:"get",success:function(E){e("#progess_content_"+y.unique).html(E.progress);if(E.progress==="finish"){clearInterval(x);e.get(v.clearProgressUrl);u.close(y.unique)}}});z++;if(z>=500){clearInterval(x)}},500);return y.unique};u.progress_old=function(x){var A=m();t(A);q++;var D=e(window).scrollTop()+Math.ceil(e(window).height()/3);var E=e(window).width()/2-200;var B=1;if(x!==f&&x>B&&x<10){B=x}var w='<div class="zeromodal-progress" style="top:'+D+"px;left:"+E+"px;z-index:"+q+'">';w+=' <div zeromodal-progress-bar="'+A.unique+'" class="zeromodal-progress-bar" style="width: 0%; background: #92c26a;">';w+=' <span class="zeromodal-progress-icon zeromodal-fa zeromodal-fa-check" style="border-color:#92c26a; color:#92c26a;"><div zeromodal-progress-val="'+A.unique+'" class="zeromodal-progress-val"> 0%</div></span>';w+=" </div>";w+=" </div>";e("body").append(w);var v=0;var C=e('[zeromodal-progress-bar="'+A.unique+'"]');var z=e('[zeromodal-progress-val="'+A.unique+'"]');var y=setInterval(function(){v+=1;C.css("width",v+"%");z.html((v>9?v:" "+v)+"%");if(v>=100){z.html('<span class="line tip"></span><span class="line long"></span>');clearInterval(y)}},B*100);return A.unique};u.alert=function(w){var v={iconClass:"show-zero2 zeromodal-icon-info",iconText:"!"};var x={};e.extend(x,v);if(typeof w==="object"){e.extend(x,w)}else{x.content=w}o(x)};u.error=function(v){var w={iconDisplay:'<div class="show-zero2 zeromodal-icon zeromodal-error"><span class="x-mark"><span class="line left"></span><span class="line right"></span></span></div>'};if(typeof v==="object"){e.extend(w,v)}else{w.content=v}o(w)};u.success=function(v){var w={iconDisplay:'<div class="show-zero2 zeromodal-icon zeromodal-success"><span class="line tip"></span><span class="line long"></span><div class="placeholder"></div></div>'};if(typeof v==="object"){e.extend(w,v)}else{w.content=v}o(w)};u.confirm=function(x,w){var v={iconClass:"show-zero2 zeromodal-icon-question",iconText:"?",};var y={};e.extend(y,v);if(typeof w==="function"){y.okFn=w}y.cancel=true;if(typeof x==="object"){e.extend(y,x)}else{y.content=x}o(y)};function m(v){var w={};e.extend(w,r);e.extend(w,v);if(typeof w.unique==="undefined"||w.unique===""){w.unique=b()}k[w.unique]=w;return w}function h(v){if(typeof v.onOpen==="function"){v.onOpen()}t(v);l(v)}function a(v){if(typeof v==="object"){if(typeof v.onCleanup==="function"){v.onCleanup()}e('[zero-unique-overlay="'+v.unique+'"]').remove();e('[zero-unique-container="'+v.unique+'"]').remove();e('[zero-unique-loading="'+v.unique+'"]').remove();if(typeof v.onClosed==="function"){v.onClosed()}}}function t(y){q++;var w=e(document).width();var x=e(document).height();if(y.overlay){var v=e('<div zero-unique-overlay="'+y.unique+'" class="zeromodal-overlay" style="opacity:'+y.opacity+";z-index:"+q+";width:"+w+"px;height:"+x+'px"></div>');e("body").append(v);if(y.overlayClose){v.css("cursor","pointer");v.click(function(){a(y)})}else{v.click(function(){s(e('[zero-unique-container="'+y.unique+'"]'))})}}}function l(w){q++;var A=w.width.replace("px","");var C=w.height.replace("px","");var v=e(window).width();var B=e(window).height();if(A.indexOf("%")!==-1){A=(v*parseInt(A.replace("%",""))/100)}if(C.indexOf("%")!==-1){C=(B*parseInt(C.replace("%",""))/100)}if(typeof A==="string"){A=parseInt(A)}if(typeof C==="string"){C=parseInt(C)}var G=(v-A)/2;var F=e(window).scrollTop()+Math.ceil((e(window).height()-C)/3);var z=e('<div zero-unique-container="'+w.unique+'" class="zeromodal-container" style="z-index:'+q+";width:"+A+"px;height:"+C+"px;left:"+G+"px;top:"+(w.transition?F-50:F)+'px"></div>');var y='<div zeromodal-unqiue-header="'+w.unique+'" class="zeromodal-header">';y+=' <div title="关闭" zero-close-unique="'+w.unique+'" class="zeromodal-close">×</div>';if(w.max){y+=' <div title="最大化/取消最大化" zero-max-unique="'+w.unique+'" class="zeromodal-max"></div>'}y+=' <span class="modal-title">'+w.title+"</span>";y+=" </div>";var E=e(y);z.append(E);e("body").append(z);e('[zero-close-unique="'+w.unique+'"]').click(function(){a(k[e(this).attr("zero-close-unique")])});e('[zero-max-unique="'+w.unique+'"]').click(function(){if(e(this).attr("max")!=="1"){g(k[e(this).attr("zero-max-unique")],"90%","85%");e(this).attr("max","1")}else{g(k[e(this).attr("zero-max-unique")]);e(this).attr("max","0")}n(w)});if(w.transition){e(".zeromodal-container").animate({top:F},300)}var x=e('<div zero-unique-body="'+w.unique+'" class="zeromodal-body"></div>');z.append(x);n(w);if(w.resize){z.append('<div zero-unique-sweep-tee="'+w.unique+'" class="zeromodal-sweep-tee"></div>');j(w.unique,w)}if(typeof w.onLoad==="function"){w.onLoad()}if(!w.url){e('[zero-unique-body="'+w.unique+'"]').addClass("zeromodal-overflow-y");x.html(w.content);if(typeof w.onComplete==="function"){w.onComplete()}}else{x.html('<div class="zeromodal-loading1"></div>');if(w.iframe){var D=e('<iframe src="'+w.url+'" class="zeromodal-frame"></iframe>');x.append(D);D.load(function(){e(".zeromodal-loading1").remove();if(typeof w.onComplete==="function"){w.onComplete()}})}else{e('[zero-unique-body="'+w.unique+'"]').addClass("zeromodal-overflow-y");e.ajax({url:w.url,dataType:"html",type:"get",success:function(H){x.append(H);e(".zeromodal-loading1").remove();if(typeof w.onComplete==="function"){w.onComplete()}}})}}c(w,z);if(w.esc){e("body").one("keyup",function(H){if(H.keyCode===27){a(w)}})}}function c(z,x){if(z.ok||z.cancel||(z.buttons!==f&&z.buttons.length>0)){var w='<div class="zeromodal-footer">';w+=z.buttonTopLine?'<div class="zeromodal-line"></div>':"";w+=' <div zeromodal-btn-container="'+z.unique+'" class="zeromodal-btn-container"></div>';w+=" </div>";x.append(w);if(z.buttons!==f&&z.buttons.length>0){var A="";for(var y=0;y<z.buttons.length;y++){var v=z.buttons[y];A+='<button class="'+(v.className||"")+'"'+(v.attr!==f?" "+v.attr:"")+">"+v.name+"</button>"}e('[zeromodal-btn-container="'+z.unique+'"]').append(A)}else{if(z.ok){var B=e('<button zeromodal-btn-ok="'+z.unique+'" class="zeromodal-btn zeromodal-btn-primary">'+z.okTitle+"</button>");e('[zeromodal-btn-container="'+z.unique+'"]').append(B);B.click(function(){if(typeof z.okFn==="function"){var D=z.okFn();if(typeof D==="undefined"||D){a(z)}}else{a(z)}})}if(z.cancel){var C=e('<button zeromodal-btn-cancel="'+z.unique+'" class="zeromodal-btn zeromodal-btn-default">'+z.cancelTitle+"</button>");e('[zeromodal-btn-container="'+z.unique+'"]').append(C);C.click(function(){if(typeof z.cancelFn==="function"){var D=z.cancelFn();if(typeof D==="undefined"||D){a(z)}}else{a(z)}})}}}}function o(x){if(typeof x==="undefined"||typeof x.cancelTitle==="undefined"){x.cancelTitle="取消"}var A=m(x);A.width="360px";A.height="300px";A.esc=true;A.ok=true;A.buttonTopLine=false;if(typeof _okFn!=="undefined"){A.okFn=_okFn}if(typeof cancelFn!=="undefined"){A.cancelFn=cancelFn}var w=A.content||"";var v=A.contentDetail||"";A.content="";h(A);var y;if(typeof A.iconDisplay!=="undefined"){y=e(A.iconDisplay)}else{y=e('<div class="zeromodal-icon '+A.iconClass+'">'+A.iconText+"</div>")}var z=e('<div class="zeromodal-title1">'+w+'</div><div class="zeromodal-title2">'+v+"</div>");e('[zero-unique-body="'+A.unique+'"]').append(y);e('[zero-unique-body="'+A.unique+'"]').append(z);e('[zero-unique-body="'+A.unique+'"]').removeClass("zeromodal-overflow-y");e('[zeromodal-btn-ok="'+A.unique+'"]').focus();d=true;e(window).resize(function(){if(d){g(A)}})}function g(x,w,B){e('[zero-unique-overlay="'+x.unique+'"]').css("width",e(document).width()+"px").css("height",e(document).height()+"px");var v=e(window).width();var z=e(window).height();var y=w!==f?w.replace("px",""):x.width.replace("px","");var A=B!==f?B.replace("px",""):x.height.replace("px","");if(y.indexOf("%")!==-1){y=(v*parseInt(y.replace("%",""))/100)}if(A.indexOf("%")!==-1){A=(z*parseInt(A.replace("%",""))/100)}if(typeof y==="string"){y=parseInt(y)}if(typeof A==="string"){A=parseInt(A)}var D=(v-y)/2;var C=e(window).scrollTop()+Math.ceil((e(window).height()-A)/3);e('[zero-unique-container="'+x.unique+'"]').css("width",y+"px").css("height",A+"px").css("left",D+"px").css("top",C+"px")}function p(z){var w=e(window).width();var x=e(window).height();var v=parseInt(e('[zero-unique-container="'+z.unique+'"]').css("width").replace("px",""));var y=parseInt(e('[zero-unique-container="'+z.unique+'"]').css("height").replace("px",""));var A=(w-v)/2;var B=e(window).scrollTop()+Math.ceil((e(window).height()-y)/3);e('[zero-unique-container="'+z.unique+'"]').css("left",A+"px").css("top",B+"px")}function n(x){var w=e('[zeromodal-unqiue-header="'+x.unique+'"]').height();var y=(x.ok||x.cancel||(x.buttons!==f&&x.buttons.length>0))?60:0;var v=e('[zero-unique-container="'+x.unique+'"]').height()-w-10-y;e('[zero-unique-body="'+x.unique+'"]').css("height",v)}function s(x){if(x.length===0){return}var w=x.position().left;for(var v=0;v<2;v++){x.animate({left:w-2},50);x.animate({left:w},50);x.animate({left:w+2},50)}x.animate({left:w},50)}function i(v,x){for(var w=0;w<v.length;w++){if(v[w]===x){return true}}return false}function b(){var y=[];var v="0123456789abcdef";for(var w=0;w<36;w++){y[w]=v.substr(Math.floor(Math.random()*16),1)}y[14]="4";y[19]=v.substr((y[19]&3)|8,1);y[8]=y[13]=y[18]=y[23]="";var x=y.join("");return x}function j(B,y){var C;var w;var v;var z=false;var A=e('[zero-unique-sweep-tee="'+B+'"]')[0];var x=e('[zero-unique-body="'+B+'"]')[0];document.onmousemove=function(D){if(e('[zero-unique-container="'+y.unique+'"]').size()===0){return}w=D.pageX;v=D.pageY;if(C!==f){z=true}};A.onmousedown=function(){document.onselectstart=function(){return false};var D=v-A.offsetTop;var E=w-A.offsetLeft;C=setInterval(function(){if(C&&z){var G=w-E;var F=v-D;e(".zeromodal-container").css("width",G+3+"px").css("height",F+3+"px")}},5)};document.onmouseup=function(){if(e('[zero-unique-container="'+y.unique+'"]').size()===0){return}document.onselectstart=function(){return true};clearInterval(C);C=f;z=false;p(y);n(y);if(y.resizeAfterFn!==f&&typeof y.resizeAfterFn==="function"){y.resizeAfterFn(y)}}}return u}(jQuery))));
|