vgapp 1.3.1 → 1.3.3

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.
@@ -23,8 +23,8 @@ const NAME_KEY = "vg.alert";
23
23
  // Глобальная блокировка: предотвращаем открытие нескольких алертов
24
24
  let isAlertOpen = false;
25
25
 
26
- class VGAlert {
27
- constructor(params = {}, lang = 'ru') {
26
+ class VGAlert {
27
+ constructor(params = {}, lang = 'ru') {
28
28
  this.lang = lang;
29
29
  this._defaultParams = {
30
30
  render: {
@@ -90,10 +90,23 @@ class VGAlert {
90
90
  info: getSVG("info"),
91
91
  },
92
92
  };
93
- this._params = this._setParams(params);
94
- }
95
-
96
- static call(options = {}, lang = 'ru') {
93
+ this._params = this._setParams(params);
94
+ }
95
+
96
+ static get NAME() {
97
+ return NAME;
98
+ }
99
+
100
+ static get NAME_KEY() {
101
+ return NAME_KEY;
102
+ }
103
+
104
+ static boot() {
105
+ this._bindDataApi();
106
+ return null;
107
+ }
108
+
109
+ static call(options = {}, lang = 'ru') {
97
110
  const context = new VGAlert(options, lang);
98
111
 
99
112
  if (isAlertOpen) return Promise.reject({ accepted: false, reason: lang_messages(context.lang, NAME_KEY).reason });
@@ -205,7 +218,7 @@ class VGAlert {
205
218
  });
206
219
  }
207
220
 
208
- static confirm(elem, options = {}) {
221
+ static confirm(elem, options = {}) {
209
222
  let lang = 'ru';
210
223
 
211
224
  if ('lang' in options) {
@@ -215,9 +228,35 @@ class VGAlert {
215
228
  const context = new VGAlert(options, lang);
216
229
  if (context._params.mode !== "confirm") return;
217
230
 
218
- const instance = VGAlertConfirm.getOrCreateInstance(elem, context._params);
219
- instance.run(VGAlert);
220
- }
231
+ const instance = VGAlertConfirm.getOrCreateInstance(elem, context._params);
232
+ instance.run(VGAlert);
233
+ }
234
+
235
+ static _bindDataApi() {
236
+ if (this._isDataApiBound) {
237
+ return;
238
+ }
239
+
240
+ this._isDataApiBound = true;
241
+
242
+ EventHandler.on(document, EVENT_KEY_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
243
+ event.preventDefault();
244
+ const target = event.target;
245
+
246
+ if (!isVisible(target) || !isElement(target)) return;
247
+
248
+ VGAlert.confirm(target, {
249
+ buttons: {
250
+ agree: {
251
+ class: ["btn-primary"],
252
+ },
253
+ cancel: {
254
+ class: ["btn-outline-primary"],
255
+ },
256
+ },
257
+ });
258
+ });
259
+ }
221
260
 
222
261
  _setParams(params) {
223
262
  const merged = mergeDeepObject(this._defaultParams, params);
@@ -395,22 +434,6 @@ class VGAlertConfirm extends BaseModule {
395
434
  }
396
435
 
397
436
  // Делегирование кликов по data-атрибутам
398
- EventHandler.on(document, EVENT_KEY_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
399
- event.preventDefault();
400
- const target = event.target;
401
-
402
- if (!isVisible(target) || !isElement(target)) return;
403
-
404
- VGAlert.confirm(target, {
405
- buttons: {
406
- agree: {
407
- class: ["btn-primary"],
408
- },
409
- cancel: {
410
- class: ["btn-outline-primary"],
411
- },
412
- },
413
- });
414
- });
415
-
416
- export default VGAlert;
437
+ VGAlert._isDataApiBound = false;
438
+
439
+ export default VGAlert;