get substring from a string by regex pattern in javascript - javascript

<div class="glint-main"> <!--match product container-->
<div class="match-header sub-header"> <!--match product header-->
This Item
</div>
<div class="match-product-details"> <!--match product information container-->
<div class="product_page" role="link" tabindex="0" onkeypress="Glint.instance.statsPopup(event, "product", "01b8d44df669e090ba13bc32f1a90116", "https://cdn.motherandbaby.co.uk/web/1/root/green-monkey-front-999-wwwmatchstickmonkeycom_w555_h555.jpg", "1272961", "https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F253013006125", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")" onclick="Glint.instance.statsPopup(event, "product", "01b8d44df669e090ba13bc32f1a90116", "https://cdn.motherandbaby.co.uk/web/1/root/green-monkey-front-999-wwwmatchstickmonkeycom_w555_h555.jpg", "1272961", "https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F253013006125", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")">
<div class="match-product-img-container">
<img alt="" class="match-product-image" nopin="nopin" src="./Twelve Top Baby Teething Buys _ Mother&Baby_files/1272961-thumb.jpg"> <!--match product image-->
</div>
<div class="match-product-description"> <!--match product text information container-->
<p class="match-name">
Matchstick Monkey Chewable Teething Gel...
</p>
<div class="product_price">
<span class="currency">£</span>
0.99
</div>
</div>
</div>
</div>
</div> <!--end match product container-->
<div class="similar-products"> <!--similar product for match container-->
<div class="similar-header sub-header"> <!--similar product header-->
Similar Item
</div>
<button class="all_item_btn" onclick="Glint.instance.statsPopup(event, "link", "01b8d44df669e090ba13bc32f1a90116", "https://cdn.motherandbaby.co.uk/web/1/root/green-monkey-front-999-wwwmatchstickmonkeycom_w555_h555.jpg", "1272961", "Matchstick Monkey teething gel applicator", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")">
Shop >
</button>
<div class="toggle-container">
<ul class="similar-product-list">
<li class="similar-item-container">
<div class="product_page" role="link" tabindex="0" onkeypress="Glint.instance.statsPopup(event, "similar", "01b8d44df669e090ba13bc32f1a90116", "https://cdn.motherandbaby.co.uk/web/1/root/green-monkey-front-999-wwwmatchstickmonkeycom_w555_h555.jpg", "1272965", "https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F302247889639", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")" onclick="Glint.instance.statsPopup(event, "similar", "01b8d44df669e090ba13bc32f1a90116", "https://cdn.motherandbaby.co.uk/web/1/root/green-monkey-front-999-wwwmatchstickmonkeycom_w555_h555.jpg", "1272965", "https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F302247889639", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")">
<span class="clipped"> - opens in new window or tab</span>
<div class="similar_image_container">
<img alt="" class="similar-product-image" src="./Twelve Top Baby Teething Buys _ Mother&Baby_files/1272965-thumb.jpg"><!--similar product image-->
</div>
<div class="similar-product-description"> <!--similar product text information container-->
<p class="name">Matchstick Monkey Teething Gel</p>
<div class="product_price">
<span class="currency">£</span>
19.23
</div>
</div>
</div>
</li>
</ul>
</div>
</div><!--end similar product for match container-->
</div><!--end product full border-->
</div><!--end product full container-->
<div class="ebay_footer">
<span class="clipped"> - opens in new window or tab</span>
<img alt="ebay logo" src="./Twelve Top Baby Teething Buys _ Mother&Baby_files/ebay-transparent-logo.png">
</div>
<div class="similar-products"> <!--similar product for match container-->
<div class="similar-header sub-header"> <!--similar product header-->
Similar Item
</div>
<button class="all_item_btn" onclick="Glint.instance.statsPopup(event, "link", "46843f60877ce41020b2c34e2832788f", "https://cdn.motherandbaby.co.uk/web/1/root/uki-be_w555_h555.jpg", "1272958", "Baby Kids Silicone Elephant Teething Pacifier ", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")">
Shop >
</button>
<div class="toggle-container">
<ul class="similar-product-list">
<li class="similar-item-container">
<div class="product_page" role="link" tabindex="0" onkeypress="Glint.instance.statsPopup(event, "similar", "46843f60877ce41020b2c34e2832788f", "https://cdn.motherandbaby.co.uk/web/1/root/uki-be_w555_h555.jpg", "1272958", "https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F291879917428", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")" onclick="Glint.instance.statsPopup(event, "similar", "46843f60877ce41020b2c34e2832788f", "https://cdn.motherandbaby.co.uk/web/1/root/uki-be_w555_h555.jpg", "1272958", "https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F291879917428", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")">
<span class="clipped"> - opens in new window or tab</span>
<div class="similar_image_container">
<img alt="" class="similar-product-image" src="./Twelve Top Baby Teething Buys _ Mother&Baby_files/1272958-thumb.jpg"><!--similar product image-->
</div>
<div class="similar-product-description"> <!--similar product text information container-->
<p class="name">New 1xBaby Kids Silicone</p>
<div class="product_price">
<span class="currency">£</span>
2.04
</div>
</div>
</div>
</li>
</ul>
</div>
</div><!--end similar product for match container-->
</div><!--end product full border-->
</div><!--end product full container-->
<div class="ebay_footer">
<span class="clipped"> - opens in new window or tab</span>
<img alt="ebay logo" src="./Twelve Top Baby Teething Buys _ Mother&Baby_files/ebay-transparent-logo.png">
</div>
function Extractallroverlinks(document_root) {
debugger;
try {
var number = 0;
var listoflinks = [];
var linkname = '';
var links = ["rover.ffff.com"];
var html = '';
var subStr = document_root.documentElement.outerHTML.match("(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,#?^=%&:/~+#-]*[\w#?^=%&/~+#-])?");
}
catch (ex) {
alert(ex);
}
return listoflinks;
}
I need sub-string which contains rover.ffff.com from https or http to end of the links.
like from this dummy html i need result like this
listoflinks[0]=https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F302247889639", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")
listoflinks[1]=https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F291879917428", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")
listoflinks[2]=https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F291879917428", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")
listoflinks[3]=https%3A%2F%2Frover.ffff.com%2Frover%2F1%2F710-53481-19255-0%2F1%3Fff3%3D4%26pub%3D5575316449%26toolid%3D11334%26campid%3D5338146124%26customid%3D%26mpre%3Dhttp%3A%2F%2Fwww.ebay.co.uk%2Fi%2F291879917428", "d2c1a14a-c575-8a00-3e14-4ce959df2e08")

Related

Trigger modal card from menu item not top-level menu - HTML, CSS, JS

I'm new to coding and hope someone can help be understand where I am going wrong. I am having a problem with getting a modal card popup to trigger from a navbar-item. Everything that I have tried so far triggers the modal at the top menu item. Each of the navbar-items on the drop down will have a link to a modal card.
Thank you in advance for your help!!
const item = document.querySelector(".navbar-item");
const modalBg = document.querySelector('.modal-background');
const modal = document.querySelector('.modal');
item.addEventListener('click', () => {
modal.classList.add('is-active');
});
modalBg.addEventListener('click', () => {
modal.classList.remove('is-active');
});
<section>
<nav class="navbar has-shadow" role="navigation" aria-label="dropdown navigation" id="navbar_link_modal">
<div class="navbar-brand">
<a class="navbar-burger" id="burger">
<span></span>
<span></span>
<span></span>
</a>
</div>
<div class="navbar-menu" id="nav-links">
<div class="navbar-start">
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" data-target="#modal">Ford</a>
<div class="navbar-dropdown">
<a class="navbar-item">
Explorer
</a>
<a class="navbar-item" href="#framingLumber">
Focus
</a>
<a class="navbar-item">
Flex
</a>
<a class="navbar-item">
F-150
</a>
</a>
</div>
</div>
</div>
</div>
</nav>
</section>
<div class="modal is-active" id="modal">
<div class="modal-background"></div>
<div class="modal-card" id="framingLumber">
<header class="modal-card-head">
<p class="modal-card-title">Modal title</p>
<button class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body">
<!-- Content ... -->
</section>
<footer class="modal-card-foot">
<button class="button is-success">Save changes</button>
<button class="button">Cancel</button>
</footer>
</div>
</div>
You are targeting your modal at your top-level menu as data-target="#modal" which is wrong because there is no element with id 'modal'.
You need to do this at your menu item as data-target="#framingLumber" whereframingLumber is id of your modal and href is not needed.
So your code that would look like this:
<div class="navbar-menu" id="nav-links">
<div class="navbar-start">
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">Ford</a>
<div class="navbar-dropdown">
<a class="navbar-item">Explorer</a>
<a class="navbar-item" data-target="#framingLumber">Focus</a>
<a class="navbar-item">Flex</a>
<a class="navbar-item">F-150</a>
</div>
</a>
</div>
</div>
</div>

innerHTML property not working with owl carousel

I am fetching data from firestore database to create a product card so that I can display the product cards inside a carousel. Owl carousel to be specific. I am using the innerHTML property in javascript to add the product cards programmatically. The Owl carousel seems to not work when I do so but when I create the cards statically in html the carousel works. What could be the problem?
Code:
Html:
<div class="product-area most-popular section">
<div class="container">
<div class="row">
<div class="col-12">
<div class="section-title">
<h2>Hot Items</h2>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="owl-carousel popular-slider" id="owlCarousel">
<!--product cards go here-->
</div>
</div>
</div>
</div>
</div>
Javascript:
var view2 = document.getElementById("owlCarousel");
db.collection("products").where("hot" , "==" , true)
.get().then((querySnapshot)=> {
querySnapshot.forEach((doc) => {
var image = doc.data().images[0];
var image2 = doc.data().images[1];
var title = doc.data().title;
var price = doc.data().pricing.toString();
var hot = doc.data().hot;
var discount = doc.data().discount;
var price = doc.data().pricing;
//product card creation
view2.innerHTML += `
<div class="single-product">
<div class="product-img">
<a href="product-details.html">
<img class="default-img" src="${image}" alt="#">
<img class="hover-img" src="${image2}" alt="#">
<span class="out-of-stock">Hot</span>
</a>
<div class="button-head">
<div class="product-action">
<a data-toggle="modal" data-target="#exampleModal" title="Quick View" href="#"><i class=" ti-eye"></i><span>Quick Shop</span></a>
<a title="Wishlist" href="#"><i class=" ti-heart "></i><span>Add to Wishlist</span></a>
<a title="Compare" href="#"><i class="ti-bar-chart-alt"></i><span>Add to Compare</span></a>
</div>
<div class="product-action-2">
<a title="Add to cart" href="#">Add to cart</a>
</div>
</div>
</div>
<div class="product-content">
<h3>${title}</h3>
<div class="product-price">
<span>Ksh. ${price}</span>
</div>
</div>
</div>
`
});
});
I just had the same problem.
What you should do is initialize the OWL CAROUSEL after you add the template (inner html);
for example:
view.innerHtml = `<div> content </div`;
$('.owl-carousel').owlCarousel({
//here you can add the props or events
})
This worked for me! hope this could hel you :)

Modal will not open on click

