123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- define("amber/legacy/Examples", ["amber/boot", "amber/web/Web"], function($boot){"use strict";
- var $core=$boot.api,nil=$boot.nil,$recv=$boot.asReceiver,$globals=$boot.globals;
- $core.addPackage('Examples');
- $core.packages["Examples"].innerEval = function (expr) { return eval(expr); };
- $core.packages["Examples"].transport = {"type":"amd","amdNamespace":"amber/legacy"};
- $core.addClass('Counter', $globals.Widget, ['count', 'header'], 'Examples');
- //>>excludeStart("ide", pragmas.excludeIdeData);
- $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";
- //>>excludeEnd("ide");
- $core.addMethod(
- $core.method({
- selector: "decrease",
- protocol: 'actions',
- fn: function (){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- self["@count"]=$recv(self["@count"]).__minus((1));
- $recv(self["@header"])._contents_((function(html){
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx2) {
- //>>excludeEnd("ctx");
- return $recv(html)._with_($recv(self["@count"])._asString());
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
- //>>excludeEnd("ctx");
- }));
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"decrease",{},$globals.Counter)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: [],
- source: "decrease\x0a\x09count := count - 1.\x0a\x09header contents: [ :html | html with: count asString ]",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: ["-", "contents:", "with:", "asString"]
- }),
- $globals.Counter);
- $core.addMethod(
- $core.method({
- selector: "increase",
- protocol: 'actions',
- fn: function (){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- self["@count"]=$recv(self["@count"]).__plus((1));
- $recv(self["@header"])._contents_((function(html){
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx2) {
- //>>excludeEnd("ctx");
- return $recv(html)._with_($recv(self["@count"])._asString());
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1,1)});
- //>>excludeEnd("ctx");
- }));
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"increase",{},$globals.Counter)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: [],
- source: "increase\x0a\x09count := count + 1.\x0a\x09header contents: [ :html | html with: count asString ]",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: ["+", "contents:", "with:", "asString"]
- }),
- $globals.Counter);
- $core.addMethod(
- $core.method({
- selector: "initialize",
- protocol: 'initialization',
- fn: function (){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- (
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- $ctx1.supercall = true,
- //>>excludeEnd("ctx");
- $globals.Counter.superclass.fn.prototype._initialize.apply($recv(self), []));
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- $ctx1.supercall = false;
- //>>excludeEnd("ctx");;
- self["@count"]=(0);
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"initialize",{},$globals.Counter)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: [],
- source: "initialize\x0a\x09super initialize.\x0a\x09count := 0",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: ["initialize"]
- }),
- $globals.Counter);
- $core.addMethod(
- $core.method({
- selector: "renderOn:",
- protocol: 'rendering',
- fn: function (html){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- var $1,$2,$3,$4,$5,$6;
- $1=$recv(html)._h1();
- $recv($1)._with_($recv(self["@count"])._asString());
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- $ctx1.sendIdx["with:"]=1;
- //>>excludeEnd("ctx");
- $2=$recv($1)._yourself();
- self["@header"]=$2;
- $3=$recv(html)._button();
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- $ctx1.sendIdx["button"]=1;
- //>>excludeEnd("ctx");
- $recv($3)._with_("++");
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- $ctx1.sendIdx["with:"]=2;
- //>>excludeEnd("ctx");
- $4=$recv($3)._onClick_((function(){
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx2) {
- //>>excludeEnd("ctx");
- return self._increase();
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
- //>>excludeEnd("ctx");
- }));
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- $ctx1.sendIdx["onClick:"]=1;
- //>>excludeEnd("ctx");
- $5=$recv(html)._button();
- $recv($5)._with_("--");
- $6=$recv($5)._onClick_((function(){
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx2) {
- //>>excludeEnd("ctx");
- return self._decrease();
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
- //>>excludeEnd("ctx");
- }));
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},$globals.Counter)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: ["html"],
- 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 ]",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: ["with:", "h1", "asString", "yourself", "button", "onClick:", "increase", "decrease"]
- }),
- $globals.Counter);
- $core.addMethod(
- $core.method({
- selector: "tryExample",
- protocol: 'example',
- fn: function (){
- var self=this;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- return $core.withContext(function($ctx1) {
- //>>excludeEnd("ctx");
- $recv(self._new())._appendToJQuery_("body"._asJQuery());
- return self;
- //>>excludeStart("ctx", pragmas.excludeDebugContexts);
- }, function($ctx1) {$ctx1.fill(self,"tryExample",{},$globals.Counter.klass)});
- //>>excludeEnd("ctx");
- },
- //>>excludeStart("ide", pragmas.excludeIdeData);
- args: [],
- 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",
- referencedClasses: [],
- //>>excludeEnd("ide");
- messageSends: ["appendToJQuery:", "new", "asJQuery"]
- }),
- $globals.Counter.klass);
- });
|