| 1 |
/* global YoastSEO */ |
| 2 |
|
| 3 |
class PropertyHiveYoastPlugin { |
| 4 |
constructor() { |
| 5 |
// Ensure YoastSEO.js is present and can access the necessary features. |
| 6 |
if ( typeof YoastSEO === "undefined" || typeof YoastSEO.analysis === "undefined" || typeof YoastSEO.analysis.worker === "undefined" ) { |
| 7 |
return; |
| 8 |
} |
| 9 |
|
| 10 |
YoastSEO.app.registerPlugin( "PropertyHiveYoastPlugin", { status: "ready" } ); |
| 11 |
|
| 12 |
this.registerModifications(); |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Registers the addContent modification. |
| 17 |
* |
| 18 |
* @returns {void} |
| 19 |
*/ |
| 20 |
registerModifications() { |
| 21 |
const callback = this.addContent.bind( this ); |
| 22 |
|
| 23 |
// Ensure that the additional data is being seen as a modification to the content. |
| 24 |
YoastSEO.app.registerModification( "content", callback, "PropertyHiveYoastPlugin", 10 ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Adds to the content to be analyzed by the analyzer. |
| 29 |
* |
| 30 |
* @param {string} data The current data string. |
| 31 |
* |
| 32 |
* @returns {string} The data string parameter with the added content. |
| 33 |
*/ |
| 34 |
addContent( data ) { |
| 35 |
|
| 36 |
if ( jQuery('#property_rooms input[name=\'_room_name[]\']').length > 0 ) |
| 37 |
{ |
| 38 |
jQuery('#property_rooms input[name=\'_room_name[]\']').each(function() |
| 39 |
{ |
| 40 |
if ( jQuery(this).val() != '' ) |
| 41 |
{ |
| 42 |
data += " " + jQuery(this).val(); |
| 43 |
} |
| 44 |
}); |
| 45 |
} |
| 46 |
|
| 47 |
if ( jQuery('#property_rooms input[name=\'_room_dimensions[]\']').length > 0 ) |
| 48 |
{ |
| 49 |
jQuery('#property_rooms input[name=\'_room_dimensions[]\']').each(function() |
| 50 |
{ |
| 51 |
if ( jQuery(this).val() != '' ) |
| 52 |
{ |
| 53 |
data += " " + jQuery(this).val(); |
| 54 |
} |
| 55 |
}); |
| 56 |
} |
| 57 |
|
| 58 |
if ( jQuery('#property_rooms textarea[name=\'_room_description[]\']').length > 0 ) |
| 59 |
{ |
| 60 |
jQuery('#property_rooms textarea[name=\'_room_description[]\']').each(function() |
| 61 |
{ |
| 62 |
if ( jQuery(this).val() != '' ) |
| 63 |
{ |
| 64 |
data += " " + jQuery(this).val(); |
| 65 |
} |
| 66 |
}); |
| 67 |
} |
| 68 |
|
| 69 |
if ( jQuery('#property_rooms input[name=\'_description_name[]\']').length > 0 ) |
| 70 |
{ |
| 71 |
jQuery('#property_rooms input[name=\'_description_name[]\']').each(function() |
| 72 |
{ |
| 73 |
if ( jQuery(this).val() != '' ) |
| 74 |
{ |
| 75 |
data += " " + jQuery(this).val(); |
| 76 |
} |
| 77 |
}); |
| 78 |
} |
| 79 |
|
| 80 |
if ( jQuery('#property_rooms textarea[name=\'_description[]\']').length > 0 ) |
| 81 |
{ |
| 82 |
jQuery('#property_rooms textarea[name=\'_description[]\']').each(function() |
| 83 |
{ |
| 84 |
if ( jQuery(this).val() != '' ) |
| 85 |
{ |
| 86 |
data += " " + jQuery(this).val(); |
| 87 |
} |
| 88 |
}); |
| 89 |
} |
| 90 |
|
| 91 |
return data; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
jQuery( window ).on( |
| 96 |
"YoastSEO:ready", |
| 97 |
function() { |
| 98 |
jQuery(document).on( 'change', '#property_rooms input', function() |
| 99 |
{ |
| 100 |
YoastSEO.app.pluginReloaded( 'PropertyHiveYoastPlugin' ); |
| 101 |
}); |
| 102 |
jQuery(document).on( 'change', '#property_rooms textarea', function() |
| 103 |
{ |
| 104 |
YoastSEO.app.pluginReloaded( 'PropertyHiveYoastPlugin' ); |
| 105 |
}); |
| 106 |
} |
| 107 |
); |
| 108 |
|
| 109 |
/** |
| 110 |
* Adds eventlistener to load the plugin. |
| 111 |
*/ |
| 112 |
var phYoastPlugin; |
| 113 |
if ( typeof YoastSEO !== "undefined" && typeof YoastSEO.app !== "undefined" ) |
| 114 |
{ |
| 115 |
phYoastPlugin = new PropertyHiveYoastPlugin(); |
| 116 |
} |
| 117 |
else |
| 118 |
{ |
| 119 |
jQuery( window ).on( |
| 120 |
"YoastSEO:ready", |
| 121 |
function() { |
| 122 |
phYoastPlugin = new PropertyHiveYoastPlugin(); |
| 123 |
} |
| 124 |
); |
| 125 |
} |