Mercurial > repos > tabletprog
annotate mquery.js @ 291:38bbbf74b735
Initial work on event support in SDL module
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 22 Jul 2014 23:35:08 -0700 |
parents | c0bfff39abe3 |
children |
rev | line source |
---|---|
0 | 1 function each(container, fun) |
2 { | |
110
d715fb3c39ab
Implemented clicking on symbols inside inscope box to replace function name in funcall.
Mike Pavone <pavone@retrodev.com>
parents:
106
diff
changeset
|
3 if (container instanceof Array || container instanceof HTMLCollection || container instanceof NodeList) { |
0 | 4 for (var i = 0; i < container.length; i++) { |
23
068d63627b16
Populate in scope symbol buttons when clicking on a symbol in the source
Mike Pavone <pavone@retrodev.com>
parents:
14
diff
changeset
|
5 fun(i, container[i]); |
0 | 6 } |
7 } else { | |
8 for (var i in container) { | |
9 if (container.hasOwnProperty(i)) { | |
10 fun(i, container[i]); | |
11 } | |
12 } | |
13 } | |
14 } | |
15 | |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
16 function q(query, el) |
0 | 17 { |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
18 return el === undefined ? document.querySelector(query) : el.querySelector(query); |
0 | 19 } |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
20 function qall(query, el) |
0 | 21 { |
25
4d87c38404d6
List literals, fixes to implicit self property lookup, import statement and editor improvements
Mike Pavone <pavone@retrodev.com>
parents:
23
diff
changeset
|
22 return el === undefined ? document.querySelectorAll(query) : el.querySelectorAll(query); |
0 | 23 } |
24 | |
25 function hide(el) | |
26 { | |
27 el.style.display = 'none'; | |
28 } | |
29 | |
30 function show(el, dtype) | |
31 { | |
32 if (dtype === undefined) { | |
33 dtype = 'block'; | |
34 } | |
9
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
35 el.style.display = dtype; |
0 | 36 } |
37 | |
38 function onReady(fun) | |
39 { | |
40 if (document.readyState == 'complete') { | |
41 fun(); | |
42 } else { | |
43 document.onreadystatechange = function() { | |
44 if (document.readyState == 'complete') { | |
45 fun(); | |
46 document.onreadystatechange = null; | |
47 } | |
48 } | |
49 } | |
50 } | |
51 | |
52 function addClass(el, classname) | |
53 { | |
54 var classes = el.className.split(' '); | |
55 if (classes.indexOf(classname) == -1) { | |
56 classes.push(classname); | |
57 el.className = classes.join(' '); | |
58 } | |
59 } | |
60 | |
61 function removeClass(el, classname) | |
62 { | |
63 var classes = el.className.split(' '); | |
64 var idx = classes.indexOf(classname); | |
65 if (idx > -1) { | |
66 classes.splice(idx, 1); | |
67 el.className = classes.join(' '); | |
68 } | |
69 } | |
70 | |
110
d715fb3c39ab
Implemented clicking on symbols inside inscope box to replace function name in funcall.
Mike Pavone <pavone@retrodev.com>
parents:
106
diff
changeset
|
71 function hasClass(el, classname) |
d715fb3c39ab
Implemented clicking on symbols inside inscope box to replace function name in funcall.
Mike Pavone <pavone@retrodev.com>
parents:
106
diff
changeset
|
72 { |
d715fb3c39ab
Implemented clicking on symbols inside inscope box to replace function name in funcall.
Mike Pavone <pavone@retrodev.com>
parents:
106
diff
changeset
|
73 return el.className == classname || el.className.split(' ').indexOf(classname) > -1 |
d715fb3c39ab
Implemented clicking on symbols inside inscope box to replace function name in funcall.
Mike Pavone <pavone@retrodev.com>
parents:
106
diff
changeset
|
74 } |
d715fb3c39ab
Implemented clicking on symbols inside inscope box to replace function name in funcall.
Mike Pavone <pavone@retrodev.com>
parents:
106
diff
changeset
|
75 |
9
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
76 function ajax(method, url, data, onSuccess, onFail, onOthers) |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
77 { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
78 var req; |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
79 try { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
80 req = new XMLHttpRequest(); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
81 } catch (e) { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
82 req = new ActiveXObject("Microsoft.XMLHTTP"); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
83 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
84 req.onreadystatechange = function() { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
85 if (req.readyState == 4) { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
86 if ((req.status >= 200 && req.status <= 299) || req.status == 0) { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
87 onSuccess(req); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
88 } else if(onFail) { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
89 onFail(req); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
90 } else { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
91 console.log('request failed:', req); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
92 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
93 } else if(onOthers) { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
94 onOthers(req); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
95 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
96 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
97 req.open(method, url); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
98 if (data && 'mime' in data) { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
99 req.setRequestHeader('Content-Type', data.mime); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
100 req.send(data); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
101 } else { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
102 req.send(data); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
103 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
104 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
105 |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
106 function get(url, onSuccess, onFail, onOthers) |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
107 { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
108 ajax('GET', url, undefined, onSuccess, onFail, onOthers); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
109 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
110 |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
111 function post(url, data, onSuccess, onFail, onOthers) |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
112 { |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
113 ajax('POST', url, data, onSuccess, onFail, onOthers); |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
114 } |
37d7f60a8ea1
Allow use of tabletproglang programs in script tags
Mike Pavone <pavone@retrodev.com>
parents:
0
diff
changeset
|
115 |
14
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
116 function newEl(tagname, props) |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
117 { |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
118 var el = document.createElement(tagname); |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
119 if (typeof props == 'object') { |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
120 each(props, function (key, val) { |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
121 el[key] = val; |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
122 }); |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
123 } |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
124 return el; |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
125 } |
85fb6ba15bc6
Start turning AST into HTML in editor
Mike Pavone <pavone@retrodev.com>
parents:
9
diff
changeset
|
126 |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
127 function setText(parent, text) |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
128 { |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
129 parent.innerHTML = ''; |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
130 parent.appendChild(document.createTextNode(text)); |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
131 return parent; |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
132 } |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
25
diff
changeset
|
133 |
106
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
134 function bubble(el, event, handler) |
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
135 { |
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
136 el.addEventListener(event, handler, false); |
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
137 } |
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
138 |
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
139 function capture(el, event, handler) |
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
140 { |
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
141 el.addEventListener(event, handler, true); |
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
142 } |
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
143 |
76a21129e8f5
Added new bubble and capture mquery functions from the spreadsheet project.
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
144 |