I am in a javascript beginner class and I am stuck with my homework. I went over it what feels like a million times but for some reason, I am missing something and I can't find it. Many thanks in advance!!! It is set up so that if the link has the data-reveal attribute and there is a modal element with the matching ID it will allow for that link to be clicked and the modal appears.
My HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, inital-scale=1.0, shrink-to-fit=no">
<meta name="description" content="description">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<title>London</title>
<link rel="stylesheet" type="text/css" href="styles/main.css">
<link rel="stylesheet" type="text/css" href="styles/london.css">
</head>
<!-- Head End -->
<body>
<header id="header" class="header">
<!-- Image Banner -->
<div id="logoWrapper" class="logoWrapper">
<img src="images/welcometoengland.png" class="logo" title="Welcome to England" alt="Welcome to England">
</div>
<section id="banner" class="banner">
<img src="images/banner/london_banner_1.png" class="banner__image" alt="banner">
</section>
<!-- Primary navigation -->
<nav id="nav" class="nav">
<ul class="nav__links nav__items">
<li class="nav__item">
Home
</li>
<li class="nav__item">
London
</li>
<li class="nav__item">
Daytrips
</li>
<li class="nav__item">
Cost
</li>
<li class="nav__item">
Stay
</li>
<li class="nav__item">
Travel
</li>
<li class="nav__item">
Shop
</li>
<li class="nav__item">
Contact Us
</li>
</ul>
</nav>
</header>
<!-- Header End -->
<main id="main" class="main">
<!--Left Content -->
<div id="main__content" class="main__content">
<div class="intro__wrapper">
<div class="intro__left">
<h4 id="attractionLinks__heading" class="attractionLinks__heading"></h4>
<ul id="attractionLinks__list" class="attractionLinks__list"></ul>
<p class="attractionLinks__instructions">If you have already visited some attractions or would like to add additional attractions, click the button below to update your preferences:</p>
<button id="attractionLinks__showForm" class="attractionLinks__showForm">Select Attractions</button>
</div>
<div class="intro__right">
<h3 class="intro__heading">Welcome to the Lodon Attractions page!</h3>
<p class="intro__text"> As a current memeber of the International Travel Club, you may select the attractions you would like to visit and we will keeo you updated with travel tips. When you click the London tab, you will only see links to attractions you would like to visit.</p>
<div class="form__inputWrapper">
<form class="form travelerForm" id="travelerForm" name="travelerForm">
<div class="form__inputWrapper">
<label for="fullName" class="form__label">Full Name:</label>
<input name="fullName" id="fullName" class="form__input" type="text" pattern="^[A-Za-z]+\s[A-Za-z]+$" placeholder="" required>
</div>
<div class="form__inputWrapper form__inputWrapper--checkboxes">
</div>
<!--Submit-->
<div class="form__inputWrapper form__inputWrapper--submit">
<input name="submitTraveler" id="submitTraveler" class="submit button" type="submit" value="Submit Form">
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Right Sidebar -->
<div id="main__sidebar" class="main__sidebar">
<!--London Clock-->
<div id="londonTime__wrapper" class="londonTime__wrapper">
<img class="londonTime__image" src="images/bigben.png" alt="Big Ben Clock">
<p id="londonTime" class="londonTime"></p>
</div>
<!--Attractions Select Wrapper-->
<div id="attractions" class="attractions">
<div class="attractions__instructionsWrapper">
<!--Attractions Instructions-->
<h2 class="attractions__heading">
Select an item from the list to display a picture and description of the attraction.
</h2>
</div>
<!--Attractions Select Wrapper-->
<div class="attractions__selectWrapper">
<select id="attractions__list" class="attractions__list">
</select>
</div>
<!--Attractions Display Wrapper-->
<div class="attractions__displayWrapper">
<div class="attractions__imageWrapper">
<img src="images/slideshow/placeholder.jpg" class="attractions__image" alt="Attractions">
</div>
</div>
<!--Attractions Text Wrapper-->
<div class="attractions__textWrapper">
<p class="attractions__text"></p>
</div>
</div>
<!--Attractions End-->
</div>
<section class="modals">
<!--Big Ben Modal-->
<div id="BigBen_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">Big Ben</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/BigBen.jpg" alt="Big Ben">
</div>
<div class="modal__textWrapper">
<p class="modal__text">Whenever you think of London, you probably think of Big Ben, as it is one of England's most recognized landmarks.</p>
<p class="modal__text">Here are some <em>Quick Facts</em> about Big Ben:</p>
<p class="modal__text">Description: Big Ben is not actually the clock tower. It is the largest of the five bells inside of the clock tower</p>
<p class="modal__text">Location: It is at the House of Parliament in Westminster, London</p>
<p class="modal__text">Constructed; Completed in 1856, it took 13 years to build. It is about 315 feet high and hs 400 steps to reach the top</p>
<p class="modal__text">Tourists: Bet you didn't know that foreign tourists are not allowed to climb the 400 steps to the top of the tower, but native Englanders can arrange a tour through a member of parliament or a Lord. Please note that it is not wheelchair accessible.</p>
<p class="modal__text">Cost: Free</p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--London Zoo Modal-->
<div id="LondonZoo_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">London Zoo</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/londonzoo.jpg" alt="London Zoo">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--St. Paul's Cathedral Modal-->
<div id="StPaulsCathedral_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">St. Paul's Cathedral</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/StPaulsCathedral.jpg" alt="St. Paul's Cathedral">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--Tower of London Modal-->
<div id="TowerofLondon_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">Tower of London</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/toweroflondon.jpg" alt="Tower of London">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--British Museum Modal-->
<div id="BritishMuseum_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">British Museum</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/BritishMusuem.jpg" alt="British Museum">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--London Eye Modal-->
<div id="LondonEye_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">London Eye</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/londoneye.jpeg" alt="London Eye">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--London Aquarium Modal-->
<div id="LondonAquarium_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">London Aquarium</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/London Aquarium.jpg" alt="London Aquarium">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--Westminster Abbey Modal-->
<div id="WestminsterAbbey_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">Westminster Abbey</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/WestminsterAbbey.jpg" alt="Westminster Abbey">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--Thames River Cruise Modal-->
<div id="ThamesRiverCruise_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">Thames River Cruise</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/ThamesRiverCruise.jpg" alt="Thames River Cruise">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--Wellington Arch Modal-->
<div id="WillingtonArch_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">Wellington Arch</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/WellingtonArch.jpg" alt="Wellington Arch">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--Harrods Modal-->
<div id="Harrods_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">Harrods</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/Harrods.jpg" alt="Harrods">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
<!--Shopping Modal-->
<div id="Shopping_modal" class="modal">
<div class="modal__innerWrapper">
<div class="modal__content">
<h3 class="modal__heading">Shopping</h3>
<div class="modal__imageWrapper">
<img class="modal__image" src="images/Shopping.jpg" alt="Shopping">
</div>
<div class="modal__textWrapper">
<p class="modal__text"></p>
<p class="modal__text --textCenter">Content from respective websites - For learning purposes only</p>
</div>
<p class="modal__close" aria-label="Close modal" role="button">
<span aria-hidden="true">×</span>
</p>
</div>
</div>
</div> <!--End of Modal-->
</section>
</main>
<!-- Main End -->
<footer id="footer" class="footer"></footer>
<!--Footer End -->
<script src="scripts/cookies.js"></script>
<script src="scripts/main.js"></script>
<script src="scripts/select_list.js"></script>
<script src="scripts/banner.js"></script>
<script src="scripts/london.js"></script>
<script>displayLondonTime();</script>
</body>
</html>
Here is my Javascript:
const LondonAttractions = {
LondonZoo: "London Zoo",
BigBen: "Big Ben",
StPaulsCathedral: "St. Paul's Cathedral",
TowerofLondon: "Tower of London",
BritishMuseum: "British Museum",
LodonEye:"London Eye",
LondonAquarium: "London Aquarium",
WestminsterAbbey: "Westminster Abbey",
ThamesRiverCruise: "Thames River Cruise",
WellingtonArch: "Willington Arch",
Harrods: "Harrods",
Shopping: "Shopping"
};
const travelerForm = document.getElementById('travelerForm');
const travelerFormCheckboxWrapper = document.querySelector('#travelerForm .form__inputWrapper--checkboxes');
const attractionLinksHeading = document.getElementById('attractionLinks__heading');
const attractionLinksList = document.getElementById('attractionLinks__list');
const attractionLinksButton = document.getElementById('attractionLinks__showForm');
function generateCheckboxes() {
//If all the required parts exist
if(travelerForm && travelerFormCheckboxWrapper){
//For each daytrip in daytripsInfo
for(let key in LondonAttractions){
let checkbox = `
<div class="form__checkboxWrapper">
<label for="${key}" class="form__label">${LondonAttractions[key]}</label>
<input id="${key}" name="${key}" class="form__input" type="checkbox" placeholder="">
</div>
`;
travelerFormCheckboxWrapper.insertAdjacentHTML('beforeend', checkbox);
}//End of Foor Loop
} //End of if statement
} //End of function
generateCheckboxes();
if(travelerForm) {
travelerForm.addEventListener('submit', function(event) {
// Prevent the form from submitting
event.preventDefault();
var numChecked = 0;
const checkboxes = document.querySelectorAll('#travelerForm [type="checkbox"]');
// Loop over checkboxes
for(let i = 0; i < checkboxes.length; i++) {
// Check if the checkbox is checked
if(checkboxes[i].checked === true) {
// Increment numChecked variable
numChecked++;
//Set a cookie using the checkbox name
Cookies.set(checkboxes[i].name, true, {expires: 7});
}
//If a checkbox is not selected
else{
//If a cookie exists for that checkbox
if(Cookies.get(checkboxes[i].name)) {
//Delet the Cookie
Cookies.remove(checkboxes[i].name);
}
//Note: An alternative would be to set the cookie value to 'false'
//Cookies.set(checkboxes[i].name, false, { expires: 7});
}
}
if(numChecked > 0 && travelerForm.checkValidity()) {
Cookies.set('travelerName', travelerForm.fullName.value, { expires: 7});
// Submit the form
travelerForm.submit();
// Reset numChecked variable
numChecked = 0;
}
else if(numChecked === 0) {
alert('You must select at least one London attraction!');
}
});
}
//If both the 'travelerName' cookie and the attraction links heading exist
if(Cookies.get('travelerName') && attractionLinksHeading){
attractionLinksHeading.textContent = `Attraction Links for ${Cookies.get('travelerName')}`;
} else if(attractionLinksHeading) {
attractionLinksHeading.textContent = "Attraction Links";
}
if(attractionLinksList && travelerForm) {
//Show form by default
var showForm = true;
//For each of our attractions
for(let key in LondonAttractions) {
//If the cookie name esists
if(Cookies.get(key)) {
//Create our list item and link
let item = `<li class="attractionLinks__item">
<p data-reveal="${key}_modal" aria-controls="${key}" aria-haspopup="true" class="attractionLinks__link" role="button" tabindex="0">${LondonAttractions[key]}</p>
</li>`;
//Add the list item and link to the list
attractionLinksList.insertAdjacentHTML('beforeend', item);
//They have already submitted their preferences, hide from for now
showForm = false;
}
}
if(showForm === false) {
//Add modifier class that will be used to hide the form
travelerForm.classList.add('--hide');
}
const attractionLinks = document.querySelectorAll('.attractionLinks__link');
if(attractionLinks.length > 0) {
//If at least one link exists
for(let i = 0; i < attractionLinks.length; i++) {
//Get link data-reveal attribute
let id = attractionLinks[i].dataset.reveal;
//If the link has the data-reveal attribute, and there is a modal element with that matching ID
if(id && document.getElementById(id)) {
let modal = document.getElementById(id);
let closeButton = modal.querySelector('.modal__close');
//Add click event listner to link
attractionLinks[i].addEventListener('click', function(event) {
//If the modal exists and it does not have the --reveal class
if(!modal.classList.contains('--reval')) {
modal.classList.add('--reval');
}
});
//If close button exists within modal
if(closeButton) {
//Add click event listner to close button
closeButton.addEventListener('click', function(event) {
//If the modal had the --reveal class
if(modal.classList.contains('--reveal')) {
//Remove it (hides the modal)
modal.classList.remove('--reveal');
}
});
}
}
}
}
}
//If the button and the form both exist
if(attractionLinksButton && travelerForm) {
attractionLinksButton.addEventListener('click', function(event) {
//Check if the traveler form has the --hide class
if(travelerForm.classList.contains('--hide')) {
//Remove the --hide class
travelerForm.classList.remove('--hide');
//Add the --show class
travelerForm.classList.add('--show');
}
});
}
london.js -> Line 134 /* Problem */
If you add "--reveal" to the classList, that would make the class="initial --reveal"; //there is a space between initial and --reveal
Because on that line the css won't trigger
london.css -> line 82
To fix the problem:
//To solve the problem delete the line 134 from london.js and replace with
modal.className += '--reveal';

