Semantic UI. How to initialize a pop-up on an element? - javascript

I'm new with Sematic UI and jQuery, and I want to show a pop-up when I click on button "Browse1", not on "Browse2" or "Browse3.
But the pop-up also shows when I click anywhere on my menu. How can I restrict the pop-up, so it only displays when clicking on "Browse1"?
Why doesn't the following work?
$(".ui.menu").find("a:first").popup({on: 'click'});
Here's my code:
$(".ui.menu").popup({on: 'click'});
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.7/semantic.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.7/semantic.min.js"></script>
<div class="ui menu">
<a class="browse item">
Browse1 <i class="dropdown icon"></i>
</a>
<a class="browse item">
Browse2 <i class="dropdown icon"></i>
</a>
<a class="browse item">
Browse3 <i class="dropdown icon"></i>
</a>
</div>
<div class="ui fluid popup bottom left transition hidden">
<div class="ui four column relaxed equal height divided grid">
<div class="column">
<h4 class="ui header">Fabrics</h4>
<div class="ui link list">
<a class="item">Cashmere</a>
<a class="item">Linen</a>
<a class="item">Cotton</a>
<a class="item">Viscose</a>
</div>
</div>
<div class="column">
<h4 class="ui header">Size</h4>
<div class="ui link list">
<a class="item">Small</a>
<a class="item">Medium</a>
<a class="item">Large</a>
<a class="item">Plus Sizes</a>
</div>
</div>
<div class="column">
<h4 class="ui header">Colored</h4>
<div class="ui link list">
<a class="item">Neutrals</a>
<a class="item">Brights</a>
<a class="item">Pastels</a>
</div>
</div>
<div class="column">
<h4 class="ui header">Types</h4>
<div class="ui link list">
<a class="item">Knitwear</a>
<a class="item">Outerwear</a>
<a class="item">Pants</a>
<a class="item">Shoes</a>
</div>
</div>
</div>
</div>

