9
9
*/
10
10
'use strict';
11
11
12
- var React = require('./react');
13
- var ReactDOM = require('./react-dom');
14
- var FBUtils = require('./utils');
12
+ const React = require('./react');
13
+ const ReactDOM = require('./react-dom');
14
+ const FBUtils = require('./utils');
15
15
16
- var jQuery = (function (jQuery) {
16
+ const jQuery = (function (jQuery) {
17
17
if (jQuery && typeof jQuery === 'function') {
18
18
return jQuery;
19
19
} else {
@@ -27,63 +27,53 @@ var jQuery = (function (jQuery) {
27
27
}
28
28
})(window.jQuery);
29
29
30
- var ajaxify = function (url) {
30
+ const ajaxify = function (url) {
31
31
return url + '?isAjax=true&storeId=' + window.facebookBusinessExtensionConfig.storeId;
32
32
};
33
33
34
- var getAndEncodeExternalClientMetadata = function () {
34
+ const getAndEncodeExternalClientMetadata = function () {
35
35
const metaData = {
36
36
customer_token: window.facebookBusinessExtensionConfig.customApiKey
37
37
};
38
38
return encodeURIComponent(JSON.stringify(metaData));
39
39
}
40
40
41
- var ajaxParam = function (params) {
41
+ const ajaxParam = function (params) {
42
42
if (window.FORM_KEY) {
43
43
params.form_key = window.FORM_KEY;
44
44
}
45
45
return params;
46
46
};
47
47
48
48
jQuery(document).ready(function() {
49
- var FBEFlowContainer = React.createClass({
49
+ const FBEFlowContainer = React.createClass({
50
50
51
51
getDefaultProps: function() {
52
- console.log("init props installed "+window.facebookBusinessExtensionConfig.installed);
53
52
return {
54
53
installed: window.facebookBusinessExtensionConfig.installed
55
54
};
56
55
},
57
56
getInitialState: function() {
58
- console.log("change state");
59
57
return {installed: this.props.installed};
60
58
},
61
59
62
60
bindMessageEvents: function bindMessageEvents() {
63
61
const _this = this;
64
- if (FBUtils.isIE() && window.MessageChannel) {
65
- // do nothing, wait for our messaging utils to be ready
66
- } else {
67
- window.addEventListener('message', function (event) {
68
- var origin = event.origin || event.originalEvent.origin;
69
- if (FBUtils.urlFromSameDomain(origin, window.facebookBusinessExtensionConfig.popupOrigin)) {
70
- // Make ajax calls to store data from fblogin and fb installs
71
- _this.consoleLog("Message from fblogin ");
72
62
73
- const message = typeof event.data === 'string' ? JSON.parse (event.data) : event.data;
74
- if (!message) {
75
- return;
76
- }
77
-
78
- _this.handleMessage(message) ;
63
+ window.addEventListener('message', function (event) {
64
+ const origin = event.origin || event.originalEvent.origin;
65
+ if (FBUtils.urlFromSameDomain(origin, window.facebookBusinessExtensionConfig.popupOrigin)) {
66
+ const message = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
67
+ if (!message) {
68
+ return ;
79
69
}
80
- }, false);
81
- }
70
+
71
+ _this.handleMessage(message);
72
+ }
73
+ }, false);
82
74
},
83
75
handleMessage: function handleMessage(message) {
84
76
const _this = this;
85
- _this.consoleLog("Response from fb login:");
86
- _this.consoleLog(message);
87
77
88
78
// "FBE Iframe" uses the 'action' field in its messages.
89
79
// "Commerce Extension" uses the 'type' field in its messages.
@@ -92,7 +82,6 @@ jQuery(document).ready(function() {
92
82
93
83
if (action === 'delete' || messageEvent === 'CommerceExtension::UNINSTALL') {
94
84
// Delete asset ids stored in db instance.
95
- _this.consoleLog("Successfully uninstalled FBE");
96
85
_this.deleteFBAssets();
97
86
}
98
87
@@ -144,10 +133,9 @@ jQuery(document).ready(function() {
144
133
storeId: window.facebookBusinessExtensionConfig.storeId,
145
134
}),
146
135
success: function onSuccess(data, _textStatus, _jqXHR) {
147
- var response = data;
136
+ const response = data;
148
137
let msg = '';
149
138
if (response.success) {
150
- _this.setState({pixelId: response.pixelId});
151
139
msg = "The Meta Pixel with ID: " + response.pixelId + " is now installed on your website.";
152
140
} else {
153
141
msg = "There was a problem saving the pixel. Please try again";
@@ -356,7 +344,6 @@ jQuery(document).ready(function() {
356
344
const _this = this;
357
345
const isNewSplashPage = window.facebookBusinessExtensionConfig.isCommerceExtensionEnabled;
358
346
try {
359
- _this.consoleLog("query params --"+_this.queryParams());
360
347
return React.createElement(
361
348
'iframe',
362
349
{
0 commit comments