Author: jvloothuis
Date: Sat Oct  6 11:12:35 2007
New Revision: 47227

Modified:
   
kukit/docs/creating-plugins-plone-conf-2007/src/KSSDemoPlugin/kssdemoplugin/javascript/plugin.js
Log:
Finished the demo for the event

Modified: 
kukit/docs/creating-plugins-plone-conf-2007/src/KSSDemoPlugin/kssdemoplugin/javascript/plugin.js
==============================================================================
--- 
kukit/docs/creating-plugins-plone-conf-2007/src/KSSDemoPlugin/kssdemoplugin/javascript/plugin.js
    (original)
+++ 
kukit/docs/creating-plugins-plone-conf-2007/src/KSSDemoPlugin/kssdemoplugin/javascript/plugin.js
    Sat Oct  6 11:12:35 2007
@@ -72,35 +72,79 @@
 kukit.pprovidersGlobalRegistry.register(
     'demoplugin-random', RandomProvider);
 
+
+var RandomColorProvider = function() {};
+RandomColorProvider.prototype = {
+;;; check: function(args) {
+;;;     // An example of what you could check is the argument length
+// ;;;     if (args.length < 1) {
+// ;;;         // Raise an error in case something is wrong
+// ;;;         throw new Error('demoplugin-randomColor needs at least 1 
argument [max]');
+// ;;;     }
+;;; },
+    eval: function(args, node) {
+        // Return the value which for this provider
+        var color = "rgba(";
+        for(var i=0; i<3; i++){
+            color += Math.round(Math.random() * 255) + ", ";
+        }
+        return color + "0.2)";
+    }
+};
+kukit.pprovidersGlobalRegistry.register(
+    'demoplugin-randomColor', RandomColorProvider);
+
 //-----------------------------------------------------------
 //              Simple event binder for stateful events
 //-----------------------------------------------------------
 
-var ExampleEventBinder = function() {
-    // Add your initialization stuff here
-    this.exampleVar = {};
+var MovementEventBinder = function() {
+    this.x = 0;
+    this.y = 0;
 };
-ExampleEventBinder.prototype.__bind__ = function(name, func_to_bind, oper) {
-    // The following is used for logging
-;;; oper.componentName = '[demoplugin-example] event binding';
 
-    // Validate the parameters to this action, you can add multiple
-    // required or optional parameters. Optional parameters will be
-    // initialized with a default when not passed.
-    oper.evaluateParameters(['delay'], {'repeat': 'true'});
-
-    // optionally, you can check if a parameter is of a given data type,
-    // and convert to it.
-    oper.evalInt('delay');
-    oper.evalBool('repeat');
+    
+MovementEventBinder.prototype.__bind__ = function(name, func_to_bind, oper) {
+    // The following is used for logging
+;;; oper.componentName = '[demoplugin-movement] event binding';
 
-    // Add your specific event code here
+    var keyMovement = {
+        37: [-1, 0], // left
+        38: [0, -1], // up
+        39: [1, 0], // right
+        40: [0, 1] // down
+    };
+
+    oper.completeParms([], {'x': '0', 'y': '0', 'speed': '1'}, 'movement event 
binding');
+    oper.evalInt('x');
+    oper.evalInt('y');
+    oper.evalInt('speed');
+
+    var speed = oper.parms.speed;
+
+    var f = oper.makeExecuteActionsHook();
+
+    var self = this;
+    // Set filter so that only the specified keys should trigger.
+    func = function(e) {
+        var keyCode = e.keyCode.toString();
+
+        // Ignore all non movement keys
+        if(typeof(keyMovement[keyCode]) == 'undefined'){
+            return;
+        }
+
+        self.x += keyMovement[keyCode][0] * speed;
+        self.y += keyMovement[keyCode][1] * speed;
+
+        var parms = {'x': self.x, 'y': self.y};
+        f({defaultParameters: parms});
+    };
+    kukit.ut.registerEventListener(document, 'keydown', func);
 };
 
-kukit.eventsGlobalRegistry.register('demoplugin', 'exampleEvent',
-    ExampleEventBinder, '__bind__', null);
-// The above line registers the demoplugin-exampleEvent
-// with the binder method __bind__.
+kukit.eventsGlobalRegistry.register('demoplugin', 'movement',
+    MovementEventBinder, '__bind__', null);
 
 
 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to