Skip to content

Commit

Permalink
Fix eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kmgalanakis committed Apr 28, 2023
1 parent 9416685 commit 50b2b85
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 83 deletions.
2 changes: 1 addition & 1 deletion dist/js/gutenberg.js

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions src/js/classic-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@ import blurInsecure from './utils/blur-insecure';
import checkContent from './utils/check-content';
import findElements from './utils/find-elements';
import replaceContent from './utils/replace';
import $ from 'jquery';

// Listen for clicks on the publish button
$(document).on('click', '#publish', (event) => {
jQuery(document).on('click', '#publish', (event) => {
blurInsecure();
if (
!$(event.target).hasClass('disabled') &&
$('.js-icw-force-checkbox').prop('checked') !== true
!jQuery(event.target).hasClass('disabled') &&
jQuery('.js-icw-force-checkbox').prop('checked') !== true
) {
checkContent(event);
}
});

// Listen for clicks on the force publish checkbox
$(document).on('change', '#icw-force-checkbox', function () {
jQuery(document).on('change', '#icw-force-checkbox', function () {
// Enable or disable the publish button as needed
blurInsecure();
if ($(this).is(':checked')) {
$('#publish').removeClass('disabled');
if (jQuery(this).is(':checked')) {
jQuery('#publish').removeClass('disabled');
} else {
$('#publish').addClass('disabled');
jQuery('#publish').addClass('disabled');
}
});

Expand All @@ -34,27 +33,27 @@ $(document).on('change', '#icw-force-checkbox', function () {
* the update button and then the preview button,
* as it expects a page refresh after updates
*/
$(document).on('click', '#post-preview', () => {
jQuery(document).on('click', '#post-preview', () => {
blurInsecure();
if (document.querySelector('.js-icw-error')) {
if (wp.autosave) {
wp.autosave.server.resume();
wp.autosave.enableButtons();
} else {
$(document).trigger('autosave-enable-buttons');
jQuery(document).trigger('autosave-enable-buttons');
}

$('#major-publishing-actions .spinner').removeClass('is-active');
jQuery('#major-publishing-actions .spinner').removeClass('is-active');
}
});

// Listen for clicks on the fix asset links
$(document).on('click', '.js-icw-check', function (e) {
jQuery(document).on('click', '.js-icw-check', function (e) {
e.preventDefault();
blurInsecure();

const spinner = $(this).next('.js-icw-spinner');
const url = $(this).data('check');
const spinner = jQuery(this).next('.js-icw-spinner');
const url = jQuery(this).data('check');

spinner.show();

Expand All @@ -64,11 +63,11 @@ $(document).on('click', '.js-icw-check', function (e) {

// Attempt to replace if https equivalent found.
if (data === true) {
$(this).nextAll('.js-icw-fixed').show();
jQuery(this).nextAll('.js-icw-fixed').show();
replaceContent(url);
} else {
// show the error
$(this).nextAll('.js-icw-error').show();
jQuery(this).nextAll('.js-icw-error').show();
throw new Error('No https equivalent found.');
}

Expand All @@ -83,17 +82,17 @@ $(document).on('click', '.js-icw-check', function (e) {
);
});

$(document).on('click', '.js-icw-view', function (e) {
jQuery(document).on('click', '.js-icw-view', function (e) {
e.preventDefault();
blurInsecure();

const url = $(this).data('check');
const url = jQuery(this).data('check');
const elements = findElements(url);

if (elements.length) {
const $element = $(elements[0]);
const $element = jQuery(elements[0]);

$('html, body').animate(
jQuery('html, body').animate(
{
scrollTop: $element.offset().top,
},
Expand Down
26 changes: 13 additions & 13 deletions src/js/gutenberg.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { gutenbergCheck } from './utils/gutenberg-check';
import replaceContent from './utils/replace';
import blurInsecure from './utils/blur-insecure';

import { debounce } from 'underscore';
import { getScrollContainer } from '@wordpress/dom';
import apiRequest from '@wordpress/api-request';
import domReady from '@wordpress/dom-ready';
import { dispatch, select, subscribe } from '@wordpress/data';
import $ from 'jquery';
import blurInsecure from './utils/blur-insecure';
import replaceContent from './utils/replace';
import { gutenbergCheck } from './utils/gutenberg-check';

domReady(() => {
let content = select('core/editor').getEditedPostContent();
Expand Down Expand Up @@ -43,12 +41,12 @@ domReady(() => {
}, 1000),
);

$(document).on('click', '.gutenberg-js-icw-check', function (e) {
jQuery(document).on('click', '.gutenberg-js-icw-check', function (e) {
e.preventDefault();
blurInsecure();

const spinner = $(this).next('.js-icw-spinner');
const url = $(this).data('check');
const spinner = jQuery(this).next('.js-icw-spinner');
const url = jQuery(this).data('check');

spinner.show();

Expand All @@ -58,11 +56,11 @@ domReady(() => {

// Attempt to replace if https equivalent found.
if (data === true) {
$(this).nextAll('.js-icw-fixed').show();
jQuery(this).nextAll('.js-icw-fixed').show();
replaceContent(url);
} else {
// show the error
$(this).nextAll('.js-icw-error').show();
jQuery(this).nextAll('.js-icw-error').show();
throw new Error('No https equivalent found.');
}

Expand All @@ -77,10 +75,10 @@ domReady(() => {
);
});

$(document).on('click', '.gutenberg-js-icw-view', function (e) {
jQuery(document).on('click', '.gutenberg-js-icw-view', function (e) {
e.preventDefault();
blurInsecure();
const url = $(this).data('check');
const url = jQuery(this).data('check');
const blockEditor = select('core/block-editor');

const insecureBlocks = blockEditor.getBlocks().filter((block) => {
Expand All @@ -99,7 +97,9 @@ domReady(() => {

if (insecureBlock && container) {
insecureBlock.scrollIntoView();
$(`[data-block="${insecureBlocks[0].clientId}"]`).addClass('js-icw-is-insecure');
jQuery(`[data-block="${insecureBlocks[0].clientId}"]`).addClass(
'js-icw-is-insecure',
);
}
}
});
Expand Down
12 changes: 5 additions & 7 deletions src/js/utils/blur-insecure.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import $ from 'jquery';

/**
* Find element on page
*/
const blurInsecure = () => {
const $visualEditorWrap = $(document.getElementById('wp-content-wrap'));
const $visualEditorWrap = jQuery(document.getElementById('wp-content-wrap'));
let $insecure;

if ($visualEditorWrap.hasClass('tmce-active') || $visualEditorWrap.hasClass('tinymce-active')) {
$insecure = $('#content_ifr').contents().find('.js-icw-is-insecure');
$insecure = jQuery('#content_ifr').contents().find('.js-icw-is-insecure');
} else {
$insecure = $('<div>')
.append($.parseHTML($('#content').val()))
$insecure = jQuery('<div>')
.append(jQuery.parseHTML(jQuery('#content').val()))
.find('.js-icw-is-insecure');
}

$insecure.removeClass('js-icw-is-insecure');

$('.js-icw-is-insecure').removeClass('js-icw-is-insecure');
jQuery('.js-icw-is-insecure').removeClass('js-icw-is-insecure');
};

export default blurInsecure;
46 changes: 22 additions & 24 deletions src/js/utils/check-content.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
import { __, _nx, sprintf } from '@wordpress/i18n';
import blurInsecure from './blur-insecure';
import { scanElements } from './scan-elements';

import { __, _nx, sprintf } from '@wordpress/i18n';
import $ from 'jquery';

const checkContent = (event) => {
blurInsecure();
const $visualEditorWrap = $(document.getElementById('wp-content-wrap'));
const $visualEditorWrap = jQuery(document.getElementById('wp-content-wrap'));

let $elements;

// Enable the publish button
$('#publish').removeClass('disabled');
jQuery('#publish').removeClass('disabled');

if ($visualEditorWrap.hasClass('tmce-active') || $visualEditorWrap.hasClass('tinymce-active')) {
$elements = $('#content_ifr').contents().find('*');
$elements = jQuery('#content_ifr').contents().find('*');
} else {
$elements = $('<div>')
.append($.parseHTML($('#content').val()))
$elements = jQuery('<div>')
.append(jQuery.parseHTML(jQuery('#content').val()))
.find('*');
}

const scanResults = scanElements($elements);
const { insecure } = scanResults;
const { insecureElementURLs } = scanResults;

const $hr = $('#major-publishing-actions');
const $hr = jQuery('#major-publishing-actions');

if (insecure > 0) {
event.preventDefault();

// Disable the publish button
$('#publish').addClass('disabled');
jQuery('#publish').addClass('disabled');

$hr.next().remove();

const $errorContainer = $('<div>', {
const $errorContainer = jQuery('<div>', {
class: 'error js-icw-error',
text: sprintf(
_nx(
Expand All @@ -49,40 +47,40 @@ const checkContent = (event) => {
),
});

const $ol = $('<ol />');
const $ol = jQuery('<ol />');

for (let i = 0, { length } = insecureElementURLs; i < length; i++) {
const $li = $('<li>', {
const $li = jQuery('<li>', {
class: 'icw-list-item',
});
const $br = $('<br />');
const $view = $('<a>', {
const $br = jQuery('<br />');
const $view = jQuery('<a>', {
class: 'js-icw-view',
'data-check': insecureElementURLs[i],
href: '',
text: __('View element', 'insecure-content-warning'),
});
const $a = $('<a>', {
const $a = jQuery('<a>', {
class: 'js-icw-check',
'data-check': insecureElementURLs[i],
href: '',
text: __('Fix this', 'insecure-content-warning'),
});
const $spinner = $('<img>', {
const $spinner = jQuery('<img>', {
src: insecureContentAdmin.spinner,
class: 'js-icw-spinner',
style: 'display: none',
});
const $url = $('<code>', {
const $url = jQuery('<code>', {
class: 'icw-list-item-description',
text: insecureElementURLs[i],
});
const $success = $('<span>', {
const $success = jQuery('<span>', {
class: 'js-icw-fixed',
style: 'display: none; color: forestgreen; font-weight: bolder',
text: __('Success!', 'insecure-content-warning'),
});
const $error = $('<span>', {
const $error = jQuery('<span>', {
class: 'error js-icw-error',
style: 'display: none; color: #950e0d; font-weight: bolder',
text: __(
Expand All @@ -100,12 +98,12 @@ const checkContent = (event) => {
$li.append($error);
$ol.append($li);
}
const $p = $('<p>');
const $label = $('<label>', {
const $p = jQuery('<p>');
const $label = jQuery('<label>', {
for: 'icw-force-checkbox',
text: __('Publish with insecure assets', 'insecure-content-warning'),
});
const $input = $('<input>', {
const $input = jQuery('<input>', {
type: 'checkbox',
id: 'icw-force-checkbox',
class: 'js-icw-force-checkbox',
Expand All @@ -123,7 +121,7 @@ const checkContent = (event) => {

$hr.after($errorContainer);
} else {
$('.js-icw-error').remove();
jQuery('.js-icw-error').remove();
}
};

Expand Down
14 changes: 6 additions & 8 deletions src/js/utils/find-elements.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import { get } from 'underscore';

import $ from 'jquery';

/**
* Find element on page
*
* @param {string} url URL to search in element attributes
* @param {Array} $searchIn List of elements to search in (default empty array -- search in body)
* @return {Array} Elements matching the URL
* @returns {Array} Elements matching the URL
*/
const findElements = (url = '', $searchIn = []) => {
const $visualEditorWrap = $(document.getElementById('wp-content-wrap'));
const $visualEditorWrap = jQuery(document.getElementById('wp-content-wrap'));

let $from;

if ($searchIn.length) {
$from = $($searchIn);
$from = jQuery($searchIn);
} else if (
$visualEditorWrap.hasClass('tmce-active') ||
$visualEditorWrap.hasClass('tinymce-active')
) {
$from = $('#content_ifr').contents().find('*');
$from = jQuery('#content_ifr').contents().find('*');
} else {
$from = $('<div>')
.append($.parseHTML($('#content').val()))
$from = jQuery('<div>')
.append(jQuery.parseHTML(jQuery('#content').val()))
.find('*');
}

Expand Down
7 changes: 3 additions & 4 deletions src/js/utils/gutenberg-check.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import blurInsecure from './blur-insecure';
import { gutenbergScan } from './gutenberg-scan';
import { registerInsecureContentPlugin } from './gutenberg-status';

import { _nx, sprintf } from '@wordpress/i18n';
import { dispatch } from '@wordpress/data';
import { getPlugin, unregisterPlugin } from '@wordpress/plugins';
import blurInsecure from './blur-insecure';
import { gutenbergScan } from './gutenberg-scan';
import { registerInsecureContentPlugin } from './gutenberg-status';

const SECURE_CONTENT_WARNING_ID = 'secure-content-warning';

Expand Down
3 changes: 1 addition & 2 deletions src/js/utils/gutenberg-scan.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { scanElements } from './scan-elements';

import { select } from '@wordpress/data';
import { scanElements } from './scan-elements';

export const gutenbergScan = () => {
const content = select('core/editor').getEditedPostAttribute('content');
Expand Down
Loading

0 comments on commit 50b2b85

Please sign in to comment.