Trapped-Frontend.js 33 KB

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