Page 1 of 2

setting navicons as active on page load

Posted: Tue Sep 04, 2012 4:45 pm
by Lilian Akins

when i switch between screens the navicon is not changing to the current page. The last page icon is still remaining as active. How do i set the current page navmenu icon to active on page load. Also I assume i will need to change the previous page's icon to inactive.


setting navicons as active on page load

Posted: Tue Sep 04, 2012 5:38 pm
by maxkatz

Do you mean the selected tab is not updating?


setting navicons as active on page load

Posted: Tue Sep 04, 2012 5:39 pm
by maxkatz

If you can add screen shots of what's happening, that would help.


setting navicons as active on page load

Posted: Tue Sep 04, 2012 6:59 pm
by Lilian Akins

yes that is correct. on the homescreen i have the homescreen set as active. when i navigate to a second page and then back to homescreen. The second page icon stays highlighted instead of homescreen navicon


setting navicons as active on page load

Posted: Tue Sep 04, 2012 7:03 pm
by maxkatz

code
var navbar = $("[data-role='navbar']:visible");
if($('.tg-state-persist', navbar).length == 0) {
$(".ui-btn-active", navbar).addClass('tg-state-persist');
} else {
$(".ui-btn-active", navbar).removeClass('ui-btn-active');
$(".tg-state-persist", navbar).addClass('ui-btn-active');
}
/code

It's how this particular component works in jQuery Mobile.

You load Page 1 with a NavBar component. The first tab is selected. The page is now in browser DOM.
You click on the 2nd tab. jQuery Mobile makes the 2nd tab active and then loads Page 2.
On Page 2, the 2nd tab is active.
On Page 2, you click on 1st tab to go back.
Page 1 was already loaded and is now in browser DOM. As the page is in the DOM, it is simply shown (not loaded). Its last state - 2nd tab was active (from navigation).

jQuery Mobile has a fixed NavBar: http://jquerymobile.com/demos/1.1.1/d... (we don't have it yet in the palette). This one would work as expected. We will be adding it soon to the builder. The code above takes the current NavBar component and makes it a persistent NavBar.


setting navicons as active on page load

Posted: Tue Sep 04, 2012 7:28 pm
by Lilian Akins

ok thanks where exactly should i enter this code?


setting navicons as active on page load

Posted: Tue Sep 04, 2012 8:22 pm
by maxkatz

On page load, for each page you have the navbar on


setting navicons as active on page load

Posted: Tue Sep 04, 2012 9:18 pm
by Lilian Akins

hmm it doesn't seem to have had any effect. The same thing is happening.. on each screen on load i added a custom javascript code event. I also made sure that my navbar element is called navbar. No luck


setting navicons as active on page load

Posted: Tue Sep 04, 2012 9:59 pm
by maxkatz

Did you also set the selected tab on each page?


setting navicons as active on page load

Posted: Wed Sep 05, 2012 7:43 am
by Lilian Akins

ok this is my code. is there something i missed?

/this is for the home screen/
var navbar = $("[data-role='navbar']:visible");
if($('.tg-state-persist', navbar).length == 0) {
$(".ui-homebtn-active", navbar).addClass('tg-state-persist');
} else {
$(".ui-homebtn-active", navbar).removeClass('ui-homebtn-active');
$(".tg-state-persist", navbar).addClass('ui-homebtn-active');
}

/this is for the forrent screen/
var navbar = $("[data-role='navbar']:visible");
if($('.tg-state-persist', navbar).length == 0) {
$(".ui-forrentbtn-active", navbar).addClass('tg-state-persist');
} else {
$(".ui-forrentbtn-active", navbar).removeClass('ui-forrentbtn-active');
$(".tg-state-persist", navbar).addClass('ui-forrentbtn-active');
}