mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
a0ec07f797
closes #5630 - upgrade ember-cli to latest version - upgrade ember to latest 1.13.x release - upgrade ember data to latest 1.13.x release - update custom adapters and serialisers for new internal JSON-API compatible formats [(docs)][1] - update all store queries to use new standardised query methods [(docs)][2] - add ember-data-filter addon ready for store.filter removal in ember-data 2.0 [(docs)][3] - remove use of prototype extensions for computed properties and observers - consolidate pagination into a single route mixin and simplify configuration [1]: http://emberjs.com/blog/2015/06/18/ember-data-1-13-released.html#toc_transition-to-the-new-jsonserializer-and-restserializer-apis [2]: http://emberjs.com/blog/2015/06/18/ember-data-1-13-released.html#toc_simplified-find-methods [3]: http://emberjs.com/blog/2015/06/18/ember-data-1-13-released.html#toc_ds-store-filter-moved-to-an-addon
87 lines
2.5 KiB
JavaScript
87 lines
2.5 KiB
JavaScript
import Ember from 'ember';
|
|
/* global key */
|
|
|
|
// Configure KeyMaster to respond to all shortcuts,
|
|
// even inside of
|
|
// input, textarea, and select.
|
|
key.filter = function () {
|
|
return true;
|
|
};
|
|
|
|
key.setScope('default');
|
|
/**
|
|
* Only routes can implement shortcuts.
|
|
* If you need to trigger actions on the controller,
|
|
* simply call them with `this.get('controller').send('action')`.
|
|
*
|
|
* To implement shortcuts, add this mixin to your `extend()`,
|
|
* and implement a `shortcuts` hash.
|
|
* In this hash, keys are shortcut combinations and values are route action names.
|
|
* (see [keymaster docs](https://github.com/madrobby/keymaster/blob/master/README.markdown)),
|
|
*
|
|
* ```javascript
|
|
* shortcuts: {
|
|
* 'ctrl+s, command+s': 'save',
|
|
* 'ctrl+alt+z': 'toggleZenMode'
|
|
* }
|
|
* ```
|
|
* For more complex actions, shortcuts can instead have their value
|
|
* be an object like {action, options}
|
|
* ```javascript
|
|
* shortcuts: {
|
|
* 'ctrl+k': {action: 'markdownShortcut', options: 'createLink'}
|
|
* }
|
|
* ```
|
|
* You can set the scope of your shortcut by passing a scope property.
|
|
* ```javascript
|
|
* shortcuts : {
|
|
* 'enter': {action : 'confirmModal', scope: 'modal'}
|
|
* }
|
|
* ```
|
|
* If you don't specify a scope, we use a default scope called "default".
|
|
* To have all your shortcut work in all scopes, give it the scope "all".
|
|
* Find out more at the keymaster docs
|
|
*/
|
|
export default Ember.Mixin.create({
|
|
registerShortcuts: function () {
|
|
var self = this,
|
|
shortcuts = this.get('shortcuts');
|
|
|
|
Object.keys(shortcuts).forEach(function (shortcut) {
|
|
var scope = shortcuts[shortcut].scope || 'default',
|
|
action = shortcuts[shortcut],
|
|
options;
|
|
|
|
if (Ember.typeOf(action) !== 'string') {
|
|
options = action.options;
|
|
action = action.action;
|
|
}
|
|
|
|
key(shortcut, scope, function (event) {
|
|
// stop things like ctrl+s from actually opening a save dialogue
|
|
event.preventDefault();
|
|
self.send(action, options);
|
|
});
|
|
});
|
|
},
|
|
|
|
removeShortcuts: function () {
|
|
var shortcuts = this.get('shortcuts');
|
|
|
|
Object.keys(shortcuts).forEach(function (shortcut) {
|
|
var scope = shortcuts[shortcut].scope || 'default';
|
|
key.unbind(shortcut, scope);
|
|
});
|
|
},
|
|
|
|
activate: function () {
|
|
this._super();
|
|
this.registerShortcuts();
|
|
},
|
|
|
|
deactivate: function () {
|
|
this._super();
|
|
this.removeShortcuts();
|
|
}
|
|
});
|