White Wine Sauce For Pasta

This post was originally published on this site

Wine and pasta are a dream team—so why just pair them when you can cook with them? This white wine sauce is velvety, garlicky magic that makes pasta taste straight-up luxurious—in under an hour.

A fork lifting a bite of pasta with garlicky white wine sauce, fresh parsley, and black olives.

Why have a glass of wine with dinner when you can have wine in dinner? This pasta with white wine sauce is proof that the simplest ingredients can create the most unforgettable meals. Shallots, garlic, and wine simmer down into a glossy, aromatic sauce that coats every strand of pasta, making each bite feel just a little fancy—but in that effortless, weeknight-kind-of-way.

If you love a light, garlicky pasta sauce with just enough richness to feel indulgent, this one’s for you. A handful of briny olives, fresh parsley, and a warm piece of crusty bread on the side, and suddenly, you’ve got a meal that feels like it came straight out of your favorite cozy restaurant.

Pasta being twirled with two forks, showing off the creamy white wine sauce and herbs.

What Is White Wine Sauce?

White wine sauce is a flavorful, light pasta sauce made by reducing white wine with garlic, shallots, and vegan butter (or olive oil) until silky and aromatic. It’s a dairy-free alternative to cream-based sauces and pairs well with fresh herbs, briny ingredients like olives or capers, and a squeeze of lemon.

Why You’ll Love This White Wine Sauce

This velvety, light, dairy-free pasta sauce proves that simple ingredients can create something truly special. It has the depth of a slow-simmered sauce but comes together in about 45 minutes, making it perfect for both weeknights and dinner-worthy moments. Here’s why you’ll want this in your pasta rotation:

  • Velvety but light. Thanks to a simple emulsion of white wine, garlic, shallots, and vegan butter, this sauce is silky and rich without being heavy—coating every strand of pasta without overpowering it.
  • Dairy-free without compromise. No cream, no problem. This sauce uses the natural starch from pasta water to create a glossy, luxurious texture, proving you don’t need dairy for a perfectly emulsified sauce.
  • Quick but feels fancy. With just a handful of ingredients and one pan, you get restaurant-worthy flavor in a fraction of the time.
  • Pairs beautifully with add-ins. Keep it minimalist, or bulk it up with sautéed mushrooms, cherry tomatoes, soy curls, or vegan chicken. Want a little heat? A pinch of red pepper flakes makes it pop.
  • The ultimate bread-dipping sauce. That garlicky, wine-infused sauce? You’ll want to mop up every last drop with a warm, buttered slice of crusty bread or homemade focaccia.

Key Ingredients

A great pasta dish is all about balance, and this white wine sauce delivers with just the right mix of richness, acidity, and umami. It’s velvety but light, indulgent but not heavy, and packed with layers of flavor that come together in about 45 minutes. Here’s what you’ll need:

  • Vegan butter: The base of the sauce, adding richness and depth while helping everything emulsify into a silky, restaurant-worthy finish.
  • Shallots: Milder and slightly sweeter than onions, shallots bring a subtle depth of flavor that makes the sauce feel just a little fancier than your average garlic butter pasta.
  • Garlic: The backbone of the sauce, infusing every bite with that bold, aromatic goodness that makes a simple pasta dish feel like a cozy, must-make-again kind of meal.
  • Olive oil: Used alongside vegan butter to create a balanced, glossy sauce. A good extra virgin olive oil brings in a little fruitiness and body.
  • White wine: The star ingredient! A crisp, dry white wine (think Sauvignon Blanc or Pinot Grigio) adds brightness, acidity, and just a hint of complexity. The alcohol cooks off, leaving behind an elevated, almost effortless depth of flavor. Want to make sure your pick is vegan? Check out Barnivore!
  • Garlic powder: Reinforces the fresh garlic, rounding out the flavor and ensuring that garlicky warmth is infused throughout the sauce.
  • Reserved pasta water: The secret to a silky, emulsified sauce. That starchy, salted water binds everything together, giving the sauce its signature glossy texture.
  • Pasta: Use any kind you love! Long noodles like linguine or fettuccine soak up the sauce beautifully, while short pasta shapes hold onto all that garlicky, wine-infused goodness.
  • Oil-cured olives: The secret umami bomb of this dish. These deeply flavorful, briny olives contrast beautifully with the richness of the sauce, adding little bursts of saltiness in every bite.
  • Fresh parsley: A bright, herby finish that cuts through the richness and ties everything together. A sprinkle of fresh parsley at the end makes the dish feel vibrant, fresh, and ready to devour.
