Examples.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. smalltalk.addPackage('Examples', {});
  2. smalltalk.addClass('Counter', smalltalk.Widget, ['count', 'header'], 'Examples');
  3. smalltalk.Counter.comment="This is a trivial Widget example mimicking the classic Counter example in Seaside. \x0aIn order to play with it, just select the doit below and press the Do it button in the far right corner.\x0aThen take a look in the HTML document above the IDE.\x0a\x0a Counter new appendToJQuery: 'body' asJQuery"
  4. smalltalk.addMethod(
  5. "_decrease",
  6. smalltalk.method({
  7. selector: "decrease",
  8. category: 'actions',
  9. fn: function (){
  10. var self=this;
  11. return smalltalk.withContext(function($ctx1) { self["@count"]=_st(self["@count"]).__minus((1));
  12. _st(self["@header"])._contents_((function(html){
  13. return smalltalk.withContext(function($ctx2) { return _st(html)._with_(_st(self["@count"])._asString());
  14. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1)})}));
  15. return self}, function($ctx1) {$ctx1.fill(self,"decrease",{}, smalltalk.Counter)})},
  16. args: [],
  17. source: "decrease\x0a count := count - 1.\x0a header contents: [:html | html with: count asString]",
  18. messageSends: ["-", "contents:", "with:", "asString"],
  19. referencedClasses: []
  20. }),
  21. smalltalk.Counter);
  22. smalltalk.addMethod(
  23. "_increase",
  24. smalltalk.method({
  25. selector: "increase",
  26. category: 'actions',
  27. fn: function (){
  28. var self=this;
  29. return smalltalk.withContext(function($ctx1) { self["@count"]=_st(self["@count"]).__plus((1));
  30. _st(self["@header"])._contents_((function(html){
  31. return smalltalk.withContext(function($ctx2) { return _st(html)._with_(_st(self["@count"])._asString());
  32. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1)})}));
  33. return self}, function($ctx1) {$ctx1.fill(self,"increase",{}, smalltalk.Counter)})},
  34. args: [],
  35. source: "increase\x0a count := count + 1.\x0a header contents: [:html | html with: count asString]",
  36. messageSends: ["+", "contents:", "with:", "asString"],
  37. referencedClasses: []
  38. }),
  39. smalltalk.Counter);
  40. smalltalk.addMethod(
  41. "_initialize",
  42. smalltalk.method({
  43. selector: "initialize",
  44. category: 'initialization',
  45. fn: function (){
  46. var self=this;
  47. return smalltalk.withContext(function($ctx1) { smalltalk.Widget.fn.prototype._initialize.apply(_st(self), []);
  48. self["@count"]=(0);
  49. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{}, smalltalk.Counter)})},
  50. args: [],
  51. source: "initialize\x0a super initialize.\x0a count := 0",
  52. messageSends: ["initialize"],
  53. referencedClasses: []
  54. }),
  55. smalltalk.Counter);
  56. smalltalk.addMethod(
  57. "_renderOn_",
  58. smalltalk.method({
  59. selector: "renderOn:",
  60. category: 'rendering',
  61. fn: function (html){
  62. var self=this;
  63. return smalltalk.withContext(function($ctx1) { var $1,$2,$3,$4,$5,$6;
  64. $1=_st(html)._h1();
  65. _st($1)._with_(_st(self["@count"])._asString());
  66. $2=_st($1)._yourself();
  67. self["@header"]=$2;
  68. $3=_st(html)._button();
  69. _st($3)._with_("++");
  70. $4=_st($3)._onClick_((function(){
  71. return smalltalk.withContext(function($ctx2) { return _st(self)._increase();
  72. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  73. $5=_st(html)._button();
  74. _st($5)._with_("--");
  75. $6=_st($5)._onClick_((function(){
  76. return smalltalk.withContext(function($ctx2) { return _st(self)._decrease();
  77. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  78. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html}, smalltalk.Counter)})},
  79. args: ["html"],
  80. source: "renderOn: html\x0a header := html h1 \x0a\x09with: count asString;\x0a\x09yourself.\x0a html button\x0a\x09with: '++';\x0a\x09onClick: [self increase].\x0a html button\x0a\x09with: '--';\x0a\x09onClick: [self decrease]",
  81. messageSends: ["with:", "asString", "h1", "yourself", "button", "onClick:", "increase", "decrease"],
  82. referencedClasses: []
  83. }),
  84. smalltalk.Counter);
  85. smalltalk.addMethod(
  86. "_tryExample",
  87. smalltalk.method({
  88. selector: "tryExample",
  89. category: 'example',
  90. fn: function (){
  91. var self=this;
  92. return smalltalk.withContext(function($ctx1) { _st(_st(self)._new())._appendToJQuery_(_st("body")._asJQuery());
  93. return self}, function($ctx1) {$ctx1.fill(self,"tryExample",{}, smalltalk.Counter.klass)})},
  94. args: [],
  95. source: "tryExample\x0a\x09\x22In order to play with the Counter, just select the\x0a\x09doit below and press the Do it button. Then take a\x0a\x09look in the HTML document above the IDE.\x22\x0a\x0a\x09\x22Counter tryExample\x22\x0a self new appendToJQuery: 'body' asJQuery",
  96. messageSends: ["appendToJQuery:", "asJQuery", "new"],
  97. referencedClasses: []
  98. }),
  99. smalltalk.Counter.klass);