Trapped-Frontend.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. define("gh_herby_trapped/Trapped-Frontend", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber/Kernel-Objects", "amber/Canvas", "amber/Kernel-Collections"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Trapped-Frontend');
  3. smalltalk.packages["Trapped-Frontend"].transport = {"type":"amd","amdNamespace":"gh_herby_trapped"};
  4. smalltalk.addClass('TrappedBinder', smalltalk.Object, ['brush'], 'Trapped-Frontend');
  5. smalltalk.addMethod(
  6. smalltalk.method({
  7. selector: "brush:",
  8. category: 'accessing',
  9. fn: function (aTagBrush){
  10. var self=this;
  11. return smalltalk.withContext(function($ctx1) {
  12. self["@brush"]=aTagBrush;
  13. return self}, function($ctx1) {$ctx1.fill(self,"brush:",{aTagBrush:aTagBrush},smalltalk.TrappedBinder)})},
  14. args: ["aTagBrush"],
  15. source: "brush: aTagBrush\x0a\x09brush := aTagBrush",
  16. messageSends: [],
  17. referencedClasses: []
  18. }),
  19. smalltalk.TrappedBinder);
  20. smalltalk.addMethod(
  21. smalltalk.method({
  22. selector: "installFor:",
  23. category: 'action',
  24. fn: function (path){
  25. var self=this;
  26. return smalltalk.withContext(function($ctx1) {
  27. _st(self["@brush"])._trap_read_(path,self._showBlock());
  28. return self}, function($ctx1) {$ctx1.fill(self,"installFor:",{path:path},smalltalk.TrappedBinder)})},
  29. args: ["path"],
  30. source: "installFor: path\x0a\x09brush trap: path read: self showBlock",
  31. messageSends: ["trap:read:", "showBlock"],
  32. referencedClasses: []
  33. }),
  34. smalltalk.TrappedBinder);
  35. smalltalk.addMethod(
  36. smalltalk.method({
  37. selector: "prim:",
  38. category: 'converting',
  39. fn: function (anObject){
  40. var self=this;
  41. return smalltalk.withContext(function($ctx1) {
  42. return anObject.valueOf();
  43. return self}, function($ctx1) {$ctx1.fill(self,"prim:",{anObject:anObject},smalltalk.TrappedBinder)})},
  44. args: ["anObject"],
  45. source: "prim: anObject\x0a\x09<return anObject.valueOf()>",
  46. messageSends: [],
  47. referencedClasses: []
  48. }),
  49. smalltalk.TrappedBinder);
  50. smalltalk.addMethod(
  51. smalltalk.method({
  52. selector: "showBlock",
  53. category: 'action',
  54. fn: function (){
  55. var self=this;
  56. return smalltalk.withContext(function($ctx1) {
  57. var $2,$4,$6,$5,$3,$1;
  58. $1=(function(model){
  59. return smalltalk.withContext(function($ctx2) {
  60. $2=self["@brush"];
  61. _st($2)._empty();
  62. $4=$2;
  63. $6=model;
  64. if(($receiver = $6) == nil || $receiver == undefined){
  65. $5=(function(){
  66. return smalltalk.withContext(function($ctx3) {
  67. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})});
  68. } else {
  69. $5=$6;
  70. };
  71. $3=_st($4)._with_($5);
  72. return $3;
  73. }, function($ctx2) {$ctx2.fillBlock({model:model},$ctx1)})});
  74. return $1;
  75. }, function($ctx1) {$ctx1.fill(self,"showBlock",{},smalltalk.TrappedBinder)})},
  76. args: [],
  77. source: "showBlock\x0a\x09^[ :model | brush empty; with: (model ifNil: [[]]) ]",
  78. messageSends: ["empty", "with:", "ifNil:"],
  79. referencedClasses: []
  80. }),
  81. smalltalk.TrappedBinder);
  82. smalltalk.addClass('TrappedCheckedBinder', smalltalk.TrappedBinder, [], 'Trapped-Frontend');
  83. smalltalk.addMethod(
  84. smalltalk.method({
  85. selector: "installFor:",
  86. category: 'action',
  87. fn: function (path){
  88. var self=this;
  89. return smalltalk.withContext(function($ctx1) {
  90. smalltalk.TrappedCheckedBinder.superclass.fn.prototype._installFor_.apply(_st(self), [path]);
  91. _st(path)._trapDescend_((function(snap){
  92. return smalltalk.withContext(function($ctx2) {
  93. return _st(self["@brush"])._onChange_((function(){
  94. return smalltalk.withContext(function($ctx3) {
  95. return _st(snap)._modify_((function(){
  96. return smalltalk.withContext(function($ctx4) {
  97. return _st(_st(_st(self["@brush"])._asJQuery())._attr_("checked"))._notNil();
  98. }, function($ctx4) {$ctx4.fillBlock({},$ctx3)})}));
  99. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
  100. }, function($ctx2) {$ctx2.fillBlock({snap:snap},$ctx1)})}));
  101. return self}, function($ctx1) {$ctx1.fill(self,"installFor:",{path:path},smalltalk.TrappedCheckedBinder)})},
  102. args: ["path"],
  103. source: "installFor: path\x0a\x09super installFor: path.\x0a path trapDescend: [ :snap |\x0a\x09 brush onChange: [ snap modify: [\x0a (brush asJQuery attr: 'checked') notNil\x0a ]]\x0a ]",
  104. messageSends: ["installFor:", "trapDescend:", "onChange:", "modify:", "notNil", "attr:", "asJQuery"],
  105. referencedClasses: []
  106. }),
  107. smalltalk.TrappedCheckedBinder);
  108. smalltalk.addMethod(
  109. smalltalk.method({
  110. selector: "showBlock",
  111. category: 'action',
  112. fn: function (){
  113. var self=this;
  114. return smalltalk.withContext(function($ctx1) {
  115. var $2,$4,$3,$1;
  116. $1=(function(model){
  117. return smalltalk.withContext(function($ctx2) {
  118. $2=_st(self["@brush"])._asJQuery();
  119. $4=model;
  120. if(($receiver = $4) == nil || $receiver == undefined){
  121. $3=false;
  122. } else {
  123. $3=self._prim_(model);
  124. };
  125. return _st($2)._attr_put_("checked",$3);
  126. }, function($ctx2) {$ctx2.fillBlock({model:model},$ctx1)})});
  127. return $1;
  128. }, function($ctx1) {$ctx1.fill(self,"showBlock",{},smalltalk.TrappedCheckedBinder)})},
  129. args: [],
  130. source: "showBlock\x0a\x09^[ :model | brush asJQuery attr: 'checked' put: (model ifNotNil: [ self prim: model ] ifNil: [ false ]) ]",
  131. messageSends: ["attr:put:", "ifNotNil:ifNil:", "prim:", "asJQuery"],
  132. referencedClasses: []
  133. }),
  134. smalltalk.TrappedCheckedBinder);
  135. smalltalk.addClass('TrappedValBinder', smalltalk.TrappedBinder, [], 'Trapped-Frontend');
  136. smalltalk.addMethod(
  137. smalltalk.method({
  138. selector: "installFor:",
  139. category: 'action',
  140. fn: function (path){
  141. var self=this;
  142. return smalltalk.withContext(function($ctx1) {
  143. smalltalk.TrappedValBinder.superclass.fn.prototype._installFor_.apply(_st(self), [path]);
  144. _st(path)._trapDescend_((function(snap){
  145. return smalltalk.withContext(function($ctx2) {
  146. return _st(self["@brush"])._onChange_((function(){
  147. return smalltalk.withContext(function($ctx3) {
  148. return _st(snap)._modify_((function(){
  149. return smalltalk.withContext(function($ctx4) {
  150. return _st(_st(self["@brush"])._asJQuery())._val();
  151. }, function($ctx4) {$ctx4.fillBlock({},$ctx3)})}));
  152. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
  153. }, function($ctx2) {$ctx2.fillBlock({snap:snap},$ctx1)})}));
  154. return self}, function($ctx1) {$ctx1.fill(self,"installFor:",{path:path},smalltalk.TrappedValBinder)})},
  155. args: ["path"],
  156. source: "installFor: path\x0a\x09super installFor: path.\x0a path trapDescend: [ :snap |\x0a\x09 brush onChange: [ snap modify: [\x0a brush asJQuery val\x0a ]]\x0a ]",
  157. messageSends: ["installFor:", "trapDescend:", "onChange:", "modify:", "val", "asJQuery"],
  158. referencedClasses: []
  159. }),
  160. smalltalk.TrappedValBinder);
  161. smalltalk.addMethod(
  162. smalltalk.method({
  163. selector: "showBlock",
  164. category: 'action',
  165. fn: function (){
  166. var self=this;
  167. return smalltalk.withContext(function($ctx1) {
  168. var $2,$4,$3,$1;
  169. $1=(function(model){
  170. return smalltalk.withContext(function($ctx2) {
  171. $2=_st(self["@brush"])._asJQuery();
  172. $4=model;
  173. if(($receiver = $4) == nil || $receiver == undefined){
  174. $3=(function(){
  175. return smalltalk.withContext(function($ctx3) {
  176. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})});
  177. } else {
  178. $3=self._prim_(model);
  179. };
  180. return _st($2)._val_($3);
  181. }, function($ctx2) {$ctx2.fillBlock({model:model},$ctx1)})});
  182. return $1;
  183. }, function($ctx1) {$ctx1.fill(self,"showBlock",{},smalltalk.TrappedValBinder)})},
  184. args: [],
  185. source: "showBlock\x0a\x09^[ :model | brush asJQuery val: (model ifNotNil: [self prim: model] ifNil: [[]]) ]",
  186. messageSends: ["val:", "ifNotNil:ifNil:", "prim:", "asJQuery"],
  187. referencedClasses: []
  188. }),
  189. smalltalk.TrappedValBinder);
  190. smalltalk.addClass('TrappedDumbView', smalltalk.Widget, [], 'Trapped-Frontend');
  191. smalltalk.TrappedDumbView.comment="I just read and show an actual path.";
  192. smalltalk.addMethod(
  193. smalltalk.method({
  194. selector: "renderOn:",
  195. category: 'rendering',
  196. fn: function (html){
  197. var self=this;
  198. return smalltalk.withContext(function($ctx1) {
  199. _st(_st(html)._root())._trap_([]);
  200. return self}, function($ctx1) {$ctx1.fill(self,"renderOn:",{html:html},smalltalk.TrappedDumbView)})},
  201. args: ["html"],
  202. source: "renderOn: html\x0a\x09html root trap: #()",
  203. messageSends: ["trap:", "root"],
  204. referencedClasses: []
  205. }),
  206. smalltalk.TrappedDumbView);
  207. smalltalk.addClass('TrappedSingleton', smalltalk.Object, [], 'Trapped-Frontend');
  208. smalltalk.addMethod(
  209. smalltalk.method({
  210. selector: "start:",
  211. category: 'action',
  212. fn: function (args){
  213. var self=this;
  214. return smalltalk.withContext(function($ctx1) {
  215. var $1;
  216. $1=self._subclassResponsibility();
  217. return $1;
  218. }, function($ctx1) {$ctx1.fill(self,"start:",{args:args},smalltalk.TrappedSingleton)})},
  219. args: ["args"],
  220. source: "start: args\x0a\x09^ self subclassResponsibility",
  221. messageSends: ["subclassResponsibility"],
  222. referencedClasses: []
  223. }),
  224. smalltalk.TrappedSingleton);
  225. smalltalk.TrappedSingleton.klass.iVarNames = ['current'];
  226. smalltalk.addMethod(
  227. smalltalk.method({
  228. selector: "current",
  229. category: 'accessing',
  230. fn: function (){
  231. var self=this;
  232. return smalltalk.withContext(function($ctx1) {
  233. var $2,$1;
  234. $2=self["@current"];
  235. if(($receiver = $2) == nil || $receiver == undefined){
  236. self["@current"]=self._new();
  237. $1=self["@current"];
  238. } else {
  239. $1=$2;
  240. };
  241. return $1;
  242. }, function($ctx1) {$ctx1.fill(self,"current",{},smalltalk.TrappedSingleton.klass)})},
  243. args: [],
  244. source: "current\x0a\x09^ current ifNil: [ current := self new ]",
  245. messageSends: ["ifNil:", "new"],
  246. referencedClasses: []
  247. }),
  248. smalltalk.TrappedSingleton.klass);
  249. smalltalk.addMethod(
  250. smalltalk.method({
  251. selector: "start:",
  252. category: 'action',
  253. fn: function (args){
  254. var self=this;
  255. return smalltalk.withContext(function($ctx1) {
  256. _st(self._current())._start_(args);
  257. return self}, function($ctx1) {$ctx1.fill(self,"start:",{args:args},smalltalk.TrappedSingleton.klass)})},
  258. args: ["args"],
  259. source: "start: args\x0a\x09self current start: args",
  260. messageSends: ["start:", "current"],
  261. referencedClasses: []
  262. }),
  263. smalltalk.TrappedSingleton.klass);
  264. smalltalk.addClass('Trapped', smalltalk.TrappedSingleton, ['registry'], 'Trapped-Frontend');
  265. smalltalk.addMethod(
  266. smalltalk.method({
  267. selector: "binder:",
  268. category: 'binders',
  269. fn: function (aTagBrush){
  270. var self=this;
  271. var binder,tag;
  272. function $TrappedCheckedBinder(){return smalltalk.TrappedCheckedBinder||(typeof TrappedCheckedBinder=="undefined"?nil:TrappedCheckedBinder)}
  273. function $TrappedValBinder(){return smalltalk.TrappedValBinder||(typeof TrappedValBinder=="undefined"?nil:TrappedValBinder)}
  274. function $TrappedBinder(){return smalltalk.TrappedBinder||(typeof TrappedBinder=="undefined"?nil:TrappedBinder)}
  275. return smalltalk.withContext(function($ctx1) {
  276. var $1,$2,$3,$4,$6,$7,$5;
  277. tag=_st(_st(aTagBrush)._element())._nodeName();
  278. $1=_st(tag).__eq("INPUT");
  279. if(smalltalk.assert($1)){
  280. var type;
  281. type=_st(_st(aTagBrush)._asJQuery())._attr_("type");
  282. type;
  283. $2=_st(type).__eq("checkbox");
  284. if(smalltalk.assert($2)){
  285. binder=_st($TrappedCheckedBinder())._new();
  286. binder;
  287. };
  288. $3=_st(type).__eq("text");
  289. if(smalltalk.assert($3)){
  290. binder=_st($TrappedValBinder())._new();
  291. binder;
  292. };
  293. };
  294. $4=binder;
  295. if(($receiver = $4) == nil || $receiver == undefined){
  296. binder=_st($TrappedBinder())._new();
  297. binder;
  298. } else {
  299. $4;
  300. };
  301. $6=binder;
  302. _st($6)._brush_(aTagBrush);
  303. $7=_st($6)._yourself();
  304. $5=$7;
  305. return $5;
  306. }, function($ctx1) {$ctx1.fill(self,"binder:",{aTagBrush:aTagBrush,binder:binder,tag:tag},smalltalk.Trapped)})},
  307. args: ["aTagBrush"],
  308. source: "binder: aTagBrush\x0a \x22Prototype; will select based on tag etc.\x22\x0a | binder tag |\x0a tag := aTagBrush element nodeName.\x0a tag = 'INPUT' ifTrue: [\x0a | type |\x0a type := aTagBrush asJQuery attr: 'type'.\x0a type = 'checkbox' ifTrue: [ binder := TrappedCheckedBinder new ].\x0a type = 'text' ifTrue: [ binder := TrappedValBinder new ]\x0a ].\x0a binder ifNil: [ binder := TrappedBinder new ].\x0a ^ binder brush: aTagBrush; yourself",
  309. messageSends: ["nodeName", "element", "ifTrue:", "attr:", "asJQuery", "new", "=", "ifNil:", "brush:", "yourself"],
  310. referencedClasses: ["TrappedCheckedBinder", "TrappedValBinder", "TrappedBinder"]
  311. }),
  312. smalltalk.Trapped);
  313. smalltalk.addMethod(
  314. smalltalk.method({
  315. selector: "byName:",
  316. category: 'accessing',
  317. fn: function (aString){
  318. var self=this;
  319. return smalltalk.withContext(function($ctx1) {
  320. var $1;
  321. $1=_st(self["@registry"])._at_(aString);
  322. return $1;
  323. }, function($ctx1) {$ctx1.fill(self,"byName:",{aString:aString},smalltalk.Trapped)})},
  324. args: ["aString"],
  325. source: "byName: aString\x0a\x09^ registry at: aString",
  326. messageSends: ["at:"],
  327. referencedClasses: []
  328. }),
  329. smalltalk.Trapped);
  330. smalltalk.addMethod(
  331. smalltalk.method({
  332. selector: "descend:snapshotDo:",
  333. category: 'action',
  334. fn: function (anArray,aBlock){
  335. var self=this;
  336. var tpsc;
  337. function $TrappedPathStack(){return smalltalk.TrappedPathStack||(typeof TrappedPathStack=="undefined"?nil:TrappedPathStack)}
  338. function $TrappedSnapshot(){return smalltalk.TrappedSnapshot||(typeof TrappedSnapshot=="undefined"?nil:TrappedSnapshot)}
  339. return smalltalk.withContext(function($ctx1) {
  340. tpsc=_st($TrappedPathStack())._current();
  341. _st(tpsc)._append_do_(anArray,(function(){
  342. var path,model;
  343. return smalltalk.withContext(function($ctx2) {
  344. path=_st(_st(tpsc)._elements())._copy();
  345. path;
  346. model=self._byName_(_st(path)._first());
  347. model;
  348. return _st(aBlock)._value_(_st(_st($TrappedSnapshot())._new())._path_model_(path,model));
  349. }, function($ctx2) {$ctx2.fillBlock({path:path,model:model},$ctx1)})}));
  350. return self}, function($ctx1) {$ctx1.fill(self,"descend:snapshotDo:",{anArray:anArray,aBlock:aBlock,tpsc:tpsc},smalltalk.Trapped)})},
  351. args: ["anArray", "aBlock"],
  352. source: "descend: anArray snapshotDo: aBlock\x0a\x09| tpsc |\x0a tpsc := TrappedPathStack current.\x0a tpsc append: anArray do: [\x0a | path model |\x0a path := tpsc elements copy.\x0a \x09 model := self byName: path first.\x0a aBlock value: (TrappedSnapshot new path: path model: model)\x0a ]",
  353. messageSends: ["current", "append:do:", "copy", "elements", "byName:", "first", "value:", "path:model:", "new"],
  354. referencedClasses: ["TrappedPathStack", "TrappedSnapshot"]
  355. }),
  356. smalltalk.Trapped);
  357. smalltalk.addMethod(
  358. smalltalk.method({
  359. selector: "initialize",
  360. category: 'initialization',
  361. fn: function (){
  362. var self=this;
  363. return smalltalk.withContext(function($ctx1) {
  364. smalltalk.Trapped.superclass.fn.prototype._initialize.apply(_st(self), []);
  365. self["@registry"]=smalltalk.HashedCollection._from_([]);
  366. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.Trapped)})},
  367. args: [],
  368. source: "initialize\x0a\x09super initialize.\x0a\x09registry := #{}.",
  369. messageSends: ["initialize"],
  370. referencedClasses: []
  371. }),
  372. smalltalk.Trapped);
  373. smalltalk.addMethod(
  374. smalltalk.method({
  375. selector: "register:",
  376. category: 'accessing',
  377. fn: function (aListKeyedEntity){
  378. var self=this;
  379. return smalltalk.withContext(function($ctx1) {
  380. self._register_name_(aListKeyedEntity,_st(_st(aListKeyedEntity)._class())._name());
  381. return self}, function($ctx1) {$ctx1.fill(self,"register:",{aListKeyedEntity:aListKeyedEntity},smalltalk.Trapped)})},
  382. args: ["aListKeyedEntity"],
  383. source: "register: aListKeyedEntity\x0a\x09self register: aListKeyedEntity name: aListKeyedEntity class name",
  384. messageSends: ["register:name:", "name", "class"],
  385. referencedClasses: []
  386. }),
  387. smalltalk.Trapped);
  388. smalltalk.addMethod(
  389. smalltalk.method({
  390. selector: "register:name:",
  391. category: 'accessing',
  392. fn: function (aListKeyedEntity,aString){
  393. var self=this;
  394. return smalltalk.withContext(function($ctx1) {
  395. _st(self["@registry"])._at_put_(aString,aListKeyedEntity);
  396. return self}, function($ctx1) {$ctx1.fill(self,"register:name:",{aListKeyedEntity:aListKeyedEntity,aString:aString},smalltalk.Trapped)})},
  397. args: ["aListKeyedEntity", "aString"],
  398. source: "register: aListKeyedEntity name: aString\x0a\x09registry at: aString put: aListKeyedEntity",
  399. messageSends: ["at:put:"],
  400. referencedClasses: []
  401. }),
  402. smalltalk.Trapped);
  403. smalltalk.addMethod(
  404. smalltalk.method({
  405. selector: "start:",
  406. category: 'action',
  407. fn: function (args){
  408. var self=this;
  409. function $Trapped(){return smalltalk.Trapped||(typeof Trapped=="undefined"?nil:Trapped)}
  410. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  411. return smalltalk.withContext(function($ctx1) {
  412. var $1;
  413. _st(args)._do_((function(each){
  414. return smalltalk.withContext(function($ctx2) {
  415. return self._register_(each);
  416. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  417. _st("[data-trap]"._asJQuery())._each_((function(index,elem){
  418. var trap,jq,viewName,modelName,tokens,path;
  419. return smalltalk.withContext(function($ctx2) {
  420. jq=_st(elem)._asJQuery();
  421. jq;
  422. trap=_st(jq)._attr_("data-trap");
  423. trap;
  424. tokens=_st(trap)._tokenize_(":");
  425. tokens;
  426. $1=_st(_st(tokens)._size()).__eq((1));
  427. if(smalltalk.assert($1)){
  428. tokens=_st(["TrappedDumbView"]).__comma(tokens);
  429. tokens;
  430. };
  431. viewName=_st(tokens)._first();
  432. viewName;
  433. tokens=_st(_st(_st(tokens)._second())._tokenize_(" "))._select_((function(each){
  434. return smalltalk.withContext(function($ctx3) {
  435. return _st(each)._notEmpty();
  436. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx2)})}));
  437. tokens;
  438. modelName=_st(tokens)._first();
  439. modelName;
  440. path=_st($Trapped())._parse_(_st(tokens)._allButFirst());
  441. path;
  442. return _st(_st([modelName]).__comma(path))._trapDescend_((function(){
  443. return smalltalk.withContext(function($ctx3) {
  444. return _st(_st(_st(_st($Smalltalk())._current())._at_(viewName))._new())._appendToJQuery_(jq);
  445. }, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}));
  446. }, function($ctx2) {$ctx2.fillBlock({index:index,elem:elem,trap:trap,jq:jq,viewName:viewName,modelName:modelName,tokens:tokens,path:path},$ctx1)})}));
  447. return self}, function($ctx1) {$ctx1.fill(self,"start:",{args:args},smalltalk.Trapped)})},
  448. args: ["args"],
  449. source: "start: args\x0a args do: [ :each | self register: each ].\x0a\x09'[data-trap]' asJQuery each: [ :index :elem |\x0a \x09| trap jq viewName modelName tokens path |\x0a jq := elem asJQuery.\x0a trap := jq attr: 'data-trap'.\x0a tokens := trap tokenize: ':'.\x0a tokens size = 1 ifTrue: [ tokens := { 'TrappedDumbView' }, tokens ].\x0a viewName := tokens first.\x0a tokens := (tokens second tokenize: ' ') select: [ :each | each notEmpty ].\x0a modelName := tokens first.\x0a path := Trapped parse: tokens allButFirst.\x0a { modelName }, path trapDescend: [(Smalltalk current at: viewName) new appendToJQuery: jq].\x0a ]",
  450. messageSends: ["do:", "register:", "each:", "asJQuery", "attr:", "tokenize:", "ifTrue:", ",", "=", "size", "first", "select:", "notEmpty", "second", "parse:", "allButFirst", "trapDescend:", "appendToJQuery:", "new", "at:", "current"],
  451. referencedClasses: ["Trapped", "Smalltalk"]
  452. }),
  453. smalltalk.Trapped);
  454. smalltalk.addMethod(
  455. smalltalk.method({
  456. selector: "envelope:loop:before:tag:do:",
  457. category: 'private',
  458. fn: function (envelope,model,endjq,aSymbol,aBlock){
  459. var self=this;
  460. var envjq;
  461. return smalltalk.withContext(function($ctx1) {
  462. envjq=_st(envelope)._asJQuery();
  463. _st(model)._withIndexDo_((function(item,i){
  464. return smalltalk.withContext(function($ctx2) {
  465. _st(envelope)._with_((function(html){
  466. return smalltalk.withContext(function($ctx3) {
  467. return _st(_st(html)._perform_(aSymbol))._trap_read_([i],aBlock);
  468. }, function($ctx3) {$ctx3.fillBlock({html:html},$ctx2)})}));
  469. return _st(_st(_st(envjq)._children())._detach())._insertBefore_(endjq);
  470. }, function($ctx2) {$ctx2.fillBlock({item:item,i:i},$ctx1)})}));
  471. _st(envjq)._remove();
  472. return self}, function($ctx1) {$ctx1.fill(self,"envelope:loop:before:tag:do:",{envelope:envelope,model:model,endjq:endjq,aSymbol:aSymbol,aBlock:aBlock,envjq:envjq},smalltalk.Trapped.klass)})},
  473. args: ["envelope", "model", "endjq", "aSymbol", "aBlock"],
  474. source: "envelope: envelope loop: model before: endjq tag: aSymbol do: aBlock\x0a \x09| envjq |\x0a envjq := envelope asJQuery.\x0a model withIndexDo: [ :item :i |\x0a envelope with: [ :html | (html perform: aSymbol) trap: {i} read: aBlock ].\x0a envjq children detach insertBefore: endjq.\x0a ].\x0a envjq remove",
  475. messageSends: ["asJQuery", "withIndexDo:", "with:", "trap:read:", "perform:", "insertBefore:", "detach", "children", "remove"],
  476. referencedClasses: []
  477. }),
  478. smalltalk.Trapped.klass);
  479. smalltalk.addMethod(
  480. smalltalk.method({
  481. selector: "loop:between:and:tag:do:",
  482. category: 'private',
  483. fn: function (model,start,end,aSymbol,aBlock){
  484. var self=this;
  485. return smalltalk.withContext(function($ctx1) {
  486. var $1;
  487. _st(_st(_st(start)._asJQuery())._nextUntil_(_st(end)._element()))._remove();
  488. _st(start)._with_((function(html){
  489. return smalltalk.withContext(function($ctx2) {
  490. $1=model;
  491. if(($receiver = $1) == nil || $receiver == undefined){
  492. return $1;
  493. } else {
  494. return self._envelope_loop_before_tag_do_(_st(html)._div(),model,_st(end)._asJQuery(),aSymbol,aBlock);
  495. };
  496. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1)})}));
  497. return self}, function($ctx1) {$ctx1.fill(self,"loop:between:and:tag:do:",{model:model,start:start,end:end,aSymbol:aSymbol,aBlock:aBlock},smalltalk.Trapped.klass)})},
  498. args: ["model", "start", "end", "aSymbol", "aBlock"],
  499. source: "loop: model between: start and: end tag: aSymbol do: aBlock\x0a (start asJQuery nextUntil: end element) remove.\x0a start with: [ :html | model ifNotNil: [\x0a \x09self envelope: html div loop: model before: end asJQuery tag: aSymbol do: aBlock\x0a\x09]]",
  500. messageSends: ["remove", "nextUntil:", "element", "asJQuery", "with:", "ifNotNil:", "envelope:loop:before:tag:do:", "div"],
  501. referencedClasses: []
  502. }),
  503. smalltalk.Trapped.klass);
  504. smalltalk.addMethod(
  505. smalltalk.method({
  506. selector: "parse:",
  507. category: 'accessing',
  508. fn: function (anArray){
  509. var self=this;
  510. return smalltalk.withContext(function($ctx1) {
  511. var $2,$3,$1;
  512. $1=_st(anArray)._collect_((function(each){
  513. var asNum;
  514. return smalltalk.withContext(function($ctx2) {
  515. asNum=_st(each)._asNumber();
  516. asNum;
  517. $2=_st(asNum).__eq(asNum);
  518. if(smalltalk.assert($2)){
  519. return asNum;
  520. } else {
  521. $3=_st(_st(each)._first()).__eq("#");
  522. if(smalltalk.assert($3)){
  523. return [_st(each)._allButFirst()];
  524. } else {
  525. return each;
  526. };
  527. };
  528. }, function($ctx2) {$ctx2.fillBlock({each:each,asNum:asNum},$ctx1)})}));
  529. return $1;
  530. }, function($ctx1) {$ctx1.fill(self,"parse:",{anArray:anArray},smalltalk.Trapped.klass)})},
  531. args: ["anArray"],
  532. source: "parse: anArray\x0a\x09^anArray collect: [ :each |\x0a \x09| asNum |\x0a \x09asNum := each asNumber.\x0a asNum = asNum ifTrue: [ asNum ] ifFalse: [\x0a\x09\x09\x09each first = '#' ifTrue: [ { each allButFirst } ] ifFalse: [ each ]]]",
  533. messageSends: ["collect:", "asNumber", "ifTrue:ifFalse:", "allButFirst", "=", "first"],
  534. referencedClasses: []
  535. }),
  536. smalltalk.Trapped.klass);
  537. smalltalk.addClass('TrappedPathStack', smalltalk.TrappedSingleton, ['elements'], 'Trapped-Frontend');
  538. smalltalk.addMethod(
  539. smalltalk.method({
  540. selector: "append:do:",
  541. category: 'descending',
  542. fn: function (anArray,aBlock){
  543. var self=this;
  544. return smalltalk.withContext(function($ctx1) {
  545. self._with_do_(_st(self["@elements"]).__comma(anArray),aBlock);
  546. return self}, function($ctx1) {$ctx1.fill(self,"append:do:",{anArray:anArray,aBlock:aBlock},smalltalk.TrappedPathStack)})},
  547. args: ["anArray", "aBlock"],
  548. source: "append: anArray do: aBlock\x0a self with: elements, anArray do: aBlock",
  549. messageSends: ["with:do:", ","],
  550. referencedClasses: []
  551. }),
  552. smalltalk.TrappedPathStack);
  553. smalltalk.addMethod(
  554. smalltalk.method({
  555. selector: "elements",
  556. category: 'accessing',
  557. fn: function (){
  558. var self=this;
  559. return smalltalk.withContext(function($ctx1) {
  560. var $1;
  561. $1=self["@elements"];
  562. return $1;
  563. }, function($ctx1) {$ctx1.fill(self,"elements",{},smalltalk.TrappedPathStack)})},
  564. args: [],
  565. source: "elements\x0a\x09^elements",
  566. messageSends: [],
  567. referencedClasses: []
  568. }),
  569. smalltalk.TrappedPathStack);
  570. smalltalk.addMethod(
  571. smalltalk.method({
  572. selector: "initialize",
  573. category: 'initialization',
  574. fn: function (){
  575. var self=this;
  576. return smalltalk.withContext(function($ctx1) {
  577. smalltalk.TrappedPathStack.superclass.fn.prototype._initialize.apply(_st(self), []);
  578. self["@elements"]=[];
  579. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.TrappedPathStack)})},
  580. args: [],
  581. source: "initialize\x0a super initialize.\x0a\x09elements := #().",
  582. messageSends: ["initialize"],
  583. referencedClasses: []
  584. }),
  585. smalltalk.TrappedPathStack);
  586. smalltalk.addMethod(
  587. smalltalk.method({
  588. selector: "with:do:",
  589. category: 'descending',
  590. fn: function (anArray,aBlock){
  591. var self=this;
  592. var old;
  593. return smalltalk.withContext(function($ctx1) {
  594. old=self["@elements"];
  595. _st((function(){
  596. return smalltalk.withContext(function($ctx2) {
  597. self["@elements"]=anArray;
  598. self["@elements"];
  599. return _st(aBlock)._value();
  600. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._ensure_((function(){
  601. return smalltalk.withContext(function($ctx2) {
  602. self["@elements"]=old;
  603. return self["@elements"];
  604. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  605. return self}, function($ctx1) {$ctx1.fill(self,"with:do:",{anArray:anArray,aBlock:aBlock,old:old},smalltalk.TrappedPathStack)})},
  606. args: ["anArray", "aBlock"],
  607. source: "with: anArray do: aBlock\x0a\x09| old |\x0a old := elements.\x0a [ elements := anArray.\x0a\x09aBlock value ] ensure: [ elements := old ]",
  608. messageSends: ["ensure:", "value"],
  609. referencedClasses: []
  610. }),
  611. smalltalk.TrappedPathStack);
  612. smalltalk.addClass('TrappedSnapshot', smalltalk.Object, ['path', 'model'], 'Trapped-Frontend');
  613. smalltalk.addMethod(
  614. smalltalk.method({
  615. selector: "do:",
  616. category: 'action',
  617. fn: function (aBlock){
  618. var self=this;
  619. function $TrappedPathStack(){return smalltalk.TrappedPathStack||(typeof TrappedPathStack=="undefined"?nil:TrappedPathStack)}
  620. return smalltalk.withContext(function($ctx1) {
  621. _st(_st($TrappedPathStack())._current())._with_do_(self["@path"],(function(){
  622. return smalltalk.withContext(function($ctx2) {
  623. return _st(aBlock)._value_(self["@model"]);
  624. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  625. return self}, function($ctx1) {$ctx1.fill(self,"do:",{aBlock:aBlock},smalltalk.TrappedSnapshot)})},
  626. args: ["aBlock"],
  627. source: "do: aBlock\x0a\x09TrappedPathStack current with: path do: [ aBlock value: model ]",
  628. messageSends: ["with:do:", "value:", "current"],
  629. referencedClasses: ["TrappedPathStack"]
  630. }),
  631. smalltalk.TrappedSnapshot);
  632. smalltalk.addMethod(
  633. smalltalk.method({
  634. selector: "model",
  635. category: 'accessing',
  636. fn: function (){
  637. var self=this;
  638. return smalltalk.withContext(function($ctx1) {
  639. var $1;
  640. $1=self["@model"];
  641. return $1;
  642. }, function($ctx1) {$ctx1.fill(self,"model",{},smalltalk.TrappedSnapshot)})},
  643. args: [],
  644. source: "model\x0a\x09^model",
  645. messageSends: [],
  646. referencedClasses: []
  647. }),
  648. smalltalk.TrappedSnapshot);
  649. smalltalk.addMethod(
  650. smalltalk.method({
  651. selector: "modify:",
  652. category: 'action',
  653. fn: function (aBlock){
  654. var self=this;
  655. return smalltalk.withContext(function($ctx1) {
  656. _st(self._model())._modify_do_(_st(self._path())._allButFirst(),aBlock);
  657. return self}, function($ctx1) {$ctx1.fill(self,"modify:",{aBlock:aBlock},smalltalk.TrappedSnapshot)})},
  658. args: ["aBlock"],
  659. source: "modify: aBlock\x0a\x09self model modify: self path allButFirst do: aBlock",
  660. messageSends: ["modify:do:", "allButFirst", "path", "model"],
  661. referencedClasses: []
  662. }),
  663. smalltalk.TrappedSnapshot);
  664. smalltalk.addMethod(
  665. smalltalk.method({
  666. selector: "path",
  667. category: 'accessing',
  668. fn: function (){
  669. var self=this;
  670. return smalltalk.withContext(function($ctx1) {
  671. var $1;
  672. $1=self["@path"];
  673. return $1;
  674. }, function($ctx1) {$ctx1.fill(self,"path",{},smalltalk.TrappedSnapshot)})},
  675. args: [],
  676. source: "path\x0a\x09^path",
  677. messageSends: [],
  678. referencedClasses: []
  679. }),
  680. smalltalk.TrappedSnapshot);
  681. smalltalk.addMethod(
  682. smalltalk.method({
  683. selector: "path:model:",
  684. category: 'accessing',
  685. fn: function (anArray,aTrappedMW){
  686. var self=this;
  687. return smalltalk.withContext(function($ctx1) {
  688. self["@path"]=anArray;
  689. self["@model"]=aTrappedMW;
  690. return self}, function($ctx1) {$ctx1.fill(self,"path:model:",{anArray:anArray,aTrappedMW:aTrappedMW},smalltalk.TrappedSnapshot)})},
  691. args: ["anArray", "aTrappedMW"],
  692. source: "path: anArray model: aTrappedMW\x0a\x09path := anArray.\x0a model := aTrappedMW",
  693. messageSends: [],
  694. referencedClasses: []
  695. }),
  696. smalltalk.TrappedSnapshot);
  697. smalltalk.addMethod(
  698. smalltalk.method({
  699. selector: "trapDescend:",
  700. category: '*Trapped-Frontend',
  701. fn: function (aBlock){
  702. var self=this;
  703. function $Trapped(){return smalltalk.Trapped||(typeof Trapped=="undefined"?nil:Trapped)}
  704. return smalltalk.withContext(function($ctx1) {
  705. _st(_st($Trapped())._current())._descend_snapshotDo_(self,aBlock);
  706. return self}, function($ctx1) {$ctx1.fill(self,"trapDescend:",{aBlock:aBlock},smalltalk.Array)})},
  707. args: ["aBlock"],
  708. source: "trapDescend: aBlock\x0a\x09Trapped current descend: self snapshotDo: aBlock",
  709. messageSends: ["descend:snapshotDo:", "current"],
  710. referencedClasses: ["Trapped"]
  711. }),
  712. smalltalk.Array);
  713. smalltalk.addMethod(
  714. smalltalk.method({
  715. selector: "trapIter:tag:do:",
  716. category: '*Trapped-Frontend',
  717. fn: function (path,aSymbol,aBlock){
  718. var self=this;
  719. var start,end;
  720. function $Trapped(){return smalltalk.Trapped||(typeof Trapped=="undefined"?nil:Trapped)}
  721. return smalltalk.withContext(function($ctx1) {
  722. self._with_((function(html){
  723. return smalltalk.withContext(function($ctx2) {
  724. start=_st(html)._script();
  725. start;
  726. end=_st(html)._script();
  727. return end;
  728. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1)})}));
  729. _st(start)._trap_read_(path,(function(model){
  730. return smalltalk.withContext(function($ctx2) {
  731. return _st($Trapped())._loop_between_and_tag_do_(model,start,end,aSymbol,aBlock);
  732. }, function($ctx2) {$ctx2.fillBlock({model:model},$ctx1)})}));
  733. return self}, function($ctx1) {$ctx1.fill(self,"trapIter:tag:do:",{path:path,aSymbol:aSymbol,aBlock:aBlock,start:start,end:end},smalltalk.HTMLCanvas)})},
  734. args: ["path", "aSymbol", "aBlock"],
  735. source: "trapIter: path tag: aSymbol do: aBlock\x0a\x09| start end |\x0a self with: [ :html | start := html script. end := html script ].\x0a start trap: path read: [ :model |\x0a \x09Trapped loop: model between: start and: end tag: aSymbol do: aBlock.\x0a ]",
  736. messageSends: ["with:", "script", "trap:read:", "loop:between:and:tag:do:"],
  737. referencedClasses: ["Trapped"]
  738. }),
  739. smalltalk.HTMLCanvas);
  740. smalltalk.addMethod(
  741. smalltalk.method({
  742. selector: "trap:",
  743. category: '*Trapped-Frontend',
  744. fn: function (path){
  745. var self=this;
  746. function $Trapped(){return smalltalk.Trapped||(typeof Trapped=="undefined"?nil:Trapped)}
  747. return smalltalk.withContext(function($ctx1) {
  748. _st(_st(_st($Trapped())._current())._binder_(self))._installFor_(path);
  749. return self}, function($ctx1) {$ctx1.fill(self,"trap:",{path:path},smalltalk.TagBrush)})},
  750. args: ["path"],
  751. source: "trap: path\x0a\x09(Trapped current binder: self) installFor: path",
  752. messageSends: ["installFor:", "binder:", "current"],
  753. referencedClasses: ["Trapped"]
  754. }),
  755. smalltalk.TagBrush);
  756. smalltalk.addMethod(
  757. smalltalk.method({
  758. selector: "trap:read:",
  759. category: '*Trapped-Frontend',
  760. fn: function (path,aBlock){
  761. var self=this;
  762. function $KeyedPubSubUnsubscribe(){return smalltalk.KeyedPubSubUnsubscribe||(typeof KeyedPubSubUnsubscribe=="undefined"?nil:KeyedPubSubUnsubscribe)}
  763. return smalltalk.withContext(function($ctx1) {
  764. var $1;
  765. _st(path)._trapDescend_((function(snap){
  766. return smalltalk.withContext(function($ctx2) {
  767. return _st(_st(snap)._model())._watch_do_(_st(_st(snap)._path())._allButFirst(),(function(data){
  768. return smalltalk.withContext(function($ctx3) {
  769. $1=_st(_st(_st(self._asJQuery())._closest_("html"))._toArray())._isEmpty();
  770. if(smalltalk.assert($1)){
  771. _st($KeyedPubSubUnsubscribe())._signal();
  772. };
  773. return _st(snap)._do_((function(){
  774. return smalltalk.withContext(function($ctx4) {
  775. return self._with_((function(html){
  776. return smalltalk.withContext(function($ctx5) {
  777. return _st(aBlock)._value_value_(data,html);
  778. }, function($ctx5) {$ctx5.fillBlock({html:html},$ctx4)})}));
  779. }, function($ctx4) {$ctx4.fillBlock({},$ctx3)})}));
  780. }, function($ctx3) {$ctx3.fillBlock({data:data},$ctx2)})}));
  781. }, function($ctx2) {$ctx2.fillBlock({snap:snap},$ctx1)})}));
  782. return self}, function($ctx1) {$ctx1.fill(self,"trap:read:",{path:path,aBlock:aBlock},smalltalk.TagBrush)})},
  783. args: ["path", "aBlock"],
  784. source: "trap: path read: aBlock\x0a\x09path trapDescend: [ :snap |\x0a snap model watch: snap path allButFirst do: [ :data |\x0a (self asJQuery closest: 'html') toArray isEmpty ifTrue: [ KeyedPubSubUnsubscribe signal ].\x0a \x09snap do: [ self with: [ :html | aBlock value: data value: html ] ]\x0a \x09]\x0a ]",
  785. messageSends: ["trapDescend:", "watch:do:", "allButFirst", "path", "ifTrue:", "signal", "isEmpty", "toArray", "closest:", "asJQuery", "do:", "with:", "value:value:", "model"],
  786. referencedClasses: ["KeyedPubSubUnsubscribe"]
  787. }),
  788. smalltalk.TagBrush);
  789. smalltalk.addMethod(
  790. smalltalk.method({
  791. selector: "trap:toggle:",
  792. category: '*Trapped-Frontend',
  793. fn: function (path,aBlock){
  794. var self=this;
  795. return smalltalk.withContext(function($ctx1) {
  796. self._trap_toggle_ifNotPresent_(path,aBlock,(function(){
  797. return smalltalk.withContext(function($ctx2) {
  798. return _st(self._asJQuery())._hide();
  799. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  800. return self}, function($ctx1) {$ctx1.fill(self,"trap:toggle:",{path:path,aBlock:aBlock},smalltalk.TagBrush)})},
  801. args: ["path", "aBlock"],
  802. source: "trap: path toggle: aBlock\x0a self trap: path toggle: aBlock ifNotPresent: [ self asJQuery hide ]",
  803. messageSends: ["trap:toggle:ifNotPresent:", "hide", "asJQuery"],
  804. referencedClasses: []
  805. }),
  806. smalltalk.TagBrush);
  807. smalltalk.addMethod(
  808. smalltalk.method({
  809. selector: "trap:toggle:ifNotPresent:",
  810. category: '*Trapped-Frontend',
  811. fn: function (path,aBlock,anotherBlock){
  812. var self=this;
  813. var shown;
  814. return smalltalk.withContext(function($ctx1) {
  815. var $1,$2,$3,$5,$4;
  816. shown=nil;
  817. self._trap_read_(path,(function(data,html){
  818. return smalltalk.withContext(function($ctx2) {
  819. $1=_st(shown).__eq(_st(data)._notNil());
  820. if(! smalltalk.assert($1)){
  821. shown=_st(data)._notNil();
  822. shown;
  823. $2=self._asJQuery();
  824. _st($2)._empty();
  825. $3=_st($2)._show();
  826. $3;
  827. $5=shown;
  828. if(smalltalk.assert($5)){
  829. $4=aBlock;
  830. } else {
  831. $4=anotherBlock;
  832. };
  833. return _st($4)._value_value_(data,html);
  834. };
  835. }, function($ctx2) {$ctx2.fillBlock({data:data,html:html},$ctx1)})}));
  836. return self}, function($ctx1) {$ctx1.fill(self,"trap:toggle:ifNotPresent:",{path:path,aBlock:aBlock,anotherBlock:anotherBlock,shown:shown},smalltalk.TagBrush)})},
  837. args: ["path", "aBlock", "anotherBlock"],
  838. source: "trap: path toggle: aBlock ifNotPresent: anotherBlock\x0a | shown |\x0a shown := nil.\x0a self trap: path read: [ :data : html |\x0a shown = data notNil ifFalse: [\x0a shown := data notNil.\x0a self asJQuery empty; show.\x0a (shown ifTrue: [aBlock] ifFalse: [anotherBlock]) value: data value: html.\x0a ]\x0a ]",
  839. messageSends: ["trap:read:", "ifFalse:", "notNil", "empty", "asJQuery", "show", "value:value:", "ifTrue:ifFalse:", "="],
  840. referencedClasses: []
  841. }),
  842. smalltalk.TagBrush);
  843. });