How can I share the dropdown menu definition accross multiple buttons - twitter-bootstrap-3

Each line in my table have a dropdown menu that show "Edit, Delete". If i have 100 lines in my table, i have 100 identical dropdown menus definition.
If is possible to define only one dropdown menu and use it for all my dropdown buttons? It seems to work but the dropdown menu is not shown at the right place. Is there a way to tell the dropdown menu to change his position to another one?
<a data-toggle="dropdown" href="#unique-dropdown">Button1</a>
<a data-toggle="dropdown" href="#unique-dropdown">Button2</a>
<div class="dropdown" id="unique-dropdown">
<ul class="dropdown-menu">
<li><i class="fa fa-pencil fa-fw"></i> Edit</li>
<li><i class="fa fa-trash-o fa-fw"></i> Delete</li>
</ul>
</div>

actually, you were really close to get what you wanted...
look this sample: http://jsfiddle.net/1jfe3wju/2/
html:
<a class="uniquedd" data-toggle="dropdown" aria-expanded="false" data-info="idofwhatyouwanttoeditordelete" href="#unique-dropdown">Button1</a>
<a class="uniquedd" data-toggle="dropdown" aria-expanded="false" data-info="otheridofwhatyouwanttoeditordelete" href="#unique-dropdown">Button2</a>
<div class="dropdown" id="unique-dropdown">
<ul class="dropdown-menu">
<li><i class="fa fa-pencil fa-fw"></i> Edit</li>
<li><i class="fa fa-trash-o fa-fw"></i> Delete</li>
</ul>
</div>
js:
$('.uniquedd').click(function(e) {
e.preventDefault();
var that = $(this);
var p = that.offset();
actOverWhat = that.data('info');
//change the actions of the buttons edit and delete
//check if open
isOpen = $("#unique-dropdown").hasClass('open');
if( isOpen ) {
that.dropdown('toggle');
}
$("#unique-dropdown").offset({ top: (p.top + 15), left: p.left });
});
offset is document related, so probably if the page is large won't help, but you have jquery .position();

You could use less js code. All you need to do is "Append" your class="dropdown-menu" to the class="dropdown" div each time you click an element that should show the menu.
Look at this example: https://jsfiddle.net/espriella/b4mztvnz/
$CHdropdown = $('#ColumnHeaderDropdownId');
$('.sharingdropdown').click(function(e) {
$(this).append($CHdropdown);
});
And this is the HTML sample:
<table class="table table-striped table-bordered" id="ChartContentGridId">
<thead>
<tr>
<th>
<div contenteditable style="float:left">Series 1</div>
<div class="dropdown sharingdropdown" style="float:right">
<button class="btn btn-xs btn-success dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-caret-down" aria-hidden="true"></i>
</button>
</div>
</th>
<th>
<div contenteditable style="float:left">Series 2</div>
<div class="dropdown sharingdropdown" style="float:right">
<button class="btn btn-xs btn-success dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-caret-down" aria-hidden="true"></i>
</button>
</div>
</th>
<th width="20px"></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<ul class="dropdown-menu pull-right" id="ColumnHeaderDropdownId">
<li><i class="fa fa-pencil"></i> Edit</li>
<li><i class="fa fa-times"></i> Delete</li>
</ul>

Related

How to correctly output data from the database to the razor

