Skip to content

Instantly share code, notes, and snippets.

@alejandroiglesias
Last active December 15, 2015 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandroiglesias/5340740 to your computer and use it in GitHub Desktop.
Save alejandroiglesias/5340740 to your computer and use it in GitHub Desktop.
/**
* Dropdown
*/
$(document)
.on('click', '.dropdown p, .dropdown .btn', function (event) {
$(event.target)
.closest('.btn')
.attr('tabindex', '1') // Gives the element a tabindex so it can be focused and blurred afterwards.
.trigger('focus')
.next().toggle();
})
.on('blur', '.dropdown p, .dropdown .btn', function (event) {
/*jshint immed:false */
(function () {
$(event.target)
.closest('.btn')
.removeAttr('tabindex')
.next().hide();
}).delay(100);
});
// Somewhere else. this.sortFriends is not always being called.
$(document).on('click', '#sort-friends .option', this.sortFriends.bind(this));
<div id="sort-friends" class="dropdown">
<a class="btn">Order by: {{selectedOption}}</a>
<ul>
{{#each options}}
<li><a class="option" href="#" data-param="{{uid}}">{{name}}</a></li>
{{/each}}
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment