git.s-ol.nu mmm / 52c9149
link_interactive for hybrid pages s-ol 3 years ago
5 changed file(s) with 36 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
100100 when 'GET', 'HEAD'
101101 root = Fileder @store
102102 export BROWSER
103 BROWSER = :root
103 BROWSER = :root, :path
104104 fileder = root\walk path -- Fileder @store, path
105105
106106 if not fileder
44 for k,v in pairs extra
55 attr[k] = v
66
7 tourl = (path) ->
7 tourl = (path, _view) ->
88 path ..= '/'
99 if STATIC and STATIC.root
1010 path = STATIC.root .. path
11 if _view
12 path ..= _view
1113 path
1214
1315 (elements) ->
4143 BROWSER\navigate path
4244 a name, opts
4345
44 link_to = (fileder, name, origin, attr) ->
46 link_to = (fileder, name, origin, attr, _view) ->
4547 fileder = find_fileder fileder, origin
4648
4749 name or= fileder\get 'title: mmm/dom'
5153 a name, merge attr, :href, target: '_blank'
5254 else
5355 a name, merge attr, {
54 href: tourl fileder.path
56 href: tourl fileder.path, _view
5557 onclick: if MODE == 'CLIENT' then (e) =>
5658 e\preventDefault!
5759 BROWSER\navigate fileder.path
5860 }
61
62 interactive_link = (text, view=':text/html+interactive') ->
63 assert MODE == 'SERVER'
64 path = BROWSER.path
65 path = table.concat path, '/' if 'table' == type BROWSER.path
66 a text, href: tourl path, view
5967
6068 embed = (fileder, name='', origin, opts={}) ->
6169 if opts.raw
134142 {
135143 :find_fileder
136144 :link_to
145 :interactive_link
137146 :navigate_to
138147 :embed
139148 }
0 import div from require 'mmm.dom'
0 import div, a from require 'mmm.dom'
1 import interactive_link from (require 'mmm.mmmfs.util') require 'mmm.dom'
12
23 if MODE ~= 'CLIENT'
34 class Dummy
45 render: =>
5 div 'Interactive Example not available with Server-Side rendering', style:
6 position: 'relative'
7 resize: 'horizontal'
8 overflow: 'hidden'
6 div {
7 style:
8 position: 'relative'
9 resize: 'horizontal'
10 overflow: 'hidden'
911
10 width: '480px'
11 height: '270px'
12 'min-width': '270px'
13 'max-width': '100%'
12 width: '480px'
13 height: '270px'
14 'min-width': '270px'
15 'max-width': '100%'
1416
15 margin: 'auto'
16 padding: '10px'
17 boxSizing: 'border-box'
18 background: 'var(--gray-bright)'
17 margin: 'auto'
18 padding: '10px'
19 boxSizing: 'border-box'
20 background: 'var(--gray-bright)'
21
22 interactive_link '(click here for the interactive version of this article)'
23 }
1924
2025 return {
2126 UIDemo: Dummy
+0
-1
root/research/realities/_web_view: type less more
0 text/html+interactive
00 import elements from require 'mmm.component'
11 import h1, h2, p, a, i, div, ol, li, br, hr, span, button, section, article from elements
2 import interactive_link from (require 'mmm.mmmfs.util') elements
23
34 _content = div!
45 append = _content\append
1011 display: 'inline-block',
1112 width: '150px',
1213 height: '80px',
13 'line-height': '80px',
14 padding: '12px'
15 'line-height': '20px',
16 'box-sizing': 'border-box'
1417 color: '#fff',
1518 background: '#666',
1619 }
2225
2326 render: =>
2427 rplc = with div id: @id, :style
25 \append '(diagram goes here)'
28 \append interactive_link 'click for interactive version'
2629 -- \append "<script type=\"text/lua\">
2730 -- local rplc = js.global.document:getElementById('#{@id}');
2831 -- local fn = #{compile @func}