Pages

Wednesday, December 15, 2010

jQuery Treeview persist preSelected

This is another addition to the jQuery treeview plugin, developed by Jörn Zaefferer
My old addition to the script can be found here Ignore query in jQuery treeview persist location (i think it has been handled in his version too)
 It is still a "problem" with persist, this time I output the menu with the item already selected by the class selected.
But when this is done, it wont expand to the item I have pre selected, that is why I made this little addition:
case "preSelected":
    var current = this.find("a.preSelected");
    if ( current.length ) {
  // TODO update the open/closed classes
  var items = current.addClass("selected").parents("ul, li").add( current.next() ).show();
  if (settings.prerendered) {
   // if prerendered is on, replicate the basic class swapping
   items.filter("li")
    .swapClass( CLASSES.collapsable, CLASSES.expandable )
    .swapClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
    .find(">.hitarea")
     .swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
     .swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea );
  }
 }
    break;

i just copied the location method and replaced this:
var current = this.find("a").filter(function() {
 return this.href.toLowerCase() == location.href.toLowerCase();
with var current = this.find("a.preSelected")
The only thing left to do is to add the class preSelected to the selected item, when you output the treeview.

No comments:

Post a Comment