-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.min.js
1 lines (1 loc) · 4.67 KB
/
dialog.min.js
1
jQuery.dialog=function(a,b){return function(c){function d(){var b=a("<div></div>",{"class":s.titleCls});b.append(a("<label></label>")),b.append(a("<a></a>").html(s.closeText));var c=a("<div></div>",{"class":s.contentCls}),d=a("<div></div>",{"class":s.bottomCls});d.append(a("<div></div>",{"class":s.tipCls})),0==a(s.con).length&&a("body").append(a("<div></div>").attr("id",s.con.slice(1))),a(s.con).css({position:s.fix?"fixed":"absolute",display:"none","z-index":"10001",top:p(s.top),left:p(s.left),width:p(s.width),height:p(s.height)}).addClass(s.holderCls).html(b).append(c).append(d).find("."+s.titleCls+" a").click(l),s.bgCls&&0==a(s.con+"_bg").length&&a("body").append(a("<div></div>",{"class":s.bgCls,id:s.con.slice(1)+"_bg"}).css("z-index","10000"));var e=0-.5*a(s.con).width()+"px";return a(s.con).css("margin-left",e),s.drag&&q(),r}function e(b){return u?r:"undefined"==typeof b?a(s.con).find("."+s.titleCls+" label").html():(a(s.con).find("."+s.titleCls+" label").html(b),r)}function f(b,c){if(u)return r;var d=a(s.con+" ."+s.contentCls);if(null==b)return d;var e=a("<div></div>",{"class":s.barCls}).html(b);return"number"==typeof c&&c>0&&(c={"padding-top":c+"px","padding-bottom":c+"px"}),null!=c&&e.css(c),d.append(e),r}function g(){return u?r:(a(s.con).find("."+s.titleCls+" label").empty(),a(s.con).find("."+s.contentCls).empty(),a(s.con).find("."+s.buttonCls).detach(),h(""),t=0,r)}function h(b){return u?r:null==b?a(s.con).find("."+s.bottomCls).find("."+s.tipCls):(a(s.con).find("."+s.bottomCls).find("."+s.tipCls).html(b),r)}function i(b,c){if(u)return r;t++;var d={name:"确定",cls:s.buttonCls,id:"",events:l};"function"==typeof b?d.events=b:"string"==typeof b?(d.name=b,"function"==typeof c&&(d.events=c)):"object"==typeof b&&(d=a.extend(d,b));var e={"class":s.buttonCls+" "+s.buttonCls+"_"+t+" "+d.cls};""!=d.id&&(e.id=d.id);var f=a("<a></a>",e).html(d.name);return a(s.con).find("."+s.bottomCls).append(f),"string"==typeof d.events?f.attr("href",d.events):f.click(d.events),r}function j(b,c,d,e){if(u)return r;"object"!=typeof b&&(b={id:b});var g="text";"password"==b.inputtype&&(g=b.inputtype,delete b.inputtype),g='<input type="'+g+'">',d&&(g="<textarea></textarea>");var h=a(g).attr(b);return null!=c&&(h=a("<label></label>",{"for":b.id}).html(c).add(h)),f(h),"undefined"!=typeof e&&h.not("label").keyup(function(a){var b=a.which||a.keyCode;13==b&&e.call(this,a)}),r}function k(){if(u)return r;var b=a(s.con).show(),c=a(s.con+"_bg").show();return s.bgClsClose&&c.click(l),b.find("."+s.contentCls).find("textarea, input").focus(),r}function l(){return u?r:(a(s.con+"_bg, "+s.con).hide(),r)}function m(){var b=a(s.con+" input, "+s.con+" textarea");return b.attr("disabled","disabled"),u=!0,r}function n(){var b=a(s.con+" input, "+s.con+" textarea");return b.removeAttr("disabled"),u=!1,r}function o(b,c,d,e,f,g){return u?r:(a.isArray(b)&&(c=b[1],d=b[2],e=b[3],f=b[4],g=b[5],b=b[0]),s.width=null==b?s.width:b,s.height=null==c?s.height:c,s.top=null==d?s.top:d,s.left=null==e?s.left:e,null==g&&(g=n),null==f?(a(s.con).css({width:p(s.width),height:p(s.height),top:p(s.top),left:p(s.left)}),g.call(this)):(0==s.height&&(_temp=a(s.con).clone().appendTo(a(s.con).parent()).css("height","auto"),s.height=_temp.css({width:p(s.width,"width"),height:p(s.height,"height"),top:p(s.top,"top"),left:p(s.left,"left")}).outerHeight(!0),_temp.detach()),a(s.con).animate({width:p(s.width,"width"),height:p(s.height,"height"),top:p(s.top,"top"),left:p(s.left,"left")},f,g)),r)}function p(c,d){var e=!1;if(c>1)e=d?c:c+"px";else if(c>0){var f=0;"width"==d||"left"==d?f=a(s.con).parent().width():("height"==d||"top"==d)&&(f=a(s.con).parent().height()),e=d?c*f:100*c+"%"}else 0===c&&(e=d?b:"auto");return e}function q(){var b=!1,c={x:0,y:0},d={x:0,y:0},e=a(s.con);e.find("."+s.titleCls).css("cursor","move").mouseup(function(){b=!1,d={x:0,y:0},e.removeClass(s.unselectCls)}).mousedown(function(a){b=!0,c.x=a.pageX,c.y=a.pageY,d.x=e.position().left,d.y=e.position().top,e.addClass(s.unselectCls)}),a("body").mousemove(function(f){if(!u){if(b){var g=f.pageY-c.y+d.y,h=f.pageX-c.x+d.x;s.fix&&(h-=a(window).scrollLeft(),g-=a(window).scrollTop()),e.css({left:h+"px",top:g+"px"})}f.originalEvent&&f.originalEvent.preventDefault&&f.originalEvent.preventDefault()}})}var r={init:d,title:e,content:f,input:j,tip:h,button:i,show:k,hide:l,clear:g,lock:m,unlock:n,size:o},s={con:"#dialog",bgCls:"dialog-bg",holderCls:"dialog",titleCls:"dialog-title",contentCls:"dialog-content",barCls:"dialog-bar",bottomCls:"dialog-bottom",buttonCls:"dialog-button",tipCls:"dialog-tip",unselectCls:"unselect",closeText:"×",bgClose:!0,drag:!0,fix:!0,width:360,height:0,top:150,left:.5},t=0,u=!1;switch(typeof c){case"number":s.top=c;break;case"string":s.con=c;break;case"object":s=a.extend(s,c)}return r}}(jQuery);