Pasta twirled onto a form with parsley and oil-cured olives.

Flavor Variations

This white wine sauce for pasta is already a dream, but if you want to level it up, there are endless ways to customize it. Whether you’re looking for extra umami, a pop of brightness, or something hearty to make it a full meal, these ideas will take your pasta in a whole new direction.

Savory & Umami-Packed

  • Shiitake bacon: Crispy, smoky, salty. If you haven’t made shiitake bacon yet, this is your sign. It brings that little something extra that makes every bite ridiculously good.
  • Sautéed mushrooms: Cremini, shiitake, or oyster mushrooms soak up the garlicky awesome sauce like little umami sponges.
  • Oil-cured olives & capers: If you love a briny, salty kick, double down with chopped oil-cured olives and a spoonful of capers for an extra punch.

Hearty Add-Ins

  • Vegan chicken: Toss in your favorite plant-based chick’n for a protein boost that soaks up all that saucy goodness. We love Gardein and Daring brands. Check out more options in our plant-based protein guide!
  • Vegan sausage: Sliced and browned in a pan, vegan sausage adds a spiced, smoky depth that makes this pasta next-level cozy. We love Field Roast Italian style links.
  • Toasted nuts: A handful of pine nuts, walnuts, or marcona almonds adds the perfect buttery crunch to balance out the silky sauce.

Bright & Fresh

  • Roasted cherry tomatoes: Juicy and sweet, these burst into the sauce, balancing the richness with a little acidity.
  • Lemon zest & juice: A little extra lemon at the end? Yes, please. Brightens everything and makes the sauce sing.
  • Leafy greens: Spinach, arugula, or kale wilt beautifully into the warm pasta, giving it a colorful and healthy boost.

However you spin it, this white wine pasta is a perfect base for all kinds of flavors—keep it classic or go wild. Either way, don’t forget the crusty bread to mop up every last drop.

Two hands twirling a forkful of pasta, creating a cozy, restaurant-style vibe.

How To Make This Pasta

This white wine sauce for pasta comes together in just a few simple steps—no complicated techniques, no stress, just big flavor in about 45 minutes. You’ll melt, sauté, deglaze, and toss your way to a pasta dish that feels effortlessly elegant. For full recipe details, scroll to the end of this post!

Step 1: Build the Flavor BaseMelt, soften, and let the magic begin. In a wide skillet or Dutch oven, melt the vegan butter over medium heat. Once it starts to bubble, reduce the heat to medium-low and add the shallots. Let them soften until translucent—about 5 minutes—releasing all that mild, slightly sweet depth into the sauce.

Step 2: Garlic TimeThe moment your kitchen starts smelling amazing. Stir in the minced garlic and olive oil, letting everything cook for another 5 minutes. Keep the heat low enough to soften and infuse (but not brown) the garlic—it should be fragrant, mellow, and buttery.

Step 3: Deglaze with WineWhere the magic happens. Increase the heat to medium-high and let the aromatics sizzle for about a minute. Pour in the white wine, scraping up any flavorful bits from the bottom of the pan. Let it cook down for about 2 minutes, concentrating its brightness and acidity while leaving behind that deep, layered flavor.

Step 4: Season and Simmer Bringing it all together. Lower the heat and sprinkle in the garlic powder—this reinforces the garlicky warmth and rounds out the sauce. Let everything simmer gently while you cook the pasta.

Step 5: Cook the PastaSeason your water, trust the process. Bring a large pot of well-salted water to a rolling boil, then cook your pasta of choice according to the package instructions. The seasoned water is key—it’s not just cooking the pasta, it’s building the foundation for a well-balanced dish.

Step 6: Toss It All TogetherThe glossy, emulsified finish. Before draining the pasta, scoop out ⅓ cup of the pasta water—this is liquid gold. Use tongs to transfer the pasta directly into the pan with the sauce, then pour in the reserved pasta water. Toss everything over medium-low heat until the sauce thickens and clings to the pasta like a silky, glossy coating.

Step 7: Finish and ServeThe final touches make all the difference. Sprinkle in the chopped oil-cured olives and fresh parsley, stirring to distribute all those salty, briny, herby pops of flavor. Divide into bowls, grab some warm crusty bread, with a schmear of vegan butter or vegan ricotta, and serve immediately.

