rsence 2.1.5 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.5
1
+ 2.1.6
data/js/core/elem/elem.js CHANGED
@@ -12,6 +12,12 @@
12
12
  var//RSence.Core
13
13
  BROWSER_TYPE = {
14
14
 
15
+ /* Any browser on Mac OS X */
16
+ mac: false,
17
+
18
+ /* Any browser on Windows */
19
+ win: false,
20
+
15
21
  /* Any version of Microsoft Internet Explorer */
16
22
  ie: false,
17
23
 
@@ -1289,6 +1295,9 @@ ELEM = {
1289
1295
  _browserType.ie8 = _isIE && (_ua.indexOf("MSIE 8") !== -1);
1290
1296
  _browserType.ie9 = _isIE && (_ua.indexOf("MSIE 9") !== -1);
1291
1297
 
1298
+ _browserType.mac = (_ua.indexOf("Macintosh") !== -1);
1299
+ _browserType.win = (_ua.indexOf("Windows") !== -1);
1300
+
1292
1301
  // Experimental; don't treat IE9 as an IE at all.
1293
1302
  // NOTE: IE9 Beta does still not behave like a standard web browser.
1294
1303
  // It will probably require as much tuning as earlier IE versions.
@@ -118,6 +118,8 @@ HEventResponder = HClass.extend({
118
118
  * method for it is +keyDown+ and it receives the ascii key
119
119
  * code whenever a keyboard key is pressed. Can also be
120
120
  * toggled separately by using the +setKeyDown+ method.
121
+ * Also supports special mode 'repeat', when listening to
122
+ * key repetitions is needed.
121
123
  * +keyUp+:: The local +keyUp+ event state. The component receives
122
124
  * this event only if it's focused. The event responder
123
125
  * method for it is +keyUp+ and it receives the ascii key
@@ -361,7 +363,8 @@ HEventResponder = HClass.extend({
361
363
  *
362
364
  * = Parameters
363
365
  * +_flag+:: Set the keyDown event listening on/off (true/false) for
364
- * the component instance.
366
+ * the component instance. Also supports special mode 'repeat',
367
+ * when listening to key repetitions is needed.
365
368
  *
366
369
  * = Returns
367
370
  * +self+
@@ -149,7 +149,10 @@ EVENT = {
149
149
  Event.observe( _globalEventTargetElement, 'click', _this.click );
150
150
  Event.observe( _globalEventTargetElement, 'keyup', _this.keyUp );
151
151
  Event.observe( _globalEventTargetElement, 'keydown', _this.keyDown );
152
- Event.observe( _globalEventTargetElement, 'keypress', _this.keyPress );
152
+ // IE and WebKit browsers don't need keyPress for repeat
153
+ if( !BROWSER_TYPE.safari && !BROWSER_TYPE.ie){
154
+ Event.observe( _globalEventTargetElement, 'keypress', _this.keyPress );
155
+ }
153
156
  Event.observe( _globalEventTargetElement, 'contextmenu', _this.contextMenu );
154
157
  Event.observe( _globalEventTargetElement, 'resize', _this.resize );
155
158
  Event.observe( _globalEventTargetElement, 'mousewheel', _this.mouseWheel );
@@ -857,36 +860,85 @@ EVENT = {
857
860
  },
858
861
 
859
862
 
863
+ /** Mid-level mouse scroll wheel event manager.
864
+ * Delegates mouseWheel calls to the high-level event receivers of all
865
+ * controls registered for that event.
866
+ **/
867
+ mouseWheel: function(e) {
868
+ var _this = EVENT,
869
+ _delta = 0,
870
+ i = 0;
871
+ if (!e) {
872
+ e = window.event;
873
+ }
874
+ if (e.wheelDelta) {
875
+ _delta = 0 - (e.wheelDelta / 120);
876
+ }
877
+ else if (e.detail) {
878
+ _delta = 0 - (e.detail / 3);
879
+ }
880
+ if (BROWSER_TYPE.opera || BROWSER_TYPE.safari) {
881
+ _delta = 0 - _delta;
882
+ }
883
+ for (; i !== _this.focused.length; i++) {
884
+ if (_this.focused[i] === true) {
885
+ if (_this.focusOptions[i].mouseWheel === true) {
886
+ Event.stop(e);
887
+ _this.focusOptions[i].ctrl.mouseWheel(_delta);
888
+ }
889
+ }
890
+ }
891
+ },
892
+
893
+ /* Alternative right button detection, wrapper for the mouseDown method */
894
+ contextMenu: function(e) {
895
+ // EVENT.mouseDown(e, false);
896
+ Event.stop(e);
897
+
898
+ /***
899
+
900
+ IMPLEMENT SEPARATE CONTEXT-MENU EVENT HANDLING HERE
901
+
902
+ ***/
903
+
904
+ // if(Event.isLeftClick(e)){
905
+ // EVENT.status[EVENT.button2] = false;
906
+ // }
907
+ },
908
+
909
+
860
910
  /** Mid-level key press manager.
861
911
  * Gets called on the onKeyDown event.
862
912
  * Delegates keyDown calls to the high-level event receivers of all
863
913
  * controls registered for that event.
864
914
  **/
865
915
  keyDown: function(e) {
866
- var _this = EVENT,
867
- _theKeyCode = e.keyCode,
868
- _keyDownStateForActiveControl = _this.activeControl?(_this.focusOptions[_this.activeControl.elemId]?_this.focusOptions[_this.activeControl.elemId].keyDown:false):false,
869
- _repeat = (_keyDownStateForActiveControl === 'repeat'),
870
- _stopEvent = false;
916
+ var
917
+ _this = EVENT,
918
+ _keyCode = _this.translateKeyCodes(e.keyCode),
919
+ _keyDownStateForActiveControl = _this.activeControl?(_this.focusOptions[_this.activeControl.elemId]?_this.focusOptions[_this.activeControl.elemId].keyDown:false):false,
920
+ _repeat = (_keyDownStateForActiveControl === 'repeat'),
921
+ _stopEvent = false;
871
922
  _this._modifiers(e);
872
- if(!_this.status[_this.cmdKeyDown] && _this._detectCmdKey(e.keyCode)){
923
+ _this._lastKeyPressTime = new Date().getTime();
924
+ if(!_this.status[_this.cmdKeyDown] && _this._detectCmdKey(_keyCode)){
873
925
  _this.status[_this.cmdKeyDown] = true;
874
926
  }
875
927
  if (_this.activeControl && _keyDownStateForActiveControl) {
876
- if ((_this._lastKeyDown !== _theKeyCode) || _repeat) {
877
- if(_this.activeControl.keyDown(_theKeyCode)){
928
+ if ((_this._lastKeyDown !== _keyCode) || _repeat) {
929
+ if(_this.activeControl.keyDown(_keyCode)){
878
930
  _stopEvent = true;
879
931
  }
880
932
  }
881
933
  }
882
934
  // Insert key to the realtime array, remove in keyUp
883
- if (_this.status[_this.keysDown].indexOf(_theKeyCode) === -1) {
884
- _this.status[_this.keysDown].push(_theKeyCode);
935
+ if (_this.status[_this.keysDown].indexOf(_keyCode) === -1) {
936
+ _this.status[_this.keysDown].push(_keyCode);
885
937
  }
886
938
  if (!_this.status[_this.cmdKeyDown] && _stopEvent){
887
939
  Event.stop(e);
888
940
  }
889
- _this._lastKeyDown = _theKeyCode;
941
+ _this._lastKeyDown = _keyCode;
890
942
  },
891
943
 
892
944
 
@@ -898,17 +950,18 @@ EVENT = {
898
950
  * registered for that event.
899
951
  **/
900
952
  keyUp: function(e) {
901
- var _this = EVENT,
902
- _theKeyCode = e.keyCode,
903
- _keyCodeIndex,
904
- i = 0,
905
- _stopEvent = false,
906
- _ctrlId,
907
- _ctrl;
953
+ var
954
+ _this = EVENT,
955
+ _keyCode = _this.translateKeyCodes(e.keyCode),
956
+ _keyCodeIndex,
957
+ i = 0,
958
+ _stopEvent = false,
959
+ _ctrlId,
960
+ _ctrl;
908
961
  _this._modifiers(e);
909
962
  _this._lastKeyDown = null;
910
963
  if (_this.activeControl && _this.activeControl.elemId && _this.focusOptions[_this.activeControl.elemId].keyUp === true) {
911
- if(_this.activeControl.keyUp(_theKeyCode)){
964
+ if(_this.activeControl.keyUp(_keyCode)){
912
965
  _stopEvent = true;
913
966
  }
914
967
  }
@@ -924,81 +977,136 @@ EVENT = {
924
977
  if (!_this.status[_this.cmdKeyDown] && _stopEvent){
925
978
  Event.stop(e);
926
979
  }
927
- if(_this.status[_this.cmdKeyDown] && _this._detectCmdKey(e.keyCode)){
980
+ if(_this.status[_this.cmdKeyDown] && _this._detectCmdKey(_keyCode)){
928
981
  _this.status[_this.cmdKeyDown] = false;
929
982
  }
930
983
  // Remove the key from the realtime array, inserted in keyDown
931
- _keyCodeIndex = _this.status[_this.keysDown].indexOf(_theKeyCode);
984
+ _keyCodeIndex = _this.status[_this.keysDown].indexOf(_keyCode);
932
985
  if (_keyCodeIndex !== -1) {
933
986
  _this.status[_this.keysDown].splice(_keyCodeIndex, 1);
934
987
  }
935
988
  },
936
989
 
937
- /* Using keyPress as an alias for the keyDown event */
990
+ /* The keyPress itself is ignored per se and used only as a repetition event for the last keyDown. */
938
991
  keyPress: function(e) {
939
- var _this = EVENT;
940
- _this.keyDown(e);
941
- },
942
-
943
-
944
- /** Mid-level mouse scroll wheel event manager.
945
- * Delegates mouseWheel calls to the high-level event receivers of all
946
- * controls registered for that event.
947
- **/
948
- mouseWheel: function(e) {
949
- var _this = EVENT,
950
- _delta = 0,
951
- i = 0;
952
- if (!e) {
953
- e = window.event;
954
- }
955
- if (e.wheelDelta) {
956
- _delta = 0 - (e.wheelDelta / 120);
957
- }
958
- else if (e.detail) {
959
- _delta = 0 - (e.detail / 3);
960
- }
961
- if (BROWSER_TYPE.opera || BROWSER_TYPE.safari) {
962
- _delta = 0 - _delta;
992
+ var
993
+ _this = EVENT,
994
+ _timeNow = new Date().getTime();
995
+ _this._modifiers(e);
996
+ // Prevent non-repeat behaviour by waiting at least 100ms before repeating
997
+ if(_this._lastKeyPressTime > (_timeNow-100)){
998
+ return;
963
999
  }
964
- for (; i !== _this.focused.length; i++) {
965
- if (_this.focused[i] === true) {
966
- if (_this.focusOptions[i].mouseWheel === true) {
967
- Event.stop(e);
968
- _this.focusOptions[i].ctrl.mouseWheel(_delta);
1000
+ if(_this._lastKeyDown !== null){
1001
+ var
1002
+ _keyCode = _this.translateKeyCodes(_this._lastKeyDown),
1003
+ _keyDownStateForActiveControl = _this.activeControl?(_this.focusOptions[_this.activeControl.elemId]?_this.focusOptions[_this.activeControl.elemId].keyDown:false):false,
1004
+ _repeat = (_keyDownStateForActiveControl === 'repeat'),
1005
+ _stopEvent = false;
1006
+ if (_this.activeControl && _keyDownStateForActiveControl && _repeat) {
1007
+ if(_this.activeControl.keyDown(_keyCode)){
1008
+ _stopEvent = true;
969
1009
  }
970
1010
  }
1011
+ if(_stopEvent){
1012
+ Event.stop(e);
1013
+ }
971
1014
  }
972
1015
  },
973
1016
 
974
- /* Alternative right button detection, wrapper for the mouseDown method */
975
- contextMenu: function(e) {
976
- // EVENT.mouseDown(e, false);
977
- Event.stop(e);
1017
+
1018
+ // Normalization map of keyCodes for Opera specifically
1019
+ _operaKeyCodeTranslations: {
978
1020
 
979
- /***
1021
+ // Symbol keys:
1022
+ 59: 186, // [;:]
1023
+ 61: 187, // [=+]
1024
+ 44: 188, // [,<]
1025
+ 45: 189, // [-_]
1026
+ 46: 190, // [.>]
1027
+ 47: 191, // [/?]
1028
+ 96: 192, // [`~]
1029
+ 91: 219, // [[{]
1030
+ 92: 220, // [\|]
1031
+ 93: 221, // []}]
1032
+ 39: 222, // ['"]
980
1033
 
981
- IMPLEMENT SEPARATE CONTEXT-MENU EVENT HANDLING HERE
1034
+ // Numeric keypad keys can't be mapped on Opera, because Opera
1035
+ // doesn't differentiate between the keys on the numeric keypad
1036
+ // versus the functionally same keys elsewhere on the keyboard.
982
1037
 
983
- ***/
1038
+ // Branded keys:
1039
+ // Apple Command keys are same as ctrl, but ctrl is 0; Can't be re-mapped reliably.
1040
+ // The Windows Menu key also return 0, so it can't be re-mapped either.
1041
+ 219: 91, // Left Windows key (Start)
1042
+ 220: 92 // Right Windows key (Start)
1043
+ },
1044
+
1045
+ // Normalization map of keyCodes for Gecko (Mozilla) browsers specifically
1046
+ _mozillaKeyCodeTranslations: {
984
1047
 
985
- // if(Event.isLeftClick(e)){
986
- // EVENT.status[EVENT.button2] = false;
1048
+ // Symbol keys:
1049
+ 59: 186, // [;:]
1050
+ 61: 187, // [=+]
1051
+ 109: 189, // [-_]
1052
+
1053
+ // Branded keys:
1054
+ 224: 91 // Apple Command key to left windows key mapping
1055
+
1056
+ },
1057
+
1058
+ /** Translates keyCodes to the normalized pseudo-ascii used by IE and WebKit browsers.
1059
+ * Opera and Mozilla browsers use different codes, so they'll need translations.
1060
+ **/
1061
+ translateKeyCodes: function(_keyCode){
1062
+ var
1063
+ _this = EVENT,
1064
+ _transCode;
1065
+
1066
+ // We use the WebKit and IE browsers as the normalization base, because
1067
+ // there is no variance between in these. Returns the keyCode as-is for
1068
+ // browsers in this category.
1069
+ if(BROWSER_TYPE.safari || BROWSER_TYPE.ie){
1070
+ return _keyCode;
1071
+ }
1072
+ // Opera has its own keyCodes, which are different from all others.
1073
+ else if(BROWSER_TYPE.opera){
1074
+ _transCode = _this._operaKeyCodeTranslations[_keyCode];
1075
+ }
1076
+ // The assumption is that the other browsers do what mozille does.
1077
+ else {
1078
+ _transCode = _this._mozillaKeyCodeTranslations[_keyCode];
1079
+ }
1080
+ if(_transCode === undefined || _transCode === null){
1081
+ return _keyCode;
1082
+ }
1083
+ // else {
1084
+ // console.log('key map from:',_keyCode,' to:',_transCode);
987
1085
  // }
1086
+ return _transCode;
988
1087
  },
989
1088
 
990
1089
  _cmdKeys: [
991
- 224, // Mozilla Left or Right Command Key
992
- 219, // Opera Left Windows Key
993
- 220, // Opera Right Windows Key
994
- 0, // Opera Menu Key or Linux Gecko: any Windows Key
995
- 17, // Opera
1090
+ 17, // Ctrl
996
1091
  91, // Others (Left Start Key or Left Command Key)
997
1092
  92, // Others (Right Start Key)
998
1093
  93 // Others (Menu Key or Right Command Key)
999
1094
  ],
1000
1095
  _detectCmdKey: function( _keyCode ) {
1001
- return (EVENT._cmdKeys.indexOf(_keyCode) !== -1);
1096
+
1097
+ // On Opera, return true on any of the keycodes
1098
+ if(BROWSER_TYPE.opera){
1099
+ return (EVENT._cmdKeys.indexOf(_keyCode) !== -1);
1100
+ }
1101
+ // Any mac browser (except opera, above) uses left or right windows key
1102
+ // equivalent as the Command key.
1103
+ else if(BROWSER_TYPE.mac){
1104
+ return ((_keyCode === 91) || (_keyCode === 93));
1105
+ }
1106
+ // Other platforms use CTRL as the command key.
1107
+ else {
1108
+ return (_keyCode === 17);
1109
+ }
1002
1110
  },
1003
1111
 
1004
1112
  /* Handle the event modifiers. */
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsence
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 1
9
- - 5
10
- version: 2.1.5
9
+ - 6
10
+ version: 2.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Riassence Inc.
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-14 00:00:00 +02:00
18
+ date: 2010-12-16 00:00:00 +02:00
19
19
  default_executable: rsence
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency