Belle-Ve Bricks

Your Imagination

Hogwarts Magical Trunk 76399-1

30+ Best Harry Potter LEGO® Sets

Create Your

We help you from start to finish to create and deliver your tailor-made custom model.
Custom model
Continue

Are you a Harry Potter fan with a love for LEGO®? Look no further! In this article, we’ll be showcasing the best Harry Potter LEGO® sets that will transport you straight into the wizarding world. From iconic buildings like Hogwarts Castle to magical vehicles like the Knight Bus, these sets are perfect for fans of all ages. So grab your wand and get ready to experience the enchantment of Harry Potter through the creativity of LEGO®.

Key Takeaway

  • The biggest LEGO® Harry Potter set released is LEGO® Hogwarts™ Castle (71043) with 6020 pieces.
  • The Harry Potter LEGO® sets that have been released are all inspired by the Harry Potter movies.
  • There are 9 Golden LEGO® Harry Potter Minifigures to collect, these can be found in 7 sets.
  • The Harry Potter LEGO® sets can be enjoyed by fans of all ages, from kids to adults. There is a set for you no matter your age or skill level.

For more best LEGO® sets check out our hardest LEGO® Sets post.

Best Harry Potter LEGO® Sets

1. LEGO® Hogwarts™ Castle (71043)

hogwarts castle

Set Name: LEGO® Harry Potter Hogwarts™ Castle
Set Number: 71043
Year Released: 2018
No. Pieces: 6020
No. Minifigures: 4 Minifigures and 27 Microfigures
RRP: £409.99 / $469.99 / 469.99€

The LEGO Harry Potter 71043 Hogwarts Castle set is a detailed and immersive building experience that includes over 6,000 pieces. It features all the iconic locations from the series and comes with 4 Minifigures and 27 Microfigures of your favorite characters. This set is perfect for die-hard Harry Potter fans who want to bring Hogwarts to life in their own home.

2. LEGO® Hogwarts™ Icons – Collectors’ Edition (76391)

lego harry potter hogwarts collection

Set Name: LEGO® Harry Potter Hogwarts™ Icons – Collectors’ Edition
Set Number: 76391
Year Released: 2021
No. Pieces: 3010
No. Minifigures: 3 (3 unique to this set)
RRP: £259.99 / $299.99 / 299.99€

The LEGO® Harry Potter™ Hogwarts™ Icons – Collectors’ Edition is a stunning display piece with many iconic artifacts from the series. It includes 3 exclusive golden minifigures and a display stand celebrating 20 years of LEGO® Harry Potter. With over 3,000 pieces to build, it’s a great gift idea for any LEGO® Harry Potter fan.

3. LEGO® Hogwarts Express – Collectors’ Edition (76405)

LEGO Harry Potter Hogwarts Express - Collectors' Edition 76405

Set Name: LEGO® Harry Potter Hogwarts Express – Collectors’ Edition
Set Number: 76405
Year Released: 2022
No. Pieces: 5129
No. Minifigures: 20 (18 unique to this set)
RRP: £429.99 / $499.99 / 499.99€

The LEGO® Harry Potter Hogwarts Express™ – Collectors’ Edition (76405) is a 1:32 scale replica of the iconic steam train. This build-and-display project features authentic details, including 4 classic scenes from the Harry Potter™ movies and a realistic rocking motion. At over 46 inches long, it’s an enchanting conversation piece for any adult fan or model-making enthusiast.

4. LEGO® Diagon Alley (75978)

LEGO Harry Potter Diagon Alley 75978

Set Name: LEGO® Harry Potter Diagon Alley
Set Number: 75978
Year Released: 2020
No. Pieces: 5544
No. Minifigures: 17 (15 unique to this set)
RRP: £389.99 / $449.99 / 449.99€

This impressive model measures over a meter wide and features iconic stores from the movies, including Ollivanders™ Wand Shop, Weasleys’ Wizard Wheezes™ and Flourish & Blotts™. The set features 17 Minifigures and plenty of accessories too which makes this set perfect for children and adults who want to build and play.

5. LEGO® Fawkes, Dumbledore’s Phoenix (76394)

Fawkes, Dumbledore’s Phoenix 76394 Harry Potter

Set Name: LEGO® Harry Potter Fawkes, Dumbledore’s Phoenix
Set Number: 76394
Year Released: 2021
No. Pieces: 597
No. Minifigures: 1 (1 unique to this set)
RRP: £34.99 / $39.99 / 39.99€

This set features realistic jointed wings that move up and down when the handle is turned. It has impressive detail, and a sturdy base, and it also includes an Albus Dumbledore™ LEGO minifigure along with a miniature Fawkes too. The mechanical Fawkes model has a wingspan of over 14 inches and makes an impressive display piece for any Fawkes, Phoenix, or Harry Potter fan.

6. LEGO® Attack on the Burrow (75980)

Set Name: LEGO® Harry Potter Attack on the Burrow
Set Number: 75980
Year Released: 2020
No. Pieces: 1047
No. Minifigures: 8 (7 unique to this set)
RRP: £89.99 / $99.99 / 99.99€

This set features the dramatic scene where Bellatrix Lestrange and Fenrir Greyback attack The Burrow, the Weasley family home. It includes 8 minifigures and fire elements to recreate the devastating fire. Perfect for fans aged 9 and up, this set makes a great addition to any Harry Potter collection.

7. LEGO® Hedwig™ (75979)

Hedwig™ 75979 _ Harry Potter™

Set Name: LEGO® Harry Potter Hedwig™
Set Number: 75979
Year Released: 2020
No. Pieces: 630
No. Minifigures: 1 (1 unique to this set)
RRP: £34.99 / $39.99 / 39.99€

The LEGO® Harry Potter Hedwig (75979) set is a must-have for any Harry Potter fan. The 630-piece brick-built model features impressive detail and jointed wings that gracefully move up and down when the handle at the rear is turned. The set also includes a detachable LEGO Harry Potter minifigure and a smaller, open-winged Hedwig too.

8. LEGO® Hungarian Horntail Dragon (76406)

Hungarian Horntail Dragon 76406 _ Harry Potter

Set Name: LEGO® Harry Potter Hungarian Horntail Dragon
Set Number: 76406
Year Released: 2022
No. Pieces: 671
No. Minifigures: 1 (1 unique to this set)
RRP: £44.99 / $49.99 / 49.99€

The LEGO® Harry Potter™ Hungarian Horntail Dragon (76406) is an impressive build that any Harry Potter fan will love. The model features jointed wings that move up and down when the handle is turned, allowing for realistic wing flapping action. This set also comes with a Harry Potter Minifigure and a golden egg from the Triwizard Tournament. With its detailed design and sturdy base, this set makes a great addition to any Harry Potter display or collection.

9. LEGO® 12 Grimmauld Place (76408)

12 Grimmauld Place 76408

Set Name: LEGO® Harry Potter 12 Grimmauld Place
Set Number: 76408
Year Released: 2022
No. Pieces: 1083
No. Minifigures: 9 (9 unique to this set)
RRP: £114.99 / $119.99 / 129.99€

The LEGO® Harry Potter™ 12 Grimmauld Place (76408) set is a must-have for any Harry Potter fan. The rooms of this set are accessible via the open-back design which really boosts the playability factor for this set. It includes 9 Minifigures that can be used to explore the headquarters of the Order of the Phoenix™, this set will keep you busy for hours building it and even more acting out the scenes from the movies.

10. LEGO® Hogwarts Great Hall (75954)

Hogwarts Great Hall 75954

Set Name: LEGO® Harry Potter Hogwarts Great Hall
Set Number: 75954
Year Released: 2018
No. Pieces: 878
No. Minifigures: 10 (6 unique to this set)
RRP: £89.99 / $99.99 / 99.99€

The LEGO® 75954 Hogwarts™ Great Hall Harry Potter set is a detailed and immersive set for Harry Potter fans. With 10 minifigures and buildable creatures like the Basilisk, plus plenty of magical accessories, this set allows for endless imaginative play. The four-level design features a tower, potions room, treasure room, and more. It’s the perfect gift for any fan of the series.

11. LEGO® The Shrieking Shack & Whomping Willow (76407)

The Shrieking Shack & Whomping Willow 76407

Set Name: LEGO® Harry Potter The Shrieking Shack & Whomping Willow
Set Number: 76407
Year Released: 2022
No. Pieces: 777
No. Minifigures: 7 (4 unique to this set)
RRP: £79.99 / $89.99 / 89.99€

