Examples.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. define(["amber/boot", "require", "amber/web/Web"], function($boot,requirejs){"use strict";
  2. var $core=$boot.api,nil=$boot.nilAsValue,$nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. var $pkg = $core.addPackage("Examples");
  4. $pkg.innerEval = function (expr) { return eval(expr); };
  5. $pkg.transport = {"type":"amd","amdNamespace":"amber/legacy"};
  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,$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,$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,$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||$boot.nilAsClass).fn.prototype._initialize.apply($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,$self=this;
  111. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  112. return $core.withContext(function($ctx1) {
  113. //>>excludeEnd("ctx");
  114. var $1,$2,$3,$4;
  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. $self["@header"]=$recv($1)._yourself();
  121. $2=$recv(html)._button();
  122. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  123. $ctx1.sendIdx["button"]=1;
  124. //>>excludeEnd("ctx");
  125. $recv($2)._with_("++");
  126. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  127. $ctx1.sendIdx["with:"]=2;
  128. //>>excludeEnd("ctx");
  129. $3=$recv($2)._onClick_((function(){
  130. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  131. return $core.withContext(function($ctx2) {
  132. //>>excludeEnd("ctx");
  133. return $self._increase();
  134. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  135. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  136. //>>excludeEnd("ctx");
  137. }));
  138. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  139. $ctx1.sendIdx["onClick:"]=1;
  140. //>>excludeEnd("ctx");
  141. $4=$recv(html)._button();
  142. $recv($4)._with_("--");
  143. $recv($4)._onClick_((function(){
  144. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  145. return $core.withContext(function($ctx2) {
  146. //>>excludeEnd("ctx");
  147. return $self._decrease();
  148. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  149. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
  150. //>>excludeEnd("ctx");
  151. }));
  152. return self;
  153. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  154. }, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},$globals.Counter)});
  155. //>>excludeEnd("ctx");
  156. },
  157. //>>excludeStart("ide", pragmas.excludeIdeData);
  158. args: ["html"],
  159. 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 ]",
  160. referencedClasses: [],
  161. //>>excludeEnd("ide");
  162. messageSends: ["with:", "h1", "asString", "yourself", "button", "onClick:", "increase", "decrease"]
  163. }),
  164. $globals.Counter);
  165. $core.addMethod(
  166. $core.method({
  167. selector: "tryExample",
  168. protocol: "example",
  169. fn: function (){
  170. var self=this,$self=this;
  171. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  172. return $core.withContext(function($ctx1) {
  173. //>>excludeEnd("ctx");
  174. $recv($self._new())._appendToJQuery_("body"._asJQuery());
  175. return self;
  176. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  177. }, function($ctx1) {$ctx1.fill(self,"tryExample",{},$globals.Counter.a$cls)});
  178. //>>excludeEnd("ctx");
  179. },
  180. //>>excludeStart("ide", pragmas.excludeIdeData);
  181. args: [],
  182. 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",
  183. referencedClasses: [],
  184. //>>excludeEnd("ide");
  185. messageSends: ["appendToJQuery:", "new", "asJQuery"]
  186. }),
  187. $globals.Counter.a$cls);
  188. });