Bootstrap: Links to tabs in navigation bars stay active even when tab changes - twitter-bootstrap-3

I have multiple navigation bars in one page:
<ul class="nav nav-tabs">
<li>Home</li>
<li>About</li>
</ul>
<ul class="nav nav-tabs">
<li>Home</li>
<li>About</li>
</ul>
The status of a LI element becomes active when the belonging link was clicked. Problem: It stays active even when the user switches the tab in the other navigation.
It is not possible to switch back in the first navigation as the LI is already active there and can not be clicked. Things get even worse if you add a div.collapse.navbar-collapse in the main navigation bar and a simple link somewhere in the page:
<p><a data-toggle="tab" href="#about">About</a></p>

In many cases different nav (with tabs) will open a new page or interact on difference elements in the page. In your case being active of nav1 only will be a problem when nav2 removes or change the content related to your nav1 active state.
You could try to remove the active states with the tab event, see http://getbootstrap.com/javascript/#tabs. For your example this will be come something like;
$('.nav').on('show.bs.tab', function (e) {
$('.nav .active').removeClass('active');
})

I think the best solution is to set the active class manually in all the navs after each tab switch.
$(function() {
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
// add active class where nav entry is active
$('.nav a[data-toggle="tab"][href="'+$(e.target).attr("href")+'"]')
.parent().addClass('active');
// remove active class where nav entry is no longer active
$('.nav a[data-toggle="tab"][href!="'+$(e.target).attr("href")+'"]')
.parent().removeClass('active');
});
});

Related

How natively to set active menu item with metalsmith?

