From 52ffd8720a4213fcdf654f16ab1c49095d4d96ad Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Thu, 12 Jul 2012 23:27:49 +0200 Subject: [PATCH] Starts fixing cmd/control select issues on mac. --- src/_h5ai/js/inc/ext/select.js | 35 ++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/_h5ai/js/inc/ext/select.js b/src/_h5ai/js/inc/ext/select.js index c19d600c..cbb4da0a 100644 --- a/src/_h5ai/js/inc/ext/select.js +++ b/src/_h5ai/js/inc/ext/select.js @@ -13,6 +13,33 @@ modulejs.define('ext/select', ['jQuery', 'core/settings', 'core/event'], functio $document = $(document), $selectionRect = $('
'), + ctrlKeyPressed = false, + + isCtrlKey = function (code) { + + // http://github.com/madrobby/keymaster/blob/master/keymaster.js + return code === 17 || code === 91 || code === 92 || code === 93 || code === 224; + }, + + onFocus = function () { + + ctrlKeyPressed = false; + }, + + onKeydown = function (event) { + + if (isCtrlKey(event.keyCode)) { + ctrlKeyPressed = true; + } + }, + + onKeyup = function (event) { + + if (isCtrlKey(event.keyCode)) { + ctrlKeyPressed = false; + } + }, + publish = function () { var entries = _.map($('#extended .entry.selected'), function (entryElement) { @@ -90,7 +117,7 @@ modulejs.define('ext/select', ['jQuery', 'core/settings', 'core/event'], functio event.preventDefault(); $(':focus').blur(); - if (!event.ctrlKey) { + if (!ctrlKeyPressed) { $('#extended .entry').removeClass('selected'); publish(); } @@ -112,7 +139,7 @@ modulejs.define('ext/select', ['jQuery', 'core/settings', 'core/event'], functio noSelectionUnlessCtrl = function (event) { - if (!event.ctrlKey) { + if (!ctrlKeyPressed) { noSelection(event); } }, @@ -125,7 +152,11 @@ modulejs.define('ext/select', ['jQuery', 'core/settings', 'core/event'], functio $selectionRect.hide().appendTo('body'); + $(window).on('focus', onFocus); + $document + .on('keydown', onKeydown) + .on('keyup', onKeyup) .on('mousedown', '.noSelection', noSelection) .on('mousedown', '.noSelectionUnlessCtrl,input,a', noSelectionUnlessCtrl) .on('mousedown', selectionStart);