(function(b){var a=function(c){this.defaultoptions={id:a.newguid(),type:a.type_primary,size:a.size_normal,cssclass:"",title:null,message:null,buttons:[],closable:true,spinicon:a.icon_spinner,data:{},onshow:null,onhide:null,autodestroy:true,draggable:false};this.indexedbuttons={};this.registeredbuttonhotkeys={};this.draggabledata={ismousedown:false,mouseoffset:{}};this.realized=false;this.opened=false;this.initoptions(c);this.holdthisinstance()};a.namespace="bootstrap-dialog";a.type_default="type-default";a.type_info="type-info";a.type_primary="type-primary";a.type_success="type-success";a.type_warning="type-warning";a.type_danger="type-danger";a.default_texts={};a.default_texts[a.type_default]="提示信息";a.default_texts[a.type_info]="提示信息";a.default_texts[a.type_primary]="提示信息";a.default_texts[a.type_success]="success";a.default_texts[a.type_warning]="warning";a.default_texts[a.type_danger]="danger";a.size_normal="size-normal";a.size_large="size-large";a.button_sizes={};a.button_sizes[a.size_normal]="";a.button_sizes[a.size_large]="btn-lg";a.icon_spinner="glyphicon glyphicon-asterisk";a.dialogs={};a.openall=function(){b.each(a.dialogs,function(d,c){c.open()})};a.closeall=function(){b.each(a.dialogs,function(d,c){c.close()})};a.prototype={constructor:a,initoptions:function(c){this.options=b.extend(true,this.defaultoptions,c);return this},holdthisinstance:function(){a.dialogs[this.getid()]=this;return this},initmodalstuff:function(){this.setmodal(this.createmodal()).setmodaldialog(this.createmodaldialog()).setmodalcontent(this.createmodalcontent()).setmodalheader(this.createmodalheader()).setmodalbody(this.createmodalbody()).setmodalfooter(this.createmodalfooter());this.getmodal().append(this.getmodaldialog());this.getmodaldialog().append(this.getmodalcontent());this.getmodalcontent().append(this.getmodalheader()).append(this.getmodalbody()).append(this.getmodalfooter());return this},createmodal:function(){var c=b('');c.prop("id",this.getid());return c},getmodal:function(){return this.$modal},setmodal:function(c){this.$modal=c;return this},createmodaldialog:function(){return b('')},getmodaldialog:function(){return this.$modaldialog},setmodaldialog:function(c){this.$modaldialog=c;return this},createmodalcontent:function(){return b('')},getmodalcontent:function(){return this.$modalcontent},setmodalcontent:function(c){this.$modalcontent=c;return this},createmodalheader:function(){return b('')},getmodalheader:function(){return this.$modalheader},setmodalheader:function(c){this.$modalheader=c;return this},createmodalbody:function(){return b('')},getmodalbody:function(){return this.$modalbody},setmodalbody:function(c){this.$modalbody=c;return this},createmodalfooter:function(){return b('')},getmodalfooter:function(){return this.$modalfooter},setmodalfooter:function(c){this.$modalfooter=c;return this},createdynamiccontent:function(d){var c=null;if(typeof d==="function"){c=d.call(d,this)}else{c=d}if(typeof c==="string"){c=this.formatstringcontent(c)}return c},formatstringcontent:function(c){return c.replace(/\r\n/g,"
").replace(/[\r\n]/g,"
")},setdata:function(c,d){this.options.data[c]=d;return this},getdata:function(c){return this.options.data[c]},setid:function(c){this.options.id=c;return this},getid:function(){return this.options.id},gettype:function(){return this.options.type},settype:function(c){this.options.type=c;return this},getsize:function(){return this.options.size},setsize:function(c){this.options.size=c;return this},getcssclass:function(){return this.options.cssclass},setcssclass:function(c){this.options.cssclass=c;return this},gettitle:function(){return this.options.title},settitle:function(c){this.options.title=c;this.updatetitle();return this},updatetitle:function(){if(this.isrealized()){var c=this.gettitle()!==null?this.createdynamiccontent(this.gettitle()):this.getdefaulttext();this.getmodalheader().find("."+this.getnamespace("title")).html("").append(c)}return this},getmessage:function(){return this.options.message},setmessage:function(c){this.options.message=c;this.updatemessage();return this},updatemessage:function(){if(this.isrealized()){var c=this.createdynamiccontent(this.getmessage());this.getmodalbody().find("."+this.getnamespace("message")).html("").append(c)}return this},isclosable:function(){return this.options.closable},setclosable:function(c){this.options.closable=c;this.updateclosable();return this},getspinicon:function(){return this.options.spinicon},setspinicon:function(c){this.options.spinicon=c;return this},addbutton:function(c){this.options.buttons.push(c);return this},addbuttons:function(d){var c=this;b.each(d,function(e,f){c.addbutton(f)});return this},getbuttons:function(){return this.options.buttons},setbuttons:function(c){this.options.buttons=c;return this},getbutton:function(c){if(typeof this.indexedbuttons[c]!=="undefined"){return this.indexedbuttons[c]}return null},getbuttonsize:function(){if(typeof a.button_sizes[this.getsize()]!=="undefined"){return a.button_sizes[this.getsize()]}return""},isautodestroy:function(){return this.options.autodestroy},setautodestroy:function(c){this.options.autodestroy=c},getdefaulttext:function(){return a.default_texts[this.gettype()]},getnamespace:function(c){return a.namespace+"-"+c},createheadercontent:function(){var c=b("
");c.addclass(this.getnamespace("header"));c.append(this.createtitlecontent());c.append(this.createclosebutton());return c},createtitlecontent:function(){var c=b("
");c.addclass(this.getnamespace("title"));return c},createclosebutton:function(){var d=b("
");d.addclass(this.getnamespace("close-button"));var c=b('');d.append(c);d.on("click",{dialog:this},function(e){e.data.dialog.close()});return d},createbodycontent:function(){var c=b("
");c.addclass(this.getnamespace("body"));c.append(this.createmessagecontent());return c},createmessagecontent:function(){var c=b("
");c.addclass(this.getnamespace("message"));return c},createfootercontent:function(){var c=b("
");c.addclass(this.getnamespace("footer"));c.append(this.createfooterbuttons());return c},createfooterbuttons:function(){var c=this;var d=b("
");d.addclass(this.getnamespace("footer-buttons"));this.indexedbuttons={};b.each(this.options.buttons,function(e,f){if(!f.id){f.id=a.newguid()}var g=c.createbutton(f);c.indexedbuttons[f.id]=g;d.append(g)});return d},createbutton:function(c){var d=b('');d.addclass(this.getbuttonsize());d.prop("id",c.id);if(typeof c.icon!==undefined&&b.trim(c.icon)!==""){d.append(this.createbuttonicon(c.icon))}if(typeof c.label!==undefined){d.append(c.label)}if(typeof c.cssclass!==undefined&&b.trim(c.cssclass)!==""){d.addclass(c.cssclass)}else{d.addclass("btn-default")}if(typeof c.hotkey!==undefined){this.registeredbuttonhotkeys[c.hotkey]=d}d.on("click",{dialog:this,$button:d,button:c},function(g){var f=g.data.dialog;var h=g.data.$button;var e=g.data.button;if(typeof e.action==="function"){e.action.call(h,f)}if(e.autospin){h.togglespin(true)}});this.enhancebutton(d);return d},enhancebutton:function(c){c.dialog=this;c.toggleenable=function(d){var e=this;e.prop("disabled",!d).toggleclass("disabled",!d);return e};c.enable=function(){var d=this;d.toggleenable(true);return d};c.disable=function(){var d=this;d.toggleenable(false);return d};c.togglespin=function(g){var f=this;var e=f.dialog;var d=f.find("."+e.getnamespace("button-icon"));if(g){d.hide();c.prepend(e.createbuttonicon(e.getspinicon()).addclass("icon-spin"))}else{d.show();c.find(".icon-spin").remove()}return f};c.spin=function(){var d=this;d.togglespin(true);return d};c.stopspin=function(){var d=this;d.togglespin(false);return d};return this},createbuttonicon:function(d){var c=b("");c.addclass(this.getnamespace("button-icon")).addclass(d);return c},enablebuttons:function(c){b.each(this.indexedbuttons,function(e,d){d.toggleenable(c)});return this},updateclosable:function(){if(this.isrealized()){this.getmodalheader().find("."+this.getnamespace("close-button")).toggle(this.isclosable())}return this},onshow:function(c){this.options.onshow=c;return this},onhide:function(c){this.options.onhide=c;return this},isrealized:function(){return this.realized},setrealized:function(c){this.realized=c;return this},isopened:function(){return this.opened},setopened:function(c){this.opened=c;return this},handlemodalevents:function(){this.getmodal().on("show.bs.modal",{dialog:this},function(d){var c=d.data.dialog;typeof c.options.onshow==="function"&&c.options.onshow(c);c.showpagescrollbar(true)});this.getmodal().on("hide.bs.modal",{dialog:this},function(d){var c=d.data.dialog;typeof c.options.onhide==="function"&&c.options.onhide(c)});this.getmodal().on("hidden.bs.modal",{dialog:this},function(d){var c=d.data.dialog;c.isautodestroy()&&b(this).remove();c.showpagescrollbar(false)});this.getmodal().on("click",{dialog:this},function(c){c.target===this&&c.data.dialog.isclosable()&&c.data.dialog.close()});this.getmodal().on("keyup",{dialog:this},function(c){c.which===27&&c.data.dialog.isclosable()&&c.data.dialog.close()});this.getmodal().on("keyup",{dialog:this},function(d){var c=d.data.dialog;if(typeof c.registeredbuttonhotkeys[d.which]!=="undefined"){var e=b(c.registeredbuttonhotkeys[d.which]);!e.prop("disabled")&&e.focus().trigger("click")}});return this},makemodaldraggable:function(){if(this.options.draggable){this.getmodalheader().addclass(this.getnamespace("draggable")).on("mousedown",{dialog:this},function(e){var d=e.data.dialog;d.draggabledata.ismousedown=true;var c=d.getmodalcontent().offset();d.draggabledata.mouseoffset={top:e.clienty-c.top,left:e.clientx-c.left}});this.getmodal().on("mouseup mouseleave",{dialog:this},function(c){c.data.dialog.draggabledata.ismousedown=false});b("body").on("mousemove",{dialog:this},function(d){var c=d.data.dialog;if(!c.draggabledata.ismousedown){return}c.getmodalcontent().offset({top:d.clienty-c.draggabledata.mouseoffset.top,left:d.clientx-c.draggabledata.mouseoffset.left})})}return this},showpagescrollbar:function(c){b(document.body).toggleclass("modal-open",c)},realize:function(){this.initmodalstuff();this.getmodal().addclass(a.namespace).addclass(this.gettype()).addclass(this.getsize()).addclass(this.getcssclass());this.getmodalfooter().append(this.createfootercontent());this.getmodalheader().append(this.createheadercontent());this.getmodalbody().append(this.createbodycontent());this.getmodal().modal({backdrop:"static",keyboard:false,show:false});this.makemodaldraggable();this.handlemodalevents();this.setrealized(true);this.updatetitle();this.updatemessage();this.updateclosable();return this},open:function(){!this.isrealized()&&this.realize();this.getmodal().modal("show");this.setopened(true);return this},close:function(){this.getmodal().modal("hide");if(this.isautodestroy()){delete a.dialogs[this.getid()]}this.setopened(false);return this}};a.newguid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(f){var e=math.random()*16|0,d=f==="x"?e:(e&3|8);return d.tostring(16)})};a.show=function(c){return new a(c).open()};a.alert=function(c,d){return new a({message:c,data:{callback:d},closable:false,buttons:[{label:"确认",action:function(e){typeof e.getdata("callback")==="function"&&e.getdata("callback")(true);e.close()}}]}).open()};a.confirm=function(c,d){return new a({title:"确认框",message:c,closable:false,data:{callback:d},buttons:[{label:"取消",action:function(e){typeof e.getdata("callback")==="function"&&e.getdata("callback")(false);e.close()}},{label:"确认",cssclass:"btn-primary",action:function(e){typeof e.getdata("callback")==="function"&&e.getdata("callback")(true);e.close()}}]}).open()};a.init=function(){var c=(typeof module!=="undefined"&&module.exports);if(c){module.exports=a}else{if(typeof define==="function"&&define.amd){define("bootstrap-dialog",function(){return a})}else{window.bootstrapdialog=a}}};a.init()})(window.jquery);