forked from arielsalminen/TinyNav.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tinynav.js
49 lines (37 loc) · 1.17 KB
/
tinynav.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*! TinyNav.js v1.02. (c)2011-2012 Viljami Salminen. MIT License. http://tinynav.viljamis.com */
(function ($, window, i) {
$.fn.tinyNav = function (options) {
var settings = $.extend({
'active' : 'selected'
}, options);
return this.each(function () {
i++;
var $nav = $(this),
namespace = 'tinynav',
namespace_i = namespace + i,
l_namespace_i = '.l_' + namespace_i,
$select = $('<select/>').addClass(namespace + ' ' + namespace_i);
if ($nav.is('ul,ol')) {
var options = '';
$nav
.addClass('l_' + namespace_i)
.find('a')
.each(function () {
options +=
'<option value="' + $(this).attr('href') + '">' +
$(this).text() +
'</option>';
});
$select
.append(options)
.find(':eq(' + $(l_namespace_i + ' li')
.index($(l_namespace_i + ' li.' + settings.active)) + ')')
.attr('selected', true);
$select.change(function () {
window.location.href = $(this).val();
});
$(l_namespace_i).after($select);
}
});
};
})(jQuery, this, 0);