browser version working
This commit is contained in:
parent
6fb339e21c
commit
d81b4b9d18
@ -1,17 +1,4 @@
|
||||
// Reqwest
|
||||
/*!
|
||||
* Reqwest! A x-browser general purpose XHR connection manager
|
||||
* copyright Dustin Diaz 2011
|
||||
* https://github.com/ded/reqwest
|
||||
* license MIT
|
||||
*/
|
||||
!function(window){function serial(a){var b=a.name;if(a.disabled||!b)return"";b=enc(b);switch(a.tagName.toLowerCase()){case"input":switch(a.type){case"reset":case"button":case"image":case"file":return"";case"checkbox":case"radio":return a.checked?b+"="+(a.value?enc(a.value):!0)+"&":"";default:return b+"="+(a.value?enc(a.value):"")+"&"}break;case"textarea":return b+"="+enc(a.value)+"&";case"select":return b+"="+enc(a.options[a.selectedIndex].value)+"&"}return""}function enc(a){return encodeURIComponent(a)}function reqwest(a,b){return new Reqwest(a,b)}function init(o,fn){function error(a){o.error&&o.error(a),complete(a)}function success(resp){o.timeout&&clearTimeout(self.timeout)&&(self.timeout=null);var r=resp.responseText;switch(type){case"json":resp=eval("("+r+")");break;case"js":resp=eval(r);break;case"html":resp=r}fn(resp),o.success&&o.success(resp),complete(resp)}function complete(a){o.complete&&o.complete(a)}this.url=typeof o=="string"?o:o.url,this.timeout=null;var type=o.type||setType(this.url),self=this;fn=fn||function(){},o.timeout&&(this.timeout=setTimeout(function(){self.abort(),error()},o.timeout)),this.request=getRequest(o,success,error)}function setType(a){if(/\.json$/.test(a))return"json";if(/\.jsonp$/.test(a))return"jsonp";if(/\.js$/.test(a))return"js";if(/\.html?$/.test(a))return"html";if(/\.xml$/.test(a))return"xml";return"js"}function Reqwest(a,b){this.o=a,this.fn=b,init.apply(this,arguments)}function getRequest(a,b,c){if(a.type!="jsonp"){var f=xhr();f.open(a.method||"GET",typeof a=="string"?a:a.url,!0),setHeaders(f,a),f.onreadystatechange=readyState(f,b,c),a.before&&a.before(f),f.send(a.data||null);return f}var d=doc.createElement("script");window[getCallbackName(a)]=generalCallback,d.type="text/javascript",d.src=a.url,d.async=!0;var e=function(){a.success&&a.success(lastValue),lastValue=undefined,head.removeChild(d)};d.onload=e,d.onreadystatechange=function(){/^loaded|complete$/.test(d.readyState)&&e()},head.appendChild(d)}function generalCallback(a){lastValue=a}function getCallbackName(a){var b=a.jsonpCallback||"callback";if(a.url.slice(-(b.length+2))==b+"=?"){var c="reqwest_"+uniqid++;a.url=a.url.substr(0,a.url.length-1)+c;return c}var d=new RegExp(b+"=([\\w]+)");return a.url.match(d)[1]}function setHeaders(a,b){var c=b.headers||{};c.Accept="text/javascript, text/html, application/xml, text/xml, */*",c["X-Requested-With"]=c["X-Requested-With"]||"XMLHttpRequest";if(b.data){c["Content-type"]=c["Content-type"]||"application/x-www-form-urlencoded";for(var d in c)c.hasOwnProperty(d)&&a.setRequestHeader(d,c[d],!1)}}function readyState(a,b,c){return function(){a&&a.readyState==4&&(twoHundo.test(a.status)?b(a):c(a))}}var twoHundo=/^20\d$/,doc=document,byTag="getElementsByTagName",head=doc[byTag]("head")[0],xhr="XMLHttpRequest"in window?function(){return new XMLHttpRequest}:function(){return new ActiveXObject("Microsoft.XMLHTTP")},uniqid=0,lastValue;Reqwest.prototype={abort:function(){this.request.abort()},retry:function(){init.call(this,this.o,this.fn)}},reqwest.serialize=function(a){var b=a[byTag]("input"),c=a[byTag]("select"),d=a[byTag]("textarea");return(v(b).chain().toArray().map(serial).value().join("")+v(c).chain().toArray().map(serial).value().join("")+v(d).chain().toArray().map(serial).value().join("")).replace(/&$/,"")},reqwest.serializeArray=function(a){for(var b=this.serialize(a).split("&"),c=0,d=b.length,e=[],f;c<d;c++)b[c]&&(f=b[c].split("="))&&e.push({name:f[0],value:f[1]});return e};var old=window.reqwest;reqwest.noConflict=function(){window.reqwest=old;return this},window.reqwest=reqwest}(this)
|
||||
//
|
||||
|
||||
|
||||
var carto_initialize = function(carto, uri, callback) {
|
||||
reqwest(uri, function (resp) {
|
||||
window.carto['mapnik-reference'] = resp;
|
||||
callback();
|
||||
});
|
||||
};
|
||||
callback();
|
||||
};
|
||||
|
@ -170,6 +170,11 @@ carto.Parser = function Parser(env) {
|
||||
}
|
||||
}
|
||||
|
||||
function extractErrorLine(style, errorIndex) {
|
||||
return (style.slice(0, errorIndex).match(/\n/g) || '').length + 1;
|
||||
}
|
||||
|
||||
|
||||
// Make an error object from a passed set of properties.
|
||||
// Accepted properties:
|
||||
// - `message`: Text of the error message.
|
||||
@ -192,10 +197,11 @@ carto.Parser = function Parser(env) {
|
||||
einput = input;
|
||||
}
|
||||
|
||||
err.line = (einput.slice(0, err.index).match(/\n/g) || '').length + 1;
|
||||
err.line = extractErrorLine(einput, err.index);
|
||||
for (var n = err.index; n >= 0 && einput.charAt(n) !== '\n'; n--) {
|
||||
err.column++;
|
||||
}
|
||||
|
||||
return new Error(_('<%=filename%>:<%=line%>:<%=column%> <%=message%>').template(err));
|
||||
}
|
||||
|
||||
@ -207,6 +213,7 @@ carto.Parser = function Parser(env) {
|
||||
return parser = {
|
||||
|
||||
imports: imports,
|
||||
extractErrorLine: extractErrorLine,
|
||||
//
|
||||
// Parse an input string into an abstract syntax tree.
|
||||
// Throws an error on parse errors.
|
||||
|
@ -40,9 +40,9 @@
|
||||
"xml2js": "~0.1.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "1.0.x",
|
||||
"mocha": "",
|
||||
"docco": "0.3.x",
|
||||
"jshint": "0.2.x",
|
||||
"jshint": "",
|
||||
"sax": "0.1.x"
|
||||
},
|
||||
"scripts": {
|
||||
|
Loading…
Reference in New Issue
Block a user