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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/*! http://tinynav.viljamis.com v1.03 by @viljamis */
/*! Further modified by Kailash Bijayananda-www.facebook.com/FriedDust for our theme's adjustment. */
function abc(e) {
var count = 0;
if (!e.hasClass('root'))
{
if (e.is('ul'))
count++;
return count + abc(e.parent());
}
return count;
}
(function ($, window, i) {
$.fn.tinyNav = function (options) {
// Default settings
var settings = $.extend({
'active' : 'current-menu-item', // String: Set the "active" class
'header' : false // Boolean: Show header instead of the active item
}, options);
var counter = -1;
return this.each(function () {
// Used for namespacing
i++;
var $nav = $(this),
// Namespacing
namespace = 'tinynav',
namespace_i = namespace + i,
l_namespace_i = '.l_' + namespace_i,
$select = $('<select/>').addClass(namespace + ' ' + namespace_i);
if ($nav.is('ul,ol')) {
if (settings.header) {
$select.append(
$('<option/>').text('Menu')
);
}
// Build options
var options = '';
$nav
.addClass('l_' + namespace_i)
.find('a')
.each(function () {
var y = abc($(this));
var space = "";
for (var x=0; x<y; x++)
space += "--";
options +=
'<option value="' + $(this).attr('href') + '">' + space +
$(this).text() +
'</option>';
});
// Append options into a select
$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);
}
// Change window location
$select.change(function () {
window.location.href = $(this).val();
});
// Inject select
$(l_namespace_i).after($select);
}
});
};
})(jQuery, this, 0);
// Tinynav
jQuery(function () {
// TinyNav.js 1
jQuery('#access .root').tinyNav({
active: 'current-menu-item'
});
}); |
Partager