mathiasbynens / jquery-details

World’s first <details>/<summary> polyfill™
https://mths.be/details
GNU General Public License v2.0
121 stars 34 forks source link

Allow toggling `open` state #5

Open mathiasbynens opened 12 years ago

mathiasbynens commented 12 years ago

LedgeT describes a use case here:

I have a responsive design that requires the details to be closed in one view but open in another. Is it possible to do this based on changing the parent class?

E.g. $(el).details('toggle'); would toggle the open attribute and property, as well as class="open".

Maybe also $(el).details('open') and $(el).details('close').

This could also trigger event handlers:

$el.details();
$el.on('open.details', function() {
  console.log('open');
}).on('close.details', function() {
  console.log('close');
});
$el.details('open'); // opens the element and triggers `open.details`
mathiasbynens commented 12 years ago

Added the firing of custom events in 00754e987648c2134fc2c761e176740e7a01d47e.

mathiasbynens commented 10 years ago

The spec now defines a toggle event on <details> elements: http://html5.org/tools/web-apps-tracker?from=8250&to=8251