@saasquatch/squatch-js 2.6.1 → 2.6.2

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/dist/squatch.js CHANGED
@@ -411,7 +411,6 @@ function _validateAnalyticsConfig(raw) {
411
411
  return raw;
412
412
  }
413
413
 
414
- // @ts-check
415
414
  /** @hidden */
416
415
 
417
416
  var _log$8 = debug.debug("squatch-js:widget");
@@ -436,6 +435,7 @@ class Widget {
436
435
  this.context = void 0;
437
436
  this.npmCdn = void 0;
438
437
  this.container = void 0;
438
+ this.loadEventListener = null;
439
439
 
440
440
  _log$8("widget initializing ...");
441
441
 
@@ -496,6 +496,26 @@ class Widget {
496
496
  return parent.querySelector("iframe#squatchFrame");
497
497
  }
498
498
 
499
+ _detachLoadEventListener(frameDoc) {
500
+ if (this.loadEventListener) {
501
+ frameDoc.removeEventListener("sq:user-registration", this.loadEventListener);
502
+ this.loadEventListener = null;
503
+ }
504
+ }
505
+
506
+ _attachLoadEventListener(frameDoc, sqh) {
507
+ if (this.loadEventListener === null) {
508
+ this.loadEventListener = e => {
509
+ this._loadEvent(_extends({}, sqh, {
510
+ userId: e.detail.userId,
511
+ accountId: e.detail.accountId
512
+ }));
513
+ };
514
+
515
+ frameDoc.addEventListener("sq:user-registration", this.loadEventListener);
516
+ }
517
+ }
518
+
499
519
  _loadEvent(sqh) {
500
520
  var _this$analyticsApi$pu;
501
521
 
@@ -817,6 +837,8 @@ class EmbedWidget extends Widget {
817
837
  this._loadEvent(_sqh);
818
838
 
819
839
  _log$7("loaded");
840
+ } else if (frameDoc) {
841
+ this._attachLoadEventListener(frameDoc, _sqh);
820
842
  }
821
843
  });
822
844
  }
@@ -844,6 +866,10 @@ class EmbedWidget extends Widget {
844
866
  this._loadEvent(_sqh);
845
867
 
846
868
  _log$7("loaded");
869
+ } else {
870
+ if (!frame.contentDocument) return;
871
+
872
+ this._attachLoadEventListener(frame.contentDocument, _sqh);
847
873
  }
848
874
  }
849
875
 
@@ -851,6 +877,7 @@ class EmbedWidget extends Widget {
851
877
  var frame = this._findFrame();
852
878
 
853
879
  if (!frame) return _log$7("no target element to close");
880
+ if (frame.contentDocument) this._detachLoadEventListener(frame.contentDocument);
854
881
 
855
882
  var element = this._findElement();
856
883
 
@@ -1057,11 +1084,16 @@ class PopupWidget extends Widget {
1057
1084
  this._loadEvent(_sqh);
1058
1085
 
1059
1086
  _log$6("Popup opened");
1087
+ } else {
1088
+ this._attachLoadEventListener(frameDoc, _sqh);
1060
1089
  }
1061
1090
  });
1062
1091
  }
1063
1092
 
1064
1093
  close() {
1094
+ var frame = this._findFrame();
1095
+
1096
+ if (frame != null && frame.contentDocument) this._detachLoadEventListener(frame.contentDocument);
1065
1097
  var element = this.container ? this._findElement() : document.body;
1066
1098
  var parent = element.shadowRoot || element;
1067
1099
  var dialog = parent.querySelector("#" + this.id);