automatic url change in build / testing, added loader image

This commit is contained in:
2016-04-01 00:09:39 +02:00
parent 46d861e0dc
commit 2ffaf1a4af
17 changed files with 10338 additions and 124 deletions
+28 -78
View File
@@ -1,4 +1,6 @@
/*!chibi 3.0.7, Copyright 2012-2016 Kyle Barrow, released under MIT license */
// MODIFIED VERSION.
(function () {
'use strict';
@@ -6,7 +8,6 @@
loadedfn = [],
domready = false,
pageloaded = false,
jsonpcount = 0,
d = document,
w = window;
@@ -598,103 +599,52 @@
return cb;
};
// Basic XHR 1, no file support. Shakes fist at IE
cb.ajax = function (url, method, callback, nocache, nojsonp) {
cb.ajax = function (url, method, callback) {
var xhr,
query = serializeData(nodes),
type = (method) ? method.toUpperCase() : 'GET',
hostsearch = new RegExp('http[s]?://(.*?)/', 'gi'),
domain = hostsearch.exec(url),
timestamp = '_ts=' + (+new Date()),
head = d.getElementsByTagName('head')[0],
jsonpcallback = 'chibi' + (+new Date()) + (jsonpcount += 1),
script;
timestamp = '_ts=' + (+new Date());
if (query && (type === 'GET' || type === 'DELETE')) {
if (query && (type === 'GET')) {
url += (url.indexOf('?') === -1) ? '?' + query : '&' + query;
query = null;
}
// JSONP if cross domain url
if (type === 'GET' && !nojsonp && domain && w.location.host !== domain[1]) {
xhr = new XMLHttpRequest(); // we dont support IE < 9
if (nocache) {
url += (url.indexOf('?') === -1) ? '?' + timestamp : '&' + timestamp;
}
if (xhr) {
// prevent caching
url += (url.indexOf('?') === -1) ? '?' + timestamp : '&' + timestamp;
// Replace possible encoded ?
url = url.replace('=%3F', '=?');
// Douglas Crockford: "Synchronous programming is disrespectful and should not be employed in applications which are used by people"
xhr.open(type, url, true);
// Replace jsonp ? with callback
if (callback && url.indexOf('=?') !== -1) {
url = url.replace('=?', '=' + jsonpcallback);
w[jsonpcallback] = function (data) {
try {
callback(data, 200);
} catch (e) {}
// Tidy up
w[jsonpcallback] = undefined;
};
}
// JSONP
script = document.createElement('script');
script.async = true;
script.src = url;
// Tidy up
script.onload = function () {
head.removeChild(script);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (callback) {
callback(xhr.responseText, xhr.status);
}
}
};
head.appendChild(script);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
} else {
if (w.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (w.ActiveXObject) {
xhr = new ActiveXObject('Microsoft.XMLHTTP'); // IE < 9
if (type === 'POST' || type === 'PUT') {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
if (xhr) {
if (nocache) {
url += (url.indexOf('?') === -1) ? '?' + timestamp : '&' + timestamp;
}
// Douglas Crockford: "Synchronous programming is disrespectful and should not be employed in applications which are used by people"
xhr.open(type, url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (callback) {
callback(xhr.responseText, xhr.status);
}
}
};
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
if (type === 'POST' || type === 'PUT') {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
xhr.send(query);
}
xhr.send(query);
}
return cb;
};
// Alias to cb.ajax(url, 'get', callback, nocache, nojsonp)
cb.get = function (url, callback, nocache, nojsonp) {
return cb.ajax(url, 'get', callback, nocache, nojsonp);
// Alias to cb.ajax(url, 'get', callback)
cb.get = function (url, callback) {
return cb.ajax(url, 'get', callback);
};
// Alias to cb.ajax(url, 'post', callback, nocache)
cb.post = function (url, callback, nocache) {
return cb.ajax(url, 'post', callback, nocache);
// Alias to cb.ajax(url, 'post', callback)
cb.post = function (url, callback) {
return cb.ajax(url, 'post', callback);
};
return cb;
+1 -1
View File
@@ -46,7 +46,7 @@ var page_status = (function() {
}
function requestUpdate() {
$().get('/api/status.json', onUpdate, true, true);
$().get(_root+'/api/status.json', onUpdate);
}
st.init = function() {
+2 -3
View File
@@ -160,14 +160,13 @@ var page_waveform = (function () {
readoutPending = true;
//http://192.168.1.13
var url = '/api/{fmt}.json?n={n}&fs={fs}'.format({
var url = _root+'/api/{fmt}.json?n={n}&fs={fs}'.format({
fmt: dataFormat,
n: $('#count').val(),
fs: $('#freq').val()
});
$().get(url, onRxData, true, true);
$().get(url, onRxData);
return true;
}
+1 -1
View File
@@ -76,7 +76,7 @@ var page_wifi = (function () {
/** Ask the CGI what APs are visible (async) */
function scanAPs() {
$().get('http://192.168.1.13/wifi/scan.cgi', onScan, true, true); // no cache, no jsonp
$().get(_root+'/wifi/scan.cgi', onScan); // no cache, no jsonp
}
function rescan(time) {