mkfashion-sdk 2.4.4 → 2.4.6
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.
- package/index.html +2 -2
- package/package.json +1 -1
- package/src/mkfashion.js +40 -5
package/index.html
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
<script>
|
|
16
16
|
(function () {
|
|
17
|
-
var projectid = '
|
|
18
|
-
var identifier = '
|
|
17
|
+
var projectid = '69f09de7fe3120f54c06e0d6';
|
|
18
|
+
var identifier = 'demo-002';
|
|
19
19
|
|
|
20
20
|
function initMkFashion() {
|
|
21
21
|
mkfashion.addToCart(function (payload) {
|
package/package.json
CHANGED
package/src/mkfashion.js
CHANGED
|
@@ -37,6 +37,7 @@ const mkfashion = {
|
|
|
37
37
|
_container: null,
|
|
38
38
|
_escHandler: null,
|
|
39
39
|
_messageHandler: null,
|
|
40
|
+
_confirmingExit: false,
|
|
40
41
|
|
|
41
42
|
_callbacks: {
|
|
42
43
|
onReady: null,
|
|
@@ -127,9 +128,15 @@ const mkfashion = {
|
|
|
127
128
|
return
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
// Avisa o iframe pra limpar a UI de confirmacao de saida antes de esconder.
|
|
132
|
+
// Sem isso, o modal de "Tem certeza?" fica aberto e reaparece na proxima abertura
|
|
133
|
+
// (porque o iframe nao eh destruido entre open/close — apenas escondido).
|
|
134
|
+
this._postToIframe('dismiss_exit_confirmation')
|
|
135
|
+
|
|
130
136
|
this._hideModal()
|
|
131
137
|
this._triggerCallback('onClose')
|
|
132
138
|
this._isOpen = false
|
|
139
|
+
this._confirmingExit = false
|
|
133
140
|
this._log('Fechado')
|
|
134
141
|
},
|
|
135
142
|
|
|
@@ -538,19 +545,40 @@ const mkfashion = {
|
|
|
538
545
|
})
|
|
539
546
|
|
|
540
547
|
this._modal.addEventListener('click', (e) => {
|
|
541
|
-
if (e.target
|
|
542
|
-
|
|
543
|
-
}
|
|
548
|
+
if (e.target !== this._modal) return
|
|
549
|
+
this._handleBackdropOrEscapeAttempt()
|
|
544
550
|
})
|
|
545
551
|
|
|
546
552
|
this._escHandler = (e) => {
|
|
547
553
|
if (e.key === 'Escape') {
|
|
548
|
-
this.
|
|
554
|
+
this._handleBackdropOrEscapeAttempt()
|
|
549
555
|
}
|
|
550
556
|
}
|
|
551
557
|
document.addEventListener('keydown', this._escHandler)
|
|
552
558
|
},
|
|
553
559
|
|
|
560
|
+
/**
|
|
561
|
+
* Primeira tentativa: pede confirmacao no iframe (Vue mostra modal).
|
|
562
|
+
* Segunda tentativa (com flag setada): atalho UX, fecha direto.
|
|
563
|
+
*/
|
|
564
|
+
_handleBackdropOrEscapeAttempt() {
|
|
565
|
+
if (this._confirmingExit) {
|
|
566
|
+
this.close()
|
|
567
|
+
return
|
|
568
|
+
}
|
|
569
|
+
this._confirmingExit = true
|
|
570
|
+
this._postToIframe('show_exit_confirmation')
|
|
571
|
+
this._log('Confirmacao de saida solicitada ao iframe')
|
|
572
|
+
},
|
|
573
|
+
|
|
574
|
+
_postToIframe(action, data = {}) {
|
|
575
|
+
if (!this._iframe || !this._iframe.contentWindow) return
|
|
576
|
+
this._iframe.contentWindow.postMessage(
|
|
577
|
+
{ source: 'mkfashion-sdk', action, data },
|
|
578
|
+
'*'
|
|
579
|
+
)
|
|
580
|
+
},
|
|
581
|
+
|
|
554
582
|
/** Esconde o modal sem remover do DOM (preserva sessao do iframe) */
|
|
555
583
|
_hideModal() {
|
|
556
584
|
if (!this._modal) return
|
|
@@ -586,7 +614,7 @@ const mkfashion = {
|
|
|
586
614
|
|
|
587
615
|
this._escHandler = (e) => {
|
|
588
616
|
if (e.key === 'Escape') {
|
|
589
|
-
this.
|
|
617
|
+
this._handleBackdropOrEscapeAttempt()
|
|
590
618
|
}
|
|
591
619
|
}
|
|
592
620
|
document.addEventListener('keydown', this._escHandler)
|
|
@@ -603,6 +631,7 @@ const mkfashion = {
|
|
|
603
631
|
this._iframe = null
|
|
604
632
|
this._container = null
|
|
605
633
|
this._lastConfig = null
|
|
634
|
+
this._confirmingExit = false
|
|
606
635
|
|
|
607
636
|
if (this._escHandler) {
|
|
608
637
|
document.removeEventListener('keydown', this._escHandler)
|
|
@@ -632,9 +661,15 @@ const mkfashion = {
|
|
|
632
661
|
|
|
633
662
|
switch (action) {
|
|
634
663
|
case 'close_request':
|
|
664
|
+
this._confirmingExit = false
|
|
635
665
|
this.close()
|
|
636
666
|
break
|
|
637
667
|
|
|
668
|
+
case 'cancel_exit_confirmation':
|
|
669
|
+
this._confirmingExit = false
|
|
670
|
+
this._log('Confirmacao de saida cancelada pelo usuario')
|
|
671
|
+
break
|
|
672
|
+
|
|
638
673
|
case 'restart_request':
|
|
639
674
|
this.restart()
|
|
640
675
|
break
|