Skip to content

Instantly share code, notes, and snippets.

@patrickberkeley
Last active February 28, 2017 05:07
Show Gist options
  • Save patrickberkeley/3e4951dd71a7b25d6df372e1351ae09c to your computer and use it in GitHub Desktop.
Save patrickberkeley/3e4951dd71a7b25d6df372e1351ae09c to your computer and use it in GitHub Desktop.

Revisions

  1. patrickberkeley revised this gist Feb 28, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion component.js
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ export default Ember.Component.extend({

    willDestroyElement() {
    get(this, 'keyManager').deregister({
    name: 'search', // This name must match the name the binding was registered with above.
    name: 'search-modal', // This name must match the name the binding was registered with above.
    });
    },

  2. patrickberkeley created this gist Feb 28, 2017.
    33 changes: 33 additions & 0 deletions component.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    import Ember from 'ember';

    const {
    get,
    inject,
    } = Ember;

    export default Ember.Component.extend({
    keyManager: inject.service(),

    didInsertElement() {
    get(this, 'keyManager').register({
    keys: ['escape'],
    name: 'search-modal',
    downCallback: run.bind(this, function() {
    this.send('toggleModal');
    }),
    priority: 10,
    });
    },

    willDestroyElement() {
    get(this, 'keyManager').deregister({
    name: 'search', // This name must match the name the binding was registered with above.
    });
    },

    actions: {
    toggleModal(){
    this.sendAction('toggleModalAction');
    },
    },
    });
    39 changes: 39 additions & 0 deletions route.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    import Ember from 'ember';

    const {
    get,
    inject,
    } = Ember;

    export default Ember.Route.extend({
    keyManager: inject.service(),

    actions: {
    didTransition() {
    this._super(...arguments);

    get(this, 'keyManager').register({
    keys: ['escape'],
    name: 'fancy-route',
    downCallback: run.bind(this, this._redirectToLaLaLand),
    priority: 100,
    });
    },

    willTransition() {
    this._super(...arguments);

    get(this, 'keyManager').deregister({
    name: 'fancy-route',
    });
    },
    },

    // The `event` that's returned as a parameter here is the JS keyboard event.
    _redirectToLaLaLand(event) {
    if (event) {
    event.preventDefault();
    }
    this.transitionTo('main.la-la-land');
    },
    });