Skip to content

Instantly share code, notes, and snippets.

@tmeasday
Created May 29, 2012 07:30
Show Gist options
  • Select an option

  • Save tmeasday/2823119 to your computer and use it in GitHub Desktop.

Select an option

Save tmeasday/2823119 to your computer and use it in GitHub Desktop.
A really simple custom select widget implemented in Meteor
Session.set 'select.open', false
Template.select.selected_value = -> Session.get('select.selected_value')
Template.select.open = -> 'open' if Session.get('select.open')
Template.select.selected = ->
'selected' if Session.equals('select.selected_value', this.valueOf())
Template.select.events =
'click li:not(:first-child)': (e) ->
Session.set('select.selected_value', this.valueOf())
'click': ->
Session.set('select.open', !Session.get('select.open'))
.select:not(.open) li:not(:first-child) {
display: none;
}
<template name="select">
<ul class="select {{open}}">
<li class="selected_value">{{selected_value}}</li>
{{#each options}}
<li class="{{selected}}">
{{this}}
</li>
{{/each}}
</ul>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment