Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Td/class syntax #21325

Draft
wants to merge 12 commits into
base: trunk
Choose a base branch
from
Prev Previous commit
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into td/class-…
…syntax
  • Loading branch information
mhkuu committed May 13, 2024
commit ca336933e949acb094be0658ee4da840d08761da
114 changes: 11 additions & 103 deletions packages/yoastseo/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import AssessorPresenter from "./scoring/renderers/AssessorPresenter.js";
import SEOAssessor from "./scoring/seoAssessor.js";
import Paper from "./values/Paper.js";

var inputDebounceDelay = 800;
const inputDebounceDelay = 800;

/**
* Default config for YoastSEO.js
*
* @type {Object}
*/
var defaults = {
const defaults = {
callbacks: {
bindElementEvents: noop,
updateSnippetValues: noop,
Expand Down Expand Up @@ -229,24 +229,10 @@ class App {
this.showLoadingDialog();
}

if ( isValidSnippetPreview( args.snippetPreview ) ) {
this.snippetPreview = args.snippetPreview;

/* Hack to make sure the snippet preview always has a reference to this App. This way we solve the circular
dependency issue. In the future this should be solved by the snippet preview not having a reference to the
app.*/
if ( this.snippetPreview.refObj !== this ) {
this.snippetPreview.refObj = this;
}
} else if ( args.hasSnippetPreview ) {
this.snippetPreview = createDefaultSnippetPreview.call( this );
}

this._assessorOptions = {
useCornerStone: false,
};

this.initSnippetPreview();
this.initAssessorPresenters();
}

Expand Down Expand Up @@ -381,13 +367,13 @@ class App {
* @returns {Object} sampleText The extended sample text.
*/
extendSampleText( sampleText ) {
var defaultSampleText = defaults.sampleText;
const defaultSampleText = defaults.sampleText;

if ( isUndefined( sampleText ) ) {
return defaultSampleText;
}

for ( var key in sampleText ) {
for ( const key in sampleText ) {
if ( isUndefined( sampleText[ key ] ) ) {
sampleText[ key ] = defaultSampleText[ key ];
}
Expand Down Expand Up @@ -430,15 +416,6 @@ class App {
} );
}

if ( this.hasSnippetPreview() ) {
// Gets the data FOR the analyzer
var data = this.snippetPreview.getAnalyzerData();

this.rawData.metaTitle = data.title;
this.rawData.url = data.url;
this.rawData.meta = data.metaDesc;
}

if ( this.pluggable.loaded ) {
this.rawData.metaTitle = this.pluggable._applyModifications( "data_page_title", this.rawData.metaTitle );
this.rawData.meta = this.pluggable._applyModifications( "data_meta_desc", this.rawData.meta );
Expand Down Expand Up @@ -475,29 +452,6 @@ class App {
this.runAnalyzer();
}

/**
* Determines whether or not this app has a snippet preview.
*
* @returns {boolean} Whether or not this app has a snippet preview.
*/
hasSnippetPreview() {
return this.snippetPreview !== null && ! isUndefined( this.snippetPreview );
}

/**
* Initializes the snippet preview for this App.
*
* @returns {void}
*/
initSnippetPreview() {
if ( this.hasSnippetPreview() ) {
this.snippetPreview.renderTemplate();
this.snippetPreview.callRegisteredEventBinder();
this.snippetPreview.bindEvents();
this.snippetPreview.init();
}
}

/**
* Initializes the assessor presenters for content and SEO.
*
Expand Down Expand Up @@ -525,29 +479,6 @@ class App {
}
}

/**
* Binds the refresh function to the input of the targetElement on the page.
*
* @returns {void}
*/
bindInputEvent() {
for ( var i = 0; i < this.config.elementTarget.length; i++ ) {
var elem = document.getElementById( this.config.elementTarget[ i ] );
elem.addEventListener( "input", this.refresh.bind( this ) );
}
}

/**
* Runs the rerender function of the snippetPreview if that object is defined.
*
* @returns {void}
*/
reloadSnippetText() {
if ( this.hasSnippetPreview() ) {
this.snippetPreview.reRender();
}
}

/**
* Sets the startTime timestamp.
*
Expand Down Expand Up @@ -588,19 +519,13 @@ class App {

this.analyzerData = this.modifyData( this.rawData );

if ( this.hasSnippetPreview() ) {
this.snippetPreview.refresh();
}

let text = this.analyzerData.text;

// Insert HTML stripping code
text = removeHtmlBlocks( text );

let titleWidth = this.analyzerData.titleWidth;
if ( this.hasSnippetPreview() ) {
titleWidth = this.snippetPreview.getTitleWidth();
}
const titleWidth = this.analyzerData.titleWidth;

// Create a paper object for the Researcher
this.paper = new Paper( text, {
Expand All @@ -625,10 +550,6 @@ class App {
if ( this.config.dynamicDelay ) {
this.endTime();
}

if ( this.hasSnippetPreview() ) {
this.snippetPreview.reRender();
}
}

/**
Expand Down Expand Up @@ -703,10 +624,10 @@ class App {
* @returns {void}
*/
showLoadingDialog() {
var outputElement = document.getElementById( this.defaultOutputElement );
const outputElement = document.getElementById( this.defaultOutputElement );

if ( this.defaultOutputElement !== "" && ! isEmpty( outputElement ) ) {
var dialogDiv = document.createElement( "div" );
const dialogDiv = document.createElement( "div" );
dialogDiv.className = "YoastSEO_msg";
dialogDiv.id = "YoastSEO-plugin-loading";
document.getElementById( this.defaultOutputElement ).appendChild( dialogDiv );
Expand All @@ -720,13 +641,13 @@ class App {
* @returns {void}
*/
updateLoadingDialog( plugins ) {
var outputElement = document.getElementById( this.defaultOutputElement );
const outputElement = document.getElementById( this.defaultOutputElement );

if ( this.defaultOutputElement === "" || isEmpty( outputElement ) ) {
return;
}

var dialog = document.getElementById( "YoastSEO-plugin-loading" );
const dialog = document.getElementById( "YoastSEO-plugin-loading" );
dialog.textContent = "";

forEach( plugins, function( plugin, pluginName ) {
Expand All @@ -743,8 +664,8 @@ class App {
* @returns {void}
*/
removeLoadingDialog() {
var outputElement = document.getElementById( this.defaultOutputElement );
var loadingDialog = document.getElementById( "YoastSEO-plugin-loading" );
const outputElement = document.getElementById( this.defaultOutputElement );
const loadingDialog = document.getElementById( "YoastSEO-plugin-loading" );

if ( ( this.defaultOutputElement !== "" && ! isEmpty( outputElement ) ) && ! isEmpty( loadingDialog ) ) {
document.getElementById( this.defaultOutputElement ).removeChild( document.getElementById( "YoastSEO-plugin-loading" ) );
Expand Down Expand Up @@ -884,19 +805,6 @@ class App {
console.error( "This function is deprecated, please use registerAssessment" );
}

/**
* Creates the elements for the snippetPreview
*
* @deprecated Don't create a snippet preview using this method, create it directly using the prototype and pass it as
* an argument instead.
*
* @returns {void}
*/
createSnippetPreview() {
this.snippetPreview = createDefaultSnippetPreview.call( this );
this.initSnippetPreview();
}

/**
* Switches between the cornerstone and default assessors.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/yoastseo/src/scoring/contentAssessor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { map, sum } from "lodash-es";
import { map, sum } from "lodash";
import Assessor from "./assessor.js";
import ParagraphTooLong from "./assessments/readability/ParagraphTooLongAssessment.js";
import SentenceLengthInText from "./assessments/readability/SentenceLengthInTextAssessment.js";
Expand Down
19 changes: 2 additions & 17 deletions packages/yoastseo/src/scoring/renderers/AssessorPresenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,26 +334,11 @@ class AssessorPresenter {

/**
* Renders out the individual ratings.
* Here, this method is set to noop. In `post-scraper.js` and `term-scraper.js` where this method is called, it is overridden with noop as well.
*
* @returns {void}
*/
renderIndividualRatings() {
const outputTarget = document.getElementById( this.output );
const scores = this.getIndividualRatings();

outputTarget.innerHTML = template( {
scores: scores,
i18n: {
disabledMarkText: __( "Marks are disabled in current view", "wordpress-seo" ),
markInText: __( "Mark this result in the text", "wordpress-seo" ),
removeMarksInText: __( "Remove marks in the text", "wordpress-seo" ),
},
activeMarker: this._activeMarker,
markerButtonsDisabled: this._disableMarkerButtons,
} );

this.bindMarkButtons( scores );
}
renderIndividualRatings() {}

/**
* Renders out the overall rating.
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.