client/js/foundation/eventmanager/eventmanager.coffee in rsence-pre-3.0.0.3 vs client/js/foundation/eventmanager/eventmanager.coffee in rsence-pre-3.0.0.4
- old
+ new
@@ -89,11 +89,11 @@
# ctrlKeyDown => The state of the Ctrl key.
# shiftKeyDown => The state of the Shift key.
# metaKeyDown => The state of the Meta key.
# cmdKeyDown => The state of the Command key (or equivalent, like the Windows key).
# Note: Will be deprecated in favor of an hash with keys instead of numeric indexes.
- status:
+ status:
0: false
button1: false
setButton1: (f)->
@button1 = f
@[0] = f
@@ -291,11 +291,11 @@
_targetElem = @_getGlobalTargetElem()
_methods = @_eventMethods
_methods.push( 'keyPress' ) unless BROWSER_TYPE.safari or BROWSER_TYPE.ie
for _methodName in _methods
if _methodName == 'doubleClick'
- _eventName = 'dblclick'
+ _eventName = 'dblclick'
else
_eventName = _methodName.toLowerCase()
@observe( _targetElem, _eventName, _methodName )
if window.addEventListener?
@observe( window, 'DOMMouseScroll', 'mouseWheel' )
@@ -357,11 +357,11 @@
@_listeners.byEvent['keyRepeat'].unshift( _viewId )
else
_idx = @_listeners.byEvent['keyRepeat'].indexOf(_viewId)
@_listeners.byEvent['keyRepeat'].splice( _idx, 1 ) if ~_idx
unless ~@_listeners.byEvent[_key].indexOf(_viewId)
- @_listeners.byEvent[_key].unshift( _viewId )
+ @_listeners.byEvent[_key].unshift( _viewId )
if _key == 'rectHover' and _value == 'intersects' and
not ~@_listeners._rectHoverIntersectMode.indexOf( _viewId )
@_listeners._rectHoverIntersectMode.unshift( _viewId )
else # not _value
_keys = [_key]
@@ -550,13 +550,13 @@
h = _rect.height
for _elemId in [ @_debugHighlightT, @_debugHighlightL ]
ELEM.setStyle( _elemId, 'left', x+'px' )
ELEM.setStyle( _elemId, 'top', y+'px' )
for _elemId in [ @_debugHighlightT, @_debugHighlightB ]
- ELEM.setStyle( _elemId, 'width', w+'px' )
+ ELEM.setStyle( _elemId, 'width', w+'px' )
for _elemId in [ @_debugHighlightL, @_debugHighlightR ]
- ELEM.setStyle( _elemId, 'height', h+'px' )
+ ELEM.setStyle( _elemId, 'height', h+'px' )
ELEM.setStyle( @_debugHighlightB, 'top', (y+h)+'px' )
ELEM.setStyle( @_debugHighlightB, 'left', x+'px' )
ELEM.setStyle( @_debugHighlightR, 'top', y+'px' )
ELEM.setStyle( @_debugHighlightR, 'left', (x+w)+'px' )
@@ -777,11 +777,11 @@
@focus( _viewId )
@changeActiveControl(_ctrl)
@_listeners.dragged.unshift( _viewId ) unless ~@_listeners.dragged.indexOf( _viewId )
_ctrl.startDrag( @status.crsrX, @status.crsrY, @status.button2 )
#
- # Cancels text selections, which happen by
+ # Cancels text selections, which happen by
_cancelTextSelection: ->
# Remove possible selections.
ELEM.get(0).focus()
#
# Mouse button press manager. Triggered by the global mouseDown event.
@@ -1008,26 +1008,26 @@
96: 192 # [`~]
91: 219 # [[{]
92: 220 # [\|]
93: 221 # []}]
39: 222 # ['"]
-
- # Numeric keypad keys can't be mapped on Opera, because Opera
+
+ # Numeric keypad keys can't be mapped on Opera, because Opera
# doesn't differentiate between the keys on the numeric keypad
# versus the functionally same keys elsewhere on the keyboard.
-
+
# Branded keys:
# Apple Command keys are same as ctrl, but ctrl is 0; Can't be re-mapped reliably.
# The Windows Menu key also return 0, so it can't be re-mapped either.
219: 91 # Left Windows key (Start)
220: 92 # Right Windows key (Start)
mozilla:
# Symbol keys:
59: 186 # [;:]
61: 187 # [=+]
109: 189 # [-_]
-
+
# Branded keys:
224: 91 # Apple Command key to left windows key mapping
#
# Translates keyCodes to the normalized pseudo-ascii used by IE and WebKit browsers.
# Opera and Mozilla browsers use different codes, so they'll need translations.
@@ -1064,10 +1064,35 @@
else if BROWSER_TYPE.mac
return _keyCode == 91 or _keyCode == 93
# Other platforms use CTRL as the command key.
return _keyCode == 17
#
+ # Special key method handlers for ESC and RETURN, maybe others in the future
+ _defaultKeyActions:
+ '13': 'defaultKey' # return
+ '27': 'escKey' # esc
+ #
+ # Traverses down the parent hierarchy searching for a parent object
+ # that responds true to _methodName. If _ctrl is undefined, use
+ # a special default rule of auto-selecting the active control and
+ # checking all of its siblings before traversing.
+ defaultKey: (_methodName,_ctrl)->
+ if _ctrl?
+ return true if _ctrl[_methodName]? and _ctrl[_methodName]()
+ else # first special rules, check same
+ return null unless @_listeners.active
+ _ctrl = @_views[@_listeners.active[0]]
+ return true if _ctrl[_methodName]? and _ctrl[_methodName]()
+ for _viewId in _ctrl.parent.views
+ continue if _ctrl.viewId == _viewId
+ _ctrl = @_views[_viewId]
+ if _ctrl[_methodName]?
+ return true if _ctrl[_methodName]()
+ if _ctrl.parent?
+ return true if @defaultKey(_methodName,_ctrl.parent)
+ return null
+ #
# Handles the keyDown event
keyDown: (e)->
@_modifiers(e)
_keyCode = @translateKeyCodes( e.keyCode )
_stop = false
@@ -1086,9 +1111,16 @@
@status.addKeyDown( _keyCode )
for _viewId in _keyDowns
_ctrl = @_views[_viewId]
if _ctrl.keyDown?
_stop = true if _ctrl.keyDown(_keyCode)
+ #
+ # Some keys are special (esc and return) and they have their own
+ # special events: defaultKey and escKey, which aren't limited
+ # to instances of HControl, but any parent object will work.
+ if not _repeating and @_defaultKeyActions[_keyCode.toString()]
+ _defaultKeyMethod = @_defaultKeyActions[_keyCode.toString()]
+ _stop = true if @defaultKey(_defaultKeyMethod)
@_lastKeyDown = _keyCode
Event.stop(e) if _stop
keyUp: (e)->
@_modifiers(e)
_keyCode = @translateKeyCodes( e.keyCode )