The LEGO® Harry Potter The Shrieking Shack & Whomping Willow™ (76407) set brings two iconic locations from the series to life. With 7 minifigures and magical features like the spinning Whomping Willow and transforming Professor Lupin, kids can recreate scenes from Harry Potter and the Prisoner of Azkaban™.

12. LEGO® Hogwarts Chamber of Secrets (76389)

Hogwarts-Chamber-of-Secrets-76389

Set Name: LEGO® Harry Potter Hogwarts Chamber of Secrets
Set Number: 76389
Year Released: 2021
No. Pieces: 1176
No. Minifigures: 11 (10 unique to this set)
RRP: £129.99 / $149.99 / 149.99€

This set includes well-known rooms, enchanting features, and familiar characters from the Harry Potter movies. The set includes 10 Minifigures and multiple feature-packed rooms from the movie. Additionally, there are collectible treats like an exclusive golden anniversary Voldemort™ minifigure and 6 random wizard card tiles included in this fun set that can be used for explorative play or display.

13. LEGO® Hogwarts Astronomy Tower (75969)

Hogwarts Astronomy Tower (75969)

Set Name: LEGO® Harry Potter Hogwarts Astronomy Tower
Set Number: 75969
Year Released: 2020
No. Pieces: 971
No. Minifigures: 8 ( 8 unique to this set)
RRP: £89.99 / $99.99 / 99.99€

The Hogwarts Astronomy Tower is a captivating playset that brings iconic locations and popular characters from the Harry Potter movies to life. With 8 Minifigures, including popular characters like Draco Malfoy™ and Neville Longbottom™, this gift set is perfect for kids aged 9 and up who love building and Harry Potter. The tower measures over 15” (40cm) high, 11” (29cm) wide, and 6” (17cm) deep, you can also connect this set with other LEGO® Hogwarts™ sets for even more magical adventures.

14. LEGO® The Burrow (4840)

The burrow 4840

Set Name: LEGO® Harry Potter The Burrow
Set Number: 4840
Year Released: 2010 
No. Pieces: 568
No. Minifigures: 6 (4 unique to this set)
RRP: £61.99 / $59.99

This is one of the older Harry Potter sets that were released back in 2010, but don’t let the age of this set put you off as it has some great features. The set is simple but effective, it’s only made out of 568 pieces which means it is ideal for the younger generation of LEGO® Harry Potter fans to build.

15. LEGO® Newt’s Case of Magical Creatures (75952)

Newt's Case of Magical Creatures 75952

Set Name: LEGO® Harry Potter Newt’s Case of Magical Creatures
Set Number: 75952
Year Released: 2018
No. Pieces: 694
No. Minifigures: 4 (4 unique to this set)
RRP: £44.99 / $49.99 / 49.99€

Newt’s Case of Magical Creatures (75952) is an enchanting set that lets kids care for buildable creatures like the Erumpent, Occamy, and Thunderbird. The case folds up for easy transport to the next adventure and includes 4 minifigures along with Niffler and Bowtruckle figures. Kids can join Newt Scamander™, Jacob Kowalski, Tina Goldstein™, and Queenie Goldstein™ on their magical adventures with this fun LEGO set.

16. LEGO® Hogwarts Express (75955)

HogwartsExpress()
Hogwarts Express (75955)

Set Name: LEGO® Harry Potter Hogwarts Express
Set Number: 75955
Year Released: 2018
No. Pieces: 801
No. Minifigures: 6 (4 unique to this set)
RRP: £79.99 / $79.99 / 89.99€

The LEGO® Harry Potter™ 75955 Hogwarts™ Express set lets you recreate your favorite Harry Potter scenes. The set includes 6 minifigures of beloved characters like Harry Potter™, Ron Weasley™ and Hermione Granger™, along with a Dementor™ and Ron’s pet rat, Scabbers™. This set has great playability too as you can remove the train carriage roof and side panel to place the minifigures in their seats.

17. LEGO® Hogwarts™ Moment: Transfiguration Class (76382)

Hogwarts™ Moment Transfiguration Class 76382

Set Name: LEGO® Harry Potter Hogwarts™ Moment: Transfiguration Class
Set Number: 76382
Year Released: 2021
No. Pieces: 241
No. Minifigures: 3 (2 unique to this set)
RRP: £24.99 / $29.99 / 29.99€

LEGO® Harry Potter™ Hogwarts™ Moment: Transfiguration Class (76382) is a magical playset that captures the essence of Professor McGonagall’s classroom from the Harry Potter movies. The brick-built playbook opens up to reveal a transfiguration lesson with Hermione Granger™, Ron Weasley™ and Professor McGonagall™ minifigures, along with accessories like desks, chairs, a blackboard and more. Kids can practice their wizarding skills with the teacup, silver goblet and frog for transfiguration practice.

18. LEGO® Hogwarts: Dumbledore’s Office (76402)

Hogwarts Dumbledore's Office 76402

Set Name: LEGO® Harry Potter Hogwarts: Dumbledore’s Office
Set Number: 76402
Year Released: 2022
No. Pieces: 654
No. Minifigures: 6 (4 unique to this set)
RRP: £79.99 / $79.99 / 89.99€

Dumbledore’s Office (76402) is a multi-level playset that is packed with features to re-create scenes from the movie. The set includes 6 minifigures and includes fun accessories too, such as Harry’s Invisibility Cloak and Dumbledore’s Pensieve. It’s a perfect gift for true fans of the franchise aged 8 and up who want to immerse themselves in magical adventures.

19. LEGO® 4 Privet Drive (75968)

4 Privet Drive 75968-1

Set Name: LEGO® Harry Potter 4 Privet Drive
Set Number: 75968
Year Released: 2020
No. Pieces: 797
No. Minifigures: 6 (5 unique to this set)
RRP: £69.99 / $79.99 / 79.99€

LEGO® Harry Potter™ 4 Privet Drive (75968) is a must-have for any Harry Potter fan. This playset comes with 6 Minifigures, including Harry, Ron, and Dobby, and features exciting movie scenes like Harry’s secret cupboard under the stairs and his escape in the flying Ford Anglia. Perfect for kids aged 8 and up, this set encourages imaginative play and storytelling.

20. LEGO® Hogsmeade Village Visit (76388)

Hogsmeade Village Visit 76388-1

Set Name: LEGO® Harry Potter Hogsmeade Village Visit
Set Number: 76388
Year Released: 2021
No. Pieces: 851
No. Minifigures: 7 (7 unique to this set)
RRP: £79.99 / $89.99 / 89.99€

The Hogsmeade™ Village Visit (76388) set is a richly detailed set that features two buildings from the movies, Honeydukes™ and The Three Broomsticks. this play-and-display set includes 6 Minifigures and a variety of cool features, furniture, and accessories. In additional you will also get a golden Ron Weasley too! The set measures over 8.5 inches high, 11.5 inches wide, and 3.5 inches deep, this set is crammed to the rooftops with authentic details that will impress any Harry Potter fan.

21. LEGO® The Ministry of Magic (76403)

The Ministry of Magic 76403-1

Set Name: LEGO® Harry Potter The Ministry of Magic
Set Number: 76403
Year Released: 2022
No. Pieces: 990
No. Minifigures: 10 (9 unique to this set)
RRP: £89.99 / $99.99 / 99.99€

LEGO® Harry Potter The Ministry of Magic™ (76403) is a perfect set for Harry Potter fans aged 9 and up. This multistory set is mainly made from green and red pieces which match the Ministry of Magic seen in the movies. It comes with 10 Minifigures and with the accessories too this is a fun set to build and play with.

22. LEGO® Hagrid’s Hut (4738)

Hagrid's Hut 4738-1

Set Name: LEGO® Harry Potter Hagrid’s Hut
Set Number: 4738
Year Released: 2010
No. Pieces: 442
No. Minifigures: 4 (1 unique to this set)
RRP: £40.99 / $39.99

The first version of Hagrid’s hut was released in 2010, it’s only made from 442 pieces so this set is suitable for Harry Potter fans of all ages. It includes 4 Minifigures, baby spiders, and Hagrid’s pet spider Aragog. This is a small set but will give you a lot of fun!

23. LEGO® Hogwarts (4867)

Hogwarts 4867-1

