Skip to content

Commit d4311cd

Browse files
authored
[FBE.js] Modern JS; remove some unnecessary console logs (#523)
1 parent 9f82629 commit d4311cd

File tree

2 files changed

+38
-64
lines changed

2 files changed

+38
-64
lines changed

app/code/Meta/BusinessExtension/view/adminhtml/web/js/fbe_allinone.js

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
*/
1010
'use strict';
1111

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');
1515

16-
var jQuery = (function (jQuery) {
16+
const jQuery = (function (jQuery) {
1717
if (jQuery && typeof jQuery === 'function') {
1818
return jQuery;
1919
} else {
@@ -27,63 +27,53 @@ var jQuery = (function (jQuery) {
2727
}
2828
})(window.jQuery);
2929

30-
var ajaxify = function (url) {
30+
const ajaxify = function (url) {
3131
return url + '?isAjax=true&storeId=' + window.facebookBusinessExtensionConfig.storeId;
3232
};
3333

34-
var getAndEncodeExternalClientMetadata = function () {
34+
const getAndEncodeExternalClientMetadata = function () {
3535
const metaData = {
3636
customer_token: window.facebookBusinessExtensionConfig.customApiKey
3737
};
3838
return encodeURIComponent(JSON.stringify(metaData));
3939
}
4040

41-
var ajaxParam = function (params) {
41+
const ajaxParam = function (params) {
4242
if (window.FORM_KEY) {
4343
params.form_key = window.FORM_KEY;
4444
}
4545
return params;
4646
};
4747

4848
jQuery(document).ready(function() {
49-
var FBEFlowContainer = React.createClass({
49+
const FBEFlowContainer = React.createClass({
5050

5151
getDefaultProps: function() {
52-
console.log("init props installed "+window.facebookBusinessExtensionConfig.installed);
5352
return {
5453
installed: window.facebookBusinessExtensionConfig.installed
5554
};
5655
},
5756
getInitialState: function() {
58-
console.log("change state");
5957
return {installed: this.props.installed};
6058
},
6159

6260
bindMessageEvents: function bindMessageEvents() {
6361
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 ");
7262

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;
7969
}
80-
}, false);
81-
}
70+
71+
_this.handleMessage(message);
72+
}
73+
}, false);
8274
},
8375
handleMessage: function handleMessage(message) {
8476
const _this = this;
85-
_this.consoleLog("Response from fb login:");
86-
_this.consoleLog(message);
8777

8878
// "FBE Iframe" uses the 'action' field in its messages.
8979
// "Commerce Extension" uses the 'type' field in its messages.
@@ -92,7 +82,6 @@ jQuery(document).ready(function() {
9282

9383
if (action === 'delete' || messageEvent === 'CommerceExtension::UNINSTALL') {
9484
// Delete asset ids stored in db instance.
95-
_this.consoleLog("Successfully uninstalled FBE");
9685
_this.deleteFBAssets();
9786
}
9887

@@ -144,10 +133,9 @@ jQuery(document).ready(function() {
144133
storeId: window.facebookBusinessExtensionConfig.storeId,
145134
}),
146135
success: function onSuccess(data, _textStatus, _jqXHR) {
147-
var response = data;
136+
const response = data;
148137
let msg = '';
149138
if (response.success) {
150-
_this.setState({pixelId: response.pixelId});
151139
msg = "The Meta Pixel with ID: " + response.pixelId + " is now installed on your website.";
152140
} else {
153141
msg = "There was a problem saving the pixel. Please try again";
@@ -356,7 +344,6 @@ jQuery(document).ready(function() {
356344
const _this = this;
357345
const isNewSplashPage = window.facebookBusinessExtensionConfig.isCommerceExtensionEnabled;
358346
try {
359-
_this.consoleLog("query params --"+_this.queryParams());
360347
return React.createElement(
361348
'iframe',
362349
{

app/code/Meta/BusinessExtension/view/adminhtml/web/js/lib/fbe.js

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
*/
99
'use strict';
1010

11-
var React = require('./react');
12-
var ReactDOM = require('./react-dom');
13-
var FBUtils = require('./utils');
11+
const React = require('./react');
12+
const ReactDOM = require('./react-dom');
13+
const FBUtils = require('./utils');
1414

15-
var jQuery = (function (jQuery) {
15+
const jQuery = (function (jQuery) {
1616
if (jQuery && typeof jQuery === 'function') {
1717
return jQuery;
1818
} else {
@@ -26,63 +26,53 @@ var jQuery = (function (jQuery) {
2626
}
2727
})(window.jQuery);
2828

29-
var ajaxify = function (url) {
29+
const ajaxify = function (url) {
3030
return url + '?isAjax=true&storeId=' + window.facebookBusinessExtensionConfig.storeId;
3131
};
3232

33-
var getAndEncodeExternalClientMetadata = function () {
33+
const getAndEncodeExternalClientMetadata = function () {
3434
const metaData = {
3535
customer_token: window.facebookBusinessExtensionConfig.customApiKey
3636
};
3737
return encodeURIComponent(JSON.stringify(metaData));
3838
}
3939

40-
var ajaxParam = function (params) {
40+
const ajaxParam = function (params) {
4141
if (window.FORM_KEY) {
4242
params.form_key = window.FORM_KEY;
4343
}
4444
return params;
4545
};
4646

4747
jQuery(document).ready(function() {
48-
var FBEFlowContainer = React.createClass({
48+
const FBEFlowContainer = React.createClass({
4949

5050
getDefaultProps: function() {
51-
console.log("init props installed "+window.facebookBusinessExtensionConfig.installed);
5251
return {
5352
installed: window.facebookBusinessExtensionConfig.installed
5453
};
5554
},
5655
getInitialState: function() {
57-
console.log("change state");
5856
return {installed: this.props.installed};
5957
},
6058

6159
bindMessageEvents: function bindMessageEvents() {
6260
const _this = this;
63-
if (FBUtils.isIE() && window.MessageChannel) {
64-
// do nothing, wait for our messaging utils to be ready
65-
} else {
66-
window.addEventListener('message', function (event) {
67-
var origin = event.origin || event.originalEvent.origin;
68-
if (FBUtils.urlFromSameDomain(origin, window.facebookBusinessExtensionConfig.popupOrigin)) {
69-
// Make ajax calls to store data from fblogin and fb installs
70-
_this.consoleLog("Message from fblogin ");
7161

72-
const message = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
73-
if (!message) {
74-
return;
75-
}
76-
77-
_this.handleMessage(message);
62+
window.addEventListener('message', function (event) {
63+
const origin = event.origin || event.originalEvent.origin;
64+
if (FBUtils.urlFromSameDomain(origin, window.facebookBusinessExtensionConfig.popupOrigin)) {
65+
const message = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
66+
if (!message) {
67+
return;
7868
}
79-
}, false);
80-
}
69+
70+
_this.handleMessage(message);
71+
}
72+
}, false);
8173
},
8274
handleMessage: function handleMessage(message) {
8375
const _this = this;
84-
_this.consoleLog("Response from fb login:");
85-
_this.consoleLog(message);
8676

8777
// "FBE Iframe" uses the 'action' field in its messages.
8878
// "Commerce Extension" uses the 'type' field in its messages.
@@ -91,7 +81,6 @@ jQuery(document).ready(function() {
9181

9282
if (action === 'delete' || messageEvent === 'CommerceExtension::UNINSTALL') {
9383
// Delete asset ids stored in db instance.
94-
_this.consoleLog("Successfully uninstalled FBE");
9584
_this.deleteFBAssets();
9685
}
9786

@@ -143,10 +132,9 @@ jQuery(document).ready(function() {
143132
storeId: window.facebookBusinessExtensionConfig.storeId,
144133
}),
145134
success: function onSuccess(data, _textStatus, _jqXHR) {
146-
var response = data;
135+
const response = data;
147136
let msg = '';
148137
if (response.success) {
149-
_this.setState({pixelId: response.pixelId});
150138
msg = "The Meta Pixel with ID: " + response.pixelId + " is now installed on your website.";
151139
} else {
152140
msg = "There was a problem saving the pixel. Please try again";
@@ -355,7 +343,6 @@ jQuery(document).ready(function() {
355343
const _this = this;
356344
const isNewSplashPage = window.facebookBusinessExtensionConfig.isCommerceExtensionEnabled;
357345
try {
358-
_this.consoleLog("query params --"+_this.queryParams());
359346
return React.createElement(
360347
'iframe',
361348
{

0 commit comments

Comments
 (0)