Examples.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. smalltalk.addPackage('Examples', {});
  2. smalltalk.addClass('Counter', smalltalk.Widget, ['count', 'header'], 'Examples');
  3. smalltalk.Counter.comment=unescape('This%20is%20a%20trivial%20Widget%20example%20mimicking%20the%20classic%20Counter%20example%20in%20Seaside.%20%0AIn%20order%20to%20play%20with%20it%2C%20just%20select%20the%20doit%20below%20and%20press%20the%20Do%20it%20button%20in%20the%20far%20right%20corner.%0AThen%20take%20a%20look%20in%20the%20HTML%20document%20above%20the%20IDE.%0A%0A%20%20%20%20%20%20%20%20Counter%20new%20appendToJQuery%3A%20%27body%27%20asJQuery')
  4. smalltalk.addMethod(
  5. unescape('_decrease'),
  6. smalltalk.method({
  7. selector: unescape('decrease'),
  8. category: 'actions',
  9. fn: function (){
  10. var self=this;
  11. (self['@count']=((($receiver = self['@count']).klass === smalltalk.Number) ? $receiver -(1) : smalltalk.send($receiver, "__minus", [(1)])));
  12. smalltalk.send(self['@header'], "_contents_", [(function(html){return smalltalk.send(html, "_with_", [smalltalk.send(self['@count'], "_asString", [])]);})]);
  13. return self;},
  14. args: [],
  15. source: unescape('decrease%0A%20%20%20%20count%20%3A%3D%20count%20-%201.%0A%20%20%20%20header%20contents%3A%20%5B%3Ahtml%20%7C%20html%20with%3A%20count%20asString%5D'),
  16. messageSends: [unescape("-"), "contents:", "with:", "asString"],
  17. referencedClasses: []
  18. }),
  19. smalltalk.Counter);
  20. smalltalk.addMethod(
  21. unescape('_increase'),
  22. smalltalk.method({
  23. selector: unescape('increase'),
  24. category: 'actions',
  25. fn: function (){
  26. var self=this;
  27. (self['@count']=((($receiver = self['@count']).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)])));
  28. smalltalk.send(self['@header'], "_contents_", [(function(html){return smalltalk.send(html, "_with_", [smalltalk.send(self['@count'], "_asString", [])]);})]);
  29. return self;},
  30. args: [],
  31. source: unescape('increase%0A%20%20%20%20count%20%3A%3D%20count%20+%201.%0A%20%20%20%20header%20contents%3A%20%5B%3Ahtml%20%7C%20html%20with%3A%20count%20asString%5D'),
  32. messageSends: [unescape("+"), "contents:", "with:", "asString"],
  33. referencedClasses: []
  34. }),
  35. smalltalk.Counter);
  36. smalltalk.addMethod(
  37. unescape('_initialize'),
  38. smalltalk.method({
  39. selector: unescape('initialize'),
  40. category: 'initialization',
  41. fn: function (){
  42. var self=this;
  43. smalltalk.send(self, "_initialize", [], smalltalk.Widget);
  44. (self['@count']=(0));
  45. return self;},
  46. args: [],
  47. source: unescape('initialize%0A%20%20%20%20super%20initialize.%0A%20%20%20%20count%20%3A%3D%200'),
  48. messageSends: ["initialize"],
  49. referencedClasses: []
  50. }),
  51. smalltalk.Counter);
  52. smalltalk.addMethod(
  53. unescape('_renderOn_'),
  54. smalltalk.method({
  55. selector: unescape('renderOn%3A'),
  56. category: 'rendering',
  57. fn: function (html){
  58. var self=this;
  59. (self['@header']=(function($rec){smalltalk.send($rec, "_with_", [smalltalk.send(self['@count'], "_asString", [])]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send(html, "_h1", [])));
  60. (function($rec){smalltalk.send($rec, "_with_", [unescape("++")]);return smalltalk.send($rec, "_onClick_", [(function(){return smalltalk.send(self, "_increase", []);})]);})(smalltalk.send(html, "_button", []));
  61. (function($rec){smalltalk.send($rec, "_with_", [unescape("--")]);return smalltalk.send($rec, "_onClick_", [(function(){return smalltalk.send(self, "_decrease", []);})]);})(smalltalk.send(html, "_button", []));
  62. return self;},
  63. args: ["html"],
  64. source: unescape('renderOn%3A%20html%0A%20%20%20%20header%20%3A%3D%20html%20h1%20%0A%09with%3A%20count%20asString%3B%0A%09yourself.%0A%20%20%20%20html%20button%0A%09with%3A%20%27++%27%3B%0A%09onClick%3A%20%5Bself%20increase%5D.%0A%20%20%20%20html%20button%0A%09with%3A%20%27--%27%3B%0A%09onClick%3A%20%5Bself%20decrease%5D'),
  65. messageSends: ["with:", "asString", "yourself", "h1", "onClick:", "increase", "button", "decrease"],
  66. referencedClasses: []
  67. }),
  68. smalltalk.Counter);
  69. smalltalk.addMethod(
  70. unescape('_tryExample'),
  71. smalltalk.method({
  72. selector: unescape('tryExample'),
  73. category: 'example',
  74. fn: function (){
  75. var self=this;
  76. smalltalk.send(smalltalk.send(self, "_new", []), "_appendToJQuery_", [smalltalk.send("body", "_asJQuery", [])]);
  77. return self;},
  78. args: [],
  79. source: unescape('tryExample%0A%09%22In%20order%20to%20play%20with%20the%20Counter%2C%20just%20select%20the%0A%09doit%20below%20and%20press%20the%20Do%20it%20button.%20Then%20take%20a%0A%09look%20in%20the%20HTML%20document%20above%20the%20IDE.%22%0A%0A%09%22Counter%20tryExample%22%0A%20%20%20%20%20%20%20%20self%20new%20appendToJQuery%3A%20%27body%27%20asJQuery%20'),
  80. messageSends: ["appendToJQuery:", "new", "asJQuery"],
  81. referencedClasses: []
  82. }),
  83. smalltalk.Counter.klass);