diff --git a/bsdialog.js b/bsdialog.js
index c00ed40..04e1b5f 100644
--- a/bsdialog.js
+++ b/bsdialog.js
@@ -1,112 +1,186 @@
/**
* BSDialog
- * @version v0.1.0.024 (2019/07/05 2210)
+ * @version v0.1.0.029a (2019/11/09 2239)
*/
var BSDialog = {
- Create: function(id, title, url, is_big, update_body) {
- var a = this;
- var isBig = ((typeof(is_big) == "undefined") ? false : (is_big == true) ? true : false);
- var updateBody = ((typeof(update_body) == "undefined") ? false : (update_body == true) ? true : false);
+ Create: function (id, title, url, is_big, update_body, show_size) {
+ var a = this;
- if (!a.hasDialog(id)) {
- var html = a.generateModalHtml(id, title, null, isBig);
+ a.id = id;
+ a.title = title;
+ a.url = url;
+ a.isBig = ((typeof (is_big) == "undefined") ? false : (is_big == true) ? true : false);
+ a.showSize = ((typeof (show_size) == "undefined") ? true : (show_size == true) ? true : false);
- $("body").append(html);
- }
+ var updateBody = ((typeof (update_body) == "undefined") ? true : (update_body == true) ? true : false);
- $.ajax({
- url: url,
- cache: false,
- timeout: 10000,
- success: function(result, status, xhr){
- if ((xhr.status == 200) || (xhr.status == 302) || (xhr.status == 301))
- {
- if (updateBody)
- {
- a.updateContentBody(id, result);
- } else {
- $("#dlg" + id).find(".modal-content").html(result);
- }
- } else {
- a.updateContentBody(id, xhr.statusText + " (" + xhr.status + ")");
- }
- },
- error: function(xhr){
- a.updateContentBody(id, xhr.statusText + " (" + xhr.status + ")");
- },
- complete: function(xhr, status){
- // do nothing yet
- }
- });
+ if (!a.Exists(id)) {
+ a.renderContent(null);
+ }
- a.show(id);
- },
- Close: function(id) {
- if (!this.hasDialog(id)) return;
+ if (url != null) {
+ $.ajax({
+ url: url,
+ cache: false,
+ xhrFields: {
+ withCredentials:true
+ },
+ timeout: 60000,
+ success: function (result, status, xhr) {
+ if ((xhr.status == 200) || (xhr.status == 302) || (xhr.status == 301)) {
+ if (updateBody) {
+ a.updateContentBody(id, result);
+ } else {
+ $("#dlg" + id).find(".modal-content").html(result);
+ }
+ } else {
+ a.updateContentBody(id, xhr.statusText + " (" + xhr.status + ")");
+ }
+ },
+ error: function (xhr) {
+ a.updateContentBody(id, xhr.statusText + " (" + xhr.status + ")");
+ },
+ complete: function (xhr, status) {
+ // do nothing yet
+ }
+ });
+ }
- $("#dlg" + id).modal('hide');
- },
- Clear: function() {
- $("body > div[class~='modal'][role='dialog']").remove();
- $("body > div[class~='modal-backdrop']").remove();
- $("body").removeClass("modal-open");
- },
- ShowToast: function(id, title, message, is_big) {
- if (this.hasDialog(id)) return;
+ a.initialiseComponents();
+ },
+ Close: function (id) {
+ $("#dlg" + id).modal('hide');
+ },
+ Clear: function () {
+ $("body > div[class~='modal'][role='dialog']").remove();
+ $("body > div[class~='modal-backdrop']").remove();
+ $("body").removeClass("modal-open");
+ },
+ ShowToast: function (id, title, message, is_big) {
+ var a = this;
- var html = this.generateModalHtml(id, title, message, is_big);
- $("body").append(html);
+ if (a.Exists(id)) {
+ return;
+ }
- this.show(id);
- },
- hasDialog: function(id) {
- return ($("body > div[id='dlg" + id + "']").length > 0);
- },
- generateModalHtml: function(id, title, message, is_big) {
- var size = ((typeof(is_big) == "undefined") ? "sm" : (is_big == true ? "lg" : "sm"));
+ a.id = id;
+ a.title = title;
+ a.url = null;
+ a.isBig = ((typeof (is_big) == "undefined") ? false : (is_big == true) ? true : false);
- var html = "";
- html += "
";
- html += "
";
- html += "
";
- html += " ";
+ a.renderContent(message);
+ a.initialiseComponents();
+ },
+ Exists: function (id) {
+ return ($("body > div[id='dlg" + id + "']").length > 0);
+ },
+ generateModalHtml: function (message) {
+ var a = this;
+ var size = (a.isBig == true ? "lg" : "md");
- if ($.trim(message).length <= 0)
- {
- html += "
";
- } else {
- html += "
" + message + "
";
- }
+ var html = "";
+ html += "
";
+ html += "
";
+ html += "
";
+ html += " ";
- html += "
";
- html += "
";
+ if (a.showSize)
+ {
+ html += "
";
+ html += "
− ";
+ }
- return html;
- },
- show: function(id) {
- $("#dlg" + id).modal('show');
- $("#dlg" + id).off('hide.bs.modal');
- $("#dlg" + id).on('hide.bs.modal', function() {
- if ($("body > div[id='dlg" + id + "']").next().is("div[class~='modal-backdrop']")) {
- $("body > div[id='dlg" + id + "']").next().remove();
- }
+ html += "
" + a.title + " ";
+ html += "
";
- $("body > div[id='dlg" + id + "']").remove();
+ if ($.trim(message).length <= 0) {
+ html += "
";
+ } else {
+ html += "
" + message + "
";
+ }
- });
- },
- updateContentBody: function(id, text) {
- var body = $("#dlg" + id).find(".modal-body");
+ html += " ";
+ html += "
";
+ html += "
";
+ html += "
";
- if ($(body).hasClass("custom-loading")) $(body).removeClass("custom-loading");
+ return html;
+ },
+ renderContent: function (content) {
+ $("body").append(this.generateModalHtml(content));
+ },
+ initialiseComponents: function () {
+ var a = this;
+ var dialog = a.getElement();
- $(body).html(text);
- }
+ if (a.showSize)
+ {
+ var btnToggleSize = $(dialog).find("button[data-modal-action='restore']");
+ if ($(btnToggleSize).length > 0) {
+ $(btnToggleSize).off('click');
+ $(btnToggleSize).on('click', function () {
+ a.toggleSize();
+ });
+ }
+ }
+
+ $(dialog).modal('show');
+
+ $(dialog).off('hide.bs.modal');
+ $(dialog).on('hide.bs.modal', function () {
+ if ($(dialog).next().is("div[class~='modal-backdrop']")) {
+ $(dialog).next().remove();
+ }
+
+ $(dialog).remove();
+ });
+
+ $(dialog).find(".modal-header").off("mousedown");
+ $(dialog).find(".modal-header").on("mousedown", function(e) {
+ var posX = e.pageX - $(this).offset().left;
+ var posY = e.pageY - $(this).offset().top;
+
+ $("body").off("mousemove.draggable");
+ $("body").on("mousemove.draggable", function(e2) {
+ $(dialog).children(".modal-dialog").offset({ "left": (e2.pageX - posX), "top": (e2.pageY - posY) });
+ });
+
+ $("body").off("mouseup");
+ $("body").on("mouseup", function() {
+ $("body").off("mousemove.draggable");
+ });
+
+ $(dialog).off("bs.modal.hide");
+ $(dialog).on("bs.modal.hide", function() {
+ $("body").off("mousemove.draggable");
+ });
+ });
+ },
+ updateContentBody: function (id, text) {
+ var body = $("#dlg" + id).find(".modal-body");
+
+ if ($(body).hasClass("custom-loading")) $(body).removeClass("custom-loading");
+
+ $(body).html(text);
+ },
+ getElement: function () {
+ return $("#dlg" + this.id);
+ },
+ toggleSize: function () {
+ var div = $(this.getElement()).find("div[class^='modal-dialog']");
+ if ($(div).length <= 0) {
+ return;
+ }
+
+ if ($(div).hasClass("modal-md")) {
+ $(div).removeClass("modal-md");
+ $(div).addClass("modal-lg");
+ } else if ($(div).hasClass("modal-lg")) {
+ $(div).removeClass("modal-lg");
+ $(div).addClass("modal-md");
+ }
+ }
};
\ No newline at end of file
diff --git a/bsdialog.min.js b/bsdialog.min.js
index 253ab32..353a5ee 100644
--- a/bsdialog.min.js
+++ b/bsdialog.min.js
@@ -1,8 +1,5 @@
/**
* BSDialog
- * @version v0.1.0.024 (2019/07/05 2210)
+ * @version v0.1.0.029a (2019/11/09 2239)
*/
-var BSDialog={Create:function(id,title,url,is_big,update_body){var a=this;var isBig=((typeof(is_big)=="undefined")?!1:(is_big==!0)?!0:!1);var updateBody=((typeof(update_body)=="undefined")?!1:(update_body==!0)?!0:!1);if(!a.hasDialog(id)){var html=a.generateModalHtml(id,title,null,isBig);$("body").append(html)}
-$.ajax({url:url,cache:!1,timeout:10000,success:function(result,status,xhr){if((xhr.status==200)||(xhr.status==302)||(xhr.status==301)){if(updateBody){a.updateContentBody(id,result)}else{$("#dlg"+id).find(".modal-content").html(result)}}else{a.updateContentBody(id,xhr.statusText+" ("+xhr.status+")")}},error:function(xhr){a.updateContentBody(id,xhr.statusText+" ("+xhr.status+")")},complete:function(xhr,status){}});a.show(id)},Close:function(id){if(!this.hasDialog(id))return;$("#dlg"+id).modal('hide')},Clear:function(){$("body > div[class~='modal'][role='dialog']").remove();$("body > div[class~='modal-backdrop']").remove();$("body").removeClass("modal-open")},ShowToast:function(id,title,message,is_big){if(this.hasDialog(id))return;var html=this.generateModalHtml(id,title,message,is_big);$("body").append(html);this.show(id)},hasDialog:function(id){return($("body > div[id='dlg"+id+"']").length>0)},generateModalHtml:function(id,title,message,is_big){var size=((typeof(is_big)=="undefined")?"sm":(is_big==!0?"lg":"sm"));var html="";html+="";html+="
";html+="
";html+=" ";if($.trim(message).length<=0){html+="
"}else{html+="
"+message+"
"}
-html+=" ";html+="
";html+="
";html+="
";return html},show:function(id){$("#dlg"+id).modal('show');$("#dlg"+id).off('hide.bs.modal');$("#dlg"+id).on('hide.bs.modal',function(){if($("body > div[id='dlg"+id+"']").next().is("div[class~='modal-backdrop']")){$("body > div[id='dlg"+id+"']").next().remove()}
-$("body > div[id='dlg"+id+"']").remove()})},updateContentBody:function(id,text){var body=$("#dlg"+id).find(".modal-body");if($(body).hasClass("custom-loading"))$(body).removeClass("custom-loading");$(body).html(text)}}
\ No newline at end of file
+var BSDialog={Create:function(o,t,e,d,a,s){var l=this;l.id=o,l.title=t,l.url=e,l.isBig=void 0!==d&&1==d,l.showSize=void 0===s||1==s;var n=void 0===a||1==a;l.Exists(o)||l.renderContent(null),null!=e&&$.ajax({url:e,cache:!1,xhrFields:{withCredentials:!0},timeout:6e4,success:function(t,e,d){200==d.status||302==d.status||301==d.status?n?l.updateContentBody(o,t):$("#dlg"+o).find(".modal-content").html(t):l.updateContentBody(o,d.statusText+" ("+d.status+")")},error:function(t){l.updateContentBody(o,t.statusText+" ("+t.status+")")},complete:function(o,t){}}),l.initialiseComponents()},Close:function(o){$("#dlg"+o).modal("hide")},Clear:function(){$("body > div[class~='modal'][role='dialog']").remove(),$("body > div[class~='modal-backdrop']").remove(),$("body").removeClass("modal-open")},ShowToast:function(o,t,e,d){var a=this;a.Exists(o)||(a.id=o,a.title=t,a.url=null,a.isBig=void 0!==d&&1==d,a.renderContent(e),a.initialiseComponents())},Exists:function(o){return $("body > div[id='dlg"+o+"']").length>0},generateModalHtml:function(o){var t=this,e=1==t.isBig?"lg":"md",d="";return d+='',d+='
',d+='
',d+=' ",$.trim(o).length<=0?d+='
':d+='
'+o+"
",d+=' ",d+="
",d+="
",d+="
"},renderContent:function(o){$("body").append(this.generateModalHtml(o))},initialiseComponents:function(){var o=this,t=o.getElement();if(o.showSize){var e=$(t).find("button[data-modal-action='restore']");$(e).length>0&&($(e).off("click"),$(e).on("click",function(){o.toggleSize()}))}$(t).modal("show"),$(t).off("hide.bs.modal"),$(t).on("hide.bs.modal",function(){$(t).next().is("div[class~='modal-backdrop']")&&$(t).next().remove(),$(t).remove()}),$(t).find(".modal-header").off("mousedown"),$(t).find(".modal-header").on("mousedown",function(o){var e=o.pageX-$(this).offset().left,d=o.pageY-$(this).offset().top;$("body").off("mousemove.draggable"),$("body").on("mousemove.draggable",function(o){$(t).children(".modal-dialog").offset({left:o.pageX-e,top:o.pageY-d})}),$("body").off("mouseup"),$("body").on("mouseup",function(){$("body").off("mousemove.draggable")}),$(t).off("bs.modal.hide"),$(t).on("bs.modal.hide",function(){$("body").off("mousemove.draggable")})})},updateContentBody:function(o,t){var e=$("#dlg"+o).find(".modal-body");$(e).hasClass("custom-loading")&&$(e).removeClass("custom-loading"),$(e).html(t)},getElement:function(){return $("#dlg"+this.id)},toggleSize:function(){var o=$(this.getElement()).find("div[class^='modal-dialog']");$(o).length<=0||($(o).hasClass("modal-md")?($(o).removeClass("modal-md"),$(o).addClass("modal-lg")):$(o).hasClass("modal-lg")&&($(o).removeClass("modal-lg"),$(o).addClass("modal-md")))}};
\ No newline at end of file