-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #287 : Move CheatsheetService to CheatsheetController + Dialogs…
…Controller
- Loading branch information
1 parent
628dd65
commit dffb43a
Showing
12 changed files
with
190 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
(function () { | ||
var ns = $.namespace('pskl.controller.dialogs'); | ||
|
||
ns.CheatsheetController = function () { | ||
this.shortcuts = pskl.service.keyboard.Shortcuts; | ||
}; | ||
|
||
pskl.utils.inherit(ns.CheatsheetController, ns.AbstractDialogController); | ||
|
||
ns.CheatsheetController.prototype.init = function () { | ||
this.cheatsheetEl = document.getElementById('cheatsheetContainer'); | ||
if (!this.cheatsheetEl) { | ||
throw 'cheatsheetEl DOM element could not be retrieved'; | ||
} | ||
console.log('>>>>>> CheatsheetController INIT'); | ||
this.initMarkup_(); | ||
}; | ||
|
||
ns.CheatsheetController.prototype.initMarkup_ = function () { | ||
this.initMarkupForTools_(); | ||
this.initMarkupForMisc_(); | ||
this.initMarkupForColors_(); | ||
this.initMarkupForSelection_(); | ||
}; | ||
|
||
ns.CheatsheetController.prototype.initMarkupForTools_ = function () { | ||
var descriptors = this.createShortcutDescriptors_(this.shortcuts.TOOL, this.getToolShortcutClassname_); | ||
this.initMarkupForDescriptors_(descriptors, '.cheatsheet-tool-shortcuts'); | ||
}; | ||
|
||
ns.CheatsheetController.prototype.getToolShortcutClassname_ = function (shortcut) { | ||
return 'tool-icon ' + shortcut.getId(); | ||
}; | ||
|
||
ns.CheatsheetController.prototype.initMarkupForMisc_ = function () { | ||
var descriptors = this.createShortcutDescriptors_(this.shortcuts.MISC); | ||
this.initMarkupForDescriptors_(descriptors, '.cheatsheet-misc-shortcuts'); | ||
}; | ||
|
||
ns.CheatsheetController.prototype.initMarkupForColors_ = function () { | ||
var descriptors = this.createShortcutDescriptors_(this.shortcuts.COLOR); | ||
this.initMarkupForDescriptors_(descriptors, '.cheatsheet-colors-shortcuts'); | ||
}; | ||
|
||
ns.CheatsheetController.prototype.initMarkupForSelection_ = function () { | ||
var descriptors = this.createShortcutDescriptors_(this.shortcuts.SELECTION); | ||
this.initMarkupForDescriptors_(descriptors, '.cheatsheet-selection-shortcuts'); | ||
}; | ||
|
||
ns.CheatsheetController.prototype.createShortcutDescriptors_ = function (shortcutMap, classnameProvider) { | ||
return Object.keys(shortcutMap).map(function (shortcutKey) { | ||
var shortcut = shortcutMap[shortcutKey]; | ||
var classname = typeof classnameProvider == 'function' ? classnameProvider(shortcut) : ''; | ||
return this.toDescriptor_(shortcut.getKey(), shortcut.getDescription(), classname); | ||
}.bind(this)); | ||
}; | ||
|
||
ns.CheatsheetController.prototype.toDescriptor_ = function (key, description, icon) { | ||
if (pskl.utils.UserAgent.isMac) { | ||
key = key.replace('ctrl', 'cmd'); | ||
} | ||
key = key.replace('up', '↑'); | ||
key = key.replace('down', '↓'); | ||
key = key.replace(/>/g, '>'); | ||
key = key.replace(/</g, '<'); | ||
key = key.replace(/^(.*[^ ])\+([^ ].*)$/g, '$1 + $2'); | ||
|
||
return { | ||
'key' : key, | ||
'description' : description, | ||
'icon' : icon | ||
}; | ||
}; | ||
|
||
ns.CheatsheetController.prototype.initMarkupForDescriptors_ = function (descriptors, containerSelector) { | ||
var container = document.querySelector(containerSelector); | ||
descriptors.forEach(function (descriptor) { | ||
var shortcut = this.getDomFromDescriptor_(descriptor); | ||
container.appendChild(shortcut); | ||
}.bind(this)); | ||
}; | ||
|
||
ns.CheatsheetController.prototype.getDomFromDescriptor_ = function (descriptor) { | ||
var shortcutTemplate = pskl.utils.Template.get('cheatsheet-shortcut-template'); | ||
var markup = pskl.utils.Template.replace(shortcutTemplate, { | ||
shortcutIcon : descriptor.icon, | ||
shortcutDescription : descriptor.description, | ||
shortcutKey : descriptor.key | ||
}); | ||
|
||
return pskl.utils.Template.createFromHTML(markup); | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.