You need to use the Semantic UI way of assigning a popup to the menu element (in your case the first item). Check this script below I wrote for you.
$('.ui.menu .item:first-child').popup({
popup : $('.ui.popup'),
on : 'click'
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.7/semantic.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.7/semantic.min.js"></script>
<div class="ui menu">
<a class="browse item">
Browse1 <i class="dropdown icon"></i>
</a>
<a class="browse item">
Browse2 <i class="dropdown icon"></i>
</a>
<a class="browse item">
Browse3 <i class="dropdown icon"></i>
</a>
</div>
<div class="ui fluid popup bottom left transition hidden">
<div class="ui four column relaxed equal height divided grid">
<div class="column">
<h4 class="ui header">Fabrics</h4>
<div class="ui link list">
<a class="item">Cashmere</a>
<a class="item">Linen</a>
<a class="item">Cotton</a>
<a class="item">Viscose</a>
</div>
</div>
<div class="column">
<h4 class="ui header">Size</h4>
<div class="ui link list">
<a class="item">Small</a>
<a class="item">Medium</a>
<a class="item">Large</a>
<a class="item">Plus Sizes</a>
</div>
</div>
<div class="column">
<h4 class="ui header">Colored</h4>
<div class="ui link list">
<a class="item">Neutrals</a>
<a class="item">Brights</a>
<a class="item">Pastels</a>
</div>
</div>
<div class="column">
<h4 class="ui header">Types</h4>
<div class="ui link list">
<a class="item">Knitwear</a>
<a class="item">Outerwear</a>
<a class="item">Pants</a>
<a class="item">Shoes</a>
</div>
</div>
</div>
</div>

Related

semantic popup list width is too small

I am working with semantic ui and got stuck with Notification menu implementation in menu bar.
I am able to setup the popup with a list but i am getting small list item squeezed vertically , i need them to be horizontally relaxed .
Below is the html i am working with .
<div class="ui fixed stackable menu">
<a class="item" href="index.php"> <img src="logo.png" class="image"></a>
<a class="item">My Project</a>
<div class="right menu">
<div class="item">
<i class="bell outline icon"></i>
<div class="ui teal circular mini label">4</div>
<div class="ui wide notification popup bottom transition ">
<div class="ui link celled selection list">
<div class='item'>
<div class='content'>
<a class='header'>Millan kumar</a>
<span class='time'>2 hrs ago</span>
<div class='description'>Commented on <a><b>Your Post </b></a> with <a><b>Following content</b></a></div>
<div class='extra'>Thanks you for your support</div>
</div>
</div>
</div>
</div>
</div>
<a class="item" href="profile.php">Profile</a>
<a class="item" href="logout.php">Logout</a>
</div>
</div>
Javascript:
$('.teal.label')
.popup({
on: 'click'
});
JS Fiddle :
https://jsfiddle.net/jfk4wkb1/2/
I have tried putting up the things on JS Fiddle , but In there popup is not coming up even , but on my local environment popup is ok but it is vertically squeezed.
Like this: Fiddle link
You did not add jquery in your fiddle external resource . Also i add some padding and width to looks good .
<div class="ui link celled selection list" style ="padding: 20px;width: 300px;">
HTML:
<div class="ui fixed stackable menu">
<a class="item" href="index.php"> <img src="logo.png" class="image"></a>
<a class="item">My Project</a>
<div class="right menu">
<div class="item">
<i class="bell outline icon"></i>
<div class="ui teal circular mini label">4</div>
<div class="ui wide notification popup bottom right transition ">
<div class="ui link celled selection list" style ="padding: 20px;width: 300px;">
<div class='item'>
<div class='content'>
<a class='header'>Millan kumar</a>
<span class='time'>2 hrs ago</span>
<div class='description'>Commented on <a><b>Your Post </b></a> with <a><b>Following content</b></a></div>
<div class='extra'>Thanks you for your support</div>
</div>
</div>
</div>
</div>
</div>
JS:
$('.teal.label')
.popup({
on: 'click'
});

Accordion doesn't work in Bootstrap 4 collapse

https://fiddle.jshell.net/8v72rtxb/
I have the following code.
<div class="menu-horizontal container">
<div class="row menu-container" id="menu">
<div class="col-md-3 menu-item">
<a data-toggle="collapse" class="collapsed collapse-toggle" data-parent="#menu" href="#studies-collapse" aria-expanded="false" aria-controls="collapseExample">
Studies
</a>
<div class="collapse" id="studies-collapse">
<div class="container">
<div class="row">
Something...
</div>
</div>
</div>
</div>
<div class="col-md-3 menu-item">
<a data-toggle="collapse" class="collapsed collapse-toggle" data-parent="#menu" href="#research-collapse" aria-expanded="false" aria-controls="collapseExample">
Research
</a>
<div class="collapse" id="research-collapse">
<div class="container">
<div class="row">
Something...
</div>
</div>
</div>
</div>
</div>
</div>
I have no idea why data-parent doesn't work though. Expand one collapse div doesn't close the other collapse. I tried to copy the code from the example of bootstrap, but it still doesn't work.
Also in my project, I include jquery.js before bootstrap.min.js. I have checked some other questions, they said that bootstrap.min.js might have been included twice. But should that be the case?
Thanks for reading!
I figured a workaround for this. Even without using the data-parent attribute.
https://fiddle.jshell.net/zyd1vL4o/
$(document).ready(function(){
$('.collapse').on('show.bs.collapse', function (e) {
$('.collapse').collapse("hide")
})
})
Once go through this jsfiddle
And here is html code,
<div id="accordion" role="tablist" aria-multiselectable="true">
<div class="card">
<div class="card-header" role="tab" id="headingOne">
<h5 class="mb-0">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Studies
</a>
</h5>
</div>
<div id="collapseOne" class="collapse " role="tabpanel" aria-labelledby="headingOne">
<div class="card-block">
<div id="studies-collapse">
<div class="container">
<div class="row">
<div class="col-md-3">
<a href="" class="menu-subitem">
Study Guides
</a>
<a href="" class="menu-subitem">
Counselling and Instructions
</a>
<a href="" class="menu-subitem">
Student Laboratory
</a>
<a href="" class="menu-subitem">
Student Exchange
</a>
</div>
<div class="col-md-3">
<a href="" class="menu-subitem">
Post‐graduate studies
</a>
<a href="" class="menu-subitem">
Theses
</a>
<a href="" class="menu-subitem">
Exams
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header" role="tab" id="headingTwo">
<h5 class="mb-0">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Research
</a>
</h5>
</div>
<div id="collapseTwo" class="collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="card-block">
<div id="research-collapse">
<div class="container">
<div class="row">
<div class="col-md-3">
<a href="" class="menu-subitem">
Study Guides
</a>
<a href="" class="menu-subitem">
Counselling and Instructions
</a>
<a href="" class="menu-subitem">
Student Laboratory
</a>
<a href="" class="menu-subitem">
Student Exchange
</a>
</div>
<div class="col-md-3">
<a href="" class="menu-subitem">
Post‐graduate studies
</a>
<a href="" class="menu-subitem">
Theses
</a>
<a href="" class="menu-subitem">
Exams
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Use:
<div class="menu-horizontal container">
<div class="row menu-container" id="menu">
<div class="col-md-3 menu-item">
<a data-toggle="collapse" class="collapsed" data-target="#studies-collapse" href="#studies-collapse" aria-expanded="false" aria-controls="studies-collapse">
Studies
</a>
<div class="collapse" id="studies-collapse" data-parent="#menu">
<div class="container">
<div class="row">
Something...
</div>
</div>
</div>
</div>
<div class="col-md-3 menu-item">
<a data-toggle="collapse" class="collapsed" data-target="#research-collapse" href="#research-collapse" aria-expanded="false" aria-controls="research-collapse">
Research
</a>
<div class="collapse" id="research-collapse" data-parent="#menu">
<div class="container">
<div class="row">
Something...
</div>
</div>
</div>
</div>
</div>
</div>
import 'bootstrap/js/dist/collapse';
Include this in your file and the collapse should work.
If its not closing, then you might not be properly linking to to your bootstrap js. You shouldn't need to add anything extra.
check for the following js files:
bootstrap.min.js
bootstrap.bundle.min.js
If you're creating a bootstrap theme then in the functions do this:
wp_register_script( 'write your theme name here', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js', array( 'jquery' ) );

Fire onClick event to specific div

I have two cards and I am firing an onClick() event to create a dimmer on top of the card image if a user clicks on Like button (heart icon). I am trying to create the dimmer on the card image in which user clicked the heart icon.
I tried placing a condition :
if (e.target !== this)
return;
But it did not work. In real webpage, I will have a long list of cards with no identifier where I can specify the image to be dimmed. Is it possible in this scenario?
JSFiddle
So you're trying to limit your interaction to the currently selected image? Also, rather than reference a fiddle, post your working (or non-working) code here. Easier all around.
jQuery(document).ready(function($) {
$(document).on('click', '.loveit', function(e) {
e.preventDefault();
$(this).parents(".card").find('.imglove')
.dimmer('show');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/semantic-ui/2.2.2/semantic.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.2/semantic.min.js"></script>
<div class="ui card">
<div class="content">
<div class="right floated meta">14h</div>
<img class="ui avatar image" src="http://semantic-ui.com/images/avatar/large/elliot.jpg"> Elliot
</div>
<div class="image imglove">
<div class="ui dimmer">
<div class="content">
<div class="center">
<h2 class="ui inverted header">Title</h2>
<img class="ui avatar image" src="http://www.animatedimages.org/data/media/373/animated-heart-image-0455.gif">
</div>
</div>
</div>
<img src="http://semantic-ui.com/images/avatar2/large/kristy.png">
</div>
<div class="content">
<span class="right floated">
<i class="heart outline like icon loveit"></i>
17 likes
</span>
<i class="comment icon"></i>
3 comments
</div>
<div class="extra content">
<div class="ui large transparent left icon input">
<i class="heart outline icon"></i>
<input type="text" placeholder="Add Comment...">
</div>
</div>
</div>
<div class="ui card">
<div class="content">
<div class="right floated meta">14h</div>
<img class="ui avatar image" src="http://semantic-ui.com/images/avatar/large/elliot.jpg"> Elliot
</div>
<div class="image imglove">
<div class="ui dimmer">
<div class="content">
<div class="center">
<h2 class="ui inverted header">Title</h2>
<img class="ui avatar image" src="http://www.animatedimages.org/data/media/373/animated-heart-image-0455.gif">
</div>
</div>
</div>
<img src="http://semantic-ui.com/images/avatar2/large/kristy.png">
</div>
<div class="content">
<span class="right floated">
<i class="heart outline like icon loveit"></i>
17 likes
</span>
<i class="comment icon"></i>
3 comments
</div>
<div class="extra content">
<div class="ui large transparent left icon input">
<i class="heart outline icon"></i>
<input type="text" placeholder="Add Comment...">
</div>
</div>
</div>
Updated fiddle.
You should use the current clicked jQuery object $(this) instead to target the related .imglove in the same .card :
$(this).closest('.card').find('.imglove').dimmer('show');
NOTE : The .closest('.card') is used to get the related card with clicked icon loveit.
Hope this helps.
$(function() {
$(document).on('click', '.loveit', function(e) {
e.preventDefault();
$(this).closest('.card').find('.imglove').dimmer('show');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.2/semantic.min.js"></script>
<link href="https://cdn.jsdelivr.net/semantic-ui/2.2.2/semantic.min.css" rel="stylesheet"/>
<div class="ui card">
<div class="content">
<div class="right floated meta">14h</div>
<img class="ui avatar image" src="http://semantic-ui.com/images/avatar/large/elliot.jpg"> Elliot
</div>
<div class="image imglove">
<div class="ui dimmer">
<div class="content">
<div class="center">
<h2 class="ui inverted header">Title</h2>
<img class="ui avatar image" src="http://www.animatedimages.org/data/media/373/animated-heart-image-0455.gif">
</div>
</div>
</div>
<img src="http://semantic-ui.com/images/avatar2/large/kristy.png">
</div>
<div class="content">
<span class="right floated">
<i class="heart outline like icon loveit"></i>
17 likes
</span>
<i class="comment icon"></i>
3 comments
</div>
<div class="extra content">
<div class="ui large transparent left icon input">
<i class="heart outline icon"></i>
<input type="text" placeholder="Add Comment...">
</div>
</div>
</div>
<div class="ui card">
<div class="content">
<div class="right floated meta">14h</div>
<img class="ui avatar image" src="http://semantic-ui.com/images/avatar/large/elliot.jpg"> Elliot
</div>
<div class="image imglove">
<div class="ui dimmer">
<div class="content">
<div class="center">
<h2 class="ui inverted header">Title</h2>
<img class="ui avatar image" src="http://www.animatedimages.org/data/media/373/animated-heart-image-0455.gif">
</div>
</div>
</div>
<img src="http://semantic-ui.com/images/avatar2/large/kristy.png">
</div>
<div class="content">
<span class="right floated">
<i class="heart outline like icon loveit"></i>
17 likes
</span>
<i class="comment icon"></i>
3 comments
</div>
<div class="extra content">
<div class="ui large transparent left icon input">
<i class="heart outline icon"></i>
<input type="text" placeholder="Add Comment...">
</div>
</div>
</div>
Target it parent with class card then find class imglove and add dimmer to it
jQuery(document).ready(function($) {
$(document).on('click', '.loveit', function(e) {
$(this).parents('.card').find('.imglove').dimmer('show');
});
});
DEMO

How to fetch content from panel to modal using jquery

I've made a profile page on which user's posts are displayed, user can perform function delete or edit post.But,
when i click on edit post on any of my post ,only content of first post is fetched in the modal.
my js code:
$('.dropdown-menu').find('.edit').on('click', function(e) {
e.preventDefault();
var postbody = $('#fetch').find('p').text();
$('#post-body').val(postbody);
$('#edit-modal').modal();
});
my view code:
#foreach($posts as $post) #if(Auth::user()== $post->user)
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<section class="col-md-2 col-xs-2">
<img id="imagesize2" src="images/g.jpg" class="img-circle" data- action="zoom" />
</section>
<section class="col-md-5 col-xs-offset-1 col-xs-5">
<a id="alink13" href=""><h5 id="alink14">{{$post->user->firstname}}</h5> </a>
<p>on {{$post->created_at}}</p>
</section>
<section class="col-md-offset-3 col-md-2 col-xs-4 col-lg-offset-1">
<div class="btn-group">
<button id="btnclr4" type="button" class="btn btn-default dropdown- toggle" data-toggle="dropdown" aria-expanded="false"><span class="glyphicon glyphicon-chevron-down"></span>
</button>
#if(Auth::user()==$post->user)
<ul id="remove" class="dropdown-menu" role="menu">
<a id="remove2" href="{{route('post.delete',['post_id' => $post->id])}}">
<li role="presentation">Remove This Post</li>
</a>
<a href="" class="edit">
<li role="presentation">Edit This Post</li>
</a>
</ul>
#endif
</section>
</div>
</div>
<div class="panel-content">
<div class="row" id="fetch">
<section class="col-md-12">
<p>{{$post->body}}</p>
</section>
</div>
</div>

jQuery add class depending on current URL to semanti-ui dropdown

I need to add the class 'active' to links depending on it matching the current URL. I made that work using this answer but i need to make it work also for dropdown links. This is the markup I'm using:
var full_path = location.href.split("#")[0];
$("#nav a").each(function() {
var $this = $(this);
if ($this.prop("href").split("#")[0] == full_path) {
$this.addClass("active");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<div id="nav" class="ui large secondary inverted pointing menu">
<a class="toc item">
<i class="sidebar icon"></i>
</a>
Home
Server information
<div class="ui pointing dropdown link item">
<span class="text">Community</span>
<i class="dropdown icon"></i>
<div class="menu">
<a class="item" href="forum.php">Forum</a>
<a class="item" href="market.php">Item Market</a>
<a class="item" href="gallery.php">Gallery</a>
<a class="item" href="support.php">Support</a>
<a class="item" href="helpdesk.php">Helpdesk</a>
<a class="item" href="houses.php">Houses</a>
<a class="item" href="deaths.php">Deaths</a>
<a class="item" href="killers.php">Killers</a>
</div>
</div>
<div class="ui pointing dropdown link item">
<span class="text">Shop</span>
<i class="dropdown icon"></i>
<div class="menu">
<a class="item" href="buypoints.php">Buy points</a>
<a class="item" href="shop.php">Shop offers</a>
</div>
</div>
<div class="ui pointing dropdown link item">
<span class="text">Guilds<?php if ($config['guildwar_enabled'] === true) { ?> & Wars<?php } ?></span>
<i class="dropdown icon"></i>
<div class="menu">
<a class="item" href="guilds.php">Guilds</a>
<?php if ($config[ 'guildwar_enabled']===t rue) { ?>
<a class="item" href="guildwar.php">Guild Wars</a>
<?php } ?>
</div>
</div>
<div class="ui pointing dropdown link item">
<span class="text">Library</span>
<i class="dropdown icon"></i>
<div class="menu">
<a class="item" href="downloads.php">Downloads</a>
<a class="item" href="changelog.php">Changelog</a>
</div>
</div>
<div class="right item">
<a id="loginButton" class="ui blue inverted button">
<?php if (user_logged_in()===t rue) { echo 'Account'; } else { echo 'Log in';}?>
</a>
<div class="ui fluid transition login popup">
<?php if (user_logged_in()===t rue) { include 'layout/widgets/loggedin.php'; } else { include 'layout/widgets/login.php'; } ?>
</div>
<?php if (user_logged_in()===f alse) { echo '<a class="ui green inverted button" href="register.php">Register</a>'; } ?>
</div>
</div>
As you can see, dropdowns are using <span> tags, and they are showing the text of the dropdown. Is there a way to put the "name" of the link into that span when it's active ?

Categories

Resources