Tab highlighting based on buttons in angularjs - html

I have 3 tabs in my application, as below:
<li ng-class="{ active: isActive('#one')}"><a data-toggle="tab" class="tab-txt-color" href="#one" ng-click="selectTab('fruits')">Fruits</a></li>
<li ng-class="{ active: isActive('#two')}"><a data-toggle="tab" class="tab-txt-color" href="#two" ng-click="selectTab('veggies')">Veggies</a></li>
<li ng-class="{ active: isActive('#three')}"><a data-toggle="tab" class="tab-txt-color" href="#three" ng-click="selectTab('decors')">Decors</a></li>
.js
$scope.isActive = function (viewLocation) {
return viewLocation === $location.path();
};
For above code, when any of the tab is clicked it gets highlighted.
But I have previous and next buttons added to the content of above tabs. How do I make the respective tab active when clicked on previous button.
<div>
.......
......
....(content of Veggies tab)
[End of this tab there are 2 buttons]
<div class="col-md-12 col-lg-12" style="margin-top:20px;" align="right">
<img src="core/static/images/previous-btn.gif" border="0" ng-click="selectTab('fruits')">
<img src="core/static/images/next-btn.gif" border="0" ng-click="selectTab('decors')">
</div>
Please help. thanks in advance!

I have an answer if you need the next and previous actions should work on sequence.
Add an array of tabs with its names and a variable to store the current tab name
$scope.tabs = ["fruits","veggies","decors"];
$scope.currentTab = "";
Add 2 more methods for Previous and Next button click
$scope.nextTab = function(){
if($scope.currentTab == ""){
$scope.selectTab(tabs[0]);
}
else {
var index = $scope.tabs.indexOf($scope.currentTab);
var nextIndex = ((index + 1) < $scope.tabs.length) ? (index+1) : 0;
$scope.selectTab($scope.tabs[nextIndex]);
}
}
$scope.prevTab = function() {
if($scope.currentTab == ""){
$scope.selectTab(tabs[0]);
}
else {
var index = $scope.tabs.indexOf($scope.currentTab);
var prevIndex = ((index == 0) ? ($scope.tabs.length - 1) : (index-1);
$scope.selectTab($scope.tabs[prevIndex]);
}
}
Add one more line in selectTab method to store current tab name
$scope.selectTab = function(tab){
//other functionalities
//add this line
$scope.currentTab = tab;
}
Update click methods in Next and Previous buttons
<img src="core/static/images/previous-btn.gif" border="0" ng-click="prevTab()">
<img src="core/static/images/next-btn.gif" border="0" ng-click="nextTab()">
Hope it will help you.

Related

How can I load a tab via a link on my web application?

thanks for your time firstly.
Problem: I am trying to link to a profile page on my web application from a number of different places, how can I have a button redirect to a certain tab on this page?
<div class="row">
<div class="col-lg-12">
<div class="card card-tab">
<div class="card-header">
<ul class="nav nav-tabs">
<li role="tab1" class="active">
Profile
</li>
<li role="tab2">
Alerts
</li>
<li role="tab3">
Settings
</li>
<sec:authorize access="hasRole('ADMIN')">
<li role="tab4">
Admin
</li>
</sec:authorize>
</ul>
</div>
When I click a tab I can see it will be amending the url to /profile#tab1/2/3 etc however linking to that directly just displays the profile page.
https://github.com/symonk/Release-Management/blob/master/Releases/src/main/webapp/WEB-INF/views/profile.jsp
I'm guessing some Javascript will do the trick, but im not really sure where to begin
I browsed the link you gave, you use Bootstrap for the tabs and I noticed you also use jQuery.
A solution for you might be to use anchors in URL and activate the tab based on this.
For example if you go to http://sample-env.qp3bsthmnq.eu-west-2.elasticbeanstalk.com/profile#tab3
After having added this in your code :
var loadTab = function() {
var tabId = location.hash;
if(tabId !== undefined && $('.nav-tabs a[href="' + tabId + '"]') !== undefined) {
$('.nav-tabs a[href="' + tabId + '"]').tab('show');
}
};
$(document).ready(function() {
loadTab();
});
This must have activated the tab with id #tab3

LightGallery with JqueryMobile

I have a little problem with LightGallery plugin (lightGallery - Git). I use jQueryMobile.
My gallery is on a specific page. When I arrive on this page, it will request a remote server to get some pics.
Then I initialize LightGallery. No problem the first time.
But when I leave the Gallery Page and come back after (there is a new request to server), lightGallery is not running.
No error in the browser, I have my photos displayed but I can't click on it to run LightGallery like I've done the first time.
My Code:
HTML:
<div data-role="page" id="pageGallery" data-theme="a">
<div data-role="content" class="center-body">
<h3 class="nomGroupe"></h3><br/>
<div class="demo-gallery">
<ul id="lightgallery" class="list-unstyled row">
</ul>
</div>
</div>
</div>
Javscript :
$( document ).on( "pagecontainerbeforeshow", function ( event, ui ) {
var activePage = $.mobile.pageContainer.pagecontainer( "getActivePage" );
if (activePage[0].id == "pageGallery" ) {
$('#lightgallery').empty();
$(".groupName").empty().append("group "+localStorage['groupName']);
envoieRequete('http://myServer/', {'idGroup' : localStorage['idGroup'], 'token' : localStorage['token']}, 'post', function(output){
if(output.group.photos.length === 0) {
$("#lightgallery").append('<br/><p>Empty for Group : ' + localStorage['groupName']+'</p>');
}
else {
for(i=0; i<output.group.photos.length; i++) {
$('#lightgallery').append('<li class="col-xs-6 col-sm-4 col-md-3" data-responsive="http://myServer/'+localStorage['token']+'/'+localStorage['idGroup']+'/' + output.group.photos[i].id
+ '" data-src="http://myServer/'+localStorage['token']+'/'+localStorage['idGroup']+'/' + output.group.photos[i].id + '" data-sub-html="<h4>PhotoAlt</H4>"><a href=""><img class="img-responsive"\n\
src="http://myServer/'+localStorage['token']+'/'+localStorage['idGroup']+'/' + output.group.photos[i].id + '"/></a></li>');
}
}
});
}
});
$(document).on("pagecontainershow", function () {
var activePage = $.mobile.pageContainer.pagecontainer("getActivePage");
var activePageId = activePage[0].id;
switch (activePageId) {
case 'pageGallery':
$(document).on("tap", "#lightgallery li", function (){
$('#lightgallery').lightGallery({});
});
}
});
You might be using wrong html markup. you can check the following code for reference. This is sample code.
HTML
<div class="row">
<div class="large-12 columns">
<ul class="small-block-grid-2 medium-block-grid-3" id="lightgallery">
<li> <a class="item" href="img/alchemy_icon1.jpg"><img src="img/alchemy_icon1_th.jpg"></a>
</li>
<li> <a class="item" href="img/chandra1.jpg"><img src="img/chandra1-th.jpg"></a>
</li>
<li> <a class="item" href="img/Fish.jpg"><img src="img/Fish-th.jpg"></a>
</li>
</ul>
</div>
</div>
Javascript
$("#lightgallery").lightGallery({
selector: '.item'
});

Problems with getting an image to show in a paged list

I have the following code, and it displays the listed text and the pagination at the bottom all fine. But when I try to get the images from the child page into the list it errors for me. Any ideas why?
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = "SiteLayout.cshtml";
}
<div role="main" id="main">
<div id="blogPageFeatures">
<!-- loop through all of the child pages (blog posts) and grab data to output as a summary -->
#{
var pageSize =3;
var page =1;int.TryParse(Request.QueryString["page"],out page);
var items =Model.Content.Children().Where(x => x.IsDocumentType("BlogArticle")).OrderByDescending(x => x.CreateDate);
var totalPages =(int)Math.Ceiling((double)items.Count()/(double)pageSize);
if(page > totalPages)
{
page = totalPages;
}
else if(page <1)
{
page =1;
}
}
#foreach(var item in items.Skip((page -1)* pageSize).Take(pageSize))
{
<a href="#item.Url">
<!-- The next image line is where it errors -->
<img src="#Umbraco.Media(item.Children.blogArticleImage).Url">
<h2>#item.Name</h2>
<p class="blogTileDate">#item.CreateDate.ToString("dd/MM/yy")</p>
</a>
}
<div class="clearfix"></div>
<!-- Pagination START -->
#if(totalPages >1)
{
<div class="pagination">
<ul>
#if(page >1)
{
<li>Prev</li>
}
#for(int p =1; p < totalPages +1; p++)
{
var active =(p == page)?" class=\"active\"":string.Empty;
<li#(Html.Raw(active))>
#p
</li>
}
#if(page <totalPages)
{
<li>Next</li>
}
</ul>
</div>
}
<!-- Pagination END -->
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
</div>
You are getting Model.Content.Children, which is a strongly typed collection of IPublishedContent objects. You are then calling item.Children.blogArticlImage, which is not going to work, as you're trying to get the a property on the children of the item, not a property of the item itself. You're also trying to use dynamic syntax, which won't work on the strongly typed objects. Try changing your image code to:
<img src="#Umbraco.TypedMedia(item.GetPropertyValue<int>("blogArticleImage")).Url">
That should do te trick, one thing to note is that if an item doesn't have an image set, or the image that has been selected has been deleted, it'll throw an error. A more robust approach would be something like this:
var imageSrc = "ADD DEFAULT IMAGE PATH HERE";
var media = Umbraco.TypedMedia(item.GetPropertyValue<int>("blogArticleImage"));
if (media != null && !string.IsNullOrEmpty(media.Url))
{
imageSrc = media.Url;
}
<mig src="#imageSrc">

