Mercurial > repos > tabletprog
comparison editor.tp @ 21:6c8ae6b47ab5
Small improvements to property support and elimination of setP and getP functions as they are no longer needed
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 25 Mar 2012 21:11:10 -0700 |
parents | 4dd99fde5f63 |
children | 068d63627b16 |
comparison
equal
deleted
inserted
replaced
20:bf03c9f0dd55 | 21:6c8ae6b47ab5 |
---|---|
4 qall <- foreign: :query {} | 4 qall <- foreign: :query {} |
5 each <- foreign: :iterable fun {} | 5 each <- foreign: :iterable fun {} |
6 addClass <- foreign: :node className {} | 6 addClass <- foreign: :node className {} |
7 removeClass <- foreign: :node className {} | 7 removeClass <- foreign: :node className {} |
8 get <- foreign: :url onSuccess onFail onOther {} | 8 get <- foreign: :url onSuccess onFail onOther {} |
9 | |
10 //JS interop helpers | |
11 setP <- foreign: :object property val {} | |
12 getP <- foreign: :object property {} | |
13 | 9 |
14 //TP Parser | 10 //TP Parser |
15 parser <- foreign: #{ | 11 parser <- foreign: #{ |
16 parse <- foreign: :str {} | 12 parse <- foreign: :str {} |
17 } | 13 } |
36 } | 32 } |
37 | 33 |
38 editFile <- :path { | 34 editFile <- :path { |
39 get: path :request { | 35 get: path :request { |
40 addClass: (q: "body") "editorMode" | 36 addClass: (q: "body") "editorMode" |
41 src <- request getP: "responseText" | 37 src <- request responseText |
42 console log: src | 38 console log: src |
43 ast <- parser parse: src | 39 ast <- parser parse: src |
44 console log: ast | 40 console log: ast |
45 ast toHTML: (q: "#src") | 41 ast toHTML: (q: "#src") |
46 } | 42 } |
48 | 44 |
49 //editor code | 45 //editor code |
50 main <- { | 46 main <- { |
51 //bind handlers for file browser links | 47 //bind handlers for file browser links |
52 each: (qall: "a") :idx el { | 48 each: (qall: "a") :idx el { |
53 el setP: "onclick" :event { | 49 el onclick!: :event { |
54 link <- foreign: this | 50 link <- foreign: this |
55 editFile: (link getP: "href") | 51 path <- link href |
52 path <- path substr: (path indexOf: "/edit/") + 5 | |
53 console log: path | |
54 editFile: path | |
56 foreign: false | 55 foreign: false |
57 } | 56 } |
58 } | 57 } |
59 | 58 |
60 //bind handlers for editor buttons | 59 //bind handlers for editor buttons |
61 each: (qall: ".controls li") :idx el { | 60 each: (qall: ".controls li") :idx el { |
62 el setP: "onclick" :event { | 61 el onclick!: :event { |
63 srcel <- (q: "#src") | 62 srcel <- (q: "#src") |
64 srcel setP: "textContent" (srcel getP: "textContent") + (el getP: "textContent") | 63 srcel textContent!: (srcel textContent) + (el textContent) |
65 } | 64 } |
66 } | 65 } |
67 (q: "#ops_button") setP: "onclick" :event { | 66 (q: "#ops_button") onclick!: :event { |
68 addClass: (q: ".controls") "showops" | 67 addClass: (q: ".controls") "showops" |
69 } | 68 } |
70 | 69 |
71 (q: "#builtin_button") setP: "onclick" :event { | 70 (q: "#builtin_button") onclick!: :event { |
72 removeClass: (q: ".controls") "showops" | 71 removeClass: (q: ".controls") "showops" |
73 } | 72 } |
74 | 73 |
75 path <- (window getP: "location") getP: "pathname" | 74 path <- (window location) pathname |
76 if: (path indexOf: "/edit/") = 0 { | 75 if: (path indexOf: "/edit/") = 0 { |
77 editFile: (path substr: 5) | 76 editFile: (path substr: 5) |
78 } else: {} | 77 } else: {} |
79 } | 78 } |
80 | 79 |