graylaurenm
10/10/2016 - 11:40 AM

Jump and Print buttons for Meal Planner Pro

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, '&amp;')
        .replace(/"/g, '&quot;')
        .replace(/'/g, '&#39;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;');
}

function htmlUnescape(value){
    return String(value)
        .replace(/&quot;/g, '"')
        .replace(/&#39;/g, "'")
        .replace(/&lt;/g, '<')
        .replace(/&gt;/g, '>')
        .replace(/&amp;/g, '&');
}