On 18/02/2007, at 2:41 AM, Karl Swedberg wrote:
> On Feb 17, 2007, at 10:22 AM, Joel Birch wrote:
>> My thoughts exactly Karl.
>>
>> On another note, I just created a simple plugin (my first ever!) that
>> I have applied to the Preshil site and may ask for feedback tomorrow
>> if it still seems like a good idea after a good night's sleep (its
>> late here). It creates a menu of in-page links out of whatever query
>> you supply as a parameter, within the jQuery elements you chain the
>> plugin to. Easier to show an example...
>>
>> Example usage:
>> $("#content").contentMenu("h2");
>
> Ha! Now you are scaring me! :) That's exactly what I've done on
> learningjquery.com! (You're not reading my mind, are you?)
>
> Well, I didn't convert it into a plugin, but I did add page-content
> links using jQuery. I've been meaning to write up a little tutorial
> on how I did it, but haven't gotten around to it yet. For my site,
> it looks through the main content area to see if there is more than
> one <h2> element. If so, it builds a page-content list based on
> those, and links to each one. If not, it tries to find more than
> one <h4> element (which is what I use for the tutorial subheadings)
> and uses those for its page contents.
>
> --Karl
> _________________
> Karl Swedberg
> www.englishrules.com
> www.learningjquery.com
Haha, awesome! I originally built my plugin so it's very customisable
(using an options object parameter and defaults) but then just
whittled it back to custom elements to make the list from (with h2 as
default as it suited my current use - Preshil - best). I think I may
add back in the other options though. Here is the current code if
anyone is interested:
(function($){
$.fn.contentMenu = function(linkElem){
var linkElem = linkElem || "h2";
return this.each(function(){
$.listCount = $.listCount+1 || 0;
var $els = $(linkElem, this);
var $ul = $("<ul>");
$els.each(function(i){
if (!this.getAttribute("id")) {
this.id = "menu"+$.listCount+"-el"+i;
}
$ul.append('<li><a href="#'+this.id+'" class="inPage">
Skip to <em>'+this.innerHTML+'</em>
</a></li>');
});
$('<div class="contentMenu"></div>')
.append("<h3>Some handy links to help you navigate this
page:</h3>")
.append($ul).insertBefore($els.eq(0));
});
};
})(jQuery);
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/