Top-down view of a plate of pasta with white wine sauce, garnished with fresh herbs and briny olives.

Best Pastas for White Wine Sauce

The beauty of this dreamy sauce is that it works with just about any kind of pasta—but some pastas really shine when coated in this velvety, garlicky, wine-infused sauce. Here are the best options:

  • Long, twirl-able noodles: Linguine, fettuccine, spaghetti, or tagliatelle are classic choices. These pastas soak up the light, silky sauce beautifully, giving you that perfect forkful every time.
  • Hollow pastas that catch sauce: Bucatini and penne are great options since their hollow centers trap the white wine sauce, ensuring each bite is full of flavor.
  • Ridged or textured shapes: If you want a pasta that grips the sauce well, go for fusilli, rigatoni, or orecchiette. The little grooves help hold onto every bit of that garlicky goodness.
  • Fresh pasta for extra indulgence: Homemade or store-bought pappardelle or fresh fettuccine bring a delicate chewiness that pairs beautifully with the light but flavorful sauce.
  • Gluten-free pasta options: Chickpea, lentil, or brown rice pasta all work well with this sauce. For the best texture, opt for brands that hold their shape and don’t get mushy. Gluten-free fusilli or penne are great choices since their ridges help grip the sauce.

There’s no wrong choice, but if you want that classic restaurant feel, linguine, bucatini or fettuccine are perfect picks.

A single spoonful of pasta elegantly plated on a dark slate surface, garnished with parsley.

Pro Tips for a Silky White Wine Sauce

Making a light yet impressive sauce for pasta is simple, but a few smart techniques can take it from good to unbelievably good. Here’s how to make sure your sauce is silky, glossy, and packed with flavor:

  • Use a dry white wine. Sweet wines (like Riesling or Moscato) won’t give you the same depth. Stick with Sauvignon Blanc, Pinot Grigio, or Chardonnay for a crisp, balanced sauce.
  • Don’t rush the shallots and garlic. Giving them time to soften and release their flavor (without browning) makes all the difference. Think low and slow—about five minutes for shallots, then another five for garlic.
  • Let the wine cook down. The goal is to reduce the wine by about half, concentrating the flavor and cooking off the alcohol. This is where the magic happens—giving your sauce its signature depth.
  • Pasta water = liquid gold. Reserved pasta water is the secret to emulsification—binding the butter, olive oil, and wine into a silky, restaurant-quality sauce. Don’t skip it!
  • Finish it in the pan. Tossing the pasta directly into the sauce over low heat helps it absorb all that garlicky, wine-infused goodness. Let it sit for a minute, and watch it transform.
  • Balance it out. A squeeze of lemon brightens everything, and briny oil-cured olives add the perfect pop of saltiness. A little fresh parsley? Chef’s kiss.
  • Serve immediately. This sauce is at its best right off the heat—glossy, smooth, and coating every strand of pasta. Have your bowls (and warm crusty bread) ready to go.

FAQs

What is white wine sauce made of?

This sauce is a simple, flavorful pasta sauce made by simmering dry white wine with garlic, shallots, and vegan butter or olive oil. The wine reduces, intensifying its flavor, while pasta water helps emulsify everything into a glossy, silky sauce. It’s a light, dairy-free alternative to cream-based sauces, perfect for pairing with fresh herbs, olives, or a squeeze of lemon.

What wine is best for a white wine sauce?

A dry white wine like Sauvignon Blanc, Pinot Grigio, or Chardonnay works best, as they add acidity and depth without overpowering the dish. Avoid sweet wines like Riesling or Moscato, which can make the sauce taste too sweet.

How do you make white wine sauce for pasta?

Sauté shallots and garlic in vegan butter until soft, then deglaze the pan with white wine and let it reduce. Add pasta water to help create a silky, emulsified sauce, then toss in cooked pasta until everything is coated. Finish with fresh parsley, briny olives, or a squeeze of lemon for extra brightness.

Your New Go-To White Wine Pasta

This white wine sauce for pasta is one of those recipes that feels effortlessly elegant but is secretly so easy to make. With a garlicky, silky sauce, a pop of briny olives, and just the right balance of richness and brightness, it’s the kind of meal that makes any night feel just a little special.

Serve it up with warm crusty bread (because that sauce deserves to be scooped up to the last drop), a crisp green salad, or even a side of roasted veggies. Want to pair it with wine? Go for a Sauvignon Blanc or Pinot Grigio—the same dry white wine that makes the sauce shine.

A full plate of pasta tossed in a luscious silky sauce, ready to be enjoyed with crusty bread.

More Vegan Pasta Recipes to Try Next

If you try this white wine sauce recipe, please leave a comment and star rating below. Your feedback helps others find my content and makes my day!

Print

A close-up of a fork twirling pasta coated in a silky white wine sauce with garlic, parsley, and olives.

White Wine Sauce with Pasta


5 Stars 4 Stars 3 Stars 2 Stars 1 Star

5 from 4 reviews


  • Author:
    erin wysocarski


  • Total Time:
    45 minutes


  • Yield:
    2 servings


  • Diet:
    Vegan

const share_pin_buttons = document.getElementsByClassName( ‘share-pin button’ );
if ( share_pin_buttons ) {
for ( let share_key = 0; share_key {
e.stopPropagation();
window.open(e.target.dataset.href,’targetWindow’,’toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=500′);
return false;
} );
}
}

Description

A velvety white wine sauce that’s garlicky, buttery, and the perfect balance of fancy and effortless. The wine simmers into something rich and glossy, clinging to every strand of pasta like it was always meant to be there. Pour yourself a glass (for sipping and cooking), grab some crusty bread, and let’s do this.


Ingredients

for the sauce

  • 1/4 cup vegan butter
  • 2 shallots, minced
  • 68 cloves of garlic, minced
  • 2 tablespoons olive oil
  • 1/3 cup white wine
  • 1 teaspoon garlic powder
  • 1/3 cup reserved pasta water

to finish

  • 2 servings pasta (I used 200 grams Bucatini pasta)
  • a few tablespoons of olive oil and a generous amount of salt, to season the pasta water
  • 12 oil-cured olives, pitted and chopped
  • a handful of fresh parsley, chopped
  • crusty bread, warmed in the oven or toaster, with extra vegan butter to slather it with


Instructions

  1. Build the Flavor Base: Melt the vegan butter in a wide skillet over medium heat. Once bubbly, lower the heat to medium-low and add the shallots. Cook for about 5 minutes until soft and translucent.
  2. Infuse with Garlic: Stir in the minced garlic and olive oil, letting everything cook for another 5 minutes. Keep the heat low so the garlic softens without browning.
  3. Deglaze with Wine: Increase the heat to medium-high, then pour in the white wine, scraping up any browned bits. Let it cook for about 2 minutes until slightly reduced.
  4. Season & Simmer: Lower the heat again and add the garlic powder. Let the sauce gently simmer while you cook the pasta.
  5. Cook the Pasta: Bring a large pot of well-salted water to a boil and cook the pasta according to the package instructions. Before draining, reserve ⅓ cup of the pasta water.
  6. Toss & Coat: Use tongs to transfer the pasta directly into the skillet with the sauce, then add in the ⅓ cup reserved pasta water and toss over medium-low heat until the sauce turns glossy and clings to every strand.
  7. Finish & Serve: Stir in the chopped olives and fresh parsley, then divide into bowls. Serve immediately with warm crusty bread on the side.

Notes

  • Storage: Leftovers can be stored in an airtight container in the refrigerator for up to 3 days.
  • Reheating: Reheat gently on the stovetop over low heat, adding a splash of water or extra olive oil to loosen the sauce.
  • Wine Choice: Use a dry white wine like Sauvignon Blanc or Pinot Grigio for the best flavor. Avoid sweet wines.
  • Gluten-Free Option: Swap in your favorite gluten-free pasta—brown rice or chickpea pasta works well!
  • Add-Ins: Try sautéed mushrooms, roasted cherry tomatoes, or vegan chicken for extra texture and flavor.

  • Prep Time: 15 minutes
  • Cook Time: 30 minutes
  • Category: Dinner
  • Method: Sautéed, Boiled
  • Cuisine: Italian

window.trCommon={“minRating”:6,”ajaxurl”:”https://olivesfordinner.com/wp-admin/admin-ajax.php”,”ratingNonce”:””,”postId”:9982};
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 );
});

This post was originally published in 2021 and updated in 2025.

The post White Wine Sauce For Pasta appeared first on Olives for Dinner.

Spice-Rack-Maker

View posts by Spice-Rack-Maker
Dave the spice rack maker. Lived and worked in central MN for 50 years, Enjoy the lakes and woods surrounding the spice rack makers wood shop.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top
meta name="facebook-domain-verification" content="9nsylso9191eittlniq02vrtednsij" />