Set Name: LEGO® Harry Potter Hogwarts
Set Number: 4867
Year Released: 2011
No. Pieces: 466
No. Minifigures: 7 (4 unique to this set)
RRP: £49.99 / $49.99

This set is a great expansion to the Hogwarts castle, add some additional features to your existing Harry Potter collection with this fun model. It includes 7 Minifigures that can be placed in the towers watching over the bridge to Hogwarts. A great set for someone looking to expand their Harry Potter collection.

24. LEGO® Hagrid’s Hut: Buckbeak’s Rescue (75947)

Hagrid's Hut Buckbeak's Rescue 75947-1

Set Name: LEGO® Harry Potter Hagrid’s Hut: Buckbeak’s Rescue
Set Number: 75947
Year Released: 2019
No. Pieces: 496
No. Minifigures: 6 (3 unique to this set)
RRP: £49.99 / $59.99 / 59.99€

The Hagrid’s Hut: Buckbeak’s Rescue (75947) playset is perfect for fans of the Harry Potter series, particularly the Prisoner of Azkaban. With detailed interior designs and a buildable Buckbeak figure, you can immerse yourself in magical role-play scenarios. The set includes 6 Minifigures, you can expect to see nice features such as a light brick that has been used for the fireplace.

25. LEGO® The Rise of Voldemort (75965)

The Rise of Voldemort 75965-1

Set Name: LEGO® Harry Potter The Rise of Voldemort
Set Number: 75965
Year Released: 2019
No. Pieces: 184
No. Minifigures: 4 (4 unique to this set)
RRP: £19.99 / $19.99 / 19.49€

The Rise of Voldemort™ (75965) set lets you relive the iconic graveyard scene from Harry Potter and the Goblet of Fire™. With 4 Minifigures and plenty of accessories, this building set is perfect for young witches and wizards who love action-packed battles. Defense Against the Dark Arts skills will come in handy as Harry tries to escape from Voldemort’s clutches. A must-have for any Harry Potter fan!

26. LEGO® Quidditch Match (75956)

Quidditch Match 75956-1

Set Name: LEGO® Harry Potter Quidditch Match
Set Number: 75956
Year Released: 2018
No. Pieces: 500
No. Minifigures: 6 (4 unique to this set)
RRP: £34.99 / $39.99 / 38.98€

This set includes Gryffindor™, Slytherin™, Ravenclaw™ and Hufflepuff™ house towers with viewing stands and play feature functions, plus a base with Bludger stud shooter and 3 goalposts. With 6 minifigures included, including Harry Potter™ and Hermione Granger™, this set is perfect for any Harry Potter fan looking to recreate their own Quidditch matches or add to their collection.

27. LEGO® The Knight Bus (75957)

The Knight Bus 75957-1

Set Name: LEGO® Harry Potter The Knight Bus
Set Number: 75957
Year Released: 2019
No. Pieces: 403
No. Minifigures: 3 (2 unique to this set)
RRP: £34.99 / $39.99 / 39.99€

The LEGO® Harry Potter™ Knight Bus™ is a magical playset that will excite any Harry Potter fan. With 3 Minifigures and a 3-level bus that features an opening hinged side panel and removable roof, this toy offers endless possibilities for imaginative play. The sliding bed and swinging chandelier are are nice touch when acting out your favorite scenes. Perfect for Harry Potter fans who love adventure and creativity.

28. LEGO® Hogwarts Whomping Willow (75953)

HogwartsWhompingWillow()

Set Name: LEGO® Harry Potter Hogwarts Whomping Willow
Set Number: 75953
Year Released: 2018
No. Pieces: 753
No. Minifigures: 6 (2 unique to this set)
RRP: £59.99 / $69.99 / 69.99€

The LEGO Harry Potter Hogwarts Whomping Willow set is perfect for fans of Harry Potter who want to recreate iconic scenes from the movies. It includes 6 Minifigures and a Hedwig owl figure, which really adds to the playability factor of this set. It also features a buildable Whomping Willow tree, Flying Ford Anglia car, and Hogwarts castle section complete with a dormitory, potions classroom, Professor Snape’s office, and an owlery. Ideal for those who love imaginative play and constructing their own worlds.

29. LEGO® Hogwarts Magical Trunk (76399)

Hogwarts Magical Trunk 76399-1

