From 652e706f8b97d53b1740e877b8b4324357f8892d Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 26 Jul 2019 10:24:40 +0100 Subject: [PATCH] Added: bsdialog --- 2019/07/bsdialog-v0.1.0.025.js | 114 +++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 2019/07/bsdialog-v0.1.0.025.js diff --git a/2019/07/bsdialog-v0.1.0.025.js b/2019/07/bsdialog-v0.1.0.025.js new file mode 100644 index 0000000..bbb49d1 --- /dev/null +++ b/2019/07/bsdialog-v0.1.0.025.js @@ -0,0 +1,114 @@ +/** + * BSDialog + * @version v0.1.0.025 (2019/07/26 1022) + */ +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); + + if (!a.hasDialog(id)) { + var html = a.generateModalHtml(id, title, null, isBig); + + $("body").append(html); + } + + if (url != null) + { + $.ajax({ + url: url, + cache: false, + 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 + } + }); + } + 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 == true ? "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