Mercurial > repos > tabletprog
view mquery.js @ 19:132c7756860e
Use populateSymbols to generate symbol tables during compilation rather than populating them as we go. This change allows us to refer to symbols defined later in the input stream and also gives the symbol table logic a single home that can be used both by the compiler and editor.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 25 Mar 2012 16:11:19 -0700 |
parents | 85fb6ba15bc6 |
children | 068d63627b16 |
line wrap: on
line source
function each(container, fun) { if (container instanceof Array) { for (var i = 0; i < container.length; i++) { fun(i, conatiner[i]); } } else { for (var i in container) { if (container.hasOwnProperty(i)) { fun(i, container[i]); } } } } function q(query) { return document.querySelector(query); } function qall(query) { return document.querySelectorAll(query); } function hide(el) { el.style.display = 'none'; } function show(el, dtype) { if (dtype === undefined) { dtype = 'block'; } el.style.display = dtype; } function onReady(fun) { if (document.readyState == 'complete') { fun(); } else { document.onreadystatechange = function() { if (document.readyState == 'complete') { fun(); document.onreadystatechange = null; } } } } function addClass(el, classname) { var classes = el.className.split(' '); if (classes.indexOf(classname) == -1) { classes.push(classname); el.className = classes.join(' '); } } function removeClass(el, classname) { var classes = el.className.split(' '); var idx = classes.indexOf(classname); if (idx > -1) { classes.splice(idx, 1); el.className = classes.join(' '); } } function ajax(method, url, data, onSuccess, onFail, onOthers) { var req; try { req = new XMLHttpRequest(); } catch (e) { req = new ActiveXObject("Microsoft.XMLHTTP"); } req.onreadystatechange = function() { if (req.readyState == 4) { if ((req.status >= 200 && req.status <= 299) || req.status == 0) { onSuccess(req); } else if(onFail) { onFail(req); } else { console.log('request failed:', req); } } else if(onOthers) { onOthers(req); } } req.open(method, url); if (data && 'mime' in data) { req.setRequestHeader('Content-Type', data.mime); req.send(data); } else { req.send(data); } } function get(url, onSuccess, onFail, onOthers) { ajax('GET', url, undefined, onSuccess, onFail, onOthers); } function post(url, data, onSuccess, onFail, onOthers) { ajax('POST', url, data, onSuccess, onFail, onOthers); } function newEl(tagname, props) { var el = document.createElement(tagname); if (typeof props == 'object') { each(props, function (key, val) { el[key] = val; }); } return el; }