Set Name: LEGO® Harry Potter Hogwarts Magical Trunk
Set Number: 76399
Year Released: 2022
No. Pieces: 603
No. Minifigures: 1 (but there are multiple pieces to create new minifigures)
RRP: £59.99 / $64.99 / 64.99€

The LEGO® Harry Potter™ Hogwarts™ Magical Trunk (76399) is a fun and creative playset. With customizable features and authentic accessories from the movies, you can build up to 5 characters, recreate classic scenes, and bring their imaginative Hogwarts adventures to life. This portable and lockable toy trunk is perfect for Harry Potter fans on-the-go.

30. LEGO® Triwizard Tournament: The Black Lake (76420)

Triwizard Tournament The Black Lake 76420-1

Set Name: LEGO® Harry Potter Triwizard Tournament: The Black Lake
Set Number: 76420
Year Released: 2023
No. Pieces: 349
No. Minifigures: 5 (5 unique to this set)
RRP: £39.99 / $44.99 / 44.99€

This set is perfect for fans of Harry Potter and the Wizarding World. You can recreate the iconic Triwizard Tournament scene from Harry Potter and the Goblet of Fire™ with 5 minifigures, a buildable underwater scene, a pier model, and accessory elements including the Gillyweed potion. With flexible LEGO elements to create the effect of characters floating, kids can stage their own magical contest. This 349-piece set is an ideal gift for any young wizard or witch looking to add to their LEGO® Harry Potter™ collection.

List of Harry Potter MOCs From Our Website

More Info

The Best LEGO® Harry Potter Set of All Time

The best LEGO® Harry Potter set of all time has to be the LEGO® Hogwarts™ Castle (71043), it is an absolute work of art that any experienced LEGO® builder would be eager to get their hands on.

The set is made up of 6020 pieces and is just over 58cm long (dimensions are 58.5 x 49 x 19 cm), it also comes with a whopping 28 LEGO® Minifigures too. Whether you are a Harry Potter fan or not there is just so much to love about this set!

The LEGO® Hogwarts™ Castle (71043) features everything you would see when reading or watching the Harry Potter series and they haven’t missed out on the finer details either, for example, the boats that are heading into the boatyard or the Hogwarts house flags inside the Great Hall.

This is the perfect LEGO® set for the older generation of Harry Potter fans, you will definitely not be disappointed.

What Is the Biggest LEGO® Harry Potter Set?

The biggest LEGO® Harry Potter set to date is LEGO® Hogwarts™ Castle (71043), it is made from 6020 pieces and includes 28 LEGO® Minifigures.

The second biggest LEGO® Harry Potter set is LEGO® Harry Potter Diagon Alley (75978), this exciting set it made from 5544 pieces and includes 17 LEGO® Minifigures.

So if you’re ready to take on the ultimate LEGO Harry Potter challenge, then be sure to pick up the Hogwarts Castle or Diagon Alley set today!

How Many Gold LEGO® Harry Potter Minifigures Are There?

There are 9 golden LEGO® Harry Potter Minifigures that can only be found in one of 7 LEGO® sets. Here’s everything you need to know where to get your golden LEGO® Harry Potter Minifigures.

Golden Harry Potter – Hogwarts Polyjuice Potion Mistake (76386)

LEGO-Harry-Potter-76386-Hogwarts-Polyjuice-Potion-Mistake

Hermione Granger – Fluffy Encounter (76387)

LEGO-Harry-Potter-76387-Hogwarts-Fluffy-Encounter

Ron Weasley – Hogsmeade Village Visit (76388)

LEGO-Harry-Potter-76388-Hogsmeade-Village-Visit

Voldemort – Hogwarts Chamber of Secrets (76389)

LEGO-Harry-Potter-76389-Hogwarts-Chamber-of-Secrets

Professor Snape – Hogwarts Wizard’s Chess (76392)

LEGO-Harry-Potter-76392-Hogwarts-Wizards-Chess

Professor Quirrell – First Flying Lesson (76395)

LEGO-Harry-Potter-76395-Hogwarts-First-Flying-Lesson

Professor Dumbledore, Professor McGonagall and Rubeus Hagrid – Hogwarts Icons Collectors’ Edition (76391)

LEGO-Harry-Potter-76391-Hogwarts-Icons-Collectors-Edition