Error when creating Filterable Elements in Jquery mobile

I hv done a program for filterable element using Jquery Mobile
When search for the particular character in the search box its displaying all the characters and names instead of the particular character I have searched
The output I got is this
**Here is my coding**
<link rel="stylesheet" href="../css/jquery.mobile-1.4.3.min.css">
<script src="../js/jquery-1.11.1.min.js"></script>
<script src="../js/jquery-ui.js"></script>
<script src="../js/jquery.mobile-1.4.3.min.js"></script>
<div data-role="page" id="pageone">
<div data-role="header">
<h1> Names </h1>
</div>
<div data-role="main" class="ui-content">
<form class="ui-filterable">
<input id="myFilter" data-type="search" placeholder="Please type here">
</form>
<ul data-role="listview" data-filter="true" data-input="#myFilter" data-
autodividers="true" data-inset="true">
<li data-filtertext="hello">Abdul</li>
<li>Alvin</li>
<li>Bob</li>
<li>Balmer</li>
<li>Nixon</li>
<li>Mitchelle</li>
<li>william</li>
<li>vincent</li>
<li>domney</li>
<li>Brad</li>
<li>Tarvin</li>
<li>Pamela</li>
<li>Jenney</li>
<li>Rose</li>
<li>Pepe</li>
<li>Ronaldo</li>
<li>Messi</li>
<li>Kroos</li>
<li>Klose</li>
<li>Neymar</li>
<li>Fabrigas</li>
<li>Iniesta</li>
<li>Cavani</li>
<li>Silva</li>
<li>Beckham</li>
</ul>
</div>
</div>
By default, jQM filters for items that contain the search text rather than items that start with the search text. For a starts with filter, you will need to use the filterable widget's filterCallback option:
$(document).on("pagecreate", "#pageone", function(){
$("#myList").filterable('option', 'filterCallback', startsWithSearch);
});
function startsWithSearch( idx, searchValue ) {
if (searchValue && searchValue.length > 0){
var theListItems = $("#myList li");
var text = theListItems.eq(idx).text().toLowerCase();
var filttext = theListItems.eq(idx).data("filtertext") || '';
filttext = filttext.toLowerCase();
//if either text or filtertext starts with searchvalue, return false
if( text.lastIndexOf(searchValue, 0) === 0 || filttext.lastIndexOf(searchValue, 0) === 0){
return false;
} else {
return true; //filter this one out
}
} else {
return false;
}
}
On pagecreate I am setting the filterCallback option to a javascript function called startsWithSearch. That function checs to see if a searchValue has been entered. If so, it gets the text and data-filtertext of the current listitem and checks if either start with the searchValue. Any items that don't start with the value are filtered out by returning true.
Here is a working DEMO