I have 2 drop-down menus
<div class="dropdown">
<button class=" js-dropdownDate dropdown-toggle" type="button" data-toggle="dropdown" data-value="#Model.WeekNumberDayStart" id="periodTypeNumber">
<span class="toggle-text">First</span>
<span class="dropdown-caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation">
<a class="active" role="menuitem" tabindex="-1" href="#" data-value="1">First</a>
</li>
<li role="presentation">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="2">Second</a>
</li>
<li role="presentation" data-value="3">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="3">Third</a>
</li>
<li role="presentation" data-value="4">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="4">Fourth</a>
</li>
<li role="presentation" data-value="5">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="5">Fifth</a>
</li>
</ul>
</div>
<div class="dropdown">
<button class=" js-dropdownDate dropdown-toggle" type="button" data-toggle="dropdown" id="periodTypeDay" data-value="#Model.DayNubmerOfWeek">
<span class="toggle-text">monday</span>
<span class="dropdown-caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation" data-value="1">
<a class="active" role="menuitem" tabindex="-1" href="#" data-value="1">monday</a>
</li>
<li role="presentation" data-value="2">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="2">tuesday</a>
</li>
<li role="presentation" data-value="3">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="3">wednesday</a>
</li>
<li role="presentation" data-value="4">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="4">thursday</a>
</li>
<li role="presentation" data-value="5">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="5">friday </a>
</li>
<li role="presentation" data-value="6">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="6">saturday</a>
</li>
<li role="presentation" data-value="7">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="7">sunday</a>
</li>
</ul>
</div>
and if the date from #Model.WeekNumberDayStart(int - like 1,2,3,4...) = data-value = "1" then need to write class = "active" otherwise just class = ""
maybe somehow it can be done differently through the menu itself through DropDownList?
and if the date from #Model.WeekNumberDayStart(int - like 1,2,3,4...)
= data-value = "1" then need to write class = "active" otherwise just class = ""
It cannot be achieved by menu itself. You need to use jquery code to achieve.
Since you have two dropdown menus, you need to distinguish the a tag of these two menus.
Therefore, you can add custom attributes and corresponding values to each group of a tags to ensure that the corresponding elements can be obtained in jquery.
Below is the class active binding for the first group of dropdown menu example.
<div class="dropdown">
<button class=" js-dropdownDate dropdown-toggle" type="button" data-toggle="dropdown" data-value="#Model.WeekNumberDayStart" id="periodTypeNumber">
<span class="toggle-text">First</span>
<span class="dropdown-caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation">
<a class="active" role="menuitem" tabindex="-1" href="#" data-value="1" droptype="WeekNumberDayStart">First</a>
</li>
<li role="presentation">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="2" droptype="WeekNumberDayStart">Second</a>
</li>
<li role="presentation" data-value="3">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="3" droptype="WeekNumberDayStart">Third</a>
</li>
<li role="presentation" data-value="4">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="4" droptype="WeekNumberDayStart">Fourth</a>
</li>
<li role="presentation" data-value="5">
<a class="" role="menuitem" tabindex="-1" href="#" data-value="5" droptype="WeekNumberDayStart">Fifth</a>
</li>
</ul>
</div>
jquery to change binding class active according to #Model.WeekNumberDayStart value:
<script>
$(function () {
$("a[droptype=WeekNumberDayStart]").each(function () {
$(this).removeClass("active");
if ($(this).attr("data-value") == $("#periodTypeNumber").attr("data-value")) {
$(this).addClass("active");
}
})
})
</script>

make dropdown over my datatabe

after click in my single button ,the dropdown is under my datatables !
my code :
<div class="dropdown">
<button type="button" class="btn btn-icon" aria-label="btnGroup" data-toggle="dropdown" >
<i class="icon icon-dots-vertical"></i>
</button>
<div class="dropdown-menu" aria-labelledby="btnGroup">
<a class="dropdown-item" href="#">Modifier Contrat</a>
<a class="dropdown-item" href="#">Supprimer Contrat</a>
</div>
</div>
If you want the dropdown to stay within your modal without adjusting the z-index you can align the dropdown the the right edge of your button using the class 'dropdown-menu-right' on the 'dropdown-menu' div:
<div class="dropdown">
<button type="button" class="btn btn-icon" aria-label="btnGroup" data-toggle="dropdown" >
<i class="icon icon-dots-vertical"></i>
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="btnGroup">
<a class="dropdown-item" href="#">Modifier Contrat</a>
<a class="dropdown-item" href="#">Supprimer Contrat</a>
</div>

Add dynamic items in bootstrap carousel /asp.net mvc5

