hideshow.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Andy Langton's show/hide/mini-accordion @ http://andylangton.co.uk/jquery-show-hide
  2. // this tells jquery to run the function below once the DOM is ready
  3. $(document).ready(function() {
  4. // append show/hide links to the element directly preceding the element with a class of "toggle"
  5. $('.m-toggle').not('.current').prev().append('<a href="#" class="m-toggle-link icon-chevron-down" style="text-decoration:none;">&nbsp;</a>');
  6. $('.m-toggle.current').prev().append('<a href="#" class="m-toggle-link icon-chevron-up" style="text-decoration:none;">&nbsp;</a>');
  7. // hide all of the elements with a class of 'toggle'
  8. $('.m-toggle').not('.current').hide();
  9. // capture clicks on the toggle links
  10. $('h3.m-toggle-link').click(function() {
  11. // change the link text depending on whether the element is shown or hidden
  12. if ($(this).hasClass('current')) {
  13. //$(this).toggleClass("icon-chevron-up").toggleClass("icon-chevron-down");
  14. $(this).next('.m-toggle').slideUp('slow');
  15. $(this).toggleClass('current');
  16. }
  17. else {
  18. var previousCurrent = $(this).parent().find('.m-toggle-link.current');
  19. previousCurrent.next('.m-toggle').slideUp('slow');
  20. previousCurrent.toggleClass('current');
  21. //$(this).toggleClass("icon-chevron-up").toggleClass("icon-chevron-down");
  22. $(this).next('.m-toggle').slideDown('slow');
  23. $(this).toggleClass('current');
  24. }
  25. // return false so any link destination is not followed
  26. return false;
  27. });
  28. });