Trapped-Frontend.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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. self["@brush"]=aTagBrush;
  11. return self},
  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. smalltalk.send(self["@brush"],"_trap_read_",[path,smalltalk.send(self,"_showBlock",[])]);
  26. return self},
  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 anObject.valueOf();
  41. ;
  42. return self},
  43. args: ["anObject"],
  44. source: "prim: anObject\x0a\x09<return anObject.valueOf()>",
  45. messageSends: [],
  46. referencedClasses: []
  47. }),
  48. smalltalk.TrappedBinder);
  49. smalltalk.addMethod(
  50. "_showBlock",
  51. smalltalk.method({
  52. selector: "showBlock",
  53. category: 'action',
  54. fn: function (){
  55. var self=this;
  56. smalltalk.send(self,"_subclassResponsibility",[]);
  57. return self},
  58. args: [],
  59. source: "showBlock\x0a\x09self subclassResponsibility",
  60. messageSends: ["subclassResponsibility"],
  61. referencedClasses: []
  62. }),
  63. smalltalk.TrappedBinder);
  64. smalltalk.addClass('TrappedAttrBinder', smalltalk.TrappedBinder, ['attr'], 'Trapped-Frontend');
  65. smalltalk.addMethod(
  66. "_attr_",
  67. smalltalk.method({
  68. selector: "attr:",
  69. category: 'accessing',
  70. fn: function (aString){
  71. var self=this;
  72. self["@attr"]=aString;
  73. return self},
  74. args: ["aString"],
  75. source: "attr: aString\x0a\x09attr := aString",
  76. messageSends: [],
  77. referencedClasses: []
  78. }),
  79. smalltalk.TrappedAttrBinder);
  80. smalltalk.addMethod(
  81. "_installFor_",
  82. smalltalk.method({
  83. selector: "installFor:",
  84. category: 'action',
  85. fn: function (path){
  86. var self=this;
  87. smalltalk.send(self,"_installFor_",[path],smalltalk.TrappedBinder);
  88. smalltalk.send(path,"_trapDescend_",[(function(){
  89. var actual;
  90. actual=smalltalk.send((smalltalk.Trapped || Trapped),"_path",[]);
  91. actual;
  92. return smalltalk.send(self["@brush"],"_onChange_",[(function(){
  93. return smalltalk.send(actual,"_trapDescend_",[(function(){
  94. return smalltalk.send(self["@brush"],"_trap_modify_",[[],(function(){
  95. return smalltalk.send(smalltalk.send(smalltalk.send(self["@brush"],"_asJQuery",[]),"_attr_",["checked"]),"_notNil",[]);
  96. })]);
  97. })]);
  98. })]);
  99. })]);
  100. return self},
  101. args: ["path"],
  102. source: "installFor: path\x0a\x09super installFor: path.\x0a path trapDescend: [ | actual |\x0a actual := Trapped path.\x0a\x09 brush onChange: [ actual trapDescend: [ brush trap: #() modify: [\x0a (brush asJQuery attr: 'checked') notNil\x0a ]]]\x0a ]",
  103. messageSends: ["installFor:", "trapDescend:", "path", "onChange:", "trap:modify:", "notNil", "attr:", "asJQuery"],
  104. referencedClasses: ["Trapped"]
  105. }),
  106. smalltalk.TrappedAttrBinder);
  107. smalltalk.addMethod(
  108. "_showBlock",
  109. smalltalk.method({
  110. selector: "showBlock",
  111. category: 'action',
  112. fn: function (){
  113. var self=this;
  114. var $1;
  115. $1=(function(model){
  116. return smalltalk.send(smalltalk.send(self["@brush"],"_asJQuery",[]),"_attr_put_",[self["@attr"],smalltalk.send(self,"_prim_",[model])]);
  117. });
  118. return $1;
  119. },
  120. args: [],
  121. source: "showBlock\x0a\x09^[ :model | brush asJQuery attr: attr put: (self prim: model) ]",
  122. messageSends: ["attr:put:", "prim:", "asJQuery"],
  123. referencedClasses: []
  124. }),
  125. smalltalk.TrappedAttrBinder);
  126. smalltalk.addClass('TrappedDispatcher', smalltalk.KeyedPubSubBase, [], 'Trapped-Frontend');
  127. smalltalk.TrappedDispatcher.comment="I am base class for change event dispatchers.\x0aI manage changed path - action block subscriptions.\x0aThese subscription are instances of TrappedSubscription\x0a\x0aMy subclasses need to provide implementation for:\x0a\x09add:\x0a do:\x0a clean\x0a (optionally) run\x0a"
  128. smalltalk.addMethod(
  129. "_subscriptionKey_block_",
  130. smalltalk.method({
  131. selector: "subscriptionKey:block:",
  132. category: 'action',
  133. fn: function (key,aBlock){
  134. var self=this;
  135. var $2,$3,$1;
  136. $2=smalltalk.send((smalltalk.TrappedSubscription || TrappedSubscription),"_new",[]);
  137. smalltalk.send($2,"_key_block_",[key,aBlock]);
  138. $3=smalltalk.send($2,"_yourself",[]);
  139. $1=$3;
  140. return $1;
  141. },
  142. args: ["key", "aBlock"],
  143. source: "subscriptionKey: key block: aBlock\x0a\x09^TrappedSubscription new key: key block: aBlock; yourself\x0a",
  144. messageSends: ["key:block:", "new", "yourself"],
  145. referencedClasses: ["TrappedSubscription"]
  146. }),
  147. smalltalk.TrappedDispatcher);
  148. smalltalk.addClass('TrappedDumbView', smalltalk.Widget, [], 'Trapped-Frontend');
  149. smalltalk.TrappedDumbView.comment="I just read and show an actual path."
  150. smalltalk.addMethod(
  151. "_renderOn_",
  152. smalltalk.method({
  153. selector: "renderOn:",
  154. category: 'rendering',
  155. fn: function (html){
  156. var self=this;
  157. smalltalk.send(smalltalk.send(html,"_root",[]),"_trapShow_",[[]]);
  158. return self},
  159. args: ["html"],
  160. source: "renderOn: html\x0a\x09html root trapShow: #()",
  161. messageSends: ["trapShow:", "root"],
  162. referencedClasses: []
  163. }),
  164. smalltalk.TrappedDumbView);
  165. smalltalk.addClass('TrappedModelWrapper', smalltalk.Object, ['dispatcher', 'payload'], 'Trapped-Frontend');
  166. smalltalk.TrappedModelWrapper.comment="I am base class for model wrappers.\x0aI wrap a model which can be any object.\x0a\x0aMy subclasses need to provide implementation for:\x0a\x09read:do:\x0a modify:do:\x0a\x09(optionally) name\x0a\x0aand must issue these call when initializing:\x0a\x09model:\x0a\x09dispatcher: (with a subclass of TrappedDispatcher)\x0a"
  167. smalltalk.addMethod(
  168. "_dispatcher",
  169. smalltalk.method({
  170. selector: "dispatcher",
  171. category: 'accessing',
  172. fn: function (){
  173. var self=this;
  174. return self["@dispatcher"];
  175. },
  176. args: [],
  177. source: "dispatcher\x0a\x09^dispatcher",
  178. messageSends: [],
  179. referencedClasses: []
  180. }),
  181. smalltalk.TrappedModelWrapper);
  182. smalltalk.addMethod(
  183. "_dispatcher_",
  184. smalltalk.method({
  185. selector: "dispatcher:",
  186. category: 'accessing',
  187. fn: function (aDispatcher){
  188. var self=this;
  189. self["@dispatcher"]=aDispatcher;
  190. return self},
  191. args: ["aDispatcher"],
  192. source: "dispatcher: aDispatcher\x0a\x09dispatcher := aDispatcher",
  193. messageSends: [],
  194. referencedClasses: []
  195. }),
  196. smalltalk.TrappedModelWrapper);
  197. smalltalk.addMethod(
  198. "_model_",
  199. smalltalk.method({
  200. selector: "model:",
  201. category: 'accessing',
  202. fn: function (anObject){
  203. var self=this;
  204. self["@payload"]=anObject;
  205. smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[[]]);
  206. return self},
  207. args: ["anObject"],
  208. source: "model: anObject\x0a\x09payload := anObject.\x0a self dispatcher changed: #()",
  209. messageSends: ["changed:", "dispatcher"],
  210. referencedClasses: []
  211. }),
  212. smalltalk.TrappedModelWrapper);
  213. smalltalk.addMethod(
  214. "_name",
  215. smalltalk.method({
  216. selector: "name",
  217. category: 'accessing',
  218. fn: function (){
  219. var self=this;
  220. var $1;
  221. $1=smalltalk.send(smalltalk.send(self,"_class",[]),"_name",[]);
  222. return $1;
  223. },
  224. args: [],
  225. source: "name\x0a\x09^ self class name",
  226. messageSends: ["name", "class"],
  227. referencedClasses: []
  228. }),
  229. smalltalk.TrappedModelWrapper);
  230. smalltalk.addMethod(
  231. "_start",
  232. smalltalk.method({
  233. selector: "start",
  234. category: 'action',
  235. fn: function (){
  236. var self=this;
  237. smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_register_name_",[self,smalltalk.send(self,"_name",[])]);
  238. return self},
  239. args: [],
  240. source: "start\x0a\x09Trapped current register: self name: self name",
  241. messageSends: ["register:name:", "name", "current"],
  242. referencedClasses: ["Trapped"]
  243. }),
  244. smalltalk.TrappedModelWrapper);
  245. smalltalk.addMethod(
  246. "_watch_do_",
  247. smalltalk.method({
  248. selector: "watch:do:",
  249. category: 'action',
  250. fn: function (path,aBlock){
  251. var self=this;
  252. smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_on_hook_",[path,(function(){
  253. return smalltalk.send(self,"_read_do_",[path,aBlock]);
  254. })]);
  255. return self},
  256. args: ["path", "aBlock"],
  257. source: "watch: path do: aBlock\x0a\x09self dispatcher on: path hook: [ self read: path do: aBlock ]\x0a",
  258. messageSends: ["on:hook:", "read:do:", "dispatcher"],
  259. referencedClasses: []
  260. }),
  261. smalltalk.TrappedModelWrapper);
  262. smalltalk.addMethod(
  263. "_start",
  264. smalltalk.method({
  265. selector: "start",
  266. category: 'action',
  267. fn: function (){
  268. var self=this;
  269. var $2,$3,$1;
  270. $2=smalltalk.send(self,"_new",[]);
  271. smalltalk.send($2,"_start",[]);
  272. $3=smalltalk.send($2,"_yourself",[]);
  273. $1=$3;
  274. return $1;
  275. },
  276. args: [],
  277. source: "start\x0a\x09^self new start; yourself",
  278. messageSends: ["start", "new", "yourself"],
  279. referencedClasses: []
  280. }),
  281. smalltalk.TrappedModelWrapper.klass);
  282. smalltalk.addClass('TrappedMWDirect', smalltalk.TrappedModelWrapper, [], 'Trapped-Frontend');
  283. smalltalk.TrappedMWDirect.comment="I am TrappedModelWrapper that directly manipulate\x0athe object passed to model:"
  284. smalltalk.addMethod(
  285. "_modify_do_",
  286. smalltalk.method({
  287. selector: "modify:do:",
  288. category: 'action',
  289. fn: function (path,aBlock){
  290. var self=this;
  291. var newValue;
  292. var eavModel;
  293. eavModel=smalltalk.send(path,"_asEavModel",[]);
  294. newValue=smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[self["@payload"]])]);
  295. smalltalk.send((function(){
  296. return smalltalk.send(eavModel,"_on_put_",[self["@payload"],newValue]);
  297. }),"_ensure_",[(function(){
  298. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
  299. })]);
  300. return self},
  301. args: ["path", "aBlock"],
  302. source: "modify: path do: aBlock\x0a | newValue eavModel |\x0a eavModel := path asEavModel.\x0a newValue := aBlock value: (eavModel on: payload).\x0a [ eavModel on: payload put: newValue ] ensure: [ self dispatcher changed: path ]\x0a",
  303. messageSends: ["asEavModel", "value:", "on:", "ensure:", "changed:", "dispatcher", "on:put:"],
  304. referencedClasses: []
  305. }),
  306. smalltalk.TrappedMWDirect);
  307. smalltalk.addMethod(
  308. "_read_do_",
  309. smalltalk.method({
  310. selector: "read:do:",
  311. category: 'action',
  312. fn: function (path,aBlock){
  313. var self=this;
  314. var eavModel;
  315. eavModel=smalltalk.send(path,"_asEavModel",[]);
  316. smalltalk.send(aBlock,"_value_",[smalltalk.send(eavModel,"_on_",[self["@payload"]])]);
  317. return self},
  318. args: ["path", "aBlock"],
  319. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := path asEavModel.\x0a aBlock value: (eavModel on: payload)\x0a",
  320. messageSends: ["asEavModel", "value:", "on:"],
  321. referencedClasses: []
  322. }),
  323. smalltalk.TrappedMWDirect);
  324. smalltalk.addClass('TrappedMWIsolated', smalltalk.TrappedModelWrapper, [], 'Trapped-Frontend');
  325. smalltalk.TrappedMWIsolated.comment="I am TrappedModelWrapper than wrap access\x0ato an object passed to model: via Isolator."
  326. smalltalk.addMethod(
  327. "_model_",
  328. smalltalk.method({
  329. selector: "model:",
  330. category: 'accessing',
  331. fn: function (anObject){
  332. var self=this;
  333. smalltalk.send(self,"_model_",[smalltalk.send((smalltalk.Isolator || Isolator),"_on_",[anObject])],smalltalk.TrappedModelWrapper);
  334. return self},
  335. args: ["anObject"],
  336. source: "model: anObject\x0a\x09super model: (Isolator on: anObject)",
  337. messageSends: ["model:", "on:"],
  338. referencedClasses: ["Isolator"]
  339. }),
  340. smalltalk.TrappedMWIsolated);
  341. smalltalk.addMethod(
  342. "_modify_do_",
  343. smalltalk.method({
  344. selector: "modify:do:",
  345. category: 'action',
  346. fn: function (path,aBlock){
  347. var self=this;
  348. var eavModel;
  349. eavModel=smalltalk.send(smalltalk.send([smalltalk.symbolFor("root")],"__comma",[path]),"_asEavModel",[]);
  350. smalltalk.send((function(){
  351. return smalltalk.send(self["@payload"],"_model_modify_",[eavModel,aBlock]);
  352. }),"_ensure_",[(function(){
  353. return smalltalk.send(smalltalk.send(self,"_dispatcher",[]),"_changed_",[path]);
  354. })]);
  355. return self},
  356. args: ["path", "aBlock"],
  357. source: "modify: path do: aBlock\x0a | eavModel |\x0a eavModel := ({#root},path) asEavModel.\x0a [ payload model: eavModel modify: aBlock ] ensure: [ self dispatcher changed: path ]\x0a",
  358. messageSends: ["asEavModel", ",", "ensure:", "changed:", "dispatcher", "model:modify:"],
  359. referencedClasses: []
  360. }),
  361. smalltalk.TrappedMWIsolated);
  362. smalltalk.addMethod(
  363. "_read_do_",
  364. smalltalk.method({
  365. selector: "read:do:",
  366. category: 'action',
  367. fn: function (path,aBlock){
  368. var self=this;
  369. var eavModel;
  370. eavModel=smalltalk.send(smalltalk.send([smalltalk.symbolFor("root")],"__comma",[path]),"_asEavModel",[]);
  371. smalltalk.send(self["@payload"],"_model_read_",[eavModel,aBlock]);
  372. return self},
  373. args: ["path", "aBlock"],
  374. source: "read: path do: aBlock\x0a | eavModel |\x0a eavModel := ({#root},path) asEavModel.\x0a payload model: eavModel read: aBlock\x0a",
  375. messageSends: ["asEavModel", ",", "model:read:"],
  376. referencedClasses: []
  377. }),
  378. smalltalk.TrappedMWIsolated);
  379. smalltalk.addClass('TrappedSingleton', smalltalk.Object, [], 'Trapped-Frontend');
  380. smalltalk.addMethod(
  381. "_start",
  382. smalltalk.method({
  383. selector: "start",
  384. category: 'action',
  385. fn: function (){
  386. var self=this;
  387. var $1;
  388. $1=smalltalk.send(self,"_subclassResponsibility",[]);
  389. return $1;
  390. },
  391. args: [],
  392. source: "start\x0a\x09^ self subclassResponsibility",
  393. messageSends: ["subclassResponsibility"],
  394. referencedClasses: []
  395. }),
  396. smalltalk.TrappedSingleton);
  397. smalltalk.TrappedSingleton.klass.iVarNames = ['current'];
  398. smalltalk.addMethod(
  399. "_current",
  400. smalltalk.method({
  401. selector: "current",
  402. category: 'accessing',
  403. fn: function (){
  404. var self=this;
  405. var $1;
  406. if(($receiver = self["@current"]) == nil || $receiver == undefined){
  407. self["@current"]=smalltalk.send(self,"_new",[]);
  408. $1=self["@current"];
  409. } else {
  410. $1=self["@current"];
  411. };
  412. return $1;
  413. },
  414. args: [],
  415. source: "current\x0a\x09^ current ifNil: [ current := self new ]",
  416. messageSends: ["ifNil:", "new"],
  417. referencedClasses: []
  418. }),
  419. smalltalk.TrappedSingleton.klass);
  420. smalltalk.addMethod(
  421. "_start",
  422. smalltalk.method({
  423. selector: "start",
  424. category: 'action',
  425. fn: function (){
  426. var self=this;
  427. smalltalk.send(smalltalk.send(self,"_current",[]),"_start",[]);
  428. return self},
  429. args: [],
  430. source: "start\x0a\x09self current start",
  431. messageSends: ["start", "current"],
  432. referencedClasses: []
  433. }),
  434. smalltalk.TrappedSingleton.klass);
  435. smalltalk.addClass('Trapped', smalltalk.TrappedSingleton, ['registry'], 'Trapped-Frontend');
  436. smalltalk.addMethod(
  437. "_binder_",
  438. smalltalk.method({
  439. selector: "binder:",
  440. category: 'binders',
  441. fn: function (aTagBrush){
  442. var self=this;
  443. var $2,$3,$1;
  444. $2=smalltalk.send((smalltalk.TrappedAttrBinder || TrappedAttrBinder),"_new",[]);
  445. smalltalk.send($2,"_attr_",["checked"]);
  446. smalltalk.send($2,"_brush_",[aTagBrush]);
  447. $3=smalltalk.send($2,"_yourself",[]);
  448. $1=$3;
  449. return $1;
  450. },
  451. args: ["aTagBrush"],
  452. source: "binder: aTagBrush\x0a \x22Prototype; will select based on tag etc.\x22\x0a ^TrappedAttrBinder new attr: 'checked'; brush: aTagBrush; yourself",
  453. messageSends: ["attr:", "new", "brush:", "yourself"],
  454. referencedClasses: ["TrappedAttrBinder"]
  455. }),
  456. smalltalk.Trapped);
  457. smalltalk.addMethod(
  458. "_byName_",
  459. smalltalk.method({
  460. selector: "byName:",
  461. category: 'accessing',
  462. fn: function (aString){
  463. var self=this;
  464. var $1;
  465. $1=smalltalk.send(self["@registry"],"_at_",[aString]);
  466. return $1;
  467. },
  468. args: ["aString"],
  469. source: "byName: aString\x0a\x09^ registry at: aString",
  470. messageSends: ["at:"],
  471. referencedClasses: []
  472. }),
  473. smalltalk.Trapped);
  474. smalltalk.addMethod(
  475. "_initialize",
  476. smalltalk.method({
  477. selector: "initialize",
  478. category: 'initialization',
  479. fn: function (){
  480. var self=this;
  481. smalltalk.send(self,"_initialize",[],smalltalk.TrappedSingleton);
  482. self["@registry"]=smalltalk.HashedCollection._fromPairs_([]);
  483. return self},
  484. args: [],
  485. source: "initialize\x0a\x09super initialize.\x0a\x09registry := #{}.",
  486. messageSends: ["initialize"],
  487. referencedClasses: []
  488. }),
  489. smalltalk.Trapped);
  490. smalltalk.addMethod(
  491. "_register_name_",
  492. smalltalk.method({
  493. selector: "register:name:",
  494. category: 'accessing',
  495. fn: function (aFly,aString){
  496. var self=this;
  497. smalltalk.send(self["@registry"],"_at_put_",[aString,aFly]);
  498. return self},
  499. args: ["aFly", "aString"],
  500. source: "register: aFly name: aString\x0a\x09registry at: aString put: aFly",
  501. messageSends: ["at:put:"],
  502. referencedClasses: []
  503. }),
  504. smalltalk.Trapped);
  505. smalltalk.addMethod(
  506. "_start",
  507. smalltalk.method({
  508. selector: "start",
  509. category: 'action',
  510. fn: function (){
  511. var self=this;
  512. var $1;
  513. smalltalk.send(smalltalk.send("[data-trap]","_asJQuery",[]),"_each_",[(function(index,elem){
  514. var trap;
  515. var jq;
  516. var viewName;
  517. var modelName;
  518. var tokens;
  519. var path;
  520. jq=smalltalk.send(elem,"_asJQuery",[]);
  521. jq;
  522. trap=smalltalk.send(jq,"_attr_",["data-trap"]);
  523. trap;
  524. tokens=smalltalk.send(trap,"_tokenize_",[":"]);
  525. tokens;
  526. $1=smalltalk.send(smalltalk.send(tokens,"_size",[]),"__eq",[(1)]);
  527. if(smalltalk.assert($1)){
  528. tokens=smalltalk.send(["TrappedDumbView"],"__comma",[tokens]);
  529. tokens;
  530. };
  531. viewName=smalltalk.send(tokens,"_first",[]);
  532. viewName;
  533. tokens=smalltalk.send(smalltalk.send(smalltalk.send(tokens,"_second",[]),"_tokenize_",[" "]),"_select_",[(function(each){
  534. return smalltalk.send(each,"_notEmpty",[]);
  535. })]);
  536. tokens;
  537. modelName=smalltalk.send(tokens,"_first",[]);
  538. modelName;
  539. path=smalltalk.send((smalltalk.Trapped || Trapped),"_parse_",[smalltalk.send(tokens,"_allButFirst",[])]);
  540. path;
  541. return smalltalk.send(smalltalk.send([modelName],"__comma",[path]),"_trapDescend_",[(function(){
  542. return smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Smalltalk || Smalltalk),"_current",[]),"_at_",[viewName]),"_new",[]),"_appendToJQuery_",[jq]);
  543. })]);
  544. })]);
  545. return self},
  546. args: [],
  547. source: "start\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 ]",
  548. messageSends: ["each:", "asJQuery", "attr:", "tokenize:", "ifTrue:", ",", "=", "size", "first", "select:", "notEmpty", "second", "parse:", "allButFirst", "trapDescend:", "appendToJQuery:", "new", "at:", "current"],
  549. referencedClasses: ["Trapped", "Smalltalk"]
  550. }),
  551. smalltalk.Trapped);
  552. smalltalk.addMethod(
  553. "_parse_",
  554. smalltalk.method({
  555. selector: "parse:",
  556. category: 'accessing',
  557. fn: function (anArray){
  558. var self=this;
  559. var $2,$3,$1;
  560. $1=smalltalk.send(anArray,"_collect_",[(function(each){
  561. var asNum;
  562. asNum = parseInt(each);
  563. ;
  564. $2=smalltalk.send(asNum,"__eq",[asNum]);
  565. if(smalltalk.assert($2)){
  566. return asNum;
  567. } else {
  568. $3=smalltalk.send(smalltalk.send(each,"_first",[]),"__eq",["#"]);
  569. if(smalltalk.assert($3)){
  570. return smalltalk.send(smalltalk.send(each,"_allButFirst",[]),"_asSymbol",[]);
  571. } else {
  572. return each;
  573. };
  574. };
  575. })]);
  576. return $1;
  577. },
  578. args: ["anArray"],
  579. source: "parse: anArray\x0a\x09^anArray collect: [ :each |\x0a \x09| asNum |\x0a \x09<asNum = parseInt(each)>.\x0a asNum = asNum ifTrue: [ asNum ] ifFalse: [\x0a\x09\x09\x09each first = '#' ifTrue: [ each allButFirst asSymbol ] ifFalse: [ each ]]]",
  580. messageSends: ["collect:", "ifTrue:ifFalse:", "asSymbol", "allButFirst", "=", "first"],
  581. referencedClasses: []
  582. }),
  583. smalltalk.Trapped.klass);
  584. smalltalk.addMethod(
  585. "_path",
  586. smalltalk.method({
  587. selector: "path",
  588. category: 'accessing',
  589. fn: function (){
  590. var self=this;
  591. var $1;
  592. $1=smalltalk.send(smalltalk.send((smalltalk.TrappedPathStack || TrappedPathStack),"_current",[]),"_elements",[]);
  593. return $1;
  594. },
  595. args: [],
  596. source: "path\x0a\x09^TrappedPathStack current elements",
  597. messageSends: ["elements", "current"],
  598. referencedClasses: ["TrappedPathStack"]
  599. }),
  600. smalltalk.Trapped.klass);
  601. smalltalk.addClass('TrappedPathStack', smalltalk.TrappedSingleton, ['elements'], 'Trapped-Frontend');
  602. smalltalk.addMethod(
  603. "_append_",
  604. smalltalk.method({
  605. selector: "append:",
  606. category: 'descending',
  607. fn: function (anArray){
  608. var self=this;
  609. self["@elements"]=smalltalk.send(self["@elements"],"__comma",[anArray]);
  610. return self},
  611. args: ["anArray"],
  612. source: "append: anArray\x0a elements := elements, anArray",
  613. messageSends: [","],
  614. referencedClasses: []
  615. }),
  616. smalltalk.TrappedPathStack);
  617. smalltalk.addMethod(
  618. "_elements",
  619. smalltalk.method({
  620. selector: "elements",
  621. category: 'accessing',
  622. fn: function (){
  623. var self=this;
  624. return self["@elements"];
  625. },
  626. args: [],
  627. source: "elements\x0a\x09^elements",
  628. messageSends: [],
  629. referencedClasses: []
  630. }),
  631. smalltalk.TrappedPathStack);
  632. smalltalk.addMethod(
  633. "_initialize",
  634. smalltalk.method({
  635. selector: "initialize",
  636. category: 'initialization',
  637. fn: function (){
  638. var self=this;
  639. smalltalk.send(self,"_initialize",[],smalltalk.TrappedSingleton);
  640. self["@elements"]=[];
  641. return self},
  642. args: [],
  643. source: "initialize\x0a super initialize.\x0a\x09elements := #().",
  644. messageSends: ["initialize"],
  645. referencedClasses: []
  646. }),
  647. smalltalk.TrappedPathStack);
  648. smalltalk.addMethod(
  649. "_with_do_",
  650. smalltalk.method({
  651. selector: "with:do:",
  652. category: 'descending',
  653. fn: function (anArray,aBlock){
  654. var self=this;
  655. var old;
  656. old=self["@elements"];
  657. smalltalk.send((function(){
  658. smalltalk.send(self,"_append_",[anArray]);
  659. return smalltalk.send(aBlock,"_value",[]);
  660. }),"_ensure_",[(function(){
  661. self["@elements"]=old;
  662. return self["@elements"];
  663. })]);
  664. return self},
  665. args: ["anArray", "aBlock"],
  666. source: "with: anArray do: aBlock\x0a\x09| old |\x0a old := elements.\x0a [ self append: anArray.\x0a\x09aBlock value ] ensure: [ elements := old ]",
  667. messageSends: ["ensure:", "append:", "value"],
  668. referencedClasses: []
  669. }),
  670. smalltalk.TrappedPathStack);
  671. smalltalk.addClass('TrappedSubscription', smalltalk.KeyedSubscriptionBase, [], 'Trapped-Frontend');
  672. smalltalk.addMethod(
  673. "_accepts_",
  674. smalltalk.method({
  675. selector: "accepts:",
  676. category: 'testing',
  677. fn: function (aKey){
  678. var self=this;
  679. var $1;
  680. $1=smalltalk.send(smalltalk.send(smalltalk.send(aKey,"_size",[]),"__lt_eq",[smalltalk.send(self["@key"],"_size",[])]),"_and_",[(function(){
  681. return smalltalk.send(aKey,"__eq",[smalltalk.send(self["@key"],"_copyFrom_to_",[(1),smalltalk.send(aKey,"_size",[])])]);
  682. })]);
  683. return $1;
  684. },
  685. args: ["aKey"],
  686. source: "accepts: aKey\x0a ^aKey size <= key size and: [aKey = (key copyFrom: 1 to: aKey size)]",
  687. messageSends: ["and:", "=", "copyFrom:to:", "size", "<="],
  688. referencedClasses: []
  689. }),
  690. smalltalk.TrappedSubscription);
  691. smalltalk.addMethod(
  692. "_trapDescend_",
  693. smalltalk.method({
  694. selector: "trapDescend:",
  695. category: '*Trapped-Frontend',
  696. fn: function (aBlock){
  697. var self=this;
  698. smalltalk.send(smalltalk.send((smalltalk.TrappedPathStack || TrappedPathStack),"_current",[]),"_with_do_",[self,aBlock]);
  699. return self},
  700. args: ["aBlock"],
  701. source: "trapDescend: aBlock\x0a\x09TrappedPathStack current with: self do: aBlock",
  702. messageSends: ["with:do:", "current"],
  703. referencedClasses: ["TrappedPathStack"]
  704. }),
  705. smalltalk.Array);
  706. smalltalk.addMethod(
  707. "_trapDescend_",
  708. smalltalk.method({
  709. selector: "trapDescend:",
  710. category: '*Trapped-Frontend',
  711. fn: function (aBlock){
  712. var self=this;
  713. smalltalk.send(smalltalk.send((smalltalk.TrappedPathStack || TrappedPathStack),"_current",[]),"_with_do_",[self,aBlock]);
  714. return self},
  715. args: ["aBlock"],
  716. source: "trapDescend: aBlock\x0a\x09TrappedPathStack current with: self do: aBlock",
  717. messageSends: ["with:do:", "current"],
  718. referencedClasses: ["TrappedPathStack"]
  719. }),
  720. smalltalk.Array);
  721. smalltalk.addMethod(
  722. "_trap_modify_",
  723. smalltalk.method({
  724. selector: "trap:modify:",
  725. category: '*Trapped-Frontend',
  726. fn: function (path,aBlock){
  727. var self=this;
  728. smalltalk.send(path,"_trapDescend_",[(function(){
  729. var actual;
  730. var model;
  731. actual=smalltalk.send((smalltalk.Trapped || Trapped),"_path",[]);
  732. actual;
  733. model=smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_byName_",[smalltalk.send(actual,"_first",[])]);
  734. model;
  735. return smalltalk.send(model,"_modify_do_",[smalltalk.send(actual,"_allButFirst",[]),aBlock]);
  736. })]);
  737. return self},
  738. args: ["path", "aBlock"],
  739. source: "trap: path modify: aBlock\x0a\x09path trapDescend: [ | actual model |\x0a \x09actual := Trapped path.\x0a model := Trapped current byName: actual first.\x0a model modify: actual allButFirst do: aBlock\x0a ]",
  740. messageSends: ["trapDescend:", "path", "byName:", "first", "current", "modify:do:", "allButFirst"],
  741. referencedClasses: ["Trapped"]
  742. }),
  743. smalltalk.TagBrush);
  744. smalltalk.addMethod(
  745. "_trap_read_",
  746. smalltalk.method({
  747. selector: "trap:read:",
  748. category: '*Trapped-Frontend',
  749. fn: function (path,aBlock){
  750. var self=this;
  751. var $1;
  752. smalltalk.send(path,"_trapDescend_",[(function(){
  753. var actual;
  754. var model;
  755. actual=smalltalk.send((smalltalk.Trapped || Trapped),"_path",[]);
  756. actual;
  757. model=smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_byName_",[smalltalk.send(actual,"_first",[])]);
  758. model;
  759. return smalltalk.send(model,"_watch_do_",[smalltalk.send(actual,"_allButFirst",[]),(function(data){
  760. $1=smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self,"_asJQuery",[]),"_closest_",["html"]),"_toArray",[]),"_isEmpty",[]);
  761. if(smalltalk.assert($1)){
  762. smalltalk.send((smalltalk.KeyedPubSubUnsubscribe || KeyedPubSubUnsubscribe),"_signal",[]);
  763. };
  764. return smalltalk.send(actual,"_trapDescend_",[(function(){
  765. return smalltalk.send(self,"_with_",[(function(html){
  766. return smalltalk.send(aBlock,"_value_value_",[data,html]);
  767. })]);
  768. })]);
  769. })]);
  770. })]);
  771. return self},
  772. args: ["path", "aBlock"],
  773. source: "trap: path read: aBlock\x0a\x09path trapDescend: [ | actual model |\x0a \x09actual := Trapped path.\x0a model := Trapped current byName: actual first.\x0a model watch: actual allButFirst do: [ :data |\x0a (self asJQuery closest: 'html') toArray isEmpty ifTrue: [ KeyedPubSubUnsubscribe signal ].\x0a \x09actual trapDescend: [ self with: [ :html | aBlock value: data value: html ] ]\x0a \x09]\x0a ]",
  774. messageSends: ["trapDescend:", "path", "byName:", "first", "current", "watch:do:", "allButFirst", "ifTrue:", "signal", "isEmpty", "toArray", "closest:", "asJQuery", "with:", "value:value:"],
  775. referencedClasses: ["Trapped", "KeyedPubSubUnsubscribe"]
  776. }),
  777. smalltalk.TagBrush);
  778. smalltalk.addMethod(
  779. "_trap_toggle_",
  780. smalltalk.method({
  781. selector: "trap:toggle:",
  782. category: '*Trapped-Frontend',
  783. fn: function (path,aBlock){
  784. var self=this;
  785. smalltalk.send(self,"_trap_toggle_ifNotPresent_",[path,aBlock,(function(){
  786. return smalltalk.send(smalltalk.send(self,"_asJQuery",[]),"_hide",[]);
  787. })]);
  788. return self},
  789. args: ["path", "aBlock"],
  790. source: "trap: path toggle: aBlock\x0a self trap: path toggle: aBlock ifNotPresent: [ self asJQuery hide ]",
  791. messageSends: ["trap:toggle:ifNotPresent:", "hide", "asJQuery"],
  792. referencedClasses: []
  793. }),
  794. smalltalk.TagBrush);
  795. smalltalk.addMethod(
  796. "_trap_toggle_ifNotPresent_",
  797. smalltalk.method({
  798. selector: "trap:toggle:ifNotPresent:",
  799. category: '*Trapped-Frontend',
  800. fn: function (path,aBlock,anotherBlock){
  801. var self=this;
  802. var $1,$2,$3,$4;
  803. var shown;
  804. shown=nil;
  805. smalltalk.send(self,"_trap_read_",[path,(function(data,html){
  806. $1=smalltalk.send(shown,"__eq",[smalltalk.send(data,"_notNil",[])]);
  807. if(! smalltalk.assert($1)){
  808. shown=smalltalk.send(data,"_notNil",[]);
  809. shown;
  810. $2=smalltalk.send(self,"_asJQuery",[]);
  811. smalltalk.send($2,"_empty",[]);
  812. $3=smalltalk.send($2,"_show",[]);
  813. $3;
  814. if(smalltalk.assert(shown)){
  815. $4=aBlock;
  816. } else {
  817. $4=anotherBlock;
  818. };
  819. return smalltalk.send($4,"_value_value_",[data,html]);
  820. };
  821. })]);
  822. return self},
  823. args: ["path", "aBlock", "anotherBlock"],
  824. 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 ]",
  825. messageSends: ["trap:read:", "ifFalse:", "notNil", "empty", "asJQuery", "show", "value:value:", "ifTrue:ifFalse:", "="],
  826. referencedClasses: []
  827. }),
  828. smalltalk.TagBrush);
  829. smalltalk.addMethod(
  830. "_trapBind_",
  831. smalltalk.method({
  832. selector: "trapBind:",
  833. category: '*Trapped-Frontend',
  834. fn: function (path){
  835. var self=this;
  836. smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.Trapped || Trapped),"_current",[]),"_binder_",[self]),"_installFor_",[path]);
  837. return self},
  838. args: ["path"],
  839. source: "trapBind: path\x0a\x09(Trapped current binder: self) installFor: path",
  840. messageSends: ["installFor:", "binder:", "current"],
  841. referencedClasses: ["Trapped"]
  842. }),
  843. smalltalk.TagBrush);
  844. smalltalk.addMethod(
  845. "_trapIter_tag_do_",
  846. smalltalk.method({
  847. selector: "trapIter:tag:do:",
  848. category: '*Trapped-Frontend',
  849. fn: function (path,aSymbol,aBlock){
  850. var self=this;
  851. smalltalk.send(self,"_trap_read_",[path,(function(model,html){
  852. smalltalk.send(smalltalk.send(html,"_root",[]),"_empty",[]);
  853. if(($receiver = model) == nil || $receiver == undefined){
  854. return model;
  855. } else {
  856. return smalltalk.send(model,"_withIndexDo_",[(function(item,i){
  857. return smalltalk.send(smalltalk.send(html,"_perform_",[aSymbol]),"_trap_read_",[[i],aBlock]);
  858. })]);
  859. };
  860. })]);
  861. return self},
  862. args: ["path", "aSymbol", "aBlock"],
  863. source: "trapIter: path tag: aSymbol do: aBlock\x0a self trap: path read: [ :model :html |\x0a html root empty.\x0a model ifNotNil: [ model withIndexDo: [ :item :i |\x0a (html perform: aSymbol) trap: {i} read: aBlock\x0a ]]\x0a ]",
  864. messageSends: ["trap:read:", "empty", "root", "ifNotNil:", "withIndexDo:", "perform:"],
  865. referencedClasses: []
  866. }),
  867. smalltalk.TagBrush);
  868. smalltalk.addMethod(
  869. "_trapShow_",
  870. smalltalk.method({
  871. selector: "trapShow:",
  872. category: '*Trapped-Frontend',
  873. fn: function (path){
  874. var self=this;
  875. smalltalk.send(self,"_trapShow_default_",[path,(function(){
  876. })]);
  877. return self},
  878. args: ["path"],
  879. source: "trapShow: path\x0a\x09self trapShow: path default: []",
  880. messageSends: ["trapShow:default:"],
  881. referencedClasses: []
  882. }),
  883. smalltalk.TagBrush);
  884. smalltalk.addMethod(
  885. "_trapShow_default_",
  886. smalltalk.method({
  887. selector: "trapShow:default:",
  888. category: '*Trapped-Frontend',
  889. fn: function (path,anObject){
  890. var self=this;
  891. var $2,$1;
  892. smalltalk.send(self,"_trap_read_",[path,(function(model){
  893. smalltalk.send(self,"_empty",[]);
  894. if(($receiver = model) == nil || $receiver == undefined){
  895. $2=anObject;
  896. } else {
  897. $2=model;
  898. };
  899. $1=smalltalk.send(self,"_with_",[$2]);
  900. return $1;
  901. })]);
  902. return self},
  903. args: ["path", "anObject"],
  904. source: "trapShow: path default: anObject\x0a\x09self trap: path read: [ :model | self empty; with: (model ifNil: [anObject]) ]",
  905. messageSends: ["trap:read:", "empty", "with:", "ifNil:"],
  906. referencedClasses: []
  907. }),
  908. smalltalk.TagBrush);