Skip to content

Commit

Permalink
Wrap select in form that is submitted to change URL
Browse files Browse the repository at this point in the history
  • Loading branch information
wheeyls committed Aug 7, 2015
1 parent 4258cb3 commit 732bfb3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tinynav.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
'active' : 'selected', // String: Set the "active" class
'header' : '', // String: Specify text for "header" and show header instead of the active item
'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)
'label' : '', // String: sets the <label> text for the <select> (if not set, no label will be added)
'formClasses' : '' // String: sets the class of the surrounding form object
}, options);

return this.each(function () {
Expand All @@ -20,6 +21,7 @@
namespace = 'tinynav',
namespace_i = namespace + i,
l_namespace_i = '.l_' + namespace_i,
$form = $('<form method="get"/>'),
$select = $('<select/>').attr("id", namespace_i).addClass(namespace + ' ' + namespace_i);

if ($nav.is('ul,ol')) {
Expand Down Expand Up @@ -56,13 +58,16 @@
.attr('selected', true);
}

// Change window location
$select.change(function () {
window.location.href = $(this).val();
// submit surrounding form
$select.change(function (ev) {
$form.attr('action', $(this).val());
$form.submit();
});

// Inject select
$(l_namespace_i).after($select);
$form.append($select)
$form.addClass(settings.formClasses);
$(l_namespace_i).after($form);

// Inject label
if (settings.label) {
Expand Down

0 comments on commit 732bfb3

Please sign in to comment.