Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend the jQuery accordion plugin

How to extend a jQuery plugin?

currently I am using multiopen accordion plugin.

I need to add new feature like once the expand/collapse is finished I need to callback a function as like change event in jquery ui accordion plugin.

How to add this feature in this plugin.

like image 265
SAK Avatar asked Dec 07 '12 18:12

SAK


1 Answers

you dont need the accordion widget for that. you can do this with a few lines of jQuery.

html:

<h3 class="header"> Title 1 </h3>
<div class="content"> Content 1 </div>
<h3 class="header"> Title 2 </h3>
<div class="content"> Content 2 </div>

javascrpt/jQuery:

( function( $ ){ // closure to make sure jQuery = $
  $( function(){ // on document load
    $( ".header" ).click( function( e ){ // select headers and set onClick event handler
      // here you can maybe add a class to an opened header like this
      $( this ).toggleClass( "open" );
      $( this ).next().toggle( "slow", function(){ // toggle visibility
        // what you write here will be executed after the animation
        // "this" will refer to the hidden/revealed div element
        // if you want to call a function depending on if the 
        // panel was opened or closed try this
        if ( $( this ).is( ":visible" ) ) {
          tabOpened( e, this );
        } else {
          tabClosed( e, this );
        }
      }) 
    }).next().hide()
  })
})(jQuery)

and the whole thing working on jsfiddle http://jsfiddle.net/qpqL9/

like image 188
lordvlad Avatar answered Sep 30 '22 01:09

lordvlad