[SPIP Zone] r4457 - /_plugins_/_squelettes_/pagination_article2/pagination_article2.js

Author: renatoformato@virgilio.it
Date: Wed Aug 9 13:10:41 2006
New Revision: 4457

Log:
Clicking on a summary link the page scrolls to the right place.

Modified:
    _plugins_/_squelettes_/pagination_article2/pagination_article2.js

Modified: _plugins_/_squelettes_/pagination_article2/pagination_article2.js

--- _plugins_/_squelettes_/pagination_article2/pagination_article2.js (original)
+++ _plugins_/_squelettes_/pagination_article2/pagination_article2.js Wed Aug 9 13:10:41 2006
@@ -35,31 +35,31 @@
       //reverse iteration not to change live collection indexes of the elements before the current
       for (var k=h.length-1; k>0; k--) {
         nom = classe+'-'+k;
- //create onclick function
- eval('var f = function() {'+
- '$(\'.'+classe+':visible\').slideUp();$(\'#'+nom+'\').filter(\':hidden\').slideDown();' +
- '}');
+ //create onclick function. On slideDown complete scroll to the right heading
+ eval("var f = function() {"+
+ "$('."+classe+"+div:visible').slideUp();$('#"+nom+"+div:hidden').slideDown(null,function(){window.location.hash='"+nom+"';});" +
+ "}");
         //Get current heading
         var my_heading = $('>:nth-child('+h[k-1]+')',this)
         //bind click function evaluating on each iteration "classe" and "nom"
         .click(f)
- //add the div container and get the heading for later use
- .after('<div id="'+nom+'" class="'+classe+'"></div>').get(0);
+ //add the div container and set id and class for the heading
+ .after('<div></div>').addClass(classe).set('id',nom)
         //append all elements between the current heading and the next one to the div and hide it
         //that are all children of "this" with index lower than h[k]+1
         //(we've just added a div after the heading) and higher than h[k-1]+1
         //NB: the filter selector must not have ">" since we have already all children in the
         //current set of elements
- $('#'+nom).append($('>*:lt('+(h[k]+1)+')',this).filter('*:gt('+(h[k-1]+1)+')').get()).hide();
+ .find('+div').append($('>*:lt('+(h[k]+1)+')',this).filter('*:gt('+(h[k-1]+1)+')').get()).hide()
+ //go back to the heading and get it
+ .end().get(0);
// $('#'+nom).prepend(my_heading);
         //build table
- table.prepend('<li><a></a></li>').find('li:first-child a').set('href','#'+nom).html(my_heading.innerHTML).click(f).end();
- //manage links inside the page to the blocks.
- //$('a[@href$="#'+nom+'"]').click(f);
+ table.prepend('<li><a></a></li>').find('li:first-child a').html(my_heading.innerHTML).click(f).end();
       }
     }
   );
}
-if(window.location.hash) $(window.location.hash).show();
+if(window.location.hash) $(window.location.hash+'+div').show();
}
);