0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-22 17:27:57 +01:00

Add esc/enter support to cancel or accept popups.

This commit is contained in:
Wouter R 2014-01-16 23:28:58 +01:00
parent 31cec107b0
commit 57c928f195
4 changed files with 42 additions and 10 deletions

View File

@ -7,7 +7,10 @@ function initShapeDialog() {
$("#btnShapePlus").on("onButtonHold",onShapePlus); $("#btnShapePlus").on("onButtonHold",onShapePlus);
$("#btnShapeMin").on("onButtonHold",onShapeMin); $("#btnShapeMin").on("onButtonHold",onShapeMin);
updateShapePreview(); updateShapePreview();
shapePopup = new Popup($("#popupShape"), $("#popupMask")); shapePopup = new Popup($("#popupShape"), $("#popupMask"));
shapePopup.setEscapeKeyHandler(onShapeCancel);
shapePopup.setEnterKeyHandler(onShapeOk);
} }
function showShapeDialog() { function showShapeDialog() {

View File

@ -1,4 +1,5 @@
var keyboardShortcutsEnabled = true; var keyboardShortcutsEnabled = true;
var keyboardEscapeEnterEnabled = false;
var wordBuffer = ""; var wordBuffer = "";
var wordFuncs = { var wordFuncs = {
@ -14,6 +15,17 @@ function initKeyboard() {
$(document).keypress(function(event) { $(document).keypress(function(event) {
if (keyboardEscapeEnterEnabled) {
switch (event.keyCode) {
case 13:
$(document).trigger("onEnterKey");
break;
case 27:
$(document).trigger("onEscapeKey");
break;
}
}
if (!keyboardShortcutsEnabled) return; if (!keyboardShortcutsEnabled) return;
if (event.ctrlKey && event.altKey && ! event.metaKey) processWords(event); if (event.ctrlKey && event.altKey && ! event.metaKey) processWords(event);
if (event.altKey || event.ctrlKey || event.metaKey) return; //ignore key presses with modifier keys except shift if (event.altKey || event.ctrlKey || event.metaKey) return; //ignore key presses with modifier keys except shift

View File

@ -1,20 +1,34 @@
function Popup(element,mask) { function Popup(element, mask) {
var self = this; var self = this;
var escapeKeyHandler = null;
var enterKeyHandler = null;
this.open = function(complete,disableMaskClick) { this.open = function(complete, disableMaskClick) {
mask.fadeIn(POPUP_SHOW_DURATION); mask.fadeIn(POPUP_SHOW_DURATION);
element.fadeIn(POPUP_SHOW_DURATION, complete); element.fadeIn(POPUP_SHOW_DURATION, complete);
keyboardShortcutsEnabled=false;
document.body.removeEventListener('touchmove',prevent,false); keyboardShortcutsEnabled = false;
keyboardEscapeEnterEnabled = true;
document.body.removeEventListener('touchmove', prevent, false);
mask.bind("onButtonClick", function() { self.close() }); mask.bind("onButtonClick", function() { self.close() });
if (escapeKeyHandler) $(document).bind("onEscapeKey", escapeKeyHandler);
if (enterKeyHandler) $(document).bind("onEnterKey", enterKeyHandler);
} }
this.close = function(complete) { this.close = function(complete) {
mask.fadeOut(POPUP_SHOW_DURATION); mask.fadeOut(POPUP_SHOW_DURATION);
element.fadeOut(POPUP_SHOW_DURATION,complete); element.fadeOut(POPUP_SHOW_DURATION, complete);
keyboardShortcutsEnabled=true; keyboardShortcutsEnabled = true;
document.body.addEventListener('touchmove',prevent,false); keyboardEscapeEnterEnabled = false;
document.body.addEventListener('touchmove', prevent, false);
mask.unbind("onButtonClick"); mask.unbind("onButtonClick");
if (escapeKeyHandler) $(document).unbind("onEscapeKey");
if (enterKeyHandler) $(document).unbind("onEnterKey");
} }
this.setEscapeKeyHandler = function(hnd) { escapeKeyHandler = hnd; }
this.setEnterKeyHandler = function(hnd) { enterKeyHandler = hnd; }
} }

View File

@ -1,11 +1,14 @@
var wordArtPopup; var wordArtPopup;
function initWordArt() { function initWordArt() {
$("body").append('<div id="svgfont" style="display:none"></div>'); $("body").append('<div id="svgfont" style="display:none"></div>');
$("#svgfont").load("img/font.svg?"); $("#svgfont").load("img/font.svg?");
$("#btnWordArtOk").on("onButtonClick",onWordArtOk); $("#btnWordArtOk").on("onButtonClick",onWordArtOk);
$("#btnWordArtCancel").on("onButtonClick",onWordArtCancel); $("#btnWordArtCancel").on("onButtonClick",onWordArtCancel);
wordArtPopup = new Popup($("#popupWordArt"),$("#popupMask")); wordArtPopup = new Popup($("#popupWordArt"),$("#popupMask"));
wordArtPopup.setEscapeKeyHandler(onWordArtCancel);
wordArtPopup.setEnterKeyHandler(onWordArtOk);
} }
function showWordArtDialog() { function showWordArtDialog() {