Trapped-Frontend.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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) { var $2,$3,$1;
  477. $1=_st(anArray)._collect_((function(each){
  478. var asNum;
  479. return smalltalk.withContext(function($ctx2) { _st(asNum).__eq(_st(each)._asNumber());
  480. $2=_st(asNum).__eq(asNum);
  481. if(smalltalk.assert($2)){
  482. return asNum;
  483. } else {
  484. $3=_st(_st(each)._first()).__eq("#");
  485. if(smalltalk.assert($3)){
  486. return _st(_st(each)._allButFirst())._asSymbol();
  487. } else {
  488. return each;
  489. };
  490. };
  491. }, function($ctx2) {$ctx2.fillBlock({each:each,asNum:asNum},$ctx1)})}));
  492. return $1;
  493. }, function($ctx1) {$ctx1.fill(self,"parse:",{anArray:anArray},smalltalk.Trapped.klass)})},
  494. args: ["anArray"],
  495. 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 asSymbol ] ifFalse: [ each ]]]",
  496. messageSends: ["collect:", "=", "asNumber", "ifTrue:ifFalse:", "asSymbol", "allButFirst", "first"],
  497. referencedClasses: []
  498. }),
  499. smalltalk.Trapped.klass);
  500. smalltalk.addClass('TrappedPathStack', smalltalk.TrappedSingleton, ['elements'], 'Trapped-Frontend');
  501. smalltalk.addMethod(
  502. "_append_do_",
  503. smalltalk.method({
  504. selector: "append:do:",
  505. category: 'descending',
  506. fn: function (anArray,aBlock){
  507. var self=this;
  508. return smalltalk.withContext(function($ctx1) { _st(self)._with_do_(_st(self["@elements"]).__comma(anArray),aBlock);
  509. return self}, function($ctx1) {$ctx1.fill(self,"append:do:",{anArray:anArray,aBlock:aBlock},smalltalk.TrappedPathStack)})},
  510. args: ["anArray", "aBlock"],
  511. source: "append: anArray do: aBlock\x0a self with: elements, anArray do: aBlock",
  512. messageSends: ["with:do:", ","],
  513. referencedClasses: []
  514. }),
  515. smalltalk.TrappedPathStack);
  516. smalltalk.addMethod(
  517. "_elements",
  518. smalltalk.method({
  519. selector: "elements",
  520. category: 'accessing',
  521. fn: function (){
  522. var self=this;
  523. return smalltalk.withContext(function($ctx1) { var $1;
  524. $1=self["@elements"];
  525. return $1;
  526. }, function($ctx1) {$ctx1.fill(self,"elements",{},smalltalk.TrappedPathStack)})},
  527. args: [],
  528. source: "elements\x0a\x09^elements",
  529. messageSends: [],
  530. referencedClasses: []
  531. }),
  532. smalltalk.TrappedPathStack);
  533. smalltalk.addMethod(
  534. "_initialize",
  535. smalltalk.method({
  536. selector: "initialize",
  537. category: 'initialization',
  538. fn: function (){
  539. var self=this;
  540. return smalltalk.withContext(function($ctx1) { smalltalk.TrappedSingleton.fn.prototype._initialize.apply(_st(self), []);
  541. self["@elements"]=[];
  542. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.TrappedPathStack)})},
  543. args: [],
  544. source: "initialize\x0a super initialize.\x0a\x09elements := #().",
  545. messageSends: ["initialize"],
  546. referencedClasses: []
  547. }),
  548. smalltalk.TrappedPathStack);
  549. smalltalk.addMethod(
  550. "_with_do_",
  551. smalltalk.method({
  552. selector: "with:do:",
  553. category: 'descending',
  554. fn: function (anArray,aBlock){
  555. var self=this;
  556. var old;
  557. return smalltalk.withContext(function($ctx1) { old=self["@elements"];
  558. _st((function(){
  559. return smalltalk.withContext(function($ctx2) { self["@elements"]=anArray;
  560. self["@elements"];
  561. return _st(aBlock)._value();
  562. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._ensure_((function(){
  563. return smalltalk.withContext(function($ctx2) { self["@elements"]=old;
  564. return self["@elements"];
  565. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  566. return self}, function($ctx1) {$ctx1.fill(self,"with:do:",{anArray:anArray,aBlock:aBlock,old:old},smalltalk.TrappedPathStack)})},
  567. args: ["anArray", "aBlock"],
  568. source: "with: anArray do: aBlock\x0a\x09| old |\x0a old := elements.\x0a [ elements := anArray.\x0a\x09aBlock value ] ensure: [ elements := old ]",
  569. messageSends: ["ensure:", "value"],
  570. referencedClasses: []
  571. }),
  572. smalltalk.TrappedPathStack);
  573. smalltalk.addClass('TrappedSnapshot', smalltalk.Object, ['path', 'model'], 'Trapped-Frontend');
  574. smalltalk.addMethod(
  575. "_do_",
  576. smalltalk.method({
  577. selector: "do:",
  578. category: 'action',
  579. fn: function (aBlock){
  580. var self=this;
  581. return smalltalk.withContext(function($ctx1) { _st(_st((smalltalk.TrappedPathStack || TrappedPathStack))._current())._with_do_(self["@path"],(function(){
  582. return smalltalk.withContext(function($ctx2) { return _st(aBlock)._value_(self["@model"]);
  583. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  584. return self}, function($ctx1) {$ctx1.fill(self,"do:",{aBlock:aBlock},smalltalk.TrappedSnapshot)})},
  585. args: ["aBlock"],
  586. source: "do: aBlock\x0a\x09TrappedPathStack current with: path do: [ aBlock value: model ]",
  587. messageSends: ["with:do:", "value:", "current"],
  588. referencedClasses: ["TrappedPathStack"]
  589. }),
  590. smalltalk.TrappedSnapshot);
  591. smalltalk.addMethod(
  592. "_model",
  593. smalltalk.method({
  594. selector: "model",
  595. category: 'accessing',
  596. fn: function (){
  597. var self=this;
  598. return smalltalk.withContext(function($ctx1) { var $1;
  599. $1=self["@model"];
  600. return $1;
  601. }, function($ctx1) {$ctx1.fill(self,"model",{},smalltalk.TrappedSnapshot)})},
  602. args: [],
  603. source: "model\x0a\x09^model",
  604. messageSends: [],
  605. referencedClasses: []
  606. }),
  607. smalltalk.TrappedSnapshot);
  608. smalltalk.addMethod(
  609. "_modify_",
  610. smalltalk.method({
  611. selector: "modify:",
  612. category: 'action',
  613. fn: function (aBlock){
  614. var self=this;
  615. return smalltalk.withContext(function($ctx1) { _st(_st(self)._model())._modify_do_(_st(_st(self)._path())._allButFirst(),aBlock);
  616. return self}, function($ctx1) {$ctx1.fill(self,"modify:",{aBlock:aBlock},smalltalk.TrappedSnapshot)})},
  617. args: ["aBlock"],
  618. source: "modify: aBlock\x0a\x09self model modify: self path allButFirst do: aBlock",
  619. messageSends: ["modify:do:", "allButFirst", "path", "model"],
  620. referencedClasses: []
  621. }),
  622. smalltalk.TrappedSnapshot);
  623. smalltalk.addMethod(
  624. "_path",
  625. smalltalk.method({
  626. selector: "path",
  627. category: 'accessing',
  628. fn: function (){
  629. var self=this;
  630. return smalltalk.withContext(function($ctx1) { var $1;
  631. $1=self["@path"];
  632. return $1;
  633. }, function($ctx1) {$ctx1.fill(self,"path",{},smalltalk.TrappedSnapshot)})},
  634. args: [],
  635. source: "path\x0a\x09^path",
  636. messageSends: [],
  637. referencedClasses: []
  638. }),
  639. smalltalk.TrappedSnapshot);
  640. smalltalk.addMethod(
  641. "_path_model_",
  642. smalltalk.method({
  643. selector: "path:model:",
  644. category: 'accessing',
  645. fn: function (anArray,aTrappedMW){
  646. var self=this;
  647. return smalltalk.withContext(function($ctx1) { self["@path"]=anArray;
  648. self["@model"]=aTrappedMW;
  649. return self}, function($ctx1) {$ctx1.fill(self,"path:model:",{anArray:anArray,aTrappedMW:aTrappedMW},smalltalk.TrappedSnapshot)})},
  650. args: ["anArray", "aTrappedMW"],
  651. source: "path: anArray model: aTrappedMW\x0a\x09path := anArray.\x0a model := aTrappedMW",
  652. messageSends: [],
  653. referencedClasses: []
  654. }),
  655. smalltalk.TrappedSnapshot);
  656. smalltalk.addMethod(
  657. "_trapDescend_",
  658. smalltalk.method({
  659. selector: "trapDescend:",
  660. category: '*Trapped-Frontend',
  661. fn: function (aBlock){
  662. var self=this;
  663. return smalltalk.withContext(function($ctx1) { _st(_st((smalltalk.Trapped || Trapped))._current())._descend_snapshotDo_(self,aBlock);
  664. return self}, function($ctx1) {$ctx1.fill(self,"trapDescend:",{aBlock:aBlock}, smalltalk.Array)})},
  665. args: ["aBlock"],
  666. source: "trapDescend: aBlock\x0a\x09Trapped current descend: self snapshotDo: aBlock",
  667. messageSends: ["descend:snapshotDo:", "current"],
  668. referencedClasses: ["Trapped"]
  669. }),
  670. smalltalk.Array);
  671. smalltalk.addMethod(
  672. "_trapIter_tag_do_",
  673. smalltalk.method({
  674. selector: "trapIter:tag:do:",
  675. category: '*Trapped-Frontend',
  676. fn: function (path,aSymbol,aBlock){
  677. var self=this;
  678. var start,end;
  679. return smalltalk.withContext(function($ctx1) { _st(self)._with_((function(html){
  680. return smalltalk.withContext(function($ctx2) { start=_st(html)._script();
  681. start;
  682. end=_st(html)._script();
  683. return end;
  684. }, function($ctx2) {$ctx2.fillBlock({html:html},$ctx1)})}));
  685. _st(start)._trap_read_(path,(function(model){
  686. return smalltalk.withContext(function($ctx2) { return _st((smalltalk.Trapped || Trapped))._loop_between_and_tag_do_(model,start,end,aSymbol,aBlock);
  687. }, function($ctx2) {$ctx2.fillBlock({model:model},$ctx1)})}));
  688. return self}, function($ctx1) {$ctx1.fill(self,"trapIter:tag:do:",{path:path,aSymbol:aSymbol,aBlock:aBlock,start:start,end:end}, smalltalk.HTMLCanvas)})},
  689. args: ["path", "aSymbol", "aBlock"],
  690. 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 ]",
  691. messageSends: ["with:", "script", "trap:read:", "loop:between:and:tag:do:"],
  692. referencedClasses: ["Trapped"]
  693. }),
  694. smalltalk.HTMLCanvas);
  695. smalltalk.addMethod(
  696. "_trap_",
  697. smalltalk.method({
  698. selector: "trap:",
  699. category: '*Trapped-Frontend',
  700. fn: function (path){
  701. var self=this;
  702. return smalltalk.withContext(function($ctx1) { _st(_st(_st((smalltalk.Trapped || Trapped))._current())._binder_(self))._installFor_(path);
  703. return self}, function($ctx1) {$ctx1.fill(self,"trap:",{path:path}, smalltalk.TagBrush)})},
  704. args: ["path"],
  705. source: "trap: path\x0a\x09(Trapped current binder: self) installFor: path",
  706. messageSends: ["installFor:", "binder:", "current"],
  707. referencedClasses: ["Trapped"]
  708. }),
  709. smalltalk.TagBrush);
  710. smalltalk.addMethod(
  711. "_trap_read_",
  712. smalltalk.method({
  713. selector: "trap:read:",
  714. category: '*Trapped-Frontend',
  715. fn: function (path,aBlock){
  716. var self=this;
  717. return smalltalk.withContext(function($ctx1) { var $1,$3,$4,$6,$5,$2;
  718. $1=path;
  719. $2=(function(snap){
  720. return smalltalk.withContext(function($ctx2) { $3=_st(snap)._model();
  721. $4=_st(_st(snap)._path())._allButFirst();
  722. $5=(function(data){
  723. return smalltalk.withContext(function($ctx3) { $6=_st(_st(_st(_st(self)._asJQuery())._closest_("html"))._toArray())._isEmpty();
  724. if(smalltalk.assert($6)){
  725. _st((smalltalk.KeyedPubSubUnsubscribe || KeyedPubSubUnsubscribe))._signal();
  726. };
  727. return _st(snap)._do_((function(){
  728. return smalltalk.withContext(function($ctx4) { return _st(self)._with_((function(html){
  729. return smalltalk.withContext(function($ctx5) { return _st(aBlock)._value_value_(data,html);
  730. }, function($ctx5) {$ctx5.fillBlock({html:html},$ctx1)})}));
  731. }, function($ctx4) {$ctx4.fillBlock({},$ctx1)})}));
  732. }, function($ctx3) {$ctx3.fillBlock({data:data},$ctx1)})});
  733. return _st($3)._watch_do_($4,$5);
  734. }, function($ctx2) {$ctx2.fillBlock({snap:snap},$ctx1)})});
  735. _st($1)._trapDescend_($2);
  736. return self}, function($ctx1) {$ctx1.fill(self,"trap:read:",{path:path,aBlock:aBlock}, smalltalk.TagBrush)})},
  737. args: ["path", "aBlock"],
  738. 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 ]",
  739. messageSends: ["trapDescend:", "watch:do:", "allButFirst", "path", "ifTrue:", "signal", "isEmpty", "toArray", "closest:", "asJQuery", "do:", "with:", "value:value:", "model"],
  740. referencedClasses: ["KeyedPubSubUnsubscribe"]
  741. }),
  742. smalltalk.TagBrush);
  743. smalltalk.addMethod(
  744. "_trap_toggle_",
  745. smalltalk.method({
  746. selector: "trap:toggle:",
  747. category: '*Trapped-Frontend',
  748. fn: function (path,aBlock){
  749. var self=this;
  750. return smalltalk.withContext(function($ctx1) { _st(self)._trap_toggle_ifNotPresent_(path,aBlock,(function(){
  751. return smalltalk.withContext(function($ctx2) { return _st(_st(self)._asJQuery())._hide();
  752. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  753. return self}, function($ctx1) {$ctx1.fill(self,"trap:toggle:",{path:path,aBlock:aBlock}, smalltalk.TagBrush)})},
  754. args: ["path", "aBlock"],
  755. source: "trap: path toggle: aBlock\x0a self trap: path toggle: aBlock ifNotPresent: [ self asJQuery hide ]",
  756. messageSends: ["trap:toggle:ifNotPresent:", "hide", "asJQuery"],
  757. referencedClasses: []
  758. }),
  759. smalltalk.TagBrush);
  760. smalltalk.addMethod(
  761. "_trap_toggle_ifNotPresent_",
  762. smalltalk.method({
  763. selector: "trap:toggle:ifNotPresent:",
  764. category: '*Trapped-Frontend',
  765. fn: function (path,aBlock,anotherBlock){
  766. var self=this;
  767. var shown;
  768. return smalltalk.withContext(function($ctx1) { var $1,$2,$4,$6,$7,$9,$8,$5,$3;
  769. shown=nil;
  770. $1=self;
  771. $2=path;
  772. $3=(function(data,html){
  773. return smalltalk.withContext(function($ctx2) { $4=_st(shown).__eq(_st(data)._notNil());
  774. $5=(function(){
  775. return smalltalk.withContext(function($ctx3) { shown=_st(data)._notNil();
  776. shown;
  777. $6=_st(self)._asJQuery();
  778. _st($6)._empty();
  779. $7=_st($6)._show();
  780. $7;
  781. $9=shown;
  782. if(smalltalk.assert($9)){
  783. $8=aBlock;
  784. } else {
  785. $8=anotherBlock;
  786. };
  787. return _st($8)._value_value_(data,html);
  788. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})});
  789. return _st($4)._ifFalse_($5);
  790. }, function($ctx2) {$ctx2.fillBlock({data:data,html:html},$ctx1)})});
  791. _st($1)._trap_read_($2,$3);
  792. return self}, function($ctx1) {$ctx1.fill(self,"trap:toggle:ifNotPresent:",{path:path,aBlock:aBlock,anotherBlock:anotherBlock,shown:shown}, smalltalk.TagBrush)})},
  793. args: ["path", "aBlock", "anotherBlock"],
  794. 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 ]",
  795. messageSends: ["trap:read:", "ifFalse:", "notNil", "empty", "asJQuery", "show", "value:value:", "ifTrue:ifFalse:", "="],
  796. referencedClasses: []
  797. }),
  798. smalltalk.TagBrush);