@memberstack/dom 1.9.7 → 1.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  export declare type OpenModalParams = {
2
2
  type: "LOGIN" | "SIGNUP" | "FORGOT_PASSWORD" | "RESET_PASSWORD" | "PROFILE";
3
3
  };
4
+ export declare const initDefaultMessageBox: () => void;
4
5
  export declare const showMessage: (msg: any, isError: any) => void;
5
6
  export declare const showLoader: (element?: any) => void;
6
7
  export declare const hideLoader: (element?: any) => void;
@@ -39,25 +39,49 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.hideModal = exports.openModal = exports.handleRedirect = exports.hideLoader = exports.showLoader = exports.showMessage = void 0;
42
+ exports.hideModal = exports.openModal = exports.handleRedirect = exports.hideLoader = exports.showLoader = exports.showMessage = exports.initDefaultMessageBox = void 0;
43
+ var defaultMessageBox_js_1 = require("../../utils/defaultMessageBox.js");
43
44
  var main_dom_js_1 = __importDefault(require("./main-dom.js"));
45
+ exports.initDefaultMessageBox = function () {
46
+ if (document.readyState !== "loading") {
47
+ initMessageBoxes();
48
+ }
49
+ else {
50
+ document.addEventListener("DOMContentLoaded", function (event) {
51
+ initMessageBoxes();
52
+ });
53
+ }
54
+ function initMessageBoxes() {
55
+ defaultMessageBox_js_1.initCSS();
56
+ defaultMessageBox_js_1.addSuccessBox();
57
+ defaultMessageBox_js_1.addErrorBox();
58
+ }
59
+ };
44
60
  exports.showMessage = function (msg, isError) {
45
- var cssEl = document.createElement("style");
46
- var css = ".ms-error-message { position: fixed; left: 5%; right: 5%; bottom: 3%; z-index: 10000000; display: block; margin-right: auto; margin-left: auto; padding-top: 1em; padding-right: 10px; padding-bottom: 1em; border-radius: 3px; background-color: #fd3a57; box-shadow: 0 0 0 2px #fff; color: #fff; font-size: 1.1em; line-height: 1.8em; font-weight: 700; text-align: center; }";
47
- cssEl.setAttribute("data-ms-style", "");
48
- cssEl.appendChild(document.createTextNode(css));
49
- document.head.appendChild(cssEl);
50
- var color = isError ? "#FD3A57" : "#40c88b";
51
- var messageHTML = "<div data-ms-message style=\"background: " + color + "\" class=\"ms-error-message\"><div id=\"ms-message\">" + msg + "</div></div>";
52
- var div = document.createElement("div");
53
- div.setAttribute("data-ms-message", "");
54
- div.innerHTML = messageHTML;
55
- document.body.appendChild(div);
61
+ if (!document.querySelector("[data-ms-message='success']")) {
62
+ exports.initDefaultMessageBox();
63
+ }
64
+ var messageBox;
65
+ if (isError) {
66
+ messageBox = document.querySelector("[data-ms-message='error']");
67
+ }
68
+ else {
69
+ messageBox = document.querySelector("[data-ms-message='success']");
70
+ }
71
+ //set text
72
+ var messageTextBox = messageBox.querySelector("[data-ms-message-text]");
73
+ if (messageTextBox) {
74
+ messageTextBox.innerHTML = msg;
75
+ }
76
+ messageBox.style.display = "block";
77
+ //add event listener to close button
78
+ var closeBtn = messageBox.querySelector("[data-ms-message-close]");
79
+ closeBtn === null || closeBtn === void 0 ? void 0 : closeBtn.addEventListener("click", function () {
80
+ messageBox.style.display = "none";
81
+ });
56
82
  setTimeout(function () {
57
- var _a, _b;
58
- (_a = document.querySelector("[data-ms-style]")) === null || _a === void 0 ? void 0 : _a.remove();
59
- (_b = document.querySelector("[data-ms-message]")) === null || _b === void 0 ? void 0 : _b.remove();
60
- }, 4000);
83
+ messageBox.style.display = "none";
84
+ }, 7000);
61
85
  };
62
86
  exports.showLoader = function (element) {
63
87
  if (element) {
@@ -72,7 +96,14 @@ exports.showLoader = function (element) {
72
96
  var div = document.createElement("div");
73
97
  div.setAttribute("data-ms-loader", "true");
74
98
  div.innerHTML = loaderHTML;
75
- document.body.appendChild(div);
99
+ if (document.readyState !== "loading") {
100
+ document.body.appendChild(div);
101
+ }
102
+ else {
103
+ document.addEventListener("DOMContentLoaded", function (event) {
104
+ document.body.appendChild(div);
105
+ });
106
+ }
76
107
  };
77
108
  exports.hideLoader = function (element) {
78
109
  var _a;
@@ -84,9 +115,9 @@ exports.hideLoader = function (element) {
84
115
  };
85
116
  exports.handleRedirect = function (redirect, redirectOverride) {
86
117
  if (redirectOverride)
87
- return window.location.href = redirectOverride;
88
- if (redirect && (window.location.pathname !== redirect))
89
- return window.location.href = redirect;
118
+ return (window.location.href = redirectOverride);
119
+ if (redirect && window.location.pathname !== redirect)
120
+ return (window.location.href = redirect);
90
121
  };
91
122
  var modal;
92
123
  exports.openModal = function (type, params) {
@@ -103,13 +134,15 @@ exports.openModal = function (type, params) {
103
134
  display: type.toLowerCase(),
104
135
  params: params,
105
136
  onSuccess: resolveModal,
106
- }
137
+ },
107
138
  });
108
139
  return [2 /*return*/, modalPromise];
109
140
  });
110
141
  });
111
142
  };
112
143
  exports.hideModal = function () {
144
+ var _a;
113
145
  modal === null || modal === void 0 ? void 0 : modal.$destroy();
114
146
  exports.hideLoader();
147
+ (_a = document.querySelector("#msOverlay")) === null || _a === void 0 ? void 0 : _a.remove();
115
148
  };