Author: reebalazs
Date: Thu Oct 25 13:04:05 2007
New Revision: 47908

Modified:
   kukit/kukit.js/trunk/kukit/oper.js
   kukit/kukit.js/trunk/kukit/plugin.js
Log:
Fix key events to work

Modified: kukit/kukit.js/trunk/kukit/oper.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/oper.js  (original)
+++ kukit/kukit.js/trunk/kukit/oper.js  Thu Oct 25 13:04:05 2007
@@ -272,9 +272,9 @@
         // (XXX XXX TODO it should happen here, that we change to a different
         // oper class. This is for the future when we separate the BindOper
         // from the ActionOper.)
-
         var newoper = self.clone(dict, true);
         // call the filter and if it says skip it, we are done
+        // (Filter has a chance to set a defaultParameters on oper.
         if (filter && ! filter(newoper)) return false;
         // execute the event's actions
         newoper.binder._EventBinder_triggerEvent(eventName, newoper);

Modified: kukit/kukit.js/trunk/kukit/plugin.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/plugin.js        (original)
+++ kukit/kukit.js/trunk/kukit/plugin.js        Thu Oct 25 13:04:05 2007
@@ -213,20 +213,68 @@
     oper.evalList('keycodes');
     oper.evalBool('preventdefault');
     oper.evalBool('allowbubbling');
-    var filter;
-    if (oper.parms.keycodes.length >= 0) {
+    oper.evalBool('preventbubbling');
+    var selected_keycodes_only = false;
+    if (oper.parms.keycodes.length > 0) {
         // Convert keyCode to dict
         var keycodes = {};
         for (var i=0; i<oper.parms.keycodes.length; i++) {
-            keyCode = oper.parms.keycodes[i];
+            var keyCode = oper.parms.keycodes[i];
             keycodes[keyCode] = true;
         }
         // Set filter so that only the specified keys should trigger.
-        filter = function(oper) {
-            var keyCode = oper.browserevent.keyCode.toString();
-            return keycodes[keyCode];
-        };
+        selected_keycodes_only = true;
     }
+    // We set a filter to execute in any case. This will be used to 
+    // set the keycode on the defaultParameters, and also to select 
+    // if we want the actions to execute or not.
+    var filter = function(oper) {
+        // XXX this is still a bit wrong... shift, control, altgr keys
+        // may work inconsistently through events and browsers.
+        // We attempt to fix this for the alphabet at least
+        // (a..z, A..Z)
+        var keyCode = oper.browserevent.keyCode;
+        //kukit.log('keyCode: ' + keyCode);
+        if (keyCode == 0) {
+            // need to check also charCode. In case of non-control
+            // characters on IE this will have the value.
+            keyCode = oper.browserevent.charCode;
+            //kukit.log('charCode: ' + keyCode);
+        } else {
+            // Because of IE madness, we need to consider the shift
+            // state in order to have a consistent result.
+            if (keyCode >= 65 && keyCode <= 90 && 
+                    oper.browserevent.shiftKey == false) { // 'A' <= key <= 'Z'
+                // make it a small cap!
+                keyCode = keyCode + 32;
+                //kukit.log('keyCode compensated: ' + keyCode);
+            }
+        }
+        // Stringify the keycode.
+        if (keyCode) {
+            keyCode = keyCode.toString();
+        } else {
+            kukit.logWarning(keyCode);
+            keyCode = '0';
+        }
+        kukit.log(keyCode);
+        // Store the keycode on parms, so actions can access it
+        // with the value provider pass(keycode).
+        oper.defaultParameters = {keycode: keyCode};
+        // Return filter result.
+        if (selected_keycodes_only) {
+            if (keyCode == '0') {
+                // Key pressed without an ascii value, like shift or altgr
+                // We ignore this.
+                return false;
+            } else {
+                return keycodes[keyCode];
+            }
+        } else {
+            // no filtering: execute the actions in case of any key.
+            return true;
+        }
+    };
     kukit.pl.registerBrowserEvent(oper, filter);
 };
 
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to