Using jQuery to apply function on a specific Div generated by EJS - javascript

I have coded a series of bootstrap collapsible Divs using the Javascript forEach function in an EJS file. These divs all have a button to expand and collapse the div. Initially, pressing on any button will expand all divs but I have managed to overcome that by indexing the IDs of those divs.
My problem now is I have a separate JS file running jQuery. The jQuery is used to hide and show specific font-awesome icons. When the div is collapsed, it shows an arrow-down icon and hides the arrow-up icon. When a div is expanded, it shows an arrow-up icon and hides the arrow-down icon. My jQuery when activated will apply the changes to all divs but I only want to apply it to the div that I clicked. I briefly recall I could use $(this) but haven't been able to find anything that could help me with it.
Please see my JS and EJS files below.
list.js
$('#collapsibleDivBtn').on('click', () => {
var downHiddenStatus = $(".fa-caret-square-down").is("[hidden]")
var upHiddenStatus=$(".fa-caret-square-up").is("[hidden]")
$(".fa-caret-square-down").toggleClass('hidden')
$(".fa-caret-square-down").attr('hidden',!downHiddenStatus)
$(".fa-caret-square-up").toggleClass('hidden')
$(".fa-caret-square-up").attr('hidden',!upHiddenStatus)
});
list.ejs
<!-- Start of the page -->
<div class="container mt-3">
<!-- Title of the page -->
<h3>List of Racks</h3>
<% data.forEach((rack, index) => { %>
<div class="card mb-3" >
<div class="card-body">
<div class="d-flex justify-content-between">
<div>
<h5 class="card-title"><strong><%= rack['Cabinet ID'] %></strong></h5>
</div>
<div>
<a id="collapsibleDivBtn" href="#collapsibleDiv<%= index %>" class="btn p-0" data-toggle="collapse">
<i class="far fa-caret-square-down text-primary bg-white"></i>
<i hidden class="hidden far fa-caret-square-up text-danger bg-white"></i>
</a>
</div>
</div>
<h6 class="card-subtitle mb-2 text-muted"><%= rack['Abbreviated Address'] %></h6>
<hr>
<div id="collapsibleDiv<%= index %>" class="collapse">
<div class="row mb-2">
<div class="col">
<p class="card-text">User Status: <br />
<span id="siteStatus" class="statusUpdate" ><%= rack['User Status'] %>
</span>
</p>
</div>
<div class="col">
<p class="card-text">Site Status: <br />
<span id="userStatus" class="statusUpdate">Online
</span>
</p>
</div>
</div>
<div class="row">
<div class="col d-flex justify-content-center">
<p class="mb-0">After Service Status: <br />
<span id="aft_service_status" class="statusUpdate">Unknown
</span>
</p>
</div>
</div>
</div>
</div>
</div>
<% }); %>
</div>