i got a simple static site with a main navigation. working with the metalsmith generator.
Is there a native way to set current menu items active?
My current unautomated solution:
I just made a workaround like following.
A MD file page1.md as source of content with some variables i can define at top:
---
title: this is the site title
currentPage1: current
layout: main.html
---
<article class="featurette">
<p class="lead">Some content text...</p>
</article>
and my layout HTML file main.html. Where handlebars is used as engine.
i just post the part of the menu here:
<ul class="nav">
<li>
Link to Page1
</li>
<li>
Link to Page2
</li>
</ul>
both are going through the metalsmith rendering.
I got a current class on the Page1 in the menu.
Question
My solution is working so far, but as my site scales. I need to define the "current" for every site again and again. If I don't watch out this will lead to misconfiguration...
I do like to have freedom on my main navigation markup, as there are some specialities in. So I'm fine with creating this for new pages by myself.
Can i set active menu items somehow with the metalsmith-permalinks or metalsmith-canonical plugin or does there exists a metalsmith plugin suited for this case or maybe with another clever JS manipulation?
Use metalsmith-collections to create a collection of pages
.use(collections({
pages: {
pattern: '*.html'
}
}))
Then in your template loop through them to create your links:
{{#each collections.pages}}
<li>
<a href="{{path}}" {{#if_eq ../id this.id}} class="active" {{/if_eq}}>{{title}}</a>
</li>
{{/each}}
You will need to register a block helper like this: Handlebars.js if block helper ==
Make sure each page ID is unique.
For example:
---
id: phillip
layout: base.hbs
tagline: I haven't thought of one.
pagename: phils page
href: /phil/
navorder: 3
private: true
---

Vue.js Navigation Sub Menus via WP REST API

In inspiration from Sarah Drasner's Smashing Magazine article Replacing jQuery with Vue, I've replaced all of my jQuery with Vue in my Wordpress theme. Things are going nicely as I've already replaced functionality for modals, form validation/submission, at the like. I even got a boost in my page speed grade from Google's page speed insights tool.
The last piece of my puzzle is finishing off my navigation menu. The menu is built and working, but I'm not happy with it. My primary dissatisfaction is in conditionally rendering submenus better. For example, menu items without children receive an empty child:
<ul class="submenu"></ul>
Here's what I have so far:
Here's the shape of my Nav menu data: https://api.myjson.com/bins/jfld4
Important property definitions:
"obeject_id" is a unique indentifier
"post_parent" refers to the nav item's parent "object_id"
Notice notice top level menu items have "post_parent: 0"
Here's my Vue code for rendering the menu:" https://codepen.io/JosephAllen/pen/zLQqRr?editors=0011
<ul class="menu" id="primary-menu">
<menu-item
v-for="item in navItems"
v-if="item.post_parent == 0"
:key="item.object_id"
:class="{active: item.active}"
v-bind:url="item.url"
v-bind:object_id="item.object_id"
v-bind:post_parent="item.post_parent"
v-bind:title="item.title">
<ul class="sub-menu">
<menu-item
v-for="subItem in navItems"
:key="subItem.object_id"
v-if="subItem.post_parent == item.object_id"
v-bind:object_id="subItem.object_id"
v-bind:url="subItem.url"
v-bind:ID="subItem.ID"
v-bind:post_parent="subItem.post_parent"
v-bind:title="subItem.title">
</menu-item>
</ul>
</menu-item>
</ul>
On your <ul class="sub-menu"> element, include v-if or v-show with a test if the item contains any subItems (e.g. <ul class="sub-menu" v-show="hasSubItems"> once you've computed hasSubItems of course). Check out conditional rendering in the Vue docs.

Refreshing left navigation bar after clicking on the main navigation bar (top horizontal) in asp.net MVC

I'm creating a menu navigation bar (main menu) which all submenus will be located at the left side. Since the main menu bar were called/build-up inside the _Layout.cshtml, how can i rebuild/refresh the submenus if it will be resided on the _Layout.cshtml and also on every click action of the main item(s)?
<div>
#{ Html.RenderAction("Menu", "Home"); }
</div>
<div class="leftmenu">
#{ Html.RenderAction("SubMenu", "Home"); }
</div>
Hoping for your kind response. Thank you.
If I understood correctly, you have both menus in the _Layout.cshtml file. The main menu is fixed, and the left menu depends on every specific page (but it's also fixed, per page).
In that case, my approach would be to create a section in the _Layout.cshtml file, called i.e. "SubMenu", where each page would be able to define it's sub menu items.
_Layout.cshtml page
#RenderSection("SubMenu", required: false)
_SpecificPageView.cshtml
#section SubMenu {
<div class="leftmenu">
#{ Html.RenderAction("SubMenu", "Home"); }
</div>
}

Behat works fine but PhantomJS fails on dropdown menu when trying to click

Gherkin below works fine with behat but when I use PhantomJS I get error on When I follow "Profile" line below:
Note: The element is a dropdown menu from bootstrap so it toggles after click.
Error:
Exception thrown by (//html/.//a[./#href][(((./#id = 'Profile' or contains(normalize-space(string(.)), 'Profile')) or contains(./#title, 'Profile') or contains(./#rel, 'Profile')) or .//img[contains(./#alt, 'Profile')])] | .//*[./#role = 'link'][((./#id = 'Profile' or contains(./#value, 'Profile')) or contains(./#title, 'Profile') or contains(normalize-space(string(.)), 'Profile'))])[1]
{"errorMessage":"Element is not currently visible and may not be manipulated","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-Length":"27","Content-Type":"application/json; charset=utf-8","Host":"localhost:5140","User-Agent":"Apache-HttpClient/4.3.4 (java 1.5)"},"httpVersion":"1.1","method":"POST","post":"{\"id\":\":wdc:1412065547042\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/5b7c0830-487b-11e4-adc0-a162f25e4a98/element/%3Awdc%3A1412065547042/click"}}
Gherkin:
When I follow "Profile"
And I follow "Edit"
HTML:
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
Profile <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Show</li>
<li>Edit</li>
</ul>
</li>
</ul>
I've discovered why and solved with a small fix as shown below.
When using Bootstrap, the menus get squashed down and only an icon appears to represent the same menu which is the normal behaviour for responsive design. All fine for now but when PhantomJS is run, it cannot find the text it is looking for. e.g. "Profile" menu in my case.
Original state of the menu, which always works fine:
After squashed down version which causes PhantomJS to fail:
SOLUTION:
Just set the window size to something bigger so that the menu doesn't get squashed down when testing. You can change the screen size from 1024X768 to something else as you wish.
#symfony/src/Site/CommonBundle/Features/Context/FeatureContext.php
/**
* #BeforeStep
*/
public function beforeStep()
{
$this->getSession()->resizeWindow(1024, 768, 'current');
}

How to get Jquery UI tab to be blank

I have a JQuery UI tab dialog that is the detail of a Master-Detail interface. When someone selects an element in the master, the tabs all get their href's populated with URLs giving details of that selected item.
For example, see
http://www.trirand.com/blog/jqgrid/jqgrid.html and browse to Advanced->Master Detail.
But instead of updating a second grid, I'm updating the links of a jquery-ui tabs element like so:
var urls = {
0 : "/url1",
1 : "/url2",
};
jqgrid(....
onSelectRow: function(location_id) {
for (url in urls){
$('#tabs').tabs('url', url , urls[url]+location_id );
}
var selectedTab = $('#tabs').tabs("option", "selected");
$('#tabs').tabs('load', selectedTab);
}
);
$(#tabs.tabs({});
With html like:
<div id="tabs">
<ul>
<li><a id="URL1" href="blank.html">Info</a></li>
<li><a id="URL2" href="blank.html">History</a></li>
</ul>
</div>
I shouldn't have to use a blank.html dummy link. Is there something I can do (when I don't have anything selected in the master) that doesn't cause my tabs to cause a fetch and instead just be empty?
If you set the tab to be blank in your coding nothing will appear in it (obviously), but if you need to empty it on page load use this:
$(document).ready(function() {
$('#divID').empty();
});