Examples.js 3.6 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. self["@count"]=smalltalk.send(self["@count"],"__minus",[(1)]);
  12. smalltalk.send(self["@header"],"_contents_",[(function(html){
  13. return smalltalk.send(html,"_with_",[smalltalk.send(self["@count"],"_asString",[])]);
  14. })]);
  15. return self},
  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. self["@count"]=smalltalk.send(self["@count"],"__plus",[(1)]);
  30. smalltalk.send(self["@header"],"_contents_",[(function(html){
  31. return smalltalk.send(html,"_with_",[smalltalk.send(self["@count"],"_asString",[])]);
  32. })]);
  33. return self},
  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. smalltalk.send(self,"_initialize",[],smalltalk.Widget);
  48. self["@count"]=(0);
  49. return self},
  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. var $1,$2,$3,$4,$5,$6;
  64. $1=smalltalk.send(html,"_h1",[]);
  65. smalltalk.send($1,"_with_",[smalltalk.send(self["@count"],"_asString",[])]);
  66. $2=smalltalk.send($1,"_yourself",[]);
  67. self["@header"]=$2;
  68. $3=smalltalk.send(html,"_button",[]);
  69. smalltalk.send($3,"_with_",["++"]);
  70. $4=smalltalk.send($3,"_onClick_",[(function(){
  71. return smalltalk.send(self,"_increase",[]);
  72. })]);
  73. $5=smalltalk.send(html,"_button",[]);
  74. smalltalk.send($5,"_with_",["--"]);
  75. $6=smalltalk.send($5,"_onClick_",[(function(){
  76. return smalltalk.send(self,"_decrease",[]);
  77. })]);
  78. return self},
  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. smalltalk.send(smalltalk.send(self,"_new",[]),"_appendToJQuery_",[smalltalk.send("body","_asJQuery",[])]);
  93. return self},
  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);