Best LEGO® Harry Potter Set Video

YouTube video

Conclusion

So there we have it, thats our list of the Best LEGO® Harry Potter sets that have been released to date. It’s clear that LEGO® have taken a very inclusive approach when it comes to the types of Harry Potter sets they have designed, if you enjoy Harry Potter no matter your age or LEGO® skill level there is a set that you will fall in love with.

Are you interested in for more of the best LEGO® sets? Take a look at our other posts for LEGO® Star Wars or LEGO® Spider-Man for more options.

<div class="badge-base LI-profile-badge" data-locale="en_US" data-size="large" data-theme="dark" data-type="HORIZONTAL" data-vanity="ferdi-vol" data-version="v1"><a class="badge-base__link LI-simple-link" href="https://www.linkedin.com/in/%E2%9C%85-ferdi-vol-corporate-gifts/?trk=profile-badge"></a></div>
/* Auto generated, hash = 5dceu9kevqjdyuy2uw1atqrsu */
//TODO: Break this file down so that we can actually unit test it.
(function(window) {
  /**
  * Renders all unrendred LinkedIn Badges on the page
  */
  window.LIRenderAll = function () {
    var CALLBACK_NAME     = 'LIBadgeCallback', //Must match callback on helpers.js
        BADGE_NAMES       = '.LI-profile-badge, .LI-entity-badge',
        // TODO -- tracking param for other badge types
        TRACKING_PARAM    = 'profile-badge',
        responsesReceived = 0, //Keeps track of number of responses recieved for proper cleanup when finished
        expectedResponses = 0, //Keeps track of number of responses to expect
        scripts           = [ ], //Keeps track of scripts added for proper cleanup when finished
        childScripts      = {}, //Keeps track of child scripts to render
        badges            = Array.prototype.slice.call(document.querySelectorAll(BADGE_NAMES));

    var i, len, badge, rendered;
    for (i = 0, len = badges.length;  i < len; i++) {
      badge    = badges[i];
      rendered =  badge.getAttribute('data-rendered');
      if (!rendered) {
        expectedResponses++;
        badge.setAttribute('data-rendered', true);
        renderBadge(badge);
      }
    }

    function isCNDomain() {
      if (typeof window !== "undefined") {
        var hostName = window.location && window.location.hostname ||  '';
        return (/linkedin(-ei)?.cn$/).test(hostName);
      }

      return false;
    }

    function generateUrl(isEI) {
      var domainPrefix = isEI ? 'https://badges.linkedin-ei' : 'https://badges.linkedin';
      if (isCNDomain()) {
        return domainPrefix + ".cn/";
      }

      return domainPrefix + ".com/";
    }

    function getBadgeKeyQueryParams(badge) {
      return Array.prototype.slice.call(badge.attributes).filter(function (attr) {
        return attr.name.lastIndexOf('data-key-', 0) !== -1;
      }).map(function (attr) {
        // Most browsers automatically lowercase the attribute name when its being read
        // We are calling lowercase on it again to ensure consistency for any browsers that are lagging behind.
        return encodeURIComponent(attr.name.replace('data-', '').toLowerCase()) + '=' + encodeURIComponent(attr.value);
      });
    }

    /*
    * Renders a single badge on the page
    * @param badge: div element of badge to render
    */
    function renderBadge(badge) {
      var size       = badge.getAttribute('data-size'),
          locale     = badge.getAttribute('data-locale'),
          type       = badge.getAttribute('data-type'),
          theme      = badge.getAttribute('data-theme'),
          vanity     = badge.getAttribute('data-vanity'),
          version    = badge.getAttribute('data-version'),
          isEI       = badge.hasAttribute('data-ei'),
          entity     = badge.getAttribute('data-entity'),
          isCreatePage = badge.hasAttribute('data-iscreate'),
          uid        = Math.round(1000000 * Math.random()),
          baseUrl = generateUrl(isEI),
          queryParams = [
            'locale=' + encodeURIComponent(locale),
            'badgetype=' + encodeURIComponent(type),
            'badgetheme=' + encodeURIComponent(theme),
            'uid=' + encodeURIComponent(uid),
            'version=' + encodeURIComponent(version)
          ],
          url;

      if (version === 'v2') {
        baseUrl += 'view';
        queryParams.push('badgesize=' + encodeURIComponent(size));
        queryParams.push('entity=' + encodeURIComponent(entity));
        queryParams = queryParams.concat(getBadgeKeyQueryParams(badge));
      } else {
        baseUrl += 'profile';
        queryParams.push('maxsize=' + encodeURIComponent(size));
        queryParams.push('trk=' + encodeURIComponent(TRACKING_PARAM));
        queryParams.push('vanityname=' + encodeURIComponent(vanity));
      }

      if (isCreatePage) {
        queryParams.push('fromCreate=true');
      }

      url = baseUrl + '?' + queryParams.join('&');
      badge.setAttribute('data-uid' , uid);
      jsonp(url); //Calls responseHandler when done
    }

    /**
    * Handles a response from the server. Finds badge matching badgeUid and inserts badgeHtml there
    * @param badgeHtml: String representing contents of the badge
    * @param badgeUid: UID of the badge to target
    **/
    function responseHandler(badgeHtml, badgeUid) {
      responsesReceived ++;

      var i, badge, uid, isCreate;
      var defaultWidth = 330 // max possible width
      var defaultHeight = 300 // max possible height

      for (i = 0, len = badges.length; i < len; i++) {
        badge = badges[i];
        // isCreate needed to prevent reloading artdeco script tag
        isCreate = badge.getAttribute('data-iscreate');
        uid   = parseInt(badge.getAttribute('data-uid'), 10);
        if (uid === badgeUid) {
          var badgeMarkup = `<body>${badgeHtml}</body>`
          var iframe = document.createElement('iframe');
          iframe.onload = function() {
            var iframeBody = iframe.contentWindow.document.body;
            // 5 px buffer to avoid the badge border being cut off.
            iframe.setAttribute('height', (iframeBody.scrollHeight || defaultHeight) + 5);
            iframe.setAttribute('width', (iframeBody.scrollWidth || defaultWidth) + 5);
          };
          iframe.setAttribute('frameBorder', '0');
          iframe.style.display = 'block';
          badge.appendChild(iframe);
          iframe.contentWindow.document.open();
          iframe.contentWindow.document.write(badgeMarkup);
          iframe.contentWindow.document.close();
          replaceScriptTags(badge, isCreate);
        }
      }
      tryClean();
    }

  // These functions are needed because badge markup is added via innerHtml property which does not run script tags
  function replaceScriptTags(node, isCreate) {
    if (shouldReplaceNode(node, isCreate)) {
      node.parentNode.replaceChild(cloneScriptNode(node), node);
      childScripts[node.src] = true;
    } else {
      var i = 0,
          children = node.childNodes;
      while (i < children.length) {
        replaceScriptTags(children[i++], isCreate);
      }
    }
    return node;
  }

  function shouldReplaceNode(node, isCreate) {
    return isScriptNode(node) && !childScripts[node.src] && (!isCreate || (isCreate && !node.getAttribute('data-isartdeco')));
  }

  function isScriptNode(node) {
    return node.tagName === 'SCRIPT';
  }

  function cloneScriptNode(node){
    var script  = document.createElement("script");
    for( var i = node.attributes.length-1; i >= 0; i-- ) {
      script.setAttribute( node.attributes[i].name, node.attributes[i].value );
    }
    return script;
  }

    // Gets all incoming responses
    window[CALLBACK_NAME] = responseHandler;

    /**
    * Tries to clean added tags
    **/
    function tryClean() {
      //Clean up after all requests are done..
      //Accounts for people including script more than once
      var done = (responsesReceived >= expectedResponses && expectedResponses > 0) || responsesReceived >= badges.length;
      if (done) {
        delete window[CALLBACK_NAME];

        // remove all script tags
        scripts.map(function(script){
          document.body.removeChild(script);
        });

      }
    }

    /*
    * Makes Jsonp request, responses handles by CALLBACK_NAME
    * @param url String: url of server to make request to
    */
    function jsonp(url) {
      var script = document.createElement('script');
      script.src = url;
      scripts.push(script);
      document.body.appendChild(script);
    }
  };

  if (document.readyState === 'complete') {
    window.LIRenderAll();
  } else {
    window.addEventListener('load', window.LIRenderAll, false);
  }

})(window);
Popular Posts