Umbraco 6 razor menu

Hi I want to add a class of "active" to my li, if it is active or if I am on a page under that. I have the following code
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = null;
}
<nav class="topNav">
<ul>
#foreach (var item in Model.Content.AncestorOrSelf(1).Children.Where(x => x.IsVisible() && x.IsDocumentType("Subfrontpage") || x.IsDocumentType("Procesguide")))
{
<li>
#item.Name
</li>
}
</ul>
</nav>
I think I can do something with this, but it gives an error
var isSelected = Model.Path.Contains(item.Id.ToString()) ? "active" : "";
<li class="#Html.Raw(isSelected)">
#item.Name
</li>
This is the error I get. Line 10.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'Path' and no extension method 'Path' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 8: #foreach (var item in Model.Content.AncestorOrSelf(1).Children.Where(x => x.IsVisible() && x.IsDocumentType("Subfrontpage") || x.IsDocumentType("Procesguide")))
Line 9: {
Line 10: var isSelected = Model.Path.Contains(item.Id.ToString()) ? "active" : "";
Line 11:
Line 12: <li class="#Html.Raw(isSelected)">
I have now tried with this, but no lunk
<ul>
<li>
#home.Name
</li>
#foreach (var item in Model.Content.AncestorOrSelf(1).Children.Where(x => x.IsVisible() && x.IsDocumentType("Subfrontpage") || x.IsDocumentType("Procesguide")))
{
var isSelected = item.IsDescendant(Model,"active", "");
<li class="#Html.Raw(isSelected)">
#item.Name
</li>
}
</ul>
ok here is the solution. This is for typed, not dynamic cshtml.
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
#{
Layout = null;
var home = Model.Content.AncestorOrSelf(1);
}
<ul>
#*Render Home item*#
#{ var homeActive = ""; }
#if( home.Id == Model.Content.Id){
homeActive = "active";
}
<li class="#homeActive">
<a href="#home.Url">
#home.Name
</a>
</li>
#*Render Home children*#
#foreach (var item in home.Children.Where(x => x.IsVisible()))
{
var active = "";
if(home.Id != Model.Content.Id){ #* if NOT home *#
if (item.Id == Model.Content.AncestorOrSelf(2).Id){
#* if foreach id and currentpage ancestor id is equal *#
active = "active";
}
}
<li class="#active">
<a href="#item.Url">
#item.Name
</a>
</li>
}
</ul>
You can try something like this:
var isSelected = item.IsDescendant(Model,"active", "");
Here is a list of the functions you can use:
#Model.AncestorOrSelf(string nodeTypeAlias)
#Model.AncestorOrSelf(int level)
#Model.AncestorOrSelf(Func<DynamicNode, bool> func)
and those Helper functions:
#Model.IsDescendant(DynamicNode[,valueIfTrue][,valueIfFalse])
#Model.IsDescendantOrSelf(DynamicNode[,valueIfTrue][,valueIfFalse])
Reference: Is the current page a descendant of a specific node id?
The following is the default script for navigation produced by umbraco:
#inherits umbraco.MacroEngines.DynamicNodeContext
#*
Macro to display child pages below the root page of a standard website.
Also highlights the current active page/section in the navigation with
the css class "current".
*#
#{
#*Get the root of the website *#
var root = Model.AncestorOrSelf(1);
}
<ul>
#foreach (var page in root.Children.Where("Visible"))
{
<li class="#page.IsAncestorOrSelf(Model, "current", "")">
#page.Name
</li>
}
</ul>
I just created a menu myself and needed the Home page to be active also. Working with just the method IsAncestorOrSelf doesn't work for the homepage.
The piece of code I've created is this:
#{
var root = Model.AncestorOrSelf(1);
var homeClass = root.Id == Model.Id ? "active" : "";
}
<ul id="nav" class="nav navbar-nav pull-right">
<li class="#homeClass"><a href="/" >Home</a></li>
#foreach (var page in root.Children.Where("Visible"))
{
<li class="#page.IsAncestorOrSelf(Model, "active", "")">
#page.Name
</li>
}
</ul>
This iterates through all children of the root node (1). To be able to discover if you are on the Home page, I'm checking the Id's of the page and set the active class accordingly.