Skip to content

Instantly share code, notes, and snippets.

@HenryVonfire
Last active May 6, 2016 08:59
Show Gist options
  • Save HenryVonfire/7dbfaf5d8ed62d7b07902607d7fb8b0f to your computer and use it in GitHub Desktop.
Save HenryVonfire/7dbfaf5d8ed62d7b07902607d7fb8b0f to your computer and use it in GitHub Desktop.
sidenav
import Ember from 'ember';
import SideNavMixin from '../mixins/side-nav';
export default Ember.Controller.extend(SideNavMixin,{
appName: 'Ember Twiddle'
});
import Ember from 'ember';
const { Mixin } = Ember;
export default Mixin.create({
rightSidebarOpen: false,
rightSidebarHeight: 300,
buttonMenuId: 'button1',
rightSidebarId: 'mySidenav',
_autoClose(e){
const element = e.target;
const menuId = this.get('rightSidebarId');
if(element.id === this.get('buttonMenuId')){
if(!this.get('rightSidebarOpen')){
this._toggleMenu('open');
} else {
this._toggleMenu('close');
}
} else {
if(this.get('rightSidebarOpen')){
this._toggleMenu('close');
}
}
},
_toggleMenu(action){
const menuId = this.get('rightSidebarId');
if(document.getElementById(menuId)){
if(action === 'open'){
document.getElementById(menuId).style.maxHeight ='300px';
document.getElementById(menuId).style.transition ='0.5s';
} else {
document.getElementById(menuId).style.maxHeight = "0";
document.getElementById(menuId).style.transition ='0.1s';
}
this.toggleProperty('rightSidebarOpen');
}
},
init(){
this._super(...arguments);
document.addEventListener('click', this._autoClose.bind(this));
},
willDestroyElement(){
this._super(...arguments);
Ember.Logger.log('event removed');
document.removeEventListener('click', this._autoClose.bind(this));
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.sidenav {
max-height: 0;
width: 200px;
position: absolute;
z-index: 1;
//top: 140px;
right: 0;
background-color: $white;
overflow: hidden;
transition: 0.5s;
box-shadow: 0 0 4px $mobile-shadow;
& ul {
list-style-type: none;
margin:0;
padding:0;
& li {
cursor:pointer;
text-align: center;
padding:10px;
border-bottom: 1px solid $mobile-shadow;
white-space: nowrap;
}
}
}
<b>rightSidebarOpen</b>:{{rightSidebarOpen}}<br>
<b>rightSidebarId</b>:{{rightSidebarId}}<br>
<br>
<button id={{buttonMenuId}}>...</button>
<div id={{rightSidebarId}} class="sidenav">
<ul>
<li>option1</li>
<li>option2</li>
<li>option3</li>
</ul>
</div>
{
"version": "0.8.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.5.1",
"ember-data": "2.5.2",
"ember-template-compiler": "2.5.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment