Author: rgardler
Date: Wed Nov  2 15:43:25 2011
New Revision: 1196641

URL: http://svn.apache.org/viewvc?rev=1196641&view=rev
Log:
add a mechanism for adding event callbacks. This will allow widgets to bind to 
key events and respond appropriately.

Modified:
    incubator/wookie/trunk/widgets/templates/browse/readme.txt
    incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js

Modified: incubator/wookie/trunk/widgets/templates/browse/readme.txt
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/browse/readme.txt?rev=1196641&r1=1196640&r2=1196641&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/browse/readme.txt (original)
+++ incubator/wookie/trunk/widgets/templates/browse/readme.txt Wed Nov  2 
15:43:25 2011
@@ -40,4 +40,23 @@ The XML returned is then transformed usi
 into the expanded control. The location of the XSLT file is defined by 
"browse.detail.xsl.url" and
 defaults to "detail2html.xsl". We recommend copying this 
 stylesheet to your widget definition and editing it to process the data 
returned by your
-API.
\ No newline at end of file
+API.
+** Events
+
+You can register callbacks for events using the
+WIDGETNAME_browse_controller.register(EVENTNAME, callback function)
+method.
+
+Available events are:
+
+*** Expand
+
+Called whenever an item in the browse list has been expanded. The
+function is passed an event object (which is generated by JQuery) and
+the ID of the item being expanded.
+
+#+BEGIN_SRC javascript
+${widget.shortname}_browse_controller.register("expand", function(event, 
itemid) {
+    alert("expanded item with id " + itemId);
+});
+#+END_SRC

Modified: 
incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js?rev=1196641&r1=1196640&r2=1196641&view=diff
==============================================================================
--- 
incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js 
(original)
+++ 
incubator/wookie/trunk/widgets/templates/browse/scripts/browse_controller.js 
Wed Nov  2 15:43:25 2011
@@ -20,6 +20,12 @@
  * This is used to wire up the view and model with actions
  */ 
 var ${widget.shortname}_browse_controller = {
+    /**
+     * A dictionary of callback function that are called whenver an
+     * event is fired by this widget.
+     */
+    callbacks: {},
+
     init:function() {
         ${widget.shortname}_browse_controller.update();
         ${widget.shortname}_browse_controller.search()
@@ -78,6 +84,18 @@ var ${widget.shortname}_browse_controlle
     },
     
     /**
+     * Register a callback function for an an event in this widget.
+     */
+    register:function(event, callback) {
+       var cbks = ${widget.shortname}_browse_controller.callbacks[event];
+       if (cbks === undefined) {
+           cbks = new Array();
+       }
+       cbks.push(callback);
+       ${widget.shortname}_browse_controller.callbacks[event] = cbks;
+    },
+    
+    /**
      * Retrieve the details of an item and display them in the detail section.
      */
     displaySummary:function(itemId){
@@ -103,5 +121,10 @@ $('#home').live('pageshow',function(even
  * Display the content of a result item when it is expanded.
  */
 $('div.result').live('expand', function(event) {
-       
${widget.shortname}_browse_controller.displaySummary($(this).attr("wid"))
+    ${widget.shortname}_browse_controller.displaySummary($(this).attr("wid"));
+    var cbks = ${widget.shortname}_browse_controller.callbacks["expand"];
+    if (cbks === undefined) return;
+    for (var i = 0; i < cbks.length; i++) {
+       cbks[i](event, $(this).attr("wid"));
+    }
 });
\ No newline at end of file


Reply via email to