Skip to content

Commit 9736560

Browse files
authored
Merge pull request #107 from Kit/add-js-coding-standards
Add JS Coding Standards
2 parents 90964f4 + 1160332 commit 9736560

6 files changed

Lines changed: 55 additions & 45 deletions

File tree

.distignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
.env.example
1616
.env.testing
1717
.env
18+
.eslintrc.js
1819
.gitignore
1920
.stylelintrc.json
2021
ACTIONS-FILTERS.md

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
extends: 'plugin:@wordpress/eslint-plugin/recommended',
3+
globals: {
4+
WPFormsBuilder: 'readonly',
5+
},
6+
};

.github/workflows/coding-standards.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ jobs:
132132
working-directory: ${{ env.PLUGIN_DIR }}
133133
run: npm run lint:css
134134

135+
# Run JS Coding Standards on Plugin.
136+
- name: Run WordPress JS Coding Standards
137+
working-directory: ${{ env.PLUGIN_DIR }}
138+
run: npm run lint:js
139+
135140
# Run PHPStan for static analysis.
136141
- name: Run PHPStan Static Analysis
137142
working-directory: ${{ env.PLUGIN_DIR }}

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@
2828
"phpcbf-tests": "vendor/bin/phpcbf ./tests --standard=phpcs.tests.xml -s -v",
2929
"lint-css": "npm run lint:css",
3030
"fix-css": "npm run fix:css",
31+
"lint-js": "npm run lint:js",
32+
"fix-js": "npm run fix:js",
3133
"phpstan": "vendor/bin/phpstan analyse --memory-limit=1250M",
3234
"php-coding-standards": "vendor/bin/phpcs ./ -s -v",
3335
"fix-php-coding-standards": "vendor/bin/phpcbf ./ -s -v",
3436
"php-coding-standards-on-tests": "vendor/bin/phpcs ./tests --standard=phpcs.tests.xml -s -v",
3537
"fix-php-coding-standards-on-tests": "vendor/bin/phpcbf ./tests --standard=phpcs.tests.xml -s -v",
3638
"css-coding-standards": "npm run lint:css",
3739
"fix-css-coding-standards": "npm run fix:css",
40+
"js-coding-standards": "npm run lint:js",
41+
"fix-js-coding-standards": "npm run fix:js",
3842
"php-static-analysis": "vendor/bin/phpstan analyse --memory-limit=1250M",
3943
"test": [
4044
"vendor/bin/codecept build @no_additional_args",

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"private": true,
44
"scripts": {
55
"lint:css": "wp-scripts lint-style --max-warnings=0",
6-
"fix:css": "wp-scripts lint-style --fix"
6+
"fix:css": "wp-scripts lint-style --fix",
7+
"lint:js": "wp-scripts lint-js --max-warnings=0",
8+
"fix:js": "wp-scripts lint-js --fix"
79
},
810
"prettier": "@wordpress/prettier-config",
911
"devDependencies": {

resources/backend/js/form-builder.js

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*
44
* @since 1.8.4
55
*
6-
* @package Integrate_ConvertKit_WPForms
76
* @author ConvertKit
87
*/
98

@@ -13,7 +12,6 @@
1312
* @since 1.8.4
1413
*/
1514
const IntegrateConvertKitWPFormsOauth = (function () {
16-
1715
/**
1816
* Public functions and properties.
1917
*
@@ -22,32 +20,26 @@ const IntegrateConvertKitWPFormsOauth = (function () {
2220
* @type {Object}
2321
*/
2422
const app = {
25-
2623
/**
2724
* If the OAuth popup is open.
2825
*
2926
* @since 1.8.4
3027
*/
31-
isOpened : false,
28+
isOpened: false,
3229

3330
/**
3431
* Initialize.
3532
*
3633
* @since 1.8.4
3734
*/
38-
init: function () {
39-
35+
init() {
4036
// Show the OAuth popup window when the user clicks the "Connect to Kit" button
4137
// when editing a WPForms Form at Marketing > Kit.
42-
document.addEventListener(
43-
'click',
44-
function ( e ) {
45-
if ( e.target.matches( 'a[data-provider="convertkit"]' ) ) {
46-
app.showWindow( e );
47-
}
38+
document.addEventListener('click', function (e) {
39+
if (e.target.matches('a[data-provider="convertkit"]')) {
40+
app.showWindow(e);
4841
}
49-
);
50-
42+
});
5143
},
5244

5345
/**
@@ -57,29 +49,35 @@ const IntegrateConvertKitWPFormsOauth = (function () {
5749
*
5850
* @param {Event} e Click event.
5951
*/
60-
showWindow: function ( e ) {
61-
52+
showWindow(e) {
6253
e.preventDefault();
6354

64-
if ( app.isOpened ) {
55+
if (app.isOpened) {
6556
return;
6657
}
6758

6859
// Define popup width, height and positioning.
69-
const width = 640,
70-
height = 750,
71-
top = ( window.screen.height - height ) / 2,
72-
left = ( window.screen.width - width ) / 2;
60+
const width = 640,
61+
height = 750,
62+
top = (window.screen.height - height) / 2,
63+
left = (window.screen.width - width) / 2;
7364

7465
// Open popup.
7566
const kitPopup = window.open(
7667
e.target.href,
7768
'convertkit_popup_window',
78-
'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left
69+
'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' +
70+
width +
71+
',height=' +
72+
height +
73+
',top=' +
74+
top +
75+
',left=' +
76+
left
7977
);
8078

8179
// Center popup and focus.
82-
kitPopup.moveTo( left, top );
80+
kitPopup.moveTo(left, top);
8381
kitPopup.focus();
8482

8583
// Mark popup as opened.
@@ -92,27 +90,21 @@ const IntegrateConvertKitWPFormsOauth = (function () {
9290
// document changes (e.g. as the user steps through OAuth flow), and doesn't fire when
9391
// the window is closed.
9492
// See https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128.
95-
const checkWindowClosed = setInterval(
96-
function () {
97-
if ( kitPopup.closed ) {
98-
clearInterval( checkWindowClosed );
99-
100-
// Save the form builder and reload, to reflect the changes.
101-
WPFormsBuilder.formSave( false ).done(
102-
function () {
103-
WPFormsBuilder.setCloseConfirmation( false );
104-
WPFormsBuilder.showLoadingOverlay();
105-
window.location.reload();
106-
}
107-
);
108-
109-
app.isOpened = false;
110-
}
111-
},
112-
1000
113-
);
114-
115-
}
93+
const checkWindowClosed = setInterval(function () {
94+
if (kitPopup.closed) {
95+
clearInterval(checkWindowClosed);
96+
97+
// Save the form builder and reload, to reflect the changes.
98+
WPFormsBuilder.formSave(false).done(function () {
99+
WPFormsBuilder.setCloseConfirmation(false);
100+
WPFormsBuilder.showLoadingOverlay();
101+
window.location.reload();
102+
});
103+
104+
app.isOpened = false;
105+
}
106+
}, 1000);
107+
},
116108
};
117109

118110
// Provide access to public functions/properties.

0 commit comments

Comments
 (0)