No need for hiding elements. Just use CSS rotate for your icons.
$(".container").on("click", function(){
$(this).find("i").toggleClass("arrowUp");
});
.container{
width: 50px;
height: 50px;
font-size: 50px;
}
.container i{
transition: all 0.4s ease;
}
.arrowUp {
transform: rotateZ(-180deg);
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<div>
<a class="container">
<i class="fa fa-arrow-down"></i>
</a>
<a class="container">
<i class="fa fa-arrow-down"></i>
</a>
<a class="container">
<i class="fa fa-arrow-down"></i>
</a>
</div>

Related

Bootstrap5 tab content on second tab creates unlimited white space

in my project I want to show statistics for the current month and the current year. To split this statistics I created a card with tabs that split month and year.
The month tab is loaded as default. If i now go on the year tab everything is loading but then it will load unlimited empty "stuff / white data" (I don't know how to explain it better), and you can't use this tab because the site will be bigger and bigger. There is also no error in the
This has first been poped up after I changed alle my charts (chart.js) to an dynamic way that you can go e.g. to the next month or the month before. If I load all charts with "fixed" data then the tab works correctly.
What is the problem?
Actual look:
How it has to be looked:
After some testing i see this:
Code snippet:
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.9.2/dist/umd/popper.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="card-header">
<div>
<ul class="nav nav-pills nav-fill mt-4" role="tablist">
<li class="nav-item active">
<a class="nav-link" data-bs-toggle="tab" href="#Month" role="tab">
<span><strong>Current Month</strong></span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="tab" href="#Year" role="tab">
<span><strong>Current Year</strong></span>
</a>
</li>
</ul>
</div>
</div>
<div class="card-body">
<div class="tab-content">
<div class="tab-pane active" id="Month" role="tabpanel">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="card-header d-flex justify-content-between align-items-center">
<h2 class="card-title" id="month"></h2>
<div class="justify-content-end">
<button class="btn btn-info last-month" id="last-month"><i class="fas fa-chevron-left"></i></button>
<button class="btn btn-info current-month" id="current-month">Current Month</button>
<button class="btn btn-info next-month" id="next-month"><i class="fas fa-chevron-right"></i></button>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header bg-inverse">
<h2 class="card-title text-white" id="monthly_training_sessions"></h2>
</div>
<div class="card-body">
<span class="badge chart-label-intervall">Intervall</span>
<span class="badge chart-label-longrun">Longrun</span>
<span class="badge chart-label-speedwork">Speedwork</span>
<span class="badge chart-label-stabilisation">Stabilisation</span>
<span class="badge chart-label-competition">Competition</span>
<span class="badge chart-label-cycling">Cycling</span>
<span class="badge chart-label-swimming">Swimming</span>
<br><br>
<canvas id="monthy_session_stats" width="180" height="180"></canvas>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header bg-inverse d-flex justify-content-between">
<h2 class="card-title text-white" id="monthly_training_days"></h2>
<h2 class="card-title text-white" id="monthly_injury_days"></h2>
</div>
<div class="card-body">
<div class="d-flex justify-content-evenly" style="margin-bottom: 18px">
<span class="badge chart-label-training">Training</span>
<span class="badge chart-label-injury">Free</span>
<span class="badge chart-label-free">Injury</span>
</div>
<br>
<canvas id="monthy_training_stats" width="180" height="180"></canvas>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header bg-inverse">
<h2 class="card-title text-white">Shoes</h2>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<tbody id="monthly_shoes_stats">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="Year" role="tabpanel">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="card-header d-flex justify-content-between align-items-center">
<h2 class="card-title" id="year"></h2>
<div class="justify-content-end">
<button class="btn btn-info last-year" id="last-year"><i class="fas fa-chevron-left"></i></button>
<button class="btn btn-info current-year" id="current-year">Current Year</button>
<button class="btn btn-info next-year" id="next-year"><i class="fas fa-chevron-right"></i></button>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header bg-inverse">
<h2 class="card-title text-white" id="yearly_training_sessions"></h2>
</div>
<div class="card-body">
<span class="badge chart-label-intervall">Intervall</span>
<span class="badge chart-label-longrun">Longrun</span>
<span class="badge chart-label-speedwork">Speedwork</span>
<span class="badge chart-label-stabilisation">Stabilisation</span>
<span class="badge chart-label-competition">Competition</span>
<span class="badge chart-label-cycling">Cycling</span>
<span class="badge chart-label-swimming">Swimming</span>
<br><br>
<canvas id="yearly_session_stats" width="180" height="180"></canvas>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header bg-inverse d-flex justify-content-between">
<h2 class="card-title text-white" id="yearly_training_days"></h2>
<h2 class="card-title text-white" id="yearly_injury_days"></h2>
</div>
<div class="card-body">
<div class="d-flex justify-content-evenly" style="margin-bottom: 18px">
<span class="badge chart-label-training">Training</span>
<span class="badge chart-label-injury">Free</span>
<span class="badge chart-label-free">Injury</span>
</div>
<br>
<canvas id="yearly_training_stats" width="180" height="180"></canvas>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header bg-inverse">
<h2 class="card-title text-white">Shoes</h2>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<tbody id="yearly_shoes_stats">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
After a lot of researching and reading i found the solution for this problem.
The problem occurs because of the hidden content from the hidden tab, which is realized in Bootstrap via "display: none".
.tab-content > .tab-pane, .pill-content > .pill-pane {
display: none; /* this is the problem */
}
To fix this problem you can use height: 0 and overflow-y: hidden to this . Now the charts will stay in place and no empty random space will created.
.tab-content > .tab-pane:not(.active),
.pill-content > .pill-pane:not(.active) {
display: block;
height: 0;
overflow-y: hidden;
}
It will take a little minute to go through that line by line but some of the problem is sure to be your structure of Rows and Columns. I noticed this in the first few lines - Just inside the tab-content is this...
<div class="tab-pane active" id="Month" role="tabpanel">
<div class="row">
<div class="col-md-12">
<div class="row">
With Bootstrap you're not really meant to have the Row's inside the Column's and I think what's happening is that the un-natural layout of the code is creating errors like the one you see. This answer does not discover where your white-space is coming from but I do suspect that fixing the layout of the code will also fix the white-space.

Plugin not working for second image, Javascript

In my html, there are 2 tabs once you click on a tab the other tab is hidden, while the one that is clicked on is shown, It's a normal javascript tab interface.
I have a gallery plugin, it shows the gallery of the image in the first div, but it doesn't work for the image in the second div, even after i have hidden the image in the first div and it works based on the id as light gallery, Please why doesn't it show the gallery of the second image and how can i solve this issue
This is my html
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.6.11/js/lightgallery-all.min.js"></script>
<li id="tabs1" onclick="showStuff(this)" class="active pic-list"><a href="#all" > All (35)</a></li>
<li id="tabs2" onclick="showStuff(this)" class="pic-list"></i></li>
<div id="tabs-1" class="tabContent" style="display: block;">
<div class="row" id="lightgallery">
#if(isset($images))
#foreach ($images as $image)
<div class="col-md-3 col" style="margin-bottom: 15px" data-src="{{$image->filename}}">
<div class="img-con" id="{{$image->id}}">
<a href="">
<img class="mb-2 uploaded-photos" src="{{$image->filename}}" alt="">
</a>
<div class="img-select">
<div class="new gvs-title">
<span style="color: #333333;">{{$image->description}} <i class="fa fa-upload" style="margin-left: 10px; color:#333333;"></i> <br/></span>
</div>
</div>
</div>
</div>
#endforeach
#endif
</div>
</div>
<div id="tabs-2" class="tabContent">
<div class="row" id="lightgallery">
#if(isset($images))
#foreach ($images as $image)
<div class="col-md-3 col" style="margin-bottom: 15px" data-src="{{$image->filename}}">
<div class="img-con" id="{{$image->id}}">
<a href="">
<img class="mb-2 uploaded-photos" src="{{$image->filename}}" alt="">
</a>
<div class="img-select">
<div class="new gvs-title">
<span style="color: #333333;">{{$image->description}}080808008080 <i class="fa fa-upload" style="margin-left: 10px; color:#333333;"></i> <br/></span>
</div>
</div>
</div>
</div>
#endforeach
#endif
</div>
</div>
This is my jquery code
$(document).ready(function(){
$('#lightgallery').lightGallery();
});
I solved this by basically calling two light gallery functions and changing the id of the 2 divs i.e lightgallery and lightgallery1
$(document).ready(function(){
$('#lightgallery').lightGallery();
$('#lightgallery1').lightGallery();
});

How can I put the icon and tag in the same line?

The icon and the word hi can not be put into the same line
<link href="http://code.ionicframework.com/1.3.1/css/ionic.css" rel="stylesheet"/>
<div class="row">
<div class="col">
<h5 class="title">hi</h5>
</div>
<i class="icon ion-ios-heart"></i>
</div>
Thanks!!
Method 1 - CSS
<div class="row">
<div class="col">
<span class="item">
<h5 style="display:inline" class="title">hi</h5>
<i class="icon ion-ios-heart"></i>
</span>
</div>
</div>
Method 2 - In same column
<div class="row">
<div class="col">
<h5 class="title">hi<i class="icon ion-ios-heart"></i></h5>
</div>
</div>
Method 3 - In two columns in same row
<div class="row">
<div class="col">
<h5 class="title">hi</h5>
</div>
<div class="col">
<i class="icon ion-ios-heart"></i>
</div>
</div>
h5 will display as a block, so it has its own line.
Should work with the icon inside the h5 tags, though.

Existing div moves when I click to open another div?

When I load my page, (it's made with Bootstrap - - http://themejulies.tumblr.com) , it looks like this:
When I push the info button in the left corner (which opens a div), the little down arrow towards the bottom of the page moves up.
How do I make it so that I can click the info button to open the div, and the little down arrow does not move up?
And here's the code:
<div class="container-fluid" id="foo" style="z-index:5; display:none; height:auto;">
<center>
<div class="container-fluid" style="height:auto; margin-top:2%;">
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-3" style=" margin-top:1%;"><img class="avatar-style-circle" src="{PortraitURL-128}" /><br/><h3>{AuthorName}</h3></div>
<div class="col-xs-12 col-md-6" style="background-color:blue; margin-top:2%;"><p style="text-align:justify;">{Description}<br/></p></div></div></div>
<div class="container-fluid" style="height:auto; margin-top:2%; margin-bottom:2%;">
<center>
<div class="container-fluid">
<div class="input-group">
</div>
<form action="/search" method="get">
<input type="text" name="q" value="{SearchQuery}" placeholder="{lang:Search}" class="form-control" placeholder="Search for...">
</form>
</div><!-- /input-group -->
<br/>
<div class="btn-group" role="group" aria-label="..."> Ask
Archive
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Pages
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" style="z-index:5; margin-left:13%;">
{block:HasPages}{block:Pages}<li>{Label}</li> {/block:Pages} {/block:HasPages}
</ul>
</div><!-- /.col-lg-6 --></center>
</div>
</div>
</div>
</div>
<div class="site-wrapper">
{block:ifShowInfoButton}
<i class="fa fa-info-circle fa-3x" style="position:absolute; margin-left:0.4%; margin-top:0.4%; color:{color:Info Button Color};"></i>
{/block:ifShowInfoButton}
<div class="site-wrapper-inner">
<div class="cover-container">
<div class="inner cover">
<h1 class="pagetitle" style="position:relative; font-family:{text:Google Web Font name Title}; font-weight:700; color:{color:Title and Tagline Text};">{Title}</h1>
{block:ifShowTagLine} <p class="pagedesc" style="postition:relative; font-family: {text:Google Web Font name Tagline}, sans-serif; font-weight:500; color:{color:Title and Tagline Text};">{text:Tagline}</p>{/block:ifShowTagLine}
</div>
<div class="mastfoot">
<div class="inner">
<a name="bottom"> <i class="fa fa-angle-down fa-5x"></i></div></a>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid" id="bottom">Test</div>
Set the div that appears when you click the info button to
position:absolute;
background: #333;
this will pull it out of the document flow and will not affect the other divs
or if that is not the effect you were looking for set the div with the down arrow to position: absolute;
#media (min-width: 768px) {
.mastfoot {
position: absolute;
}
}
the problem is with position:absolute

Using font-awesome in a code

I have the following code in my JSP file
<div class="row-fluid">
<div style="text-align: left;" class="span3 row-fluid">
<label><spring:message code="alert.channels.outbound.lines"></spring:message>: </label>
</div>
<div class = "span3">
<div class="textbox">
<div class="textVal">${alertStatusForm.outboundLines}</div>
<div class="pencil span3 ">
<img src="/static/img/pencil.png" alt="Edit">
</div>
<div class="save span3">
<img src="/static/img/disk.png" alt="Save">
</div>
<div class="close span3">
<img src="/static/img/Cross.png" alt="Close">
</div>
</div>
</div>
</div>
Now I have to use the font-awesome in place of pencil.png , disk.png and Cross.png .
I have the following codes for the above pencil , disk and Cross as
Pencil =  icon-pencil ()
disk = icon-save ()
Cross = icon-remove ()
from the website http://fortawesome.github.io/Font-Awesome/cheatsheet/
Please let me know how to use the above codes in place of
You can write like this by change to <i> tag instead of <img>
<div class="row-fluid">
<div style="text-align: left;" class="span3 row-fluid">
<label><spring:message code="alert.channels.outbound.lines"></spring:message>: </label>
</div>
<div class = "span3">
<div class="textbox">
<div class="textVal">${alertStatusForm.outboundLines}</div>
<div class="pencil span3 ">
<i class="icon-edit"></i>
</div>
<div class="save span3">
<i class= "icon-save"></i>
</div>
<div class="close span3">
<i class= "icon-folder-close"></i>
</div>
</div>
</div>
</div>
Besure that you have link with font awsome css or
add this link in your layout or views
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
You need to change the <IMG> tags with the following:
<i class="icon-pencil"></i>
Setting appropriate class on the <i> element.

Categories

Resources