Author: jvloothuis
Date: Fri Sep 14 21:52:12 2007
New Revision: 46592

Added:
   
kukit/kss.base/trunk/kss/base/templates/plugin/+package+/javascript/plugin.js_tmpl
Removed:
   kukit/kss.base/trunk/kss/base/templates/plugin/+package+/javascript/plugin.js
Log:

Create a template for Javascript plugins. This has example code for
the most common use cases.


Deleted: 
/kukit/kss.base/trunk/kss/base/templates/plugin/+package+/javascript/plugin.js
==============================================================================

Added: 
kukit/kss.base/trunk/kss/base/templates/plugin/+package+/javascript/plugin.js_tmpl
==============================================================================
--- (empty file)
+++ 
kukit/kss.base/trunk/kss/base/templates/plugin/+package+/javascript/plugin.js_tmpl
  Fri Sep 14 21:52:12 2007
@@ -0,0 +1,95 @@
+/*
+
+In this file you can put your own custom Javascript. In the following
+sections you can find examples on how to create the most common
+plugins.
+
+Lines beginning with `;;;` are automatically stripped when served in
+production mode. Put these in front of lines with code like assertions
+statements or logging calls.
+
+*/
+
+
+// Create the namespace for ${package}
+if (typeof(${pacakge}) == 'undefined') {
+    var ${package} = {};
+}
+
+
+//-----------------------------------------------------------
+//                   Action example
+//-----------------------------------------------------------
+${package}.actionsGlobalRegistry.register('exampleAction', function (oper) {
+    // The following is used for logging
+;;; oper.componentName = '[exampleAction] action';
+    
+    // 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(['requiredParameter'], 
+                            {'optionalParameter': 'default'});
+
+    // You can get at the node for which this action is executed like
+    // this. An action is always invoked on a single node. Even when
+    // it applies to multiple nodes (then it will be invoked multiple
+    // times on each node).
+    var node = oper.node;
+
+    // Read a parameter from the parameters
+    var required = oper.parms.requiredParameter;
+
+    // Add your specific action code here
+});
+kukit.commandsGlobalRegistry.registerFromAction(
+    'exampleAction', kukit.cr.makeSelectorCommand);
+
+
+//-----------------------------------------------------------
+//                      Value provider
+//-----------------------------------------------------------
+${package}.ExampleProvider = function() {};
+${package}.ExampleProvider.prototype = {
+    // The check function is executed during the parsing of KSS. Use
+    // this to make sure the arguments are correct.
+    check: function(args) {
+        // An example of what you could check is the argument length
+;;;     if (args.length != 2) {
+            // Raise an error in case something is wrong
+;;;         throw new Error('exampleProvider provider needs 2 arguments [one, 
two]');
+;;;     }
+    },
+    eval: function(args, node) {
+        // Return the value which for this provider
+        return 'example';
+    }
+};
+kukit.pprovidersGlobalRegistry.register(
+    'exampleProvider', ${package}.ExampleProvider);
+// The line above registers the value provider under the name
+// `exampleProvider`
+
+
+
+//-----------------------------------------------------------
+//                      Value provider
+//-----------------------------------------------------------
+${package}.ExampleEventBinder = function() {
+    // Add your initialization stuff here
+    this.exampleVar = {};
+};
+
+${package}.ExampleEventBinder.prototype.__bind__ =
+    function(name, func_to_bind, oper) {
+    // The following is used for logging
+;;; oper.componentName = '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'});
+
+};
+
+kukit.eventsGlobalRegistry.register(null, 'exampleEvent',
+    ${package}.ExampleEventBinder, '__bind__', null);
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to