not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
998 B

  1. // Enyo interface for Sugar
  2. if (Util.onSugar()) {
  3. enyo.Sugar = {};
  4. enyo.Sugar.component = null;
  5. enyo.Sugar.sendMessage = function(name, args) {
  6. if (enyo.Sugar.component) {
  7. enyo.Sugar.component.signal(name, JSON.parse(args));
  8. }
  9. };
  10. enyo.kind({
  11. name: "Sugar",
  12. // Constructor, init component
  13. create: function() {
  14. this.inherited(arguments);
  15. this.handlers = [];
  16. enyo.Sugar.component = this;
  17. },
  18. // Connect a callback to a message
  19. connect: function(name, callback) {
  20. this.handlers[name] = callback;
  21. },
  22. // Send a message to Sugar
  23. sendMessage: function(name, args) {
  24. var msg = "";
  25. msg = msg + "enyo://"+name.length+"/"+name;
  26. if (!args)
  27. msg = msg + "/0/";
  28. else {
  29. var value = JSON.stringify(args);
  30. msg = msg + "/"+value.length+"/"+value;
  31. }
  32. console.log(msg);
  33. },
  34. // A message was sent by Sugar
  35. signal: function(name, args) {
  36. var callback = this.handlers[name];
  37. if (callback) {
  38. callback(args);
  39. }
  40. }
  41. });
  42. }