Commit ba8350da authored by ozin's avatar ozin Committed by Robert Ragas

Issue #2747541 by ozin: Update js with the latest version of the YoastSEO.js

parent 840bd053
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
/** /**
* JavaScript file that handles initializing and firing the Yoast * JavaScript file that handles initializing and firing the Yoast
* js-text-analysis library. * js-text-analysis library.
* Support YoastSEO.js v1.2.2.
*/ */
(function ($) { (function ($) {
Drupal.yoast_seo = Drupal.yoast_seo || {}; Drupal.yoast_seo = Drupal.yoast_seo || {};
...@@ -27,12 +28,12 @@ ...@@ -27,12 +28,12 @@
snippet: settings.yoast_seo.targets.snippet snippet: settings.yoast_seo.targets.snippet
}, },
snippetFields: { snippetFields: {
title: "snippet_title", title: "snippet-editor-title",
url: "snippet_cite", url: "snippet-editor-slug",
meta: "snippet_meta" meta: "snippet-editor-meta-description"
}, },
sampleText: { sampleText: {
url: settings.yoast_seo.defaultText.url, baseUrl: settings.yoast_seo.baseRoot + '/',
title: settings.yoast_seo.defaultText.title, title: settings.yoast_seo.defaultText.title,
keyword: settings.yoast_seo.defaultText.keyword, keyword: settings.yoast_seo.defaultText.keyword,
meta: settings.yoast_seo.defaultText.meta, meta: settings.yoast_seo.defaultText.meta,
...@@ -63,9 +64,8 @@ ...@@ -63,9 +64,8 @@
// Declaring the callback functions, for now we bind DrupalSource. // Declaring the callback functions, for now we bind DrupalSource.
YoastSEO.analyzerArgs.callbacks = { YoastSEO.analyzerArgs.callbacks = {
getData: DrupalSource.getData.bind(DrupalSource), getData: DrupalSource.getData.bind(DrupalSource),
getAnalyzerInput: DrupalSource.getAnalyzerInput.bind(DrupalSource),
bindElementEvents: DrupalSource.bindElementEvents.bind(DrupalSource), bindElementEvents: DrupalSource.bindElementEvents.bind(DrupalSource),
updateSnippetValues: DrupalSource.updateSnippetValues.bind(DrupalSource), saveSnippetData: DrupalSource.saveSnippetData.bind(DrupalSource),
saveScores: DrupalSource.saveScores.bind(DrupalSource) saveScores: DrupalSource.saveScores.bind(DrupalSource)
}; };
...@@ -119,7 +119,6 @@ YoastSEO_DrupalSource = function(args) { ...@@ -119,7 +119,6 @@ YoastSEO_DrupalSource = function(args) {
this.config = args; this.config = args;
this.refObj = {}; this.refObj = {};
this.analyzerData = {}; this.analyzerData = {};
this.formattedData = {};
}; };
/** /**
...@@ -135,7 +134,7 @@ YoastSEO_DrupalSource.prototype.triggerEvent = function(field) { ...@@ -135,7 +134,7 @@ YoastSEO_DrupalSource.prototype.triggerEvent = function(field) {
else { else {
document.getElementById(field).fireEvent("input"); document.getElementById(field).fireEvent("input");
} }
} };
/** /**
* Parses the input in snippet preview fields on input evt to data in the metatag and path fields * Parses the input in snippet preview fields on input evt to data in the metatag and path fields
...@@ -146,11 +145,11 @@ YoastSEO_DrupalSource.prototype.parseSnippetData = function(source, target) { ...@@ -146,11 +145,11 @@ YoastSEO_DrupalSource.prototype.parseSnippetData = function(source, target) {
var listener = function ( ev ) { var listener = function ( ev ) {
// textContent support for FF and if both innerText and textContent are // textContent support for FF and if both innerText and textContent are
// undefined we use an empty string. // undefined we use an empty string.
document.getElementById(target).value = (ev.target.innerText || ev.target.textContent || ""); document.getElementById(target).value = (ev.target.value || "");
this.triggerEvent(target); this.triggerEvent(target);
}.bind(this); }.bind(this);
document.getElementById(source).addEventListener("blur", listener); document.getElementById(source).addEventListener("blur", listener);
} };
/** /**
...@@ -164,7 +163,6 @@ YoastSEO_DrupalSource.prototype.getData = function() { ...@@ -164,7 +163,6 @@ YoastSEO_DrupalSource.prototype.getData = function() {
meta: this.getDataFromInput( "meta" ), meta: this.getDataFromInput( "meta" ),
snippetMeta: this.getDataFromInput( "meta" ), snippetMeta: this.getDataFromInput( "meta" ),
text: this.getDataFromInput( "text" ), text: this.getDataFromInput( "text" ),
snippetTitle: this.getDataFromInput( "title" ),
pageTitle: this.getDataFromInput( "title" ), pageTitle: this.getDataFromInput( "title" ),
baseUrl: this.config.baseRoot + '/', baseUrl: this.config.baseRoot + '/',
url: this.config.baseRoot + '/' + this.getDataFromInput( "url" ), url: this.config.baseRoot + '/' + this.getDataFromInput( "url" ),
...@@ -175,9 +173,6 @@ YoastSEO_DrupalSource.prototype.getData = function() { ...@@ -175,9 +173,6 @@ YoastSEO_DrupalSource.prototype.getData = function() {
if (data.meta == '') { if (data.meta == '') {
data.snippetMeta = this.config.placeholderText.description; data.snippetMeta = this.config.placeholderText.description;
} }
if (data.pageTitle == '') {
data.snippetTitle = this.config.placeholderText.title;
}
if (data.snippetCite == '') { if (data.snippetCite == '') {
data.snippetCite = this.config.placeholderText.url; data.snippetCite = this.config.placeholderText.url;
} }
...@@ -185,21 +180,6 @@ YoastSEO_DrupalSource.prototype.getData = function() { ...@@ -185,21 +180,6 @@ YoastSEO_DrupalSource.prototype.getData = function() {
return data; return data;
}; };
/**
* Initializes the snippetPreview if it isn't there.
* If it is already initialized, it get's new values from the inputs and rerenders snippet.
*/
YoastSEO_DrupalSource.prototype.getAnalyzerInput = function() {
if (typeof YoastSEO.app.snippetPreview === "undefined") {
YoastSEO.app.init();
}
else {
this.updateRawData();
YoastSEO.app.reloadSnippetText();
}
YoastSEO.app.runAnalyzerCallback();
};
YoastSEO_DrupalSource.prototype.getDataFromInput = function( field ) { YoastSEO_DrupalSource.prototype.getDataFromInput = function( field ) {
return document.getElementById(this.config.fields[field]).value; return document.getElementById(this.config.fields[field]).value;
} }
...@@ -215,7 +195,6 @@ YoastSEO_DrupalSource.prototype.updateRawData = function() { ...@@ -215,7 +195,6 @@ YoastSEO_DrupalSource.prototype.updateRawData = function() {
snippetMeta: this.getDataFromInput( "meta" ), snippetMeta: this.getDataFromInput( "meta" ),
text: this.getDataFromInput( "text" ), text: this.getDataFromInput( "text" ),
nodeTitle: this.getDataFromInput( "nodeTitle" ), nodeTitle: this.getDataFromInput( "nodeTitle" ),
snippetTitle: this.getDataFromInput( "title" ),
pageTitle: this.getDataFromInput( "title" ), pageTitle: this.getDataFromInput( "title" ),
baseUrl: this.config.baseRoot + '/', baseUrl: this.config.baseRoot + '/',
url: this.config.baseRoot + '/' + this.getDataFromInput( "url" ), url: this.config.baseRoot + '/' + this.getDataFromInput( "url" ),
...@@ -243,28 +222,6 @@ YoastSEO_DrupalSource.prototype.updateRawData = function() { ...@@ -243,28 +222,6 @@ YoastSEO_DrupalSource.prototype.updateRawData = function() {
YoastSEO.app.rawData = data; YoastSEO.app.rawData = data;
}; };
/**
* when the snippet is updated, set this data in rawData.
* @param {string} value
* @param {string} type
*/
YoastSEO_DrupalSource.prototype.setRawData = function( value, type ) {
switch ( type ) {
case 'snippet_meta':
this.parseSnippetData(type, this.config.fields.meta);
YoastSEO.app.rawData.snippetMeta = value;
break;
case 'snippet_cite':
YoastSEO.app.rawData.snippetCite = value;
break;
case 'snippet_title':
YoastSEO.app.rawData.snippetTitle = value;
break;
default:
break;
}
};
/** /**
* Calls the eventbinders. * Calls the eventbinders.
*/ */
...@@ -285,7 +242,7 @@ YoastSEO_DrupalSource.prototype.inputElementEventBinder = function() { ...@@ -285,7 +242,7 @@ YoastSEO_DrupalSource.prototype.inputElementEventBinder = function() {
}; };
/** /**
* calls getAnalyzerinput function on change event from element * Calls getAnalyzerinput function on change event from element
* @param event * @param event
*/ */
YoastSEO_DrupalSource.prototype.renewData = function ( ev ) { YoastSEO_DrupalSource.prototype.renewData = function ( ev ) {
...@@ -293,23 +250,30 @@ YoastSEO_DrupalSource.prototype.renewData = function ( ev ) { ...@@ -293,23 +250,30 @@ YoastSEO_DrupalSource.prototype.renewData = function ( ev ) {
this.config.SEOTitleOverwritten = true; this.config.SEOTitleOverwritten = true;
} }
YoastSEO.app.analyzeTimer(ev); // @TODO: implement snippetPreview rebuild
if (ev.target.id == this.config.fields.title) {
document.getElementById(this.config.snippetFields.title).value = ev.target.value;
this.triggerEvent(this.config.snippetFields.title);
}
if (ev.target.id == this.config.fields.meta) {
document.getElementById(this.config.snippetFields.meta).value = ev.target.value;
this.triggerEvent(this.config.snippetFields.meta);
}
if (ev.target.id == this.config.fields.url) {
document.getElementById(this.config.snippetFields.url).value = ev.target.value;
this.triggerEvent(this.config.snippetFields.url);
}
}; };
/** /**
* Updates the snippet values, but in reality we ignore this. * Save the snippet values, but in reality we ignore this.
* *
* @param {Object} ev * @param {Object} ev
*/ */
YoastSEO_DrupalSource.prototype.updateSnippetValues = function( ev ) { YoastSEO_DrupalSource.prototype.saveSnippetData = function (ev) {
};
/**
* calles getAnalyzerinput function on focus of the snippet elements;
* @param event
*/
YoastSEO_DrupalSource.prototype.snippetCallback = function( ev ) {
this.getAnalyzerInput();
}; };
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment