2013-11-19 02:53:12 +04:00
|
|
|
(function () {
|
|
|
|
var ns = $.namespace('pskl.service.keyboard');
|
|
|
|
|
|
|
|
ns.CheatsheetService = function () {
|
|
|
|
this.isDisplayed_ = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.CheatsheetService.prototype.init = function () {
|
|
|
|
this.cheatsheetEl_ = document.getElementById('cheatsheet-wrapper');
|
|
|
|
if (!this.cheatsheetEl_) {
|
|
|
|
throw 'cheatsheetEl_ DOM element could not be retrieved';
|
|
|
|
}
|
|
|
|
this.initMarkup_();
|
2013-11-20 02:46:33 +04:00
|
|
|
pskl.app.shortcutService.addShortcut('shift+?', this.toggleCheatsheet_.bind(this));
|
|
|
|
pskl.app.shortcutService.addShortcut('?', this.toggleCheatsheet_.bind(this));
|
2013-11-19 02:53:12 +04:00
|
|
|
$.subscribe(Events.TOGGLE_HELP, this.toggleCheatsheet_.bind(this));
|
2013-11-20 02:46:33 +04:00
|
|
|
$.subscribe(Events.ESCAPE, this.onEscape_.bind(this));
|
2013-11-19 02:53:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
ns.CheatsheetService.prototype.toggleCheatsheet_ = function () {
|
|
|
|
if (this.isDisplayed_) {
|
|
|
|
this.hideCheatsheet_();
|
|
|
|
} else {
|
|
|
|
this.showCheatsheet_();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-20 02:46:33 +04:00
|
|
|
ns.CheatsheetService.prototype.onEscape_ = function () {
|
|
|
|
if (this.isDisplayed_) {
|
|
|
|
this.hideCheatsheet_();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-19 02:53:12 +04:00
|
|
|
ns.CheatsheetService.prototype.showCheatsheet_ = function () {
|
2013-11-20 02:46:33 +04:00
|
|
|
pskl.app.shortcutService.addShortcut('ESC', this.hideCheatsheet_.bind(this));
|
2013-11-19 02:53:12 +04:00
|
|
|
this.cheatsheetEl_.style.display = 'block';
|
|
|
|
this.isDisplayed_ = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ns.CheatsheetService.prototype.hideCheatsheet_ = function () {
|
2013-11-20 02:46:33 +04:00
|
|
|
pskl.app.shortcutService.removeShortcut('ESC');
|
2013-11-19 02:53:12 +04:00
|
|
|
this.cheatsheetEl_.style.display = 'none';
|
|
|
|
this.isDisplayed_ = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.CheatsheetService.prototype.initMarkup_ = function () {
|
|
|
|
this.initMarkupForTools_();
|
2013-11-19 11:13:16 +04:00
|
|
|
this.initMarkupForMisc_();
|
2013-11-19 02:53:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
ns.CheatsheetService.prototype.initMarkupForTools_ = function () {
|
|
|
|
var shortcutTemplate = pskl.utils.Template.get('cheatsheet-shortcut-template');
|
|
|
|
|
|
|
|
var toolShortcutsContainer = $('.cheatsheet-tool-shortcuts', this.cheatsheetEl_).get(0);
|
|
|
|
var tools = pskl.app.toolController.tools;
|
|
|
|
for (var i = 0 ; i < tools.length ; i++) {
|
|
|
|
var tool = tools[i];
|
|
|
|
var shortcutEl = pskl.utils.Template.createFromHTML(
|
|
|
|
pskl.utils.Template.replace(shortcutTemplate, {
|
|
|
|
shortcutIcon : 'tool-icon ' + tool.instance.toolId,
|
|
|
|
shortcutDescription : tool.instance.helpText,
|
|
|
|
shortcutKey : tool.shortcut
|
|
|
|
})
|
|
|
|
);
|
|
|
|
toolShortcutsContainer.appendChild(shortcutEl);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-19 11:15:37 +04:00
|
|
|
ns.CheatsheetService.prototype.initMarkupForMisc_ = function () {
|
2013-11-19 02:53:12 +04:00
|
|
|
var shortcutTemplate = pskl.utils.Template.get('cheatsheet-shortcut-template');
|
|
|
|
|
|
|
|
var miscShortcutsContainer = $('.cheatsheet-misc-shortcuts', this.cheatsheetEl_).get(0);
|
|
|
|
var toDescriptor = function (shortcut, description) {
|
|
|
|
return {shortcut:shortcut, description:description};
|
|
|
|
};
|
|
|
|
var miscKeys = [
|
|
|
|
toDescriptor('X', 'Swap primary/secondary colors'),
|
2013-11-20 02:46:33 +04:00
|
|
|
toDescriptor('D', 'Reset default colors'),
|
2013-11-19 02:53:12 +04:00
|
|
|
toDescriptor('ctrl + X', 'Cut selection'),
|
|
|
|
toDescriptor('ctrl + C', 'Copy selection'),
|
|
|
|
toDescriptor('ctrl + V', 'Paste selection'),
|
|
|
|
toDescriptor('ctrl + Z', 'Undo'),
|
2013-11-20 02:46:33 +04:00
|
|
|
toDescriptor('ctrl + Y', 'Redo'),
|
|
|
|
toDescriptor('↑', 'Select previous frame'), /* ASCII for up-arrow */
|
|
|
|
toDescriptor('↓', 'Select next frame'), /* ASCII for down-arrow */
|
|
|
|
toDescriptor('N', 'Create new frame'),
|
2013-11-21 02:00:47 +04:00
|
|
|
toDescriptor('shift + N', 'Duplicate selected frame'),
|
2013-11-20 02:46:33 +04:00
|
|
|
toDescriptor('shift + ?', 'Open/Close this popup')
|
2013-11-19 02:53:12 +04:00
|
|
|
];
|
|
|
|
for (var i = 0 ; i < miscKeys.length ; i++) {
|
|
|
|
var key = miscKeys[i];
|
|
|
|
var shortcutEl = pskl.utils.Template.createFromHTML(
|
|
|
|
pskl.utils.Template.replace(shortcutTemplate, {
|
|
|
|
shortcutIcon : '',
|
|
|
|
shortcutDescription : key.description,
|
|
|
|
shortcutKey : key.shortcut
|
|
|
|
})
|
|
|
|
);
|
|
|
|
miscShortcutsContainer.appendChild(shortcutEl);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-19 11:13:16 +04:00
|
|
|
})();
|