diff options
Diffstat (limited to 'html/sugar.js')
-rw-r--r-- | html/sugar.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/html/sugar.js b/html/sugar.js new file mode 100644 index 0000000..6c9bf08 --- /dev/null +++ b/html/sugar.js @@ -0,0 +1,46 @@ +// Enyo interface for Sugar + +enyo.Sugar = {}; +enyo.Sugar.component = null; +enyo.Sugar.sendMessage = function(name, args) { + if (enyo.Sugar.component) { + enyo.Sugar.component.signal(name, JSON.parse(args)); + } +}; + +enyo.kind({ + name: "Sugar", + + // Constructor, init component + create: function() { + this.inherited(arguments); + this.handlers = []; + enyo.Sugar.component = this; + }, + + // Connect a callback to a message + connect: function(name, callback) { + this.handlers[name] = callback; + }, + + // Send a message to Sugar + sendMessage: function(name, args) { + var msg = ""; + msg = msg + "enyo://"+name.length+"/"+name; + if (!args) + msg = msg + "/0/"; + else { + var value = JSON.stringify(args); + msg = msg + "/"+value.length+"/"+value; + } + console.log(msg); + }, + + // A message was sent by Sugar + signal: function(name, args) { + var callback = this.handlers[name]; + if (callback) { + callback(args); + } + } +}); |