Bootstrap UI Collapse directive behaving weird - html

I'm a bit stumped with a problem with the bootstrap.ui module for AngularJS.
This is my HTML:
<nav id="sidebar">
<ul id="main-nav" class="open-active">
<li ng-controller="CollapseCtrl" class="dropdown">
<a ng-click="isCollapsed = !isCollapsed" href="javascript:;">
<i class="fa fa-wrench"></i>
Verktøy
<span class="caret"></span>
</a>
<ul ng-show="isCollapsed" class="sub-nav">
<li>
<a href="#/vernerunde">
<i class="fa fa-th-list"></i>
Ny Vernerunde
</a>
</li>
<li>
<a href="#/interaksjon">
<i class="fa fa-gears"></i>
Ny Interaksjon
</a>
</li>
<li>
<a href="#/brukerstyring">
<i class="fa fa-user"></i>
Brukerstyring
</a>
</li>
</ul>
</li>
<li ng-controller="CollapseCtrl" class="dropdown">
<a ng-click="isCollapsed = !isCollapsed" href="javascript:;">
<i class="fa fa-search"></i>
Lister
<span class="caret"></span>
</a>
<ul ng-show="isCollapsed" class="sub-nav">
<li>
<a href="#/list">
<i class="fa fa-desktop"></i>
Alle
</a>
</li>
</ul>
</li>
</ul>
</nav>
And this is the controller responsible for the isCollapsed model:
controllers.controller('CollapseCtrl', function ($scope) {
$scope.isCollapsed = false;
});
I've also made a small gif which I'm going to throw in that shows my actual problem. Now, I'm not too sure whether or not it's present in the gif, but it seems if I click the first element in the list, it works. Then when that first element has been toggled, and I click the element underneath, it totally breaks apart.
EDIT1:
Okay, I changed the directive from ng-show="" to collapse="", still using "isCollapsed". Now it's working, but the height of the box that's collapsed is too small.

Though I don't have much insight into the problem I strongly suspect that the issue is in here:
<a ng-click="isCollapsed = !isCollapsed" href="javascript:;">
<i class="fa fa-wrench"></i>
Verktøy
<span class="caret"></span>
</a>
Mind that the ng-click is executed once , but once a variable changes, the scope lifecycle will recalculate the scope several times. And once a variable which depends on isCollapsed will change, the scope is re-calculated again, and so forth. This might explain the unusual openings and closings of the title panes. Although I don't see exactly why isCollapse is recalculated.
Solution: Move it as a method inside the controller.

Related

How to keep the selected accordion active on page reload

I am using materialize collapsible for my navigation. Everything works fine except when I reload the page. The collapsible gets closed and I have to manually make it active again. How do I make the collapsible remain active on page reload?
Here's my code:
<ul id="slide-out" class="side-nav fixed leftside-navigation">
<ul class="collapsible" data-collapsible="expandable">
<li>
<a class="collapsible-header">
<i class="material-icons">home</i> Home
</a>
<div class="collapsible-body">
<ul>
<li ui-sref-active="active">
<a ui-sref="protect" ui-sref-opts="{reload: true}">
<i class="material-icons">dashboard</i> Dashboard
</a>
</li>
<li ui-sref-active="active">
<a ui-sref="store" ui-sref-opts="{reload: true}">
<i class="material-icons">cloud_done</i> Storage
</a>
</li>
</ul>
</div>
</li>
<li>
<a class="collapsible-header">
<i class="material-icons">event_available</i>Manage
</a>
<div class="collapsible-body">
<ul>
<li ui-sref-active="active">
<a ui-sref="manage" ui-sref-opts="{reload: true}">
<i class="material-icons">storage</i> Manage Storage
</a>
</li>
<li ui-sref-active="active">
<a ui-sref="enroll" ui-sref-opts="{reload: true}">
<i class="material-icons">file_download</i> Enroll
</a>
</li>
</ul>
</div>
</li>
</ul>
</ul>
What you want to do concerns program state, hence there's no way for you to do that unless you save the name or id of the active accordion. which can easily be done using browser local storage.

Default tab setting upon page load

How do I set the default tab to be 'active' or 'viewed'?
As far as I understand the code below should set the 'add user' as the active tab and display the content in #addUser upon page load but not in my case. The add user tab is not displayed and I have to click on the other tabs and back at the add user tab again to see the content. Am I missing something? Most of my research returns me to set a class as active but still isn't working for me.
<li role="presentation" class="active">
<a href="#addUser" role="tab" data-toggle="tab">
<i class="fa fa-plus"></i> Add User
</a>
</li>
Here's the code for the creation of the tabview.
<div class="content-body">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a href="#addUser" role="tab" data-toggle="tab">
<i class="fa fa-plus"></i> Add User
</a>
</li>
<li role="presentation">
<a href="#rUser" role="tablist" data-toggle="tab">
<i class="fa fa-minus"></i> Remove User
</a>
</li>
<li role="presentation">
<a href="#eUser" role="tab" data-toggle="tab">
<i class="fa fa-pencil-square-o"></i> Edit User
</a>
</li>
</div>
based on this the only thing i see is that you forgot to close your ul tag at the end.

How do I fix my lists so I don't have to toggle twice before the icon updates?

