2015-01-16 14:56:10 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2015-02-10 15:35:40 +08:00
|
|
|
/**
|
|
|
|
This mixin defines a "paneable" controller - this is, one that has a portion
|
|
|
|
of its interface that can be turned into a pane which slides out from the
|
|
|
|
side of the screen. This is useful, for instance, when you have nested
|
|
|
|
routes (index > discussion) and want to have the parent route's interface
|
|
|
|
transform into a side pane when entering the child route.
|
|
|
|
*/
|
2015-01-16 14:56:10 +08:00
|
|
|
export default Ember.Mixin.create({
|
2015-02-10 15:35:40 +08:00
|
|
|
needs: ['application'],
|
|
|
|
|
|
|
|
// Whether or not the "paneable" interface element is paned.
|
|
|
|
paned: false,
|
|
|
|
|
|
|
|
// Whether or not the pane should be visible on screen.
|
|
|
|
paneShowing: false,
|
|
|
|
paneHideTimeout: null,
|
|
|
|
|
|
|
|
// Whether or not the pane is always visible on screen, even when the
|
|
|
|
// mouse is taken away.
|
|
|
|
panePinned: localStorage.getItem('panePinned'),
|
|
|
|
|
|
|
|
// Disable the paneable behaviour completely, regardless of if it is
|
|
|
|
// paned, showing, or pinned.
|
|
|
|
paneDisabled: false,
|
|
|
|
|
|
|
|
paneEnabled: Ember.computed.not('paneDisabled'),
|
|
|
|
paneIsShowing: Ember.computed.and('paned', 'paneShowing', 'paneEnabled'),
|
|
|
|
paneIsPinned: Ember.computed.and('paned', 'panePinned', 'paneEnabled'),
|
|
|
|
|
|
|
|
// Tell the application controller when we pin/unpin the pane so that
|
|
|
|
// other parts of the interface can respond appropriately.
|
|
|
|
paneIsPinnedChanged: Ember.observer('paneIsPinned', function() {
|
|
|
|
this.set('controllers.application.panePinned', this.get('paneIsPinned'));
|
|
|
|
}),
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
showPane: function() {
|
|
|
|
if (this.get('paned')) {
|
|
|
|
clearTimeout(this.get('paneHideTimeout'));
|
|
|
|
this.set('paneShowing', true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
hidePane: function(delay) {
|
|
|
|
var controller = this;
|
|
|
|
controller.set('paneHideTimeout', setTimeout(function() {
|
|
|
|
controller.set('paneShowing', false);
|
|
|
|
}, delay || 250));
|
|
|
|
},
|
|
|
|
|
|
|
|
togglePinned: function() {
|
|
|
|
localStorage.setItem('panePinned', this.toggleProperty('panePinned') || '');
|
|
|
|
}
|
|
|
|
}
|
2015-02-06 08:02:45 +08:00
|
|
|
});
|