Try these easy shrimp recipes for fast and easy meals! These tested recipes are my favorite shrimp dinner ideas, from sautes to scampi to stir fries.

If you’re looking for quick and healthy dinners, shrimp recipes are one of the best places to look! As a cookbook author who eats the Mediterranean diet, I often make shrimp for dinner because it’s quick and my whole family loves it.
Here’s why I love it: shrimp cooks up in just 3 minutes, literally faster than unloading the dishwasher! It is also naturally high in protein, low in calories, and packed with nutrients. After years of recipe testing, here are my top easy shrimp recipes to turn it into a satisfying meal.
My Favorite Easy Shrimp Recipes
This is my go-to method for tender, juicy shrimp in under 10 minutes. I season the shrimp with my magic seafood blend (smoked paprika, garlic powder, onion powder, and cumin), then sauté them until they're just opaque. They're great for topping salads, stuffing into tacos, or serving over pasta.
Shrimp, butter, garlic, lemon, and white wine: what could be better? This Italian-American classic is always a crowd-pleaser when I serve it. Juicy, garlicky shrimp swim in a rich, tangy butter sauce that's delicious sopped up with crusty bread or served with linguine.
This shrimp rice bowl gets 5 stars from everyone in my house: and that's saying something. Each bowl has a generous helping of cilantro lime rice, tender shrimp and a quick black bean and corn salad. The best part is the creamy, zingy chipotle ranch dressing that covers it all!
This tasty shrimp and rice skillet is a tasty one-pan meal! Succulent, juicy shrimp sit atop a bed of fluffy rice flavored with garlic, dill and spinach. Give it a good sprinkling of feta cheese and a few spritzes of lemon juice before serving.
The sweet-savory combination of honey and garlic takes only 10 minutes to make, making a sticky glaze that coats each piece of shrimp. It hits all the comforting, satisfying dinner notes with lightning-fast prep. I've found it's especially popular with people who might be hesitant about seafood.
This luscious shrimp linguine is a wow-worthy dinner ready in 30 minutes! This is one of my favorite ways to serve shrimp: juicy shrimp are bathed in a vibrant lemon butter sauce and served with al dente linguine.
This is my go-to in the fast and easy dinner category. It's quick to put together, and the stir fry sauce is full of irresistible flavor. I add whatever vegetables I have in the fridge to make a satisfying dinner that pleases everyone.
When I want hands-off cooking, baked shrimp is the answer. I toss the shrimp with garlic, herbs, and olive oil, and pop them in the oven for about 10 minutes. The shrimp come out juicy and perfectly seasoned, freeing you up to make side dishes while dinner cooks.
There's something so fun about baking dinner on one pan in the oven, right? These sheet pan shrimp fajitas are perfect for easy weeknight meals! The shrimp comes out juicy and succulent, and everything gets infused with a combination of Tex-Mex spices.
Is there anything more delicious than succulent, garlicky shrimp right off the grill? Here’s a seriously easy recipe for grilled shrimp, using a zesty lemon and savory garlic. It takes only 2 to 4 minutes to cook! There’s nothing faster on the grill, and it makes for a simple, healthy shrimp dinner. Also try my Grilled Shrimp Skewers.
Shrimp tacos have a fun vibe that makes any dinner feel more fun. This easy recipe works as both a fast family dinner for weeknights and for a dinner party with friends. I pile them high with crunchy cabbage slaw and a drizzle of cilantro ranch.
A meal cooked on a single sheet pan never really gets old! This Mediterranean-inspired dinner combines juicy shrimp with colorful vegetables like cherry tomatoes and artichoke hearts, then tops everything with a squeeze of lemon and a hearty sprinkle of feta cheese. Serve with orzo, couscous, or rice.
This Cajun shrimp recipe makes weeknight dinners feel exciting with minimal effort. I toss the shrimp with Cajun seasoning and sauté in a hot skillet for about 5 minutes until they're spiced and aromatic. I love serving it over rice with sauteed peppers.
Broiled shrimp is so tasty, and you don't even need to preheat the oven. I place seasoned shrimp on a baking sheet, slide it under the broiler, and watch them turn pink and slightly caramelized in minutes. It's perfectly seasoned with garlic and lemon, making it ideal for busy weeknights when you need something fast.
This flavorful Tuscan shrimp recipe is the perfect easy dinner! I also call it “Marry Me Shrimp,” a meld of juicy shellfish with sun-dried tomatoes, spinach, and a creamy garlic sauce. Serve with pasta, rice, or veggies for a satisfying meal.
Pesto shrimp has "easy weeknight meal" written all over it. The bright green, garlicky pesto sauce is the perfect pairing for succulent shellfish, making a dish that tastes gourmet but comes together in minutes. I like to serve it with noodles or rice and sautéed vegetables.
This 30-minute creamy shrimp pasta is great for the weekly dinner rotation: juicy, savory shrimp and al dente pasta swim in a creamy sauce. Try it with a white wine sauce or our easy cream sauce, a Parmesan-infused sauce that’s actually made with no cream at all.
Add sauteed shrimp to Caesar salad and you've got a meal! This is one of my favorite ways to make a quick and easy dinner. Make it with my homemade Caesar dressing, but if you're running short of time store-bought works too!
Try pairing this juicy seafood with pasta and fresh vegetables in this shrimp primavera. It’s like a classic pasta primavera with shrimp added, and smothered in a light creamy sauce, it makes a simple satisfying dinner in just 30 minutes.
This cilantro lime shrimp recipe is packed with zingy flavor: and it takes less than 10 minutes to put together! It comes out beautifully tangy and fresh. It pairs perfectly with Mexican-style flavors: serve it with rice, an avocado salad, or in tacos. You can also make it into a main dish salad topped with cilantro dressing.
I'm always looking for fun and healthy dinner ideas, and these lettuce wraps are perfect: bursting with zingy flavor and crunchy veggies. The creamy peanut sauce seals the deal. This one is so flavor-packed you won’t go away unsatisfied.
Here's a shrimp recipe that’s so quick, simple and bursting with flavor, it will become a family favorite in no time. It’s amazing what a little garlic, butter, and lemon juice can do for a pile of shrimp. Throw them in the pan and it makes absolute magic in under 15 minutes of prep time!
Here's a fun recipe starring this succulent seafood: Shrimp Nachos! It makes the best fun appetizer or simple dinner atop crunchy tortilla chips with a confetti of colorful toppings. You don't even need to cook the shrimp separately: throw them on top of the chips and bake!
Looking for a fun, flavorful way to use that bag of frozen shrimp? This BBQ shrimp recipe makes a bold, tangy sauce for the shrimp to swim in, flavored with barbecue sauce and a few pantry extras. It's the perfect fast dinner for nights when you don't want to think too hard.
Looking for a healthy and easy weeknight meal that comes together fast? Shrimp and broccoli are cooked with soy sauce and rice vinegar until bright and savory. This dish packs in vegetables without any complaints from my family.
Try this go-to Marinated Shrimp Skewers! The flavors are bold, savory, and penetrate the tender, juicy flesh in a way that a simple seasoning can’t. Throw together a few pantry ingredients, no chopping required. Make them in the broiler and they cook in just 5 minutes!
I find myself coming back to blackened shrimp again and again. Blackening is a Cajun cooking technique that's all about the spices—I combine homemade blackened seasoning with grilled or pan-fried shrimp. Everyone always loves the blend of flavors.
This method is technically a combination of boiling and steaming, but it results in beautifully succulent, seasoned shrimp in just 2 to 3 minutes. I love using Old Bay seasoning for its iconic blend of celery salt, paprika, and spices.
Why not make a lobster roll…with shrimp? This recipe makes a savory, creamy filling on a warm, buttery bun. This recipe takes all the goodness of a lobster roll and makes it more budget-friendly.
Here’s a shrimp dinner idea to impress that doubles as an easy weeknight meal: try this Cajun Shrimp Pasta! This one scores major points with kids and adults alike at our table. It features irresistibly seasoned Cajun shrimp, colorful veggies, and a rich garlic Parmesan flavoring.
When I want a meal to impress with a little kick, I make Shrimp Fra Diavolo. This Italian-style dish stars tender shrimp swimming in a garlicky, spicy tomato sauce. "Fra diavolo" means to "brother devil" in Italian, alluding to the intense heat, but here you can customize the spiciness to your taste preferences.
You can make just about anything into a burger, from chicken to seafood to vegetables. So why not try a shrimp burger? Turns out, these succulent shellfish make a surprisingly juicy and satisfying patty. Slathered with a creamy sauce and served up on a bun, it’s a hearty meal that I like even better than a salmon burger.
This shrimp curry tastes better than a restaurant, but it’s a quick and easy dinner you can make at home! There is so much flavor going on here: rich coconut milk, aromatic curry paste, tangy lime and peppery basil surrounding tender, juicy shrimp. Serve it over jasmine rice.
This shrimp and grits recipe will wow everyone at the table. This recipe really is "world famous" and was blessed by Gordon Ramsey himself. Everyone loves the creamy grits, tender shrimp, and luscious veggie gravy.
This Italian-style dish is full of bold flavor: juicy, succulent shrimp sit over a bed of creamy, Parmesan and lemon-scented rice. It’s great for impressing guests as a main dish, but it’s simple enough to work as a weeknight meal, too.
Why not harness the magic of the shrimp boil for an every day meal? This shrimp boil in the oven is an easy way to make it on a weeknight: no large pot or fire required! The shrimp is tender and the veggies have browned and caramelized goodness, seasoned with the nuance of Old Bay seasoning.
Here’s a fast and easy dinner recipe that’s always a hit: shrimp pesto pasta! Coat long noodles in silky basil pesto, then add juicy, succulent shrimp. It works just as well for a dinner party as a weeknight meal.
Shrimp on a pizza is unique but absolutely delicious: the garlicky, buttery shrimp against creamy ricotta cheese is one of the best pizza topping combinations I've had! It’s like shrimp alfredo on a pizza crust instead of noodles: which tastes just as good as it sounds.
This shrimp recipe is all about comfort food vibes. The garlic, ginger and soy sauce meld perfectly with the colorful veggies, bursts of shrimp and gooey bits of egg. It’s one of my favorites for a quick dinner if I have leftover rice on hand.
Paella is a shrimp dinner idea that looks fancy but can be made on a weeknight, too. What makes the dish is the smoked paprika (pimentón), which lends an irresistibly smoky flavor. Top the saffron rice with some tender, juicy shrimp and tangy artichokes, and you’ve got one satisfying dinner.
Tips for Buying and Preparing Shrimp
Shopping for shrimp can feel overwhelming with all the options at the grocery store. Here’s what I’ve learned after years of cooking with shrimp:
Choose the right size. I typically buy medium shrimp for most recipes (labeled 41-50 count per pound). I find this size is generally bite-sized and works well regardless of the recipe.
Frozen is perfectly fine. Most shrimp you see at the grocery store has been frozen at some point, even if it’s displayed in the “fresh” case. Buying frozen shrimp is convenient to keep in the freezer for last-minute meals and generally tastes just as fresh. Here’s my guide on how to thaw shrimp.
Look for deveined shrimp. The “vein” is actually the shrimp’s digestive tract. It’s safe to eat, but removing it improves its appearance.
Look for wild caught if possible, or find a well-regulated farm. Fish that is wild caught in your country is usually a sustainable choice. There are also quality options in well-regulated farms; see Seafood Watch Consumer Guide.
How to Avoid Rubbery Shrimp
Rubbery shrimp is one of the most common cooking mistakes! Shrimp cooks in 2 to 4 minutes.
You want to catch it right at the moment shrimp turns from translucent to opaque pink. It works to pull shrimp off the heat slightly before it looks completely cooked, because residual heat will finish the cooking. Overcooking by even 30 seconds can turn perfectly tender shrimp into tough, rubbery pieces.
Another important tip: don’t crowd the pan. If shrimp are packed too tightly, they steam instead of sear. This has happened to me more times than I can count! Cook the shrimp in batches if needed to ensure each piece has enough space to develop a caramelized exterior.
My Favorite Ways to Serve Shrimp: Without A Recipe
I serve shrimp in so many different ways depending on the occasion – whip it up sauteed or baked then use one of these ideas for serving:
- Over grains: Shrimp pairs well with grains like quinoa, farro, rice, or polenta. It’s especially delicious with coconut rice.
- In tacos and bowls: Grilled shrimp tacos are a staple you can make with simply tortillas, guacamole, and pico de gallo. I also love burrito bowls with shrimp, black beans, salsa, and all the toppings.
- With pasta: It’s a natural match for noodles. I especially love it with lemon pasta or angel hair.
- In salads: I toss it with arugula salad, Caesar salad, or a simple tossed salad for quick, healthy dinners.
Storage and Reheating Tips
Cooked shrimp stores well in the refrigerator for 2-3 days in an airtight container. When reheating, use a skillet over low heat to prevent the shrimp from becoming tough and rubbery.
For meal prep, I prefer not to cook shrimp too far in advance (personally, it never seems to appeal cold). Since it cooks so quickly, I cook it right before I plan to serve.
Frequently asked questions
There are many types to choose from! Popular ones include white shrimp, brown shrimp, pink shrimp, and tiger shrimp. Each has a slightly different flavor and texture. We like using tail on shrimp for most recipes.
Both options are great! Fresh shrimp often have a slightly better flavor, but high-quality frozen shrimp can be just as delicious. If you choose frozen, thaw them in the refrigerator overnight for best results.
Deveining removes the dark intestinal tract. We recommend buying shrimp that are already deveined before making shrimp recipes. Only use shell on shrimp if the recipe calls for it.
Cooked shrimp turn opaque and a vibrant pink/orange color. They will also curl into a loose “C” shape.
Yes! Be sure to adjust cooking times as needed. Smaller shrimp cook faster than large ones.
Reheat gently to avoid overcooking and tough shrimp. Low heat on the stovetop or a quick warmup in the oven are usually preferred.
5 Minute Sauteed Shrimp
This sauteed shrimp recipe comes out juicy and seasoned to perfection in 5 minutes! A quick and healthy dinner idea.
- Prep Time: 2 minutes
- Cook Time: 3 minutes
- Total Time: 5 minutes
- Yield: 4
- Category: Main Dish
- Method: Stovetop
- Cuisine: Seafood
- Diet: Gluten Free
Ingredients
- 1 1/2 pounds medium shrimp, deveined (tail on or peeled)
- ¾ teaspoon kosher salt
- ¾ teaspoon smoked paprika (or substitute standard paprika)
- ¾ teaspoon garlic powder
- ¾ teaspoon onion powder
- ¾ teaspoon cumin
- 3 tablespoons butter or olive oil
- 3 lemon wedges
- Fresh cilantro or parsley, for garnish
Instructions
- Thaw the shrimp, if frozen. Pat the shrimp dry. In a medium bowl, mix the shrimp with the salt, smoked paprika, garlic powder, onion powder, and cumin.
- In a large skillet, heat the butter on medium high heat. Add the shrimp and cook for 1 to 2 minutes per side until just opaque and cooked through, turning them with tongs.
- Spritz with juice of the lemon wedges and serve immediately.
(function(){
window.addEventListener( ‘message’, function( event ){
if ( ( ‘https://nutrifox.com’ !== event.origin && ‘https://nutrifox.test’ !== event.origin ) ||
typeof event.data !== ‘string’ ) {
return;
}
var payload = JSON.parse( event.data );
switch ( payload.event ) {
case ‘setHeight’:
var iframe = document.getElementById( ‘nutrifox-label-‘ + payload.recipeId );
iframe.style.height = payload.height + ‘px’;
break;
}
} );
}());
window.trCommon={“minRating”:6,”ajaxurl”:”https://www.acouplecooks.com/wp-admin/admin-ajax.php”,”ratingNonce”:””,”postId”:39588};
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 );
});