Jump and Print buttons for Meal Planner Pro
(function($) {
$(function() {
var jumpID = $( '.mpprecipe-container-border' ).attr( 'id' );
var printID = $( '.butn-link.mpp-button' ).attr( 'onclick' );
var printIDEscaped = htmlEscape(printID);
if( jumpID ) {
if( printID ) { // if jump AND print
$( '.content .entry-header' ).append( '<div class="recipe-buttons"><a class="added-button jump" href="#' + jumpID + '">Jump to Recipe <i class="fa fa-book" aria-hidden="true"></i></a><a class="added-button print" title="Print this recipe" onclick="' + printIDEscaped + '">Print Recipe <i class="fa fa-print" aria-hidden="true"></i></a></div>' );
} else { // if JUST jump
$( '.content .entry-header' ).append( '<div class="recipe-buttons"><a class="added-button jump" href="#' + jumpID + '">Jump to Recipe <i class="fa fa-book" aria-hidden="true"></i></a></div>' );
}
} else if( printID ) { // if JUST print
$( '.content .entry-header' ).append( '<div class="recipe-buttons"><a class="added-button print" title="Print this recipe" onclick="' + printIDEscaped + '">Print Recipe <i class="fa fa-print" aria-hidden="true"></i></a></div>' );
}
});
})(jQuery);
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '<')
.replace(/>/g, '>');
}
function htmlUnescape(value){
return String(value)
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&');
}