Skip to content

Instantly share code, notes, and snippets.

@ayebare
Created September 27, 2017 15:52
Show Gist options
  • Select an option

  • Save ayebare/04d720865ef39fc7f348a070c5dbc59b to your computer and use it in GitHub Desktop.

Select an option

Save ayebare/04d720865ef39fc7f348a070c5dbc59b to your computer and use it in GitHub Desktop.
using json
(function($, window, document) {
var CblocksPlugin = function() {
window.YoastSEO.app.registerPlugin( 'CblocksPlugin', { status: 'loading' } );
this.getData();
};
CblocksPlugin.prototype.getData = function() {
var _self = this;
_self.container = $('.content-block-translation:visible');
window.YoastSEO.app.pluginReady('CblocksPlugin');
window.YoastSEO.app.registerModification('content', $.proxy(_self.getCustomContent, _self), 'CblocksPlugin', 5);
};
CblocksPlugin.prototype.getCustomContent = function (content) {
var $dataStore = this.container.find('.content-block-data'),
blocks = $dataStore.val(),
blockTemplate;
if (!_.isEmpty(blocks)) {debugger;
_.each(JSON.parse(blocks), function (block) {
//SELF.add(new ContentBlocks.model(block));
block.data = block.settings.content;
blockTemplate = $(document.createElement('script')).text(
$(document.getElementById(block.template)).html()
);
//If block template does not exist exit
if (0 === blockTemplate.length) {
return;
}
template = _.template(blockTemplate.html());
content += template(block);
});
}
console.log(content);
return content;
};
$( window ).on( 'YoastSEO:ready', function () {
new CblocksPlugin();
});
})(jQuery, window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment