Commit 94986563 authored by Andriy Khomych's avatar Andriy Khomych Committed by Robert Ragas

Issue #2792879 by Andriy Khomych: Node title not showing in snippet preview when creating new node

parent 6e02fe26
......@@ -5,9 +5,13 @@
*/
(function ($) {
Drupal.yoast_seo = Drupal.yoast_seo || {};
Drupal.yoast_seo_node_new = false;
Drupal.behaviors.yoast_seo = {
attach: function (context, settings) {
if(settings.path && settings.path.currentPath.indexOf('node/add') != -1){
Drupal.yoast_seo_node_new = true;
}
// Making sure we actually have data.
if (typeof settings.yoast_seo != 'undefined') {
var yoast_settings = settings.yoast_seo;
......@@ -62,7 +66,6 @@
// Create a new Yoast SEO instance.
if (typeof YoastSEO != "undefined") {
var DrupalSource = new YoastSEO_DrupalSource(YoastSEO.analyzerArgs);
// Declaring the callback functions, for now we bind DrupalSource.
YoastSEO.analyzerArgs.callbacks = {
getData: DrupalSource.getData.bind(DrupalSource),
......@@ -281,6 +284,23 @@ YoastSEO_DrupalSource.prototype.renewData = function (ev) {
}, 3000);
}
//If node is new we could use new typed title for js tokens
if (ev.target.id == this.config.fields.nodeTitle && Drupal.yoast_seo_node_new) {
var metatagTitle = document.getElementById(this.config.fields.title).value;
//If node is new replace token title with value from input title
//@todo: Review logic for better implement and remove hard
//[current-page:title]
if(metatagTitle.indexOf('[current-page:title]') != -1){
metatagTitle = metatagTitle.replace('[current-page:title]', ev.target.value);
}
//[node:title]
if(metatagTitle.indexOf('[node:title]') != -1){
metatagTitle = metatagTitle.replace('[node:title]', ev.target.value);
}
document.getElementById(this.config.snippetFields.title).value = this.tokenReplace(metatagTitle);
this.triggerEvent(this.config.snippetFields.title);
}
if (ev.target.id == this.config.fields.title) {
document.getElementById(this.config.snippetFields.title).value = this.tokenReplace(ev.target.value);
this.triggerEvent(this.config.snippetFields.title);
......
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