Note that there are some explanatory texts on larger screens.

plurals
  1. PORecreating Bootstrap Dropdown functionality in Ember.js
    primarykey
    data
    text
    <p><strong>Edit:</strong> Looking for a way to close the dropdown when anything but the button is clicked: <a href="http://jsfiddle.net/brennan/s4JTn/" rel="nofollow">http://jsfiddle.net/brennan/s4JTn/</a> </p> <p>I'm looking to (re)create twitter's dropdown menu in my ember app. I'm specifically having an issue trying to close the dropdown when anything <em>except</em> the dropdown is clicked. Ie. I'm looking for a way to add an event listener to my app to close my dropdown when the body of the app is clicked.</p> <p>Here's my (child) view.</p> <pre><code>categorySelect: Ember.View.extend({ isOpen: false, selected: /* removed for brevity */, content:[ /* removed for brevity */ /* follows structure: {slug: 1, title: 'title', isActive: true} */ ], dropdownToggle: function(e){ var open = this.get('isOpen'); if(open){ this.set('isOpen', false); }else{ this.set('isOpen', true); } }, select: function(e){ var selected = e.context; this.content.setEach('isActive', false); this.set('selected', selected); selected.set('isActive', true); this.set('isOpen', false); } }) </code></pre> <p>and here is my template code...</p> <pre><code>{{#view categorySelect tagName="div" class="btn-group" classBinding="isOpen:open"}} &lt;a class="btn dropdown-toggle btn-facebook btn-small" {{action "dropdownToggle" on="click"}} href="#"&gt; {{selected.title}} &lt;span class="caret"&gt;&lt;/span&gt; &lt;/a&gt; &lt;ul class="dropdown-menu pull-right"&gt; {{#each content}} &lt;li {{bindAttr class="isActive:active"}}&gt;&lt;a href="#" {{action "select" on="click"}}&gt;{{title}}&lt;/a&gt;&lt;/li&gt; {{/each}} &lt;/ul&gt; {{/view}} </code></pre> <p>I've tried adding event listeners to the body like the following which isn't working. Ember seems to stop propagation if I click on any ember views. So while it works if I click directly on the body, it doesn't work if i click on any of my views :(</p> <pre><code>didInsertElement: function(){ var self = this; $('body').on('click', function(){ self.set('isOpen', false); }); }, </code></pre> <p>Looking for help and advice. Also, if any of the above code looks like crap please let me know I'm looking to learn as much as I can.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload