var htmlMenu = {
generate : function htmlMenu(id) {
var headers = {};
var stack = [];
var lastLevel = 0;
var text,level;
var levels = {'H1':0,'H2':1,'H3':2,'H4':3,'H5':4}
var menu = '';
$('#' + id + ' :header').each(function(a){
actualLevel = levels[this.nodeName];
if(actualLevel < lastLevel) {
for(var r = actualLevel+1; r <= lastLevel; r++) {
delete stack[r];
}
}
text = $(this).html();
if(stack[actualLevel] == undefined) {
stack[actualLevel] = 1;
}
else {
stack[actualLevel]++;
}
var index = '';
var first = true;
for(i in stack) {
index += (first ? '' : '.') + stack[i];
first = false;
}
headers[index] = text;
$(this).append('<a name =" '">');
menu += "<a href="'#">" + index + " - " + text + "</a><br/>";
lastLevel = actualLevel;
})
return menu;
}
};
quarta-feira, 13 de janeiro de 2010
Método para Gerar Índice para HTML com JS
Assinar:
Postagens (Atom)