1
0

Examples.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. define("amber_core/Examples", ["amber/boot", "amber_core/Web"], function($boot){
  2. var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. var smalltalk=$core,_st=$recv,globals=$globals;
  4. $core.addPackage('Examples');
  5. $core.packages["Examples"].transport = {"type":"amd","amdNamespace":"amber_core"};
  6. $core.addClass('Counter', $globals.Widget, ['count', 'header'], 'Examples');
  7. //>>excludeStart("ide", pragmas.excludeIdeData);
  8. $globals.Counter.comment="This is a trivial Widget example mimicking the classic Counter example in Seaside.\x0aIn order to play with it, just evaluate the doit below in a workspace.\x0aThen take a look in the HTML document above the IDE.\x0a\x0a\x09\x09Counter tryExample";
  9. //>>excludeEnd("ide");
  10. $core.addMethod(
  11. $core.method({
  12. selector: "decrease",
  13. protocol: 'actions',
  14. fn: function (){
  15. var self=this;
  16. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  17. return $core.withContext(function($ctx1) {
  18. //>>excludeEnd("ctx");
  19. self["@count"]=$recv(self["@count"]).__minus((1));
  20. $recv(self["@header"])._contents_((function(html){
  21. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  22. return $core.withContext(function($ctx2) {
  23. //>>excludeEnd("ctx");
  24. return $recv(html)._with_($recv(self["@count"])._asString());
  25. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  26. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
  27. //>>excludeEnd("ctx");
  28. }));
  29. return self;
  30. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  31. }, function($ctx1) {$ctx1.fill(self,"decrease",{},$globals.Counter)});
  32. //>>excludeEnd("ctx");
  33. },
  34. //>>excludeStart("ide", pragmas.excludeIdeData);
  35. args: [],
  36. source: "decrease\x0a\x09count := count - 1.\x0a\x09header contents: [ :html | html with: count asString ]",
  37. referencedClasses: [],
  38. //>>excludeEnd("ide");
  39. messageSends: ["-", "contents:", "with:", "asString"]
  40. }),
  41. $globals.Counter);
  42. $core.addMethod(
  43. $core.method({
  44. selector: "increase",
  45. protocol: 'actions',
  46. fn: function (){
  47. var self=this;
  48. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  49. return $core.withContext(function($ctx1) {
  50. //>>excludeEnd("ctx");
  51. self["@count"]=$recv(self["@count"]).__plus((1));
  52. $recv(self["@header"])._contents_((function(html){
  53. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  54. return $core.withContext(function($ctx2) {
  55. //>>excludeEnd("ctx");
  56. return $recv(html)._with_($recv(self["@count"])._asString());
  57. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  58. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
  59. //>>excludeEnd("ctx");
  60. }));
  61. return self;
  62. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  63. }, function($ctx1) {$ctx1.fill(self,"increase",{},$globals.Counter)});
  64. //>>excludeEnd("ctx");
  65. },
  66. //>>excludeStart("ide", pragmas.excludeIdeData);
  67. args: [],
  68. source: "increase\x0a\x09count := count + 1.\x0a\x09header contents: [ :html | html with: count asString ]",
  69. referencedClasses: [],
  70. //>>excludeEnd("ide");
  71. messageSends: ["+", "contents:", "with:", "asString"]
  72. }),
  73. $globals.Counter);
  74. $core.addMethod(
  75. $core.method({
  76. selector: "initialize",
  77. protocol: 'initialization',
  78. fn: function (){
  79. var self=this;
  80. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  81. return $core.withContext(function($ctx1) {
  82. //>>excludeEnd("ctx");
  83. (
  84. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  85. $ctx1.supercall = true,
  86. //>>excludeEnd("ctx");
  87. $globals.Counter.superclass.fn.prototype._initialize.apply($recv(self), []));
  88. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  89. $ctx1.supercall = false;
  90. //>>excludeEnd("ctx");;
  91. self["@count"]=(0);
  92. return self;
  93. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  94. }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.Counter)});
  95. //>>excludeEnd("ctx");
  96. },
  97. //>>excludeStart("ide", pragmas.excludeIdeData);
  98. args: [],
  99. source: "initialize\x0a\x09super initialize.\x0a\x09count := 0",
  100. referencedClasses: [],
  101. //>>excludeEnd("ide");
  102. messageSends: ["initialize"]
  103. }),
  104. $globals.Counter);
  105. $core.addMethod(
  106. $core.method({
  107. selector: "renderOn:",
  108. protocol: 'rendering',
  109. fn: function (html){
  110. var self=this;
  111. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  112. return $core.withContext(function($ctx1) {
  113. //>>excludeEnd("ctx");
  114. var $1,$2,$3,$4,$5,$6;
  115. $1=$recv(html)._h1();
  116. $recv($1)._with_($recv(self["@count"])._asString());
  117. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  118. $ctx1.sendIdx["with:"]=1;
  119. //>>excludeEnd("ctx");
  120. $2=$recv($1)._yourself();
  121. self["@header"]=$2;
  122. $3=$recv(html)._button();
  123. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  124. $ctx1.sendIdx["button"]=1;
  125. //>>excludeEnd("ctx");
  126. $recv($3)._with_("++");
  127. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  128. $ctx1.sendIdx["with:"]=2;
  129. //>>excludeEnd("ctx");
  130. $4=$recv($3)._onClick_((function(){
  131. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  132. return $core.withContext(function($ctx2) {
  133. //>>excludeEnd("ctx");
  134. return self._increase();
  135. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  136. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  137. //>>excludeEnd("ctx");
  138. }));
  139. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  140. $ctx1.sendIdx["onClick:"]=1;
  141. //>>excludeEnd("ctx");
  142. $5=$recv(html)._button();
  143. $recv($5)._with_("--");
  144. $6=$recv($5)._onClick_((function(){
  145. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  146. return $core.withContext(function($ctx2) {
  147. //>>excludeEnd("ctx");
  148. return self._decrease();
  149. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  150. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  151. //>>excludeEnd("ctx");
  152. }));
  153. return self;
  154. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  155. }, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},$globals.Counter)});
  156. //>>excludeEnd("ctx");
  157. },
  158. //>>excludeStart("ide", pragmas.excludeIdeData);
  159. args: ["html"],
  160. source: "renderOn: html\x0a\x09header := html h1\x0a\x09\x09with: count asString;\x0a\x09\x09yourself.\x0a\x09html button\x0a\x09\x09with: '++';\x0a\x09\x09onClick: [ self increase ].\x0a\x09html button\x0a\x09\x09with: '--';\x0a\x09\x09onClick: [ self decrease ]",
  161. referencedClasses: [],
  162. //>>excludeEnd("ide");
  163. messageSends: ["with:", "h1", "asString", "yourself", "button", "onClick:", "increase", "decrease"]
  164. }),
  165. $globals.Counter);
  166. $core.addMethod(
  167. $core.method({
  168. selector: "tryExample",
  169. protocol: 'example',
  170. fn: function (){
  171. var self=this;
  172. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  173. return $core.withContext(function($ctx1) {
  174. //>>excludeEnd("ctx");
  175. $recv(self._new())._appendToJQuery_("body"._asJQuery());
  176. return self;
  177. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  178. }, function($ctx1) {$ctx1.fill(self,"tryExample",{},$globals.Counter.klass)});
  179. //>>excludeEnd("ctx");
  180. },
  181. //>>excludeStart("ide", pragmas.excludeIdeData);
  182. args: [],
  183. 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\x09\x09self new appendToJQuery: 'body' asJQuery",
  184. referencedClasses: [],
  185. //>>excludeEnd("ide");
  186. messageSends: ["appendToJQuery:", "new", "asJQuery"]
  187. }),
  188. $globals.Counter.klass);
  189. });