From f33b751090abc89f26943bb49432bbf213b760fe Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 3 Aug 2023 11:56:18 +0100 Subject: [PATCH] Release 0.1.0.024 --- bsdialog.js | 178 +++++++++++++++++++++++------------------------- bsdialog.min.js | 11 +-- 2 files changed, 93 insertions(+), 96 deletions(-) diff --git a/bsdialog.js b/bsdialog.js index e863980..c00ed40 100644 --- a/bsdialog.js +++ b/bsdialog.js @@ -1,116 +1,112 @@ -/** - * BSHelper - * Bootstrap Helper - * @version v0.1.0.023 (2015/07/14 1157) - */ - - /** * BSDialog - * + * @version v0.1.0.024 (2019/07/05 2210) */ var BSDialog = { - Create:function(id, title, url, is_big){ - id = "dlg" + id; - if ($("#" + id).length <= 0) this.Add(id, title, ((is_big == undefined)? false : is_big)); - //-- - $("#" + id).find(".modal-content").load(url); - $("#" + id).modal('show'); - $("#" + id).on('hide.bs.modal', function(){ - $("body > div[id='" + id + "']").remove(); - $("body > div[class~='modal-backdrop']").remove(); - $("body").removeClass("modal-open"); - }); - }, - Add:function(id, title, is_big){ - if ($("body > div#" + id).length > 0) return; - //-- - var html = ""; - html += "
"; - html += "
"; - html += "
"; - html += "
"; - html += " "; - html += " " + title + ""; - html += "
"; - html += "
"; - html += "
"; - html += " "; - html += "
"; - html += "
"; - html += "
"; - html += "
"; - //-- - $("body").append(html); - }, - Close: function (id) { - if (typeof (id) == "object") - { - var sender = null; - - do - { - if (typeof (id.target) != "undefined") - { - sender = id.target; - break; - } + 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); - if (typeof (id) != "undefined") - { - sender = id; - break; - } - } while (false); - - if (sender == null) return; + if (!a.hasDialog(id)) { + var html = a.generateModalHtml(id, title, null, isBig); - var panel = $(sender).parentsUntil("div[id^='dlg']").parent(); - if ($(panel).length > 0) - { - var dialogID = $(panel).attr("id").substr(3); - - this.Close(dialogID); - } - } else { - if ($("body > div#dlg" + id).length <= 0) return; - - $("body > div#dlg" + id).remove(); - $("body > div[class~='modal-backdrop']").remove(); - $("body").removeClass("modal-open"); + $("body").append(html); } + + $.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 + } + }); + + a.show(id); }, - Clear:function(){ + 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 ($("body > div#" + id).length > 0) return; - //-- + 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 == true ? "lg" : "sm")); + var html = ""; - html += "
"; - html += "
"; + html += "
"; + html += "
"; html += "
"; html += "
"; html += " "; - html += " " + title + ""; + html += " " + title + ""; html += "
"; - html += "
" + message + "
"; + + if ($.trim(message).length <= 0) + { + html += "
"; + } else { + html += "
" + message + "
"; + } + html += "
"; html += " "; html += "
"; html += "
"; html += "
"; html += "
"; - //-- - $("body").append(html); - //-- - $("#" + id).modal('show'); - $("#" + id).on('hide.bs.modal', function(){ - $("body > div[id='" + id + "']").remove(); - $("body > div[class~='modal-backdrop']").remove(); - $("body").removeClass("modal-open"); + + 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 diff --git a/bsdialog.min.js b/bsdialog.min.js index 9b548a9..253ab32 100644 --- a/bsdialog.min.js +++ b/bsdialog.min.js @@ -1,7 +1,8 @@ /** - * BSHelper - * Bootstrap Helper - * @version v0.1.0.023 (2015/07/14 1157) + * BSDialog + * @version v0.1.0.024 (2019/07/05 2210) */ -var BSDialog={Create:function(id,title,url,is_big){id="dlg"+id;if($("#"+id).length<=0)this.Add(id,title,((is_big==undefined)?!1:is_big));$("#"+id).find(".modal-content").load(url);$("#"+id).modal('show');$("#"+id).on('hide.bs.modal',function(){$("body > div[id='"+id+"']").remove();$("body > div[class~='modal-backdrop']").remove();$("body").removeClass("modal-open")})},Add:function(id,title,is_big){if($("body > div#"+id).length>0)return;var html="";html+="
";html+="
";html+="
";html+="
";html+=" ";html+=" "+title+"";html+="
";html+="
";html+="
";html+=" ";html+="
";html+="
";html+="
";html+="
";$("body").append(html)},Close:function(id){if(typeof(id)=="object"){var sender=null;do{if(typeof(id.target)!="undefined"){sender=id.target;break} -if(typeof(id)!="undefined"){sender=id;break}}while(!1);if(sender==null)return;var panel=$(sender).parentsUntil("div[id^='dlg']").parent();if($(panel).length>0){var dialogID=$(panel).attr("id").substr(3);this.Close(dialogID)}}else{if($("body > div#dlg"+id).length<=0)return;$("body > div#dlg"+id).remove();$("body > div[class~='modal-backdrop']").remove();$("body").removeClass("modal-open")}},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($("body > div#"+id).length>0)return;var html="";html+="
";html+="
";html+="
";html+="
";html+=" ";html+=" "+title+"";html+="
";html+="
"+message+"
";html+="
";html+=" ";html+="
";html+="
";html+="
";html+="
";$("body").append(html);$("#"+id).modal('show');$("#"+id).on('hide.bs.modal',function(){$("body > div[id='"+id+"']").remove();$("body > div[class~='modal-backdrop']").remove();$("body").removeClass("modal-open")})}} \ No newline at end of file +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+="
";html+=" ";html+=" "+title+"";html+="
";if($.trim(message).length<=0){html+="
"}else{html+="
"+message+"
"} +html+="
";html+=" ";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