Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better active item selection, headerLink and activeSelected #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions tinynav.js
Expand Up @@ -5,7 +5,9 @@
// Default settings
var settings = $.extend({
'active' : 'selected', // String: Set the "active" class
'header' : '', // String: Specify text for "header" and show header instead of the active item
'activeSelected' : true, // Boolean: Whether or not the active item should be selected
'header' : '', // String: Specify text for "header"
'headerLink' : '/', // String: Specify link for "header" if used
'indent' : '- ', // String: Specify text for indenting sub-items
'label' : '' // String: sets the <label> text for the <select> (if not set, no label will be added)
}, options);
Expand All @@ -26,7 +28,7 @@

if (settings.header !== '') {
$select.append(
$('<option/>').text(settings.header)
$('<option value="' + settings.headerLink + '" />').text(settings.header)
);
}

Expand All @@ -49,11 +51,12 @@
$select.append(options);

// Select the active item
if (!settings.header) {
$select
.find(':eq(' + $(l_namespace_i + ' li')
.index($(l_namespace_i + ' li.' + settings.active)) + ')')
.attr('selected', true);
if(settings.activeSelected === true) {
var activeMenu = $(l_namespace_i + ' li.' + settings.active + ':last a');
if(activeMenu.size()) {
var activeVal = activeMenu.attr('href');
$("option[value='" + activeVal + "']", $select).attr('selected', true);
}
}

// Change window location
Expand Down