Make Builder widget customisable by "callback" element.
authorMike Taylor <mike@indexdata.com>
Wed, 16 Apr 2014 14:34:25 +0000 (15:34 +0100)
committerMike Taylor <mike@indexdata.com>
Wed, 16 Apr 2014 14:34:25 +0000 (15:34 +0100)
Add new ConsoleBuilder widget that logs the widget to the console.

src/mkws-widget-builder.js

index fb8491c..6460b61 100644 (file)
@@ -1,4 +1,5 @@
 mkws.registerWidgetType('Builder', function() {
+    var that = this;
     var team = this.team;
 
     this.button = $('<button/>', {
@@ -15,6 +16,14 @@ mkws.registerWidgetType('Builder', function() {
                     'autosearch="' + query + '" ' +
                     'sort="' + sort + '" ' +
                     'perpage="' + perpage + '"></div>');
-        alert(html);
+        var fn = that.callback || alert;
+        fn(html);
     });
 });
+
+mkws.registerWidgetType('ConsoleBuilder', function() {
+    mkws.promotionFunction('Builder').call(this);    
+    this.callback = function(s) {
+        console.log("Generated widget: " + s);
+    }
+});