This post was originally published on this site
This is crispy tofu at its finest—caramelized edges, a rich black bean sauce that clings to every bite, and the warm, spiced magic of Chinese 5-spice to tie it all together. It’s bold, cozy, and proof that tofu can do amazing things with the right techniques.
![Chinese 5-spice tofu in a cast iron pan.](https://olivesfordinner.com/wp-content/uploads/2014/01/chinese-5-spice-tofu.jpg)
Some dishes are all about tradition, but this one leans more into creativity. We’re not reinventing tradition; we’re just borrowing some of its most delicious elements and giving them a plant-based twist. Think sautéed tofu soaking up a deeply savory black bean sauce, with the warm, aromatic kick of Chinese 5-Spice tying it all together.
It’s bold comfort food that’s simple and fun to make. With a sauce so rich and flavorful it practically does all the work, and a handful of fresh greens to keep it feeling balanced—this dish hits that sweet spot between cozy and a little bit fancy. Get ready to inject some unique flavor into your weeknight dinner routine with this easy tofu recipe!
Why You’ll Love This Recipe
There’s something about this dish that just hits all the right notes—bold, savory, and comforting, with a hint of spice to keep things interesting. Whether you’re here for the crispy tofu, the rich black bean sauce, or the easy weeknight vibes, this recipe checks all the boxes. Here’s why it’s about to become your new favorite.
- Big, Bold Flavors: The warm, aromatic notes of Chinese 5-Spice and the savory depth of black bean garlic sauce create a flavor profile that’s comforting and exciting all at once.
- Crispy Tofu Magic: No pressing, no fuss—just perfectly caramelized tofu that’s golden on the outside, tender on the inside, and soaks up sauce like a dream.
- Customizable Comfort: Whether you’re pairing it with rice, soba noodles, or fresh greens, this dish is endlessly adaptable. Keep it simple or load it up with your favorite veggies—it’s delicious either way.
- Weeknight-Friendly, Weekend-Worthy: Ready in just about an hour, this dish is quick enough for a weeknight but impressive enough to serve when you’re feeling fancy. Dinner goals = achieved.
- Sauce That Steals the Show: Let’s just say you might want to make extra. This rich, savory sauce is the kind you’ll find yourself using on everything—because it’s that good.
Key Ingredients
Here’s where the magic happens. These ingredients are simple but pack a serious punch of flavor, creating a dish that feels bold, comforting, and balanced. From the warm, aromatic kick of Chinese 5-spice to the savory richness of black bean sauce, every element plays its part in making this recipe shine. Here’s what you’ll need:
- Ginger: Fresh ginger doesn’t just add a little zip—it builds the base of the sauce with its warm, spicy undertones. It’s the quiet powerhouse that gives the dish its depth and subtle heat, tying all the flavors together seamlessly.
- Garlic: Sautéed until fragrant, garlic provides that unmistakable savory element. It’s not flashy, but it’s absolutely essential, grounding the sauce with its rich, earthy flavor.
- Scallions: Beyond their hint of oniony sweetness, scallions bring a fresh brightness that cuts through the richness of the sauce. Plus, they add a visual pop of green that makes the dish feel as vibrant as it tastes.
- Sherry: Think of sherry as the flavor amplifier. A quick splash deglazes the pan, lifting all those caramelized bits and adding a layer of complexity. It’s the quiet hero of the sauce, giving it just the right amount of richness.
- Shallots: Sweet, soft, and a little luxurious, shallots are like onions with their edges smoothed out. They melt right into the sauce, adding a smooth layer of flavor that complements the boldness of the Chinese Five Spice.
- Vegetable Broth: This is the silky base of the sauce, tying the warmth of the spices and the depth of the black bean sauce into something cohesive and comforting.
![A bowl of Chinese 5-spice powder.](https://olivesfordinner.com/wp-content/uploads/2014/01/chinese-5-spice-powder.jpg)
- Chinese 5-Spice Powder: The soul of the dish. This blend of cinnamon, fennel, star anise, cloves, and Sichuan peppercorns is what gives the recipe its signature warmth and complexity. Whether you’re new to it or looking for creative Chinese Five Spice uses, this is a perfect place to start.
- Prepared Chinese Black Bean Garlic Sauce: This ingredient carries the dish with its savory, umami-packed richness. Its bold, fermented flavor layers beautifully into the sauce, turning it into something you’ll want to drizzle on everything.
![A hand holding a few large shiitake mushrooms.](https://olivesfordinner.com/wp-content/uploads/2013/11/Hands-holding-shiitake-mushrooms.jpg)
- Shiitake Mushrooms: Shiitakes bring a meaty texture and an earthy depth that complements the tofu and sauce. They’re the ingredient that makes the dish feel hearty and satisfying without weighing it down.
![A block of tofu.](https://olivesfordinner.com/wp-content/uploads/2014/01/slab-of-tofu-1.jpg)
- Firm Tofu: Crispy on the outside, tender on the inside—this tofu is the perfect match for the bold, savory sauce. Whether you’re a tofu pro or a newbie, this five spice tofu will have you coming back for seconds.
How to Make Chinese 5-Spice Tofu with Black Bean Sauce
This recipe has everything you want in a weeknight dinner: crispy tofu, a sauce that’s rich and packed with bold, savory flavor, and just enough greens to make it feel balanced. It’s easy, cozy, and way more fun to make than you’d think. Here’s what you’ll do. For full recipe details, scroll to the end of this post!
- Step 1: Build a Bold, Flavorful Sauce – Sauté ginger, garlic, and scallions until your kitchen smells amazing. Add layers of flavor with sherry, shallots, Chinese 5-Spice, and black bean garlic sauce, then let it simmer into a rich, glossy sauce that you’ll want to put on everything.
- Step 2: Sauté the Mushrooms – Quickly cook the shiitakes until golden and tender. These little flavor sponges soak up the sauce later and add a meaty texture to balance the tofu.
- Step 3: Make Crispy Five Spice Tofu – Slice your tofu into triangles (no pressing needed!) and caramelize it in a hot pan until golden and crisp. Sprinkle with black pepper, and boom—you’ve got tofu perfection.
- Step 4: Bring It All Together – Pour the black bean sauce over the tofu, add the mushrooms and greens, and let everything simmer together for a few minutes. This step is where all the bold flavors come together into saucy, cozy harmony.
- Step 5: Plate It Up – Spoon the tofu, mushrooms, and greens over rice or noodles. Finish with an extra drizzle of sauce because you’ve earned it—and dinner is officially amazing.
![Chinese five spice tofu in a cast iron pan.](https://olivesfordinner.com/wp-content/uploads/2014/01/chinese-5-spice-tofu-cropped.jpg)
How To Serve
This dish is versatile, flavorful, and easy to pair with all kinds of sides. Whether you’re keeping it simple or building a full spread, it’s ready to deliver big comfort and bold flavors. Here’s how to make it work for you:
- Over Soba Noodles or Rice: Toss the tofu and sauce with tender soba noodles or spoon it over steamed jasmine or basmati rice. This is comfort food at its simplest and best.
- With a Side of Greens: Keep things light and fresh by serving it alongside steamed kale, snap peas, sautéed broccoli, bok choy, or tender collard greens. They soak up the sauce and balance out the bold flavors beautifully.
- As Meal Prep: Make a double batch of the tofu and sauce to enjoy throughout the week. It reheats beautifully and pairs well with just about anything you’ve got in the fridge.
- Layered into Spring Roll Bowls: Serve the tofu over vermicelli noodles with shredded carrots, cucumber, and fresh herbs like mint or Thai basil. Finish with a drizzle of the black bean sauce for a vibrant, deconstructed take on spring rolls.
Chinese 5-Spice FAQs
Chinese 5-Spice is a blend of five key spices: cinnamon, fennel, star anise, cloves, and Sichuan peppercorns. Each spice brings something unique to the mix—warmth, sweetness, spice, and a touch of numbing heat—creating a flavor profile that’s bold, balanced, and deeply aromatic. It’s the perfect seasoning for dishes like this one, where it adds a cozy, spiced kick to the sauce.
If you don’t have Chinese 5-Spice on hand, you can create a quick substitute using equal parts ground cinnamon, ground fennel, and ground cloves. For a bit of that anise flavor, add a small pinch of ground star anise if you have it, or just leave it out if not. Sichuan peppercorns are harder to replicate, but a small pinch of black pepper can add a little extra complexity in a pinch.
The taste of Chinese Five Spice is a blend of sweet, spicy, and slightly earthy flavors, with a warm and aromatic quality that feels both bold and comforting. It has a distinct sweetness from cinnamon and fennel, balanced by the spiced heat of Sichuan peppercorns and the rich, deep notes of cloves and star anise. It’s what gives this dish its signature cozy, flavorful kick.
![Five spice tofu in a cast iron pan.](https://olivesfordinner.com/wp-content/uploads/2014/01/chinese-5-spice-tofu-served.jpg)
More Terrific Tofu Recipes To Try Next
- Easy Sticky Tofu
- Deep-Fried Tofu (Crispy Take-Out Style)
- Tofu Satay With Peanut Sauce
- Easy Vegan Fire Noodles with Crispy Tofu Recipe
If you make this Chinese 5-Spice tofu, we’d love to hear what you think! Leave a comment and a star rating below—your feedback not only makes my day but also helps other readers discover this recipe.
![Chinese 5-spice tofu in a cast iron pan.](https://olivesfordinner.com/wp-content/uploads/2014/01/chinese-5-spice-tofu-150x150.jpg)
Chinese 5-Spice Tofu With Black Bean Sauce
Total Time: 1 hour 5 minutes
Yield: 2 servings
Diet: Vegan
Description
Crispy tofu meets a rich black bean sauce in this bold and cozy dish featuring the warm, aromatic kick of Chinese 5-spice. Perfect for weeknights, this five spice tofu is easy to make and packed with big, satisfying flavors. Serve it over rice or noodles with fresh greens for a comforting meal that’s anything but ordinary.
Ingredients
For the Black Bean Sauce
- 1 tablespoon vegan butter
- 2 teaspoons grated or finely minced ginger
- 2 teaspoons grated or finely minced garlic
- 4 scallions, chopped
- 6 tablespoons sherry, divided
- 4 shallots, halved and sliced
- ½ teaspoon Chinese 5-Spice powder
- 2 tablespoons prepared Chinese black bean garlic sauce
- 2 cups vegetable broth
- 1 tablespoons cornstarch, dissolved in 2-3 tablespoons cold water
- 1 cup shiitake mushrooms, whole or sliced
For the Tofu
- 1 tablespoon neutral oil, like canola or vegetable
- 1 block firm tofu, sliced into slabs, then halved to make 8 squares or 16 triangles (no need to press)
- Fresh cracked black pepper
- 1–2 shallots, halved and sliced
- 2–3 scallions, chopped
- 1–2 cups torn kale, collard greens, or finely chopped broccoli (optional)
To Serve
- Soba noodles or rice
Instructions
Make the Black Bean Sauce (You can make the sauce ahead and refrigerate until needed.)
- Heat the vegan butter in a medium cast iron pan over medium-low heat. Add ginger and garlic, sautéing for about 2 minutes until fragrant.
- Stir in the scallions and cook for 4-5 minutes, stirring frequently to prevent browning.
- Increase heat to medium and deglaze the pan with 3 tablespoons of sherry. Let it simmer until most of the liquid reduces.
- Add the shallots, cooking for 1-2 minutes until softened. Sprinkle with Chinese 5-Spice powder and stir well.
- Deglaze the pan again with the remaining 3 tablespoons of sherry. Simmer until the liquid reduces, then mix in the black bean garlic sauce.
- Add the broth, stirring occasionally as it reduces for 15-20 minutes. Once slightly thickened, stir in the cornstarch slurry until the sauce reaches your desired consistency. Set aside.
- In a separate pan, heat a small drizzle of oil over medium heat. Sauté the mushrooms for 4–5 minutes, until tender and golden. Set aside to add during the finishing steps.
Cook the Tofu
- Heat a large non-stick pan over medium-high heat and add the oil. Arrange the tofu in a single layer, fanning it around the edges of the pan (like daisy petals) and leaving the center open. Cover with a lid and cook undisturbed for 10 minutes.
- Carefully lift the lid straight up to avoid dripping condensation into the pan. Sprinkle cracked black pepper over each piece of tofu and flip carefully. Cover again and cook for another 3 minutes.
- Once both sides are caramelized, remove the lid and reduce the heat to medium. Continue cooking until both sides are golden brown and slightly crispy.
Combine and Finish
- With the tofu still in the pan, pour 1 to 1½ cups of the prepared black bean sauce over it. Gently stir to coat the tofu evenly.
- Sprinkle the sliced shallots and scallions over the top, along with mushrooms and greens if using. Let them steam and soften slightly, undisturbed, for 3-5 minutes.
- Gently stir everything together, ensuring the tofu doesn’t stick to the pan. A rich, caramelized ring should form around the edges.
Serve
Serve immediately over rice or soba noodles, with extra black bean sauce on the side if desired.
Notes
- Storage Superstar: Store leftovers in an airtight container in the fridge for up to 3 days. The flavors get even better as they sit, so it’s a win-win.
- Reheat Like a Pro: Warm the tofu and sauce gently in a nonstick pan over medium heat, adding a splash of water or broth to loosen the sauce if needed.
- Make It Ahead: The black bean sauce can be made up to 3 days in advance and stored in the fridge. Reheat it on the stove and pour it over freshly cooked tofu for an even faster dinner.
- Mushroom Swaps: Swap shiitake mushrooms for baby bella mushrooms or reconstitute dried shiitake mushrooms.
- Extra Sauce for the Win: If you love a saucy dish, double the black bean sauce recipe. It’s great over rice, veggies, or even noodles later in the week.
- Freezer Friendly: The sauce freezes well for up to 3 months, so consider making a double batch and saving some for future dinners.
Prep Time: 20 minutes
Cook Time: 45 minutes
Category: Dinner
Method: Sautéed, Simmered, Pan-Fried
Cuisine: American
window.trCommon={“minRating”:6,”ajaxurl”:”https://olivesfordinner.com/wp-admin/admin-ajax.php”,”ratingNonce”:””,”postId”:154};
window.TastyRecipes = window.TastyRecipes || {};
window.TastyRecipes.smoothScroll = {
init() {
document.addEventListener( ‘click’, ( e ) => {
let anchor = e.target;
if ( anchor.tagName !== ‘A’ ) {
anchor = anchor.closest( ‘a.tasty-recipes-scrollto’ );
}
if ( ! anchor || ! anchor.classList.contains( ‘tasty-recipes-scrollto’ ) ) {
return;
}
const elementHref = anchor.getAttribute( ‘href’ );
if ( ! elementHref ) {
return;
}
e.preventDefault();
this.goToSelector( elementHref );
});
},
goToSelector( selector ) {
const element = document.querySelector( selector );
if ( ! element ) {
return;
}
element.scrollIntoView( { behavior: ‘smooth’ } );
}
};
document.addEventListener(
‘DOMContentLoaded’,
() => window.TastyRecipes.smoothScroll.init()
);
window.TastyRecipes = window.TastyRecipes || {};
window.TastyRecipes.cookMode = {
wakeLockApi: false,
wakeLock: false,
cookModeSelector: ‘.tasty-recipes-cook-mode’,
init() {
if (“wakeLock” in navigator && “request” in navigator.wakeLock) {
this.wakeLockApi = navigator.wakeLock;
}
const cookModes = document.querySelectorAll(this.cookModeSelector);
if (cookModes.length > 0) {
for (const cookMode of cookModes) {
if (this.wakeLockApi) {
cookMode.querySelector(‘input[type=”checkbox”]’).addEventListener(“change”, event => {
this.checkboxChange(event.target);
}, false);
} else {
cookMode.style.display = “none”;
}
}
}
},
checkboxChange(checkbox) {
if (checkbox.checked) {
this.lock();
} else {
this.unlock();
}
},
setCheckboxesState(state) {
const checkboxes = document.querySelectorAll(this.cookModeSelector + ‘ input[type=”checkbox”]’);
for (const checkbox of checkboxes) {
checkbox.checked = state;
}
},
async lock() {
try {
this.wakeLock = await this.wakeLockApi.request(“screen”);
this.wakeLock.addEventListener(“release”, () => {
this.wakeLock = false;
this.setCheckboxesState(false);
});
this.setCheckboxesState(true);
} catch (error) {
this.setCheckboxesState(false);
}
},
unlock() {
if (this.wakeLock) {
this.wakeLock.release();
this.wakeLock = false;
}
this.setCheckboxesState(false);
}
};
(function(callback) {
if (document.readyState !== “loading”) {
callback();
} else {
document.addEventListener(“DOMContentLoaded”, callback);
}
})(() => {
window.TastyRecipes.cookMode.init();
});
window.TastyRecipes = window.TastyRecipes || {};
window.TastyRecipes.staticTooltip = {
element: null,
tooltipElement: null,
deleting: false,
init( element ) {
if ( this.deleting ) {
return;
}
this.element = element;
this.buildElements();
},
destroy() {
if ( ! this.tooltipElement || this.deleting ) {
return;
}
this.deleting = true;
this.tooltipElement.classList.remove( ‘opened’ );
setTimeout( () => {
this.tooltipElement.remove();
this.deleting = false;
}, 500 );
},
buildElements() {
const tooltipElement = document.createElement( ‘div’ );
tooltipElement.classList.add( ‘tasty-recipes-static-tooltip’);
tooltipElement.setAttribute( ‘id’, ‘tasty-recipes-tooltip’ );
const currentTooltipElement = document.getElementById( ‘tasty-recipes-tooltip’ );
if ( currentTooltipElement ) {
document.body.replaceChild( tooltipElement, currentTooltipElement );
} else {
document.body.appendChild( tooltipElement );
}
this.tooltipElement = document.getElementById( ‘tasty-recipes-tooltip’ );
},
show() {
if ( ! this.tooltipElement ) {
return;
}
const tooltipTop = this.element.getBoundingClientRect().top
+ window.scrollY
– 10 // 10px offset.
– this.tooltipElement.getBoundingClientRect().height;
const tooltipLeft = this.element.getBoundingClientRect().left
– ( this.tooltipElement.getBoundingClientRect().width / 2 )
+ ( this.element.getBoundingClientRect().width / 2 ) – 1;
const posLeft = Math.max( 10, tooltipLeft );
this.maybeRemoveTail( posLeft !== tooltipLeft );
this.tooltipElement.setAttribute( ‘style’, ‘top:’ + tooltipTop + ‘px;left:’ + posLeft + ‘px;’ );
this.tooltipElement.classList.add( ‘opened’ );
},
maybeRemoveTail( removeTail ) {
if ( removeTail ) {
this.tooltipElement.classList.add( ‘tr-hide-tail’ );
} else {
this.tooltipElement.classList.remove( ‘tr-hide-tail’ );
}
},
changeMessage( message ) {
if ( ! this.tooltipElement ) {
return;
}
this.tooltipElement.innerHTML = message;
}
};
window.TastyRecipes.ajax = {
sendPostRequest( url, data, success, failure ) {
const xhr = new XMLHttpRequest();
xhr.open( ‘POST’, url, true );
xhr.send( this.preparePostData( data ) );
xhr.onreadystatechange = () => {
if ( 4 !== xhr.readyState ) {
return;
}
if ( xhr.status === 200 ) {
success( JSON.parse( xhr.responseText ) );
return;
}
failure( xhr );
};
xhr.onerror = () => {
failure( xhr );
};
},
preparePostData( data ) {
const formData = new FormData();
for ( const key in data ) {
formData.append( key, data[key] );
}
return formData;
},
};
window.TastyRecipes.ratings = {
defaultRating: 0,
currentRatingPercentage: 100,
savingRating: false,
init( minRating ) {
this.minRating = minRating;
this.formWatchRating();
this.closeTooltipWhenClickOutside();
this.addBodyClassBasedOnSelectedRating();
this.backwardCompFormRatingPosition();
},
formWatchRating() {
const ratings = document.querySelectorAll(‘.tasty-recipes-no-ratings-buttons [data-rating]’);
if ( ratings.length {
event.preventDefault();
this.defaultRating = event.target.closest( ‘.checked’ ).dataset.rating;
this.setCheckedStar( event.target );
this.maybeSendRating( this.defaultRating, event.target );
this.setRatingInForm( this.defaultRating );
} );
}
},
closeTooltipWhenClickOutside() {
window.addEventListener( ‘click’, e => {
// Bailout (don’t remove the tooltip) when the clicked element is a rating star, or it’s the tooltip itself.
if ( e.target.closest( ‘.tasty-recipes-rating’ ) || e.target.classList.contains( ‘tasty-recipes-static-tooltip’ ) ) {
return;
}
window.TastyRecipes.staticTooltip.destroy();
} );
},
setRatingInForm( rating ) {
const ratingInput = document.querySelector( ‘#respond .tasty-recipes-rating[value=”‘ + rating + ‘”]’ );
if ( ! ratingInput ) {
return;
}
ratingInput.click();
},
addBodyClassBasedOnSelectedRating() {
const ratingInputs = document.querySelectorAll( ‘input.tasty-recipes-rating’ );
if ( ! ratingInputs ) {
return;
}
for ( const ratingInput of ratingInputs ) {
ratingInput.addEventListener( ‘click’, currentEvent => {
const selectedRating = currentEvent.target.getAttribute( ‘value’ );
this.handleBodyClassByRating( selectedRating );
this.toggleCommentTextareaRequired( selectedRating );
} );
}
},
handleBodyClassByRating( rating ) {
if ( rating < this.minRating ) {
document.body.classList.remove( 'tasty-recipes-selected-minimum-rating' );
return;
}
document.body.classList.add( 'tasty-recipes-selected-minimum-rating' );
},
toggleCommentTextareaRequired( rating ) {
const commentTextarea = document.getElementById( 'comment' );
if ( ! commentTextarea ) {
return;
}
if ( rating {
window.TastyRecipes.staticTooltip.changeMessage( response.data.message );
window.TastyRecipes.staticTooltip.show();
this.updateAverageText( response.data, recipeCardElement );
this.maybeFillCommentForm( response.data );
// Hide the tooltip after 5 seconds.
setTimeout( () => {
this.maybeResetTooltip( recipeCardElement, response.data, rating );
}, 5000 );
},
() => {
this.resetTooltip( recipeCardElement );
}
);
},
updateAverageText( data, recipeCardElement ) {
if ( ! data.average ) {
return;
}
this.setRatingPercent( data );
if ( ! data.count ) {
return;
}
const quickLink = document.querySelector( ‘.tasty-recipes-rating-link’ );
if ( quickLink ) {
this.setTextInContainer( quickLink, data );
this.setPartialStar( quickLink );
}
const cardStars = recipeCardElement.querySelector( ‘.tasty-recipes-ratings-buttons’ );
cardStars.dataset.trDefaultRating = data.average;
this.setTextInContainer( recipeCardElement.querySelector( ‘.tasty-recipes-rating’ ), data );
},
setTextInContainer( container, data ) {
if ( ! container ) {
return;
}
if ( data.label ) {
const ratingLabelElement = container.querySelector( ‘.rating-label’ );
if ( ratingLabelElement ) {
ratingLabelElement.innerHTML = data.label;
}
return;
}
const averageElement = container.querySelector( ‘.average’ );
if ( averageElement ) {
averageElement.textContent = data.average;
}
const countElement = container.querySelector( ‘.count’ );
if ( countElement ) {
countElement.textContent = data.count;
}
},
setPartialStar( container ) {
const highestStar = container.querySelector( ‘[data-rating=”‘ + Math.ceil( this.defaultRating ) + ‘”]’ );
if ( highestStar ) {
highestStar.dataset.trClip = this.currentRatingPercentage;
}
},
setRatingPercent( data ) {
this.defaultRating = data.average.toFixed( 1 );
const parts = data.average.toFixed( 2 ).toString().split( ‘.’ );
this.currentRatingPercentage = parts[1] ? parts[1] : 100;
if ( this.currentRatingPercentage === ’00’ ) {
this.currentRatingPercentage = 100;
}
},
setCheckedStar( target ) {
const cardRatingContainer = target.closest( ‘.tasty-recipes-ratings-buttons’ );
const selectedRatingElement = cardRatingContainer.querySelector( ‘[data-tr-checked]’ );
if ( selectedRatingElement ) {
delete selectedRatingElement.dataset.trChecked;
}
const thisStar = target.closest( ‘.tasty-recipes-rating’ );
thisStar.dataset.trChecked = 1;
thisStar.querySelector( ‘[data-tr-clip]’ ).dataset.trClip = 100;
},
maybeFillCommentForm( data ) {
if ( ! data.comment || ! data.comment.content ) {
return;
}
const commentForm = document.querySelector( ‘#commentform’ );
if ( ! commentForm ) {
return;
}
const commentBox = commentForm.querySelector( ‘[name=comment]’ );
if ( ! commentBox || commentBox.value ) {
return;
}
// Add comment details for editing.
commentBox.innerHTML = data.comment.content;
if ( data.comment.name ) {
commentForm.querySelector( ‘[name=author]’ ).value = data.comment.name;
commentForm.querySelector( ‘[name=email]’ ).value = data.comment.email;
}
},
maybeResetTooltip( recipeCardElement, data, rating ) {
if ( this.savingRating === rating ) {
this.resetTooltip( recipeCardElement, data );
}
},
resetTooltip( recipeCardElement, data ) {
window.TastyRecipes.staticTooltip.destroy();
this.savingRating = false;
// Reset the default rating.
const cardRatingContainer = recipeCardElement.querySelector( ‘.tasty-recipes-ratings-buttons’ );
if ( cardRatingContainer ) {
this.defaultRating = ( data && data.average ) ? data.average.toFixed(1) : cardRatingContainer.dataset.trDefaultRating;
cardRatingContainer.dataset.trDefaultRating = this.defaultRating;
this.resetSelectedStar( cardRatingContainer, data );
}
},
resetSelectedStar( cardRatingContainer ) {
const selectedRatingElement = cardRatingContainer.querySelector( ‘[data-rating=”‘ + Math.ceil( this.defaultRating ) + ‘”]’ );
if ( selectedRatingElement ) {
selectedRatingElement.querySelector( ‘[data-tr-clip]’ ).dataset.trClip = this.currentRatingPercentage;
selectedRatingElement.parentNode.dataset.trChecked = 1;
}
const previousSelectedElement= cardRatingContainer.querySelector( ‘[data-tr-checked]’ );
if ( previousSelectedElement ) {
const currentSelectedRating = previousSelectedElement.querySelector(‘[data-rating]’);
if ( currentSelectedRating !== selectedRatingElement ) {
delete previousSelectedElement.dataset.trChecked;
}
}
},
backwardCompFormRatingPosition() {
const ratingsButtons = document.querySelector( ‘#respond .tasty-recipes-ratings-buttons, #tasty-recipes-comment-rating .tasty-recipes-ratings-buttons’ );
if ( ! ratingsButtons ) {
return;
}
const ratingsButtonsStyles = window.getComputedStyle(ratingsButtons);
if ( ! ratingsButtonsStyles.display.includes( ‘flex’ ) ) {
ratingsButtons.style.direction = ‘rtl’;
}
if ( typeof tastyRecipesRating !== ‘undefined’ ) {
// Select the rating that was previously selected in admin.
ratingsButtons.querySelector( ‘.tasty-recipes-rating[value=”‘ + tastyRecipesRating + ‘”]’ ).checked = true;
}
const ratingSpans = ratingsButtons.querySelectorAll( ‘.tasty-recipes-rating’ );
for (const ratingSpan of ratingSpans) {
ratingSpan.addEventListener( ‘click’, event => {
if ( ratingSpan === event.target ) {
return;
}
ratingSpan.previousElementSibling.click();
} );
}
}
};
(function(callback) {
if (document.readyState !== “loading”) {
callback();
} else {
window.addEventListener( ‘load’, callback );
}
})(() => {
window.TastyRecipes.ratings.init( window.trCommon ? window.trCommon.minRating : 4 );
});
The post Chinese 5-Spice Tofu appeared first on Olives for Dinner.