So this is the view :
e#model IEnumerable<CMSFC.Models.ContentHtml>
<div id="my-carousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
#{int i = 0;}
#foreach (var item in Model)
{
i++;
var active = i == 1 ? "active" : "";
<div class="item #active">
<a href="#Url.Action("Details", "ContentHtml", new { Id = item.Id })">
<img src="#Url.Content(item.Ctl)" alt="" height="500" width="500">
</a>
</div>
}
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
I have problems with left and right controls , when i touch them , they are not affected , slides just move on automatically , but left and right controls arent working.
In the left and right controls, you define href=#myCarousel instead of href=#my-carousel.

How do I conditionally add a class in aurelia template

I am looking at a way to add a class dynamically to aurelia template. I have to add an active class if the particular li is visible.
Example
<section id="jobsCategoryContainer" class="jobsCategoryContainer">
<h1>{{title}}</h1>
<div *ngFor = "#slide of jobCategorySlides; #i = index" id="job-category-slide_{{i}}" class="job-category-slide" [ngClass]="{active: initialCarouselIndex == i}">
<ul *ngFor = "#item of slide">
<li class="jobDetails" *ngFor="#job of item; #i = index">
<div>
<span id="{{job.name}}" class="jobName">{{ job.name }}</span>
</div>
<div>
<span>{{job.noOfJobs}}</span>
</div>
</li>
</ul>
</div>
<div>
Previous
Next
</div>
</section>
I want to add the active class on below code
<div class="phs-widget-body">
<div class="phs-carousel-inner">
<ul repeat.for = "slide of nearByJobSlides" class="phs-item phs-grid-row" >
<li repeat.for = "item of slide" class="phs-small-6">
<a href="javascript:void(0)">
<div class="phs-job-title">${item.title}</div>
<div class="phs-job-info">
<span class="phs-job-loacation">${item.location}</span>
<span class="phs-job-category">${item.category}</span>
</div>
</a>
</li>
</ul>
</div>
</div>
<div class="phs-widget-footer">
<a class="left" href="#phsNearbyJobs" role="button" data-slide="prev">
<i class="fa fa-angle-left"></i> Move to Previous
</a>
<ol class="phs-carousel-indicators">
<li repeat.for = "slide of nearByJobSlides" data-target="#phsNearbyJobs" data-slide-to="${$index}" class="" click.trigger="changeActiveClass()"></li>
</ol>
<a class="right" href="#phsNearbyJobs" role="button" data-slide="next">
Move to Next <i class="fa fa-angle-right"></i>
</a>
</div>
As well how do I pass an event Object on aurelia?
Just use interpolation
<div class="${ applyMyClass ? 'my-class' : '' }">
E.g.
<div class="${ carouselIndex == $index ? 'active' : '' }">
You don't need to do this with a click event, it's the same as ng2 (only less code!)

Bootrstap 3 - list group with accordion functionality

<div class="list-group" id="menu">
MESSAGES <span class="label label-info">5</span> <span class="glyphicon glyphicon-envelope pull-right"></span>
<div id="sm" class="sublinks collapse">
<a class="list-group-item small"><span class="glyphicon glyphicon-chevron-right"></span> inbox</a>
<a class="list-group-item small"><span class="glyphicon glyphicon-chevron-right"></span> sent</a>
</div>
TASKS <span class="glyphicon glyphicon-tag pull-right"></span>
<div id="sl" class="sublinks collapse">
<a class="list-group-item small"><span class="glyphicon glyphicon-chevron-right"></span> saved tasks</a>
<a class="list-group-item small"><span class="glyphicon glyphicon-chevron-right"></span> add new task</a>
</div>
ANOTHER LINK ...<span class="glyphicon glyphicon-stats pull-right"></span>
</div>
In spite of both <a> got data-parent="#menu", none of them appearing triggers other to hide. How to update this code to hide one sublinks as other are visible?
The #menu must be a parent of the list-group, and the list-group needs to have the panel class.
http://www.bootply.com/tGF9MEGbLM