Trapped-Frontend.js 29 KB

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