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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 function each(container, fun)
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
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
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
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
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 } else {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 for (var i in container) {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 if (container.hasOwnProperty(i)) {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10 fun(i, container[i]);
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
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
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
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
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
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
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
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
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
25 function hide(el)
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26 {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27 el.style.display = 'none';
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
29
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30 function show(el, dtype)
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31 {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 if (dtype === undefined) {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
33 dtype = 'block';
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
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
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
38 function onReady(fun)
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 if (document.readyState == 'complete') {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41 fun();
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
42 } else {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 document.onreadystatechange = function() {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 if (document.readyState == 'complete') {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45 fun();
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
46 document.onreadystatechange = null;
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 function addClass(el, classname)
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
54 var classes = el.className.split(' ');
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 if (classes.indexOf(classname) == -1) {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56 classes.push(classname);
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
57 el.className = classes.join(' ');
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
58 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61 function removeClass(el, classname)
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
62 {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
63 var classes = el.className.split(' ');
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
64 var idx = classes.indexOf(classname);
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
65 if (idx > -1) {
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
66 classes.splice(idx, 1);
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 el.className = classes.join(' ');
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 }
3d1b8e96f5dc Initial commit
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
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