Shuffle.js - filter images on page load

There are 2 tabs (data-groups) - Graphics and Logo, with images, each one has 3 images, total 6 images. The filter works well, when you click first tab, it becomes active and shows 3 images filtered and belong to first data-group (Graphics). But when you refresh page, you see first active tab (data-group Graphics) as well, but showing all 6 images, which is wrong. Filter starts working only when you click the tab. It should show only 3 of them matched by data-group. I've tried several scripts and solution from this post. Nothing worked. Any solution?
function portfolio_init() {
var portfolio_grid = $('#portfolio_grid'),
portfolio_filter = $('#portfolio_filters');
if (portfolio_grid) {
portfolio_grid.shuffle({
speed: 450,
itemSelector: 'figure'
});
$('.site-main-menu').on("click", "a", function(e) {
portfolio_grid.shuffle('update');
});
portfolio_filter.on("click", ".filter", function(e) {
portfolio_grid.shuffle('update');
e.preventDefault();
$('#portfolio_filters .filter').parent().removeClass('active');
$(this).parent().addClass('active');
portfolio_grid.shuffle('shuffle', $(this).attr('data-group'));
});
}
}
<!-- Portfolio Subpage -->
<section class="pt-page pt-page-4" data-id="portfolio">
<div class="border-block-top-110"></div>
<div class="section-inner">
<div class="section-title-block">
<div class="section-title-wrapper">
<h2 class="section-title">Portfolio</h2>
<h5 class="section-description">Works</h5>
</div>
</div>
<!-- Portfolio Content -->
<div class="portfolio-content">
<!-- Portfolio filter -->
<ul id="portfolio_filters" class="portfolio-filters">
<li class="active">
<a class="filter btn btn-sm btn-link active" data-group="graphics">Graphics</a>
</li>
<li>
<a class="filter btn btn-sm btn-link" data-group="logo">Logo</a>
</li>
<li>
<a class="filter btn btn-sm btn-link" data-group="print">Print</a>
</li>
<li>
<a class="filter btn btn-sm btn-link" data-group="billboards">Billboards</a>
</li>
<li>
<a class="filter btn btn-sm btn-link" data-group="misc">Misc</a>
</li>
<li>
<a class="filter btn btn-sm btn-link" data-group="photo">Photo</a>
</li>
</ul>
<!-- End of Portfolio filter -->
<!-- Portfolio Grid -->
<div id="portfolio_grid" class="portfolio-grid portfolio-masonry masonry-grid-3">
<!-- Portfolio 1 - Graphics -->
<figure class="item gallery" data-groups='["graphics"]'>
<a href="images/portfolio/full/3.jpg" class="lightbox f-gallery" title="bnr 1">
<img src="images/portfolio/3.jpg" alt="">
<div>
<h5 class="name">bnr 1</h5>
<small>Graphics</small>
<i class="pe-7s-icon pe-7s-photo"></i>
</div>
</a>
</figure>
<figure class="item gallery" data-groups='["graphics"]'>
<a href="images/portfolio/full/3.jpg" class="lightbox f-gallery" title="bnr 2">
<img src="images/portfolio/3.jpg" alt="">
<div>
<h5 class="name">bnr 2</h5>
<small>Graphics</small>
<i class="pe-7s-icon pe-7s-photo"></i>
</div>
</a>
</figure>
<figure class="item gallery" data-groups='["graphics"]'>
<a href="images/portfolio/full/3.jpg" class="lightbox f-gallery" title="bnr 3">
<img src="images/portfolio/3.jpg" alt="">
<div>
<h5 class="name">bnr 3</h5>
<small>Graphics</small>
<i class="pe-7s-icon pe-7s-photo"></i>
</div>
</a>
</figure>
<!-- /Portfolio 1 - Graphics -->
<!-- Portfolio 2 - Logo -->
<figure class="item gallery" data-groups='["logo"]'>
<a href="images/portfolio/full/3.jpg" class="lightbox f-gallery" title="logo 1">
<img src="images/portfolio/3.jpg" alt="">
<div>
<h5 class="name">logo 1</h5>
<small>Logo</small>
<i class="pe-7s-icon pe-7s-photo"></i>
</div>
</a>
</figure>
<figure class="item gallery" data-groups='["logo"]'>
<a href="images/portfolio/full/3.jpg" class="lightbox f-gallery" title="logo 2">
<img src="images/portfolio/3.jpg" alt="">
<div>
<h5 class="name">logo 2</h5>
<small>Logo</small>
<i class="pe-7s-icon pe-7s-photo"></i>
</div>
</a>
</figure>
<figure class="item gallery" data-groups='["logo"]'>
<a href="images/portfolio/full/3.jpg" class="lightbox f-gallery" title="logo 3">
<img src="images/portfolio/3.jpg" alt="">
<div>
<h5 class="name">logo 3</h5>
<small>Logo</small>
<i class="pe-7s-icon pe-7s-photo"></i>
</div>
</a>
</figure>
<!-- /Portfolio 2 - Logo -->
</div>
<!-- /Portfolio Grid -->
</div>
<!-- /Portfolio Content -->
</div>
</section>
<!-- /Portfolio Subpage -->
Now it works, images filtered on page load. Add this code.
$(document).ready(function() {
$('#portfolio_filters .grph').trigger( "click" );
});
}
// /Portfolio subpage filters
Also I added class "grph" here:
<!-- Portfolio filter -->
<ul id="portfolio_filters" class="portfolio-filters">
<li class="active">
<a class="filter btn btn-sm btn-link active grph" data-group="graphics">Graphics</a>
</li>
<li>
I came here looking for an answer to the same problem, but couldn't get the solution to work, however it successfully pointed me in the right direction to finally solving it by creating a function to execute on page load:
function shuffleInit (id){
$(document).ready(function() {
$('#grid').hide();
jQuery('#'+id)[0].click();
$('#grid').show();
$('#'+id).trigger('click');
});
<body onload="shuffleInit('graphics');">
Remember to add IDs to the filter divs so they can be targeted by the shuffleInit() function. Note that #grid is the default shuffle.js container for the images - I added the hide and show commands to hide the visible re-shuffle animation on page load. The last click trigger line is just a cosmetic addition highlighting the button so the user can see which filter option has been applied.
This works with Bootstrap 3. Hope it helps someone!

Multiple Divs Show/Hide One at a time

I have a set of div's, What I want to do is when I click the read more button It shows the div "myContent" and hides the button for that particular container not all the divs with the same class name. and when I click the close button it hides the div (and because the button is there it should technically hide the button as well) and show the read more button again.
Whats happening right now is either all are showing or none are showing.
I am a newbie (using Jquery) Any help most appreciated.
The HTML
<!-- -->
<div class="member-content">
<div class="member-box">
<div class="photo">
<img src="" alt="" />
</div>
<div class="contact-details">
<h3>Mike</h3>
<span class="role">Member</span><br>
<span class="telephone">07595 8674523</span><br>
Read More
</div><!-- .contact-details -->
</div><!-- .member-box -->
</div><!-- .member-content -->
<div class="te contentDiv">
<div class="myContent" style="display:none">
<p>This Text is hidden</p>
<a id="close_btn" href="#" class="close-more">Close</a>
</div>
</div>
<!-- -->
<!-- -->
<div class="member-content">
<div class="member-box">
<div class="photo">
<img src="" alt="" />
</div>
<div class="contact-details">
<h3>Mike</h3>
<span class="role">Member</span><br>
<span class="telephone">07595 8674523</span><br>
Read More
</div><!-- .contact-details -->
</div><!-- .member-box -->
</div><!-- .member-content -->
<div class="te contentDiv">
<div class="myContent" style="display:none">
<p>This Text is hidden</p>
<a id="close_btn" href="#" class="close-more">Close</a>
</div>
</div>
<!-- -->
<!-- -->
<div class="member-content">
<div class="member-box">
<div class="photo">
<img src="" alt="" />
</div>
<div class="contact-details">
<h3>Mike</h3>
<span class="role">Member</span><br>
<span class="telephone">07595 8674523</span><br>
Read More
</div><!-- .contact-details -->
</div><!-- .member-box -->
</div><!-- .member-content -->
<div class="te contentDiv">
<div class="myContent" style="display:none">
<p>This Text is hidden</p>
<a id="close_btn" href="#" class="close-more">Close</a>
</div>
</div>
<!-- -->
Thanks!
You can try this, Based on my understanding.
$('.read-more').click(function () {
$(this).closest('.member-content').next('.contentDiv').find('.myContent').show();
$(this).hide();
});
$('.close-more').click(function () {
$(this).closest('.contentDiv').prev('.member-content').find('.read-more').show();
$(this).closest('.myContent').hide();
});
DEMO
If I understand right here is what you are looking for :)
$('.read-more').click(function () {
$(this).closest('.member-content').next('.contentDiv').find('.myContent').fadeIn();
$(this).hide();
});
$('.close-more').click(function () {
$(this).closest('.contentDiv').prev('.member-content').find('.read-more').fadeIn();
$(this).closest('.myContent').hide();
});

Categories