I'm trying to create a Bootstrap multi-column dropdown menu for nav-tabs. With the code below, I can select each tab. When I switch to another tab, I can't go back to the prior tab. It looks like all tabs remain active. How can I fix this?
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.dropdown-menu.multi-column {
width: 400px;
}
.dropdown-menu.multi-column .dropdown-menu {
display: block !important;
position: static !important;
margin: 0 !important;
border: none !important;
box-shadow: none !important;
min-width:100px;
}
</style>
<ul class="nav nav-tabs" id="myTabs" role="tablist">
<li role="presentation" class="active">Summary Table</li>
<li class="dropdown"> States
<div class="dropdown-menu multi-column">
<div class="row">
<div class="col-md-6">
<ul class="dropdown-menu">
<li>Alabama</li>
<li>Alaska</li>
</ul>
</div>
<div class="col-md-6">
<ul class="dropdown-menu">
<li>Maine</li>
<li>Maryland</li>
</ul>
</div>
</div>
</div>
</li>
</ul>
<div class="tab-content" id="myTabContent" style="color:black">
<div class="tab-pane fade in active" role="tabpanel" id="main" aria-labelledby="main-tab">
<table class="table table-striped table-hover table-bordered table-responsive" id="rates">
<thead>
<tr><th>State</th><th>Tax Rate</th></tr>
</thead>
<tbody>
<tr><td id="AL">Alabama</td><td id="AL_T">6.00%</td></tr>
<tr><td id="AK">Alaska</td><td id="AK_T">2.70%</td></tr>
<tr><td id="ME">Maine</td><td id="ME_T">3.00%</td></tr>
<tr><td id="MD">Maryland</td><td id="MD_T">3.00%</td></tr>
</tbody>
</table><br/>
</div>
<div class="tab-pane fade in" role="tabpanel" id="Alabama" aria-labelledby="Alabama-tab">
<h5><span style="text-decoration: underline;">Alabama </span></h5>
</div>
<div class="tab-pane fade in" role="tabpanel" id="Alaska" aria-labelledby="Alaska-tab">
<h5><span style="text-decoration: underline;">Alaska </span></h5>
</div>
<div class="tab-pane fade in" role="tabpanel" id="Maine" aria-labelledby="Maine-tab">
<h5><span style="text-decoration: underline;">Maine </span></h5>
</div>
<div class="tab-pane fade in" role="tabpanel" id="Maryland" aria-labelledby="Maryland-tab">
<h5><span style="text-decoration: underline;">Maryland </span></h5>
</div>
</div>
Add this to the bottom
<script type="text/javascript">
$(function() {
var active = $('a[data-toggle="tab"]').parents('.active').length;
var tabClicked = false;
// Closes current active tab (toggle and pane):
var close = function() {
$('a[data-toggle="tab"]').parent().removeClass('active');
$('.tab-pane.active').removeClass('active');
active = null;
}
// Closing active tab when clicking on toggle:
$('[data-toggle=tab]').click(function(){
if ($(this).parent().hasClass('active')){
$($(this).attr("href")).toggleClass('active');
active = null;
} else {
tabClicked = true;
active = this;
}
});
// Closing active tab when clicking outside tab context (toggle and pane):
$(document).on('click.bs.tab.data-api', function(event) {
if(active && !tabClicked && !$(event.target).closest('.tab-pane.active').length) {
close();
}
tabClicked = false;
});
// Closing active tab on ESC key release:
$(document).keyup(function(e){
if(active && e.keyCode === 27) { // ESC
close();
}
});
});
</script>
And a button before the last < / div >
Close active tab
I know that is not the best solution, but does the work and with a little bit of patience you can do it better.
The answer by #Filipe Amaral was 95% of what this problem needed. After a couple of modifications, it works like a charm.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.dropdown-menu li').click (function(){
$('.dropdown-menu li').removeClass('active')
});
$('#main-tab').click (function(){
$('.dropdown-menu li').removeClass('active')
});
});
$(function() {
var active = $('a[data-toggle="tab"]').parents('.active').length;
var tabClicked = false;
// Closes current active tab (toggle and pane):
var close = function() {
$('a[data-toggle="tab"]').parent().removeClass('active');
$('.tab-pane.active').removeClass('active');
active = null;
}
// Closing active tab when clicking on toggle:
$('[data-toggle=tab]').click(function(){
if ($(this).parent().hasClass('active')){
$($(this).attr("href")).toggleClass('active');
active = null;
} else {
tabClicked = true;
active = this;
}
});
// Closing active tab when clicking outside tab context (toggle and pane):
$(document).on('click.bs.tab.data-api', function(event) {
if(active && !tabClicked && !$(event.target).closest('.tab-pane.active').length) {
close();
}
tabClicked = false;
});
// Closing active tab on ESC key release:
$(document).keyup(function(e){
if(active && e.keyCode === 27) { // ESC
close();
}
});
});
</script>
<style>
.dropdown-menu.multi-column {
width: 400px;
}
.dropdown-menu.multi-column .dropdown-menu {
display: block !important;
position: static !important;
margin: 0 !important;
border: none !important;
box-shadow: none !important;
min-width:100px;
}
</style>
<ul class="nav nav-tabs" id="myTabs" role="tablist">
<li role="presentation" class="active">Summary Table</li>
<li class="dropdown"> States
<div class="dropdown-menu multi-column">
<div class="row">
<div class="col-md-6">
<ul class="dropdown-menu">
<li>Alabama</li>
<li>Alaska</li>
</ul>
</div>
<div class="col-md-6">
<ul class="dropdown-menu">
<li>Maine</li>
<li>Maryland</li>
</ul>
</div>
</div>
</div>
</li>
</ul>
<div class="tab-content" id="myTabContent" style="color:black">
<div class="tab-pane fade in active" role="tabpanel" id="main" aria-labelledby="main-tab">
<table class="table table-striped table-hover table-bordered table-responsive" id="rates">
<thead>
<tr><th>State</th><th>Tax Rate</th></tr>
</thead>
<tbody>
<tr><td id="AL">Alabama</td><td id="AL_T">6.00%</td></tr>
<tr><td id="AK">Alaska</td><td id="AK_T">2.70%</td></tr>
<tr><td id="ME">Maine</td><td id="ME_T">3.00%</td></tr>
<tr><td id="MD">Maryland</td><td id="MD_T">3.00%</td></tr>
</tbody>
</table><br/>
</div>
<div class="tab-pane fade in" role="tabpanel" id="Alabama" aria-labelledby="Alabama-tab">
<h5><span style="text-decoration: underline;">Alabama </span></h5>
</div>
<div class="tab-pane fade in" role="tabpanel" id="Alaska" aria-labelledby="Alaska-tab">
<h5><span style="text-decoration: underline;">Alaska </span></h5>
</div>
<div class="tab-pane fade in" role="tabpanel" id="Maine" aria-labelledby="Maine-tab">
<h5><span style="text-decoration: underline;">Maine </span></h5>
</div>
<div class="tab-pane fade in" role="tabpanel" id="Maryland" aria-labelledby="Maryland-tab">
<h5><span style="text-decoration: underline;">Maryland </span></h5>
</div>
</div>
Related
In a previous question, I asked how to achieve something like this:
Where clicking any tab would reveal the contents of said tab and keep those of other tabs hidden. #BradleyCoupland suggested the following code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div style="text-align: justify">[Introduction text]</div>
<br>
<br>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#Vspoiler" id="defaultOpen" onclick="openPage('Vspoiler')">Vulgate version</a></li>
<li><a data-toggle="tab" href="#Cspoiler" onclick="openPage('Cspoiler')">Campbell version</a></li>
</ul>
<div id="Vspoiler" class="tab-pane tabcontent active">
<br>
<table>
<tbody>
<tr>
<td>
<div class="column" style="padding-left: 80px">
[Contents of col 1 of tab 1]
</div>
</td>
<td>
<div class="column" style="padding-left: 80px">
[Contents of col 2 of tab 2]
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="Cspoiler" class="tab-pane tabcontent">
<br>
<table>
<tbody>
<tr>
<td>
<div class="column" style="padding-left: 80px">
[Contents of col 1 of tab 2]
</div>
</td>
<td>
<div class="column" style="padding-left: 80px">
[Contents of col 2 of tab 2]
</div>
</td>
</tr>
</tbody>
</table>
</div>
<script>
function openPage(pageName) {
var i, tabcontent;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
document.getElementById(pageName).style.display = "block";
}
document.getElementById("defaultOpen").click();
</script>
And it worked like a charm. But suppose I now want to do multiple independent sets of tabs, like this:
I tried just copy-pasting the <ul> part twice, and the result was that the second set of tabs showed nothing on loading, and clicking on a tab in any tab set would do the right thing in its set, but hide all the tabs of the other set as well. For example, clicking on "weird-meter older reconstruction" would show what you see in the image for that tab, but hide the contents of the "P.Oxy. version" tab below. Simplifying the code above to a minimal example:
<div style="text-align: justify">Intro</div>
<br>
<br>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#Vspoiler" id="defaultOpen" onclick="openPage('Vspoiler')">Vulgate version</a></li>
<li><a data-toggle="tab" href="#Cspoiler" onclick="openPage('Cspoiler')">Campbell version</a></li>
</ul>
<div id="Vspoiler" class="tab-pane tabcontent"><br>
Pefanthi
</div>
<div id="Cspoiler" class="tab-pane tabcontent"><br>
Abanthi
</div>
<br>
<br>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#Vspoiler2" id="defaultOpen" onclick="openPage('Vspoiler2')">Vulgate version</a></li>
<li><a data-toggle="tab" href="#Cspoiler2" onclick="openPage('Cspoiler2')">Campbell version</a></li>
</ul>
<div id="Vspoiler2" class="tab-pane tabcontent"><br>
Pefanthi
</div>
<div id="Cspoiler2" class="tab-pane tabcontent"><br>
Abanthi
</div>
<br>
<br>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
function openPage(pageName) {
var i, tabcontent;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
document.getElementById(pageName).style.display = "block";
}
document.getElementById("defaultOpen").click();
</script>
Which loads to this:
And where clicking the lower "Vulgate version" tab produces this:
Now the obvious solution to this problem is to duplicate the script, by making an otherwise identical function openPage2 which appends a 2 to everything it works with, and then use openPage2, tabcontent2 and defaultOpen2 for the second set of tabs and the no-2 versions for the first one. Now suppose you have more than 2 sets. Say you have 10. 10 scripts? Surely there must be a less clumsy way of fixing this problem? I was thinking maybe one could set a variable to store the number of tabs and then make a script with a for loop that would result in running all the openPage<x> scripts at the right time by writing a single script, but I'm not sure how to go about this.
Any suggestions?
You don't need to use javascript to close/toggle the nav-tabs, bootstrap has this functionality built in. The reason why it's not working out of the box is because there are a few things missing in the html. You need to wrap all the tab content inside a div with class="tab-content" as shown below:
<ul class="nav nav-tabs">
<!-- add data-toggle attribute to the anchors -->
<li class="active"><a data-toggle="tab" href="#home">Home</a></li>
<li><a data-toggle="tab" href="#menu1">Menu 1</a></li>
<li><a data-toggle="tab" href="#menu2">Menu 2</a></li>
</ul>
<div class="tab-content"> <!-- wrapper for all tab content -->
<div id="home" class="tab-pane fade in active">
<h3>HOME</h3>
<p>Some content.</p>
</div>
<div id="menu1" class="tab-pane fade">
<h3>Menu 1</h3>
<p>Some content in menu 1.</p>
</div>
<div id="menu2" class="tab-pane fade">
<h3>Menu 2</h3>
<p>Some content in menu 2.</p>
</div>
</div>
Here is a live demo stacking two of the snippets above:
https://www.bootply.com/WuuHKy9jwR
Here is the code that I am trying to improve
http://jsbin.com/cexixamuma/edit?html,output
The links are foldable, they fold when the user clicks on them.
Mu understanding is that the a:visited css is not honored by the newer browsers for privacy reasons.
I would like to give to my readers the option to check mark a like (✔) when they are done with the topic but my problem is that the when the user clicks on the link (line) the event is already used to fold, unfold the line What other options do I have?
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript">
window.toggleDiv = function(divId) {
var ele = document.getElementById(divId);
var state=jQuery(ele).is(':visible');
jQuery(ele).toggle();
state=jQuery(ele).is(':visible');
localStorage.setItem( divId, state);
}
</script>
<script type="text/javascript">
(function($){
$( document ).ready(function() {
$(".collapsible").each(function(index) {
if (typeof($(this).attr('id'))!="undefined") {
id=$(this).attr('id');
var state = localStorage.getItem(id);
ele = document.getElementById(id);
if (state=="true") {
ele.style.display = 'block' ;}
else {
ele.style.display = 'none'; }
}
});
});
})(jQuery)
</script>
<link rel="stylesheet" type="text/css" href="https://aa4d96bd21c195e7b862b851b0818e89fb8ee102.googledrive.com/host/0B77cxO0Vjbb2MlYyUFpmVXhTUWc/knowledgetree.css" />
<a class="ConceptLevel1" href="javascript:toggleDiv('PktS/h+L5EeSqM/4hMH9JA==');" style="font-
size:13pt">Root</a><br>
<div class="collapsible" style="display:none " id="PktS/h+L5EeSqM/4hMH9JA==">
<a class="ConceptLevel2" href="javascript:toggleDiv('KlHtq+Xe60essn+0zs9E6g==');" style="font-
size:12pt">level 1</a><br>
<div class="collapsible" style="" id="KlHtq+Xe60essn+0zs9E6g==">
<div>Level 2</div>
<a class="ConceptLevel3" href="javascript:toggleDiv('EdMUp+28okWIWHVbvUaU1g==');" style="font-
size:11pt">Level 2</a><br>
<div class="collapsible" style="" id="EdMUp+28okWIWHVbvUaU1g==">
<a class="ConceptLevel4" href="javascript:toggleDiv('wIZCSCx/Xk2YShMAkF33Pg==');"
style="font-size:10pt">Level 3</a><br>
<div class="collapsible" style="" id="wIZCSCx/Xk2YShMAkF33Pg==">
<div>Level 4</div>
<a class="ConceptLevel5" href="javascript:toggleDiv('7GKbN5XRqkybT
+XsbHkyqw==');" style="font-size:9pt">Level 4</a><br>
<div class="collapsible" style="" id="7GKbN5XRqkybT+XsbHkyqw==">
<div>Level 5</div>
<a class="ConceptLevel6" href="javascript:toggleDiv
('rV75pTUXp0KP6Mx6EJznDg==');" style="font-size:8pt">Level 5</a><br>
<div class="collapsible" style="display:none "
id="rV75pTUXp0KP6Mx6EJznDg==">
<div class="details">Conclusion: for all the below levels ....</div>
<a class="ConceptLevel7" href="javascript:toggleDiv
('a5qCUDoqI0CPlS4pPGcODQ==');" style="font-size:7pt">Level 6</a><br>
<div class="collapsible" style=""
id="a5qCUDoqI0CPlS4pPGcODQ==">
<div>Level 7</div>
<div>Level 7</div>
</div>
<div>Level 6</div>
</div>
</div>
</div>
<div>Level 3</div>
</div>
</div>
</div>
Update: I ended up using dblclick for marking the paragraph as done
So basically you need to add a class for the visited links? With jQuery that would be: .addClass().
I have a JSON file which has this structure:
{ "short_title":"HB_START_SHORT_TITLE",
"tips{"1":"HB_START_TIPS_1_1","2":"HB_START_TIPS_1_2","3":"HB_START_TIPS_1_3","4":"HB_START_TIPS_1_4"},
},
I would like to print the nested item "tips" as a slider with previous-next buttons.
Therefore I wrote this code in my HTML below:
<ul class="sb-parentlist">
<div data-ng-repeat="parts in data track by $index">
<li>
<div class="sb-open" ng-show="showDetails">
{{parts.short_text|translate}}
<br>
<li><span class="sb-text-title" href="#" ng-click="OpenTips = ! OpenTips"><b>Tips</b></span>
<span ng-show="OpenTips" class="sb-open">
<br>
<div ng-repeat="data in parts.tips track by $index" ng-class="{'tips-hide': $index > $index + 1}">
{{data|translate}}
<br>
<div class="keys">
<button type="button" class="btn btn-pre" ng-click="$index = $index > 1 ? $index - 1 : 1">Previous</button>
<button type="button" class="btn btn-next" ng-click="$index = $index < data.length ? $index + 1 : data.length">Next</button>
</div>
</div>
</span>
</li>
</ul>
</div>
</li>
</div>
</ul>
and the tips-hide class in CSS:
.tips-hide {
left: -100px !important;
opacity: 0 !important;
}
.sb-open {
display: block;
height: auto;
opacity: 1;
transition:all 0.6s ease;
li {
display: block;
}
}
But what I am getting is every element in the list one after the other, with the buttons on the bottom of each one of them.
ScreenShot below:
ng-repeat on object can't be tracked by index (at least not in that way)
I've changed few parts on code to simulate on code snippet, see if it helps.
var app = angular.module('app', []);
app.controller('DemoCtrl', function($scope) {
this.openTips = true;
$scope.tipsIndex = 1;
this.info = [{ "short_title":"HB_START_SHORT_TITLE",
"tips" : {"1":"HB_START_TIPS_1_1","2":"HB_START_TIPS_1_2","3":"HB_START_TIPS_1_3","4":"HB_START_TIPS_1_4"}
}];
$scope.decrement = function() {
if($scope.tipsIndex > 1){
$scope.tipsIndex = $scope.tipsIndex - 1;
}
};
$scope.increment = function(partsIndex) {
if($scope.tipsIndex < partsIndex){
$scope.tipsIndex = $scope.tipsIndex + 1;
}
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="app">
<div ng-controller="DemoCtrl as demo">
<ul class="sb-parentlist">
<ul class="sb-parentlist">
<div data-ng-repeat="parts in demo.info track by $index">
<li>
<div class="sb-open">
{{parts.short_title}}
<br>
<li><span href="#" ng-click="demo.openTips = !demo.openTips"><b>Tips</b></span>
<span ng-show="demo.openTips" class="sb-open">
<br>
<div ng-repeat="(key, value) in parts.tips" ng-show="key == tipsIndex">
{{key}}
{{value}}
<br>
<div class="keys">
{{Object.size(parts.tips)}}
</div>
</div>
<button ng-click='decrement()'>Previous</button>
<button type="button" class="btn btn-next" ng-click="increment(3)">Next</button>
</span>
</li>
</div>
</ul>
</li>
</div>
</ul>
</ul>
</div>
</body>
Ok, so I'm currently trying to create a simple weather app as part of learning how to use RSS feeds. I have the weather being displayed as text E.g. Friday: Sunny, Max Temp, Min Temp.
I want to change that text into symbols, so that instead of saying "Sunny" it displayed the image of a sun. I'll show the HTML and Javascript below. Hopefully it makes sense and I can get this problem sorted out.
HTML
<div id="home" data-role="page">
<div data-role="header" data-add-back-btn="true" >
<h1>Your Handy Little Weather App</h1>
</div>
<div data-role="content">
<img src ="./images/UWSLogo.png" width ="174" height ="116" alt ="Logo" align ="right"/>
<h2>UWS Weather</h2>
<p>Check the weather at the UWS Campuses.</p>
<p>Choose your desired location.</p>
<ul data-role="listview" data-inset="true">
<li><a id="ayrFeed" href="#ayr">Ayr</a></li>
<li><a id="dumfriesFeed" href="#dumfries">Dumfries</a></li>
<li><a id="hamiltonFeed" href="#hamilton">Hamilton</a></li>
<li><a id="paisleyFeed" href="#paisley">Paisley</a></li>
</ul>
<h2>Other Weather</h2>
<p>Find out more with our other weather options.</p>
<ul data-role="listview" data-inset="true">
<li><a id="uniFeed" href="#uni">Other Universities</a></li>
<li><a id="holidayFeed" href="#holiday">Popular Holiday Destinations</a> </li>
</ul>
</div>
</div>
</div>
<div id="ayr" data-role="page">
<div data-role="header">
<h1 id="ayrTitle"></h1>
</div>
<div data-role="content">
<ul id="ayrList" data-role="listview" data-inset="true">
<!-- Weather reports go here. -->
</ul>
</div>
</div>
<div id="dumfries" data-role="page">
<div data-role="header">
<h1 id="dumfriesTitle"></h1>
</div>
<div data-role="content">
<ul id="dumfriesList" data-role="listview" data-inset="true">
<!-- Weather reports go here. -->
</ul>
</div>
</div>
</div>
<div id="hamilton" data-role="page">
<div data-role="header">
<h1 id="hamiltonTitle"></h1>
</div>
<div data-role="content">
<ul id="hamiltonList" data-role="listview" data-inset="true">
<!-- Weather reports go here. -->
</ul>
</div>
</div>
Javscript
$(document).ready(function() {
$("#ayrFeed").bind('click', function() {
getFeed("http://open.live.bbc.co.uk/weather/feeds/en/2656708/3dayforecast.rss",
showAyrWeatherFeed);
});
$("#dumfriesFeed").bind('click', function() {
getFeed("http://open.live.bbc.co.uk/weather/feeds/en/2650798/3dayforecast.rss",
showDumfriesWeatherFeed);
});
$("#hamiltonFeed").bind('click', function() {
getFeed("http://open.live.bbc.co.uk/weather/feeds/en/2647570/3dayforecast.rss",
showHamiltonWeatherFeed);
});
function getFeed(url, success){
if(window.navigator.onLine) {
$.jGFeed(url, function(feeds) {
// Check for errors
if(!feeds){
// there was an error
return false;
} else {
localStorage.setItem(url, JSON.stringify(feeds));
success(feeds.title, feeds.entries);
}
});
} else {
// Get the fall-back...
var feed = JSON.parse(localStorage.getItem(url));
if(feed && feed.length > 0) {
success(feed.title, feed.entries);
}
}
}
function showPaisleyWeatherFeed(title, items) {
$("#paisleyTitle").text(title);
var list = $("#paisleyList");
list.empty();
for(var index = 0; index < items.length; index += 1) {
list.append(formatItem(items[index]));
}
$.mobile.changePage($("#paisley"), "flip");
list.listview("refresh");
}
function showHamiltonWeatherFeed(title, items) {
$("#hamiltonTitle").text(title);
var list = $("#hamiltonList");
list.empty();
for(var index = 0; index < items.length; index += 1) {
list.append(formatItem(items[index]));
}
$.mobile.changePage($("#hamilton"), "flip");
list.listview("refresh");
}
function formatItem(item) {
var listItem = document.createElement("li"),
anchor = document.createElement("a");
anchor.setAttribute("href", item.link);
anchor.innerText = item.title;
listItem.innerHTML = anchor.outerHTML;
return listItem.outerHTML;
}
<img src="url" alt="some_text">
Just add this to your code and include the url of the image you would like in the tag.
Here's a FIDDLE with little example if it helps you.
<div>New York Sunny 85F</div>
div {
background: #ddd;
width: 200px;
height: 80px;
line-height: 80px;
font-size: 23px;
text-align: center;
border-radius: 4px;
}
.weather-icon {
width: 38px;
height: 38px;
vertical-align: text-bottom;
}
$(function() {
$('div').html(function() {
return $(this).html().replace('Sunny','<img src="https://cdn1.iconfinder.com/data/icons/iconsland-weather/PNG/256x256/Sunny.png" class="weather-icon">');
});
});
I've a nav bar and when I click any tab in the nav bar, it takes me to that tab.
<section id="tabs">
<div class="mob-nav">
<div class="nav nav-tabs nav-fill nav-tabs-scroll" id="nav-tab" role="tablist">
<!-- N add new class nav-tabs-scroll -->
<a class="nav-item nav-link" style="padding-top: 10px;"
ng-class="{ active: $index == 0 }"
id="nav-{{menuTab.menuURL}}-tab"
data-toggle="{{menuTab.dataToggle}}"
data-target="#{{menuTab.menuURL}}"
href="#{{menuTab.menuURL}}" role="tab"
aria-controls="nav-{{menuTab.menuURL}}"
ng-repeat="menuTab in menuList">
</a>
</div>
</div>
</section>
<!-- Tab Details -->
<section id="tabs">
<div class="">
<div class="">
<div class="mb-d-150">
<div class="tab-content py-3 px-sm-0 pl-0 pr-0"
id="nav-tabContent">
<!-- N removed py-3 class -->
<div class="tab-pane fade show"
ng-class="{ active: $index == 0 }"
id="{{menuTab.menuURL}}" role="tabpanel"
data-target="#{{menuTab.menuURL}}"
aria-labelledby="nav-{{menuTab.menuURL}}-tab"
ng-include="menuTab.colDef"
ng-repeat="menuTab in menuList">
</div>
<div class="tab-pane fade" id="changepass" role="tabpanel"
aria-labelledby="nav-about-tab"
ng-include="changePasswordTemplate">
</div>
</div>
</div>
</div>
</div>
</section>
Here's an example of menuList.
[{
menuID: "USER LANDING PAGE"
caption: "Dashboard"
parent: "root"
menuURL: "exampleModal"
cssClass: "fas fa-cog fa-lg"
cssParent: "nav navbar-nav"
aClass: "customerLandingPageTemplate"
SlNum: 98
colDef: "/js/templates/user-landing-page.html"
menuList: []
dataToggle: "modal"
},{
menuID: "USER QUERIES"
caption: "USER QUERIES"
parent: "root"
menuURL: "user-queries"
cssClass: "fas fa-comment-alt fa-lg"
cssParent: "nav navbar-nav"
aClass: "userQueriesTemplate"
SlNum: 100
colDef: "/js/templates/user-queries.html"
menuList: []
dataToggle: "tab"
}]
Here's the angularjs part which gives me the menuList:
GetData.async(CONFIG.urlMaker('ws/menulist?userid=' + userid)).then(function (data) {
$scope.menuList = data;
console.log($scope.menuList)
});
When I refresh browser, it always takes me back to the USER LANDING PAGE no matter where I refresh. But on browser refresh, I need to reload the page where I was before refreshing.
You could use the session storage for saving the last state.
Internal code snippet does not allow to use session storage.
A working example on JSBin.
angular.module('app', ['ui.router'])
.config(($stateProvider) => {
const helloState = {
name: 'hello',
url: '/hello',
template: '<h3>hello world!</h3>'
}
const aboutState = {
name: 'about',
url: '/about',
template: '<h3>Its the UI-Router hello world app!</h3>'
}
$stateProvider.state(helloState);
$stateProvider.state(aboutState);
})
.run(($state, $transitions) => {
$transitions.onSuccess({}, transition => {
sessionStorage.setItem('lastState', transition.to().name);
});
const lastState = sessionStorage.getItem('lastState');
if (lastState) {
$state.go(lastState);
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.9/angular.min.js"></script>
<script src="//unpkg.com/#uirouter/angularjs/release/angular-ui-router.min.js"></script>
<body ng-app="app">
<a ui-sref="hello" ui-sref-active="active">Hello</a>
<a ui-sref="about" ui-sref-active="active">About</a>
<ui-view></ui-view>
</body>