Basically what happens is when I load my page and then drop down either my outer collapsible menu (the .admin) or the nested collapsible menu (.unitsofstudy), it does not update the glyphicon I have set using the :after selector unless I toggle it twice.
Would anyone be able to take a look and see if they can spot where I have screwed this up; I have been at this for a few hours now trying to fix but with no success. If any more info is needed let me know.
HTML:
<div id="sidebar-collapse" class="col-sm-3 col-lg-2 sidebar">
<ul class="nav menu" id="navmenu-sidebar">
<!-- Admin dropdown -->
<li>
<a class="admin" data-toggle="collapse" href="#admin"><i class="fa fa-tasks" style="margin-right: 16px;"></i>Admin</a>
<ul id="admin" class="nav collapse">
<li>
<a class="unitsofstudy" data-toggle="collapse" href="#unitsofstudy"> <i class="fa fa-book" style="margin-right: 12px;"></i>Units of Study</a>
<ul id="unitsofstudy" class="nav collapse">
<li>
<i class="fa fa-book" style="margin-right: 8px;"></i> View Units
</li>
<li>
<i class="fa fa-plus" style="margin-right: 10px;"></i> Create Unit Offerings
</li>
<li>
<i class="fa fa-plus" style="margin-right: 10px;"></i> Register Units
</li>
<li>
<i class="fa fa-plus" style="margin-right: 10px;"></i> Register Semesters
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
My CSS:
.admin:after, .unitsofstudy:after {
font-family: 'Glyphicons Halflings';
content: "\e114";
float: right;
color: grey;
}
.admin.collapsed:after, .unitsofstudy.collapsed:after {
content: "\e080";
}
You need to give your anchors an initial class of .collapsed
<li>
<a class="admin collapsed" data-toggle="collapse" href="#admin">
<i class="fa fa-tasks" style="margin-right: 16px;"></i>Admin
</a>
</li>
So class both admin and unitsofstudy to let bootstrap know the initial state of the menu is collapsed
Working example
http://codepen.io/jcoulterdesign/pen/6443069430f54e0b635e726c2cb9da02

Adding Thumbnail Image to Bootstrap Dropdown Menu

I am trying to add a user's profile picture to a dropdown menu using Bootstrap 3.
Here is a code snippet of the dropdown menu currently in my code:
<ul class="nav navbar-right top-nav">
<li class="dropdown">
<i class="fa fa-user"></i>Administrator <b class="caret"></b>
<ul class="dropdown-menu">
<img class="thumbnail" style="height:100px; float-left; margin:10px" src="default.jpg">
<li>
<i class="fa fa-fw fa-user"></i> Profile
</li>
<li>
<i class="fa fa-fw fa-envelope-o"></i>Send email report
</li>
<li>
<i class="fa fa-fw fa-gear"></i> Settings
</li>
<li class="divider"></li>
<li>
<i class="fa fa-fw fa-power-off"></i> Log Out
</li>
</ul>
</li>
</ul>
This is what it currently looks like:
I have tried putting the unordered list inside of a div and gave the div the dropdown class, but this broke the nice style of the links in this menu. Also it would require a lot more formatting to move the list next to the picture.
Is there any way to create a dropdown menu with a picture floated to the left of the list items??
Thank you in advance for any help with this problem.

Bootstrap list with badges: put icon right to the badge

I have a Twitter Bootstrap list with badges, and I have also added a delete icon I currently have two problems:
The badge is automatically situated to the right of the list row, and I want the delete icon to be after and not before the badge (I think it would look better that way). I guess I'm going to need to redefine the badge style, but don't know how to do that.
The delete icon is not vertically aligned correctly, and I haven't found the way to fix it either.
HTML:
<div class="panel-body">
<ul id="mylist" class="list-group">
<li id="item1" href="#" class="list-group-item">Item1 <span id="badge" class="badge">5</span>
<i class="fa fa-remove fa-2x pull-right" style="color: red;"></i>
</li>
<li id="item2" href="#" class="list-group-item">Item2 <span id="badge" class="badge">-10</span>
<i class="fa fa-remove fa-2x pull-right" style="color: red;"></i>
</li>
</ul>
</div>
Here is a JSFiddle with a small example of my situation.
Any help?
The bootstrap elements like pull-right have the property as:
float : right
Under this property, the Document Object Model is reversed. Like:
<span>First</span><i>Second</i>
would be displayed as: (Note Only Displayed as - DOM is still same.)
<i>Second</i><span>First</span>
Ans your Solution is JSFiddle is: http://jsfiddle.net/r77wkzcg/5/ (Updated)
In right Alignment, the point of connection is right. So, the first element in the DOM gets the priority to attach to the right. Explained here: http://jsfiddle.net/tpahadi/rrrr3wq3/1/
For your items use:
<li id="item1" href="#" class="list-group-item">Item1
<div class="pull-right">
<span id="badge" class="badge" style="float:left;">5</span>
<i class="fa fa-remove fa-2x" style="color: red;"></i>
</div>
</li>
Just put the icon after the badge, it depends of html elements order :
<li id="item1" href="#" class="list-group-item">
Item1
<span id="badge" class="badge">5</span> <!-- first -->
<i class="fa fa-remove fa-2x pull-right" style="color: red;"></i> <!-- second -->
</li>
And for the vertical centering of the delete icon, you can shift top the icon with a negative margin top (it's not clean but it work, just use a precise selector to avoid overriding all bootstrap elements)
See this fiddle
Put the fa-remove icon span first..
<div class="panel-body">
<ul id="mylist" class="list-group">
<li id="item1" href="#" class="list-group-item">
<i class="fa fa-remove fa-2x pull-right" style="color: red;"></i>Item1 <span id="badge" class="badge">5</span>
</li>
<li id="item2" href="#" class="list-group-item">
<i class="fa fa-remove fa-2x pull-right" style="color: red;"></i>Item2 <span id="badge" class="badge">-10</span>
</li>
</ul>
</div>
http://bootply.com/8wySK2DPfw