justintadlock / whistles

Something new. Something different. Tabs, accordions, and all that jazz. Done right.
49 stars 15 forks source link

Allow user to set "active" section #1

Open justintadlock opened 11 years ago

justintadlock commented 11 years ago

For tabs, toggles, and accordions, the user should be able to set an active section. Something like:

[whistles active="1]

And, setting it to 0 should make no section active for toggles/accordions and leave first section active for tabs.

jesschri commented 10 years ago

I am having this same problem, where I am unable to have the first whistle in a group "closed". The code I am currently using is [whistles type="accordion" group="information" order="DESC" orderby="title" limit="-2"]. I tried adding active="0" into this but it didn't change anything. I am quite new to this so I could be doing something wrong but anything I have tried either leaves the first whistle "open" or stops the whistle group from showing at all. Do you have any advise please?

matthiaspabst commented 10 years ago

Good idea. Would also love to have this feature.

nikolas commented 10 years ago

I might send a PR for this some time but for now if you just want to prevent the first item from being open by default, you can remove the code that shows and selects the item in the JavaScript. Since I was using the whistles accordion, I commented out the following lines in whistles.js:

//jQuery( '.whistles-accordion .whistle-content:first-of-type' ).show();
//jQuery( '.whistles-accordion .whistle-title:first-of-type' ).attr( 'aria-selected', 'true' );

And compiled that to whistles.min.js, and updated the date to the current date for this script in whistles.php:

wp_register_script( 
  'whistles', 
  WHISTLES_URI . 'js/whistles.min.js', 
  array( 'jquery' ),
  '20140530',
  true
);
jamesdanielclark commented 10 years ago

Hi @nikolas - thank you for this, it has helped me out. I commented out the two lines as suggested and then compiled it to whistles.min.js, and it prevented the first item from being open by default. Great!

I haven't carried out the final step though, namely updating the date to the current date for this script in whistles.php. Is this necessary? Excuse my niavety but what is the purpose of this final step?