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( ).show();
  if (settings.prerendered) {
   // if prerendered is on, replicate the basic class swapping
    .swapClass( CLASSES.collapsable, CLASSES.expandable )
    .swapClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
     .swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
     .swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea );

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.

1 comment:

  1. Developers can get to know about JQuery. Your way is easy to understand. I am also providing Pressure Washing Services in Knoxville TN. From this service, I am doing paint their house and office.