mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Usability : keyboard shortcuts cheatsheet
- click outside of cheatsheet-wrapper closes the popup - removed jquery from CheatsheetService - removed label 'Keyboard shortcuts' in favor of tooltip
This commit is contained in:
parent
6070ebead5
commit
007e4d4e11
@ -27,12 +27,10 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 10000;
|
z-index: 10000;
|
||||||
|
|
||||||
top: 0;
|
top: 50px;
|
||||||
right: 0;
|
right: 50px;
|
||||||
bottom: 0;
|
bottom: 50px;
|
||||||
left: 0;
|
left: 50px;
|
||||||
|
|
||||||
padding: 50px;
|
|
||||||
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
-moz-box-sizing : border-box;
|
-moz-box-sizing : border-box;
|
||||||
|
@ -2,27 +2,37 @@
|
|||||||
var ns = $.namespace('pskl.service.keyboard');
|
var ns = $.namespace('pskl.service.keyboard');
|
||||||
|
|
||||||
ns.CheatsheetService = function () {
|
ns.CheatsheetService = function () {
|
||||||
this.isDisplayed_ = false;
|
this.isDisplayed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.CheatsheetService.prototype.init = function () {
|
ns.CheatsheetService.prototype.init = function () {
|
||||||
this.cheatsheetEl_ = document.getElementById('cheatsheet-wrapper');
|
this.cheatsheetLinkEl = document.querySelector('.cheatsheet-link');
|
||||||
if (!this.cheatsheetEl_) {
|
this.cheatsheetEl = document.getElementById('cheatsheet-wrapper');
|
||||||
throw 'cheatsheetEl_ DOM element could not be retrieved';
|
if (!this.cheatsheetEl) {
|
||||||
|
throw 'cheatsheetEl DOM element could not be retrieved';
|
||||||
}
|
}
|
||||||
|
|
||||||
this.initMarkup_();
|
this.initMarkup_();
|
||||||
pskl.app.shortcutService.addShortcuts(['?', 'shift+?'], this.toggleCheatsheet_.bind(this));
|
pskl.app.shortcutService.addShortcuts(['?', 'shift+?'], this.toggleCheatsheet_.bind(this));
|
||||||
|
|
||||||
var link = $('.cheatsheet-link');
|
pskl.utils.Event.addEventListener(document.body, 'click', this.onBodyClick_, this);
|
||||||
link.click(this.toggleCheatsheet_.bind(this));
|
|
||||||
|
|
||||||
|
|
||||||
$.subscribe(Events.TOGGLE_HELP, this.toggleCheatsheet_.bind(this));
|
$.subscribe(Events.TOGGLE_HELP, this.toggleCheatsheet_.bind(this));
|
||||||
$.subscribe(Events.ESCAPE, this.onEscape_.bind(this));
|
$.subscribe(Events.ESCAPE, this.onEscape_.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ns.CheatsheetService.prototype.onBodyClick_ = function (evt) {
|
||||||
|
var isOnCheatsheet = this.cheatsheetEl.contains(evt.target);
|
||||||
|
var isOnLink = this.cheatsheetLinkEl.contains(evt.target);
|
||||||
|
if (isOnLink) {
|
||||||
|
this.toggleCheatsheet_();
|
||||||
|
} else if (!isOnCheatsheet) {
|
||||||
|
this.hideCheatsheet_();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ns.CheatsheetService.prototype.toggleCheatsheet_ = function () {
|
ns.CheatsheetService.prototype.toggleCheatsheet_ = function () {
|
||||||
if (this.isDisplayed_) {
|
if (this.isDisplayed) {
|
||||||
this.hideCheatsheet_();
|
this.hideCheatsheet_();
|
||||||
} else {
|
} else {
|
||||||
this.showCheatsheet_();
|
this.showCheatsheet_();
|
||||||
@ -30,22 +40,22 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
ns.CheatsheetService.prototype.onEscape_ = function () {
|
ns.CheatsheetService.prototype.onEscape_ = function () {
|
||||||
if (this.isDisplayed_) {
|
if (this.isDisplayed) {
|
||||||
this.hideCheatsheet_();
|
this.hideCheatsheet_();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.CheatsheetService.prototype.showCheatsheet_ = function () {
|
ns.CheatsheetService.prototype.showCheatsheet_ = function () {
|
||||||
pskl.app.shortcutService.addShortcut('ESC', this.hideCheatsheet_.bind(this));
|
pskl.app.shortcutService.addShortcut('ESC', this.hideCheatsheet_.bind(this));
|
||||||
this.cheatsheetEl_.style.display = 'block';
|
this.cheatsheetEl.style.display = 'block';
|
||||||
this.isDisplayed_ = true;
|
this.isDisplayed = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ns.CheatsheetService.prototype.hideCheatsheet_ = function () {
|
ns.CheatsheetService.prototype.hideCheatsheet_ = function () {
|
||||||
pskl.app.shortcutService.removeShortcut('ESC');
|
pskl.app.shortcutService.removeShortcut('ESC');
|
||||||
this.cheatsheetEl_.style.display = 'none';
|
this.cheatsheetEl.style.display = 'none';
|
||||||
this.isDisplayed_ = false;
|
this.isDisplayed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.CheatsheetService.prototype.initMarkup_ = function () {
|
ns.CheatsheetService.prototype.initMarkup_ = function () {
|
||||||
@ -77,7 +87,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
ns.CheatsheetService.prototype.initMarkupAbstract_ = function (descriptors, containerSelector) {
|
ns.CheatsheetService.prototype.initMarkupAbstract_ = function (descriptors, containerSelector) {
|
||||||
var container = $(containerSelector, this.cheatsheetEl_).get(0);
|
var container = $(containerSelector, this.cheatsheetEl).get(0);
|
||||||
for (var i = 0 ; i < descriptors.length ; i++) {
|
for (var i = 0 ; i < descriptors.length ; i++) {
|
||||||
var descriptor = descriptors[i];
|
var descriptor = descriptors[i];
|
||||||
var shortcutEl = this.getDomFromDescriptor_(descriptor);
|
var shortcutEl = this.getDomFromDescriptor_(descriptor);
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span class="cheatsheet-link">Keyboard shortcuts</a>
|
<span
|
||||||
|
class="cheatsheet-link"
|
||||||
|
rel="tooltip" data-placement="right" title="Keyboard shortcuts"> </span>
|
||||||
<script type="text/template" id="cheatsheet-shortcut-template">
|
<script type="text/template" id="cheatsheet-shortcut-template">
|
||||||
<li class="cheatsheet-shortcut">
|
<li class="cheatsheet-shortcut">
|
||||||
<div class="cheatsheet-icon {{shortcutIcon}}"></div>
|
<div class="cheatsheet-icon {{shortcutIcon}}"></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user