2015-04-24 16:12:48 +02:00
|
|
|
/******************************************************
|
|
|
|
*
|
|
|
|
* Utils
|
|
|
|
* requires jQuery, Three.js
|
|
|
|
*
|
|
|
|
******************************************************/
|
|
|
|
|
|
|
|
var D3D = {
|
2015-05-07 14:09:36 +02:00
|
|
|
"version": "0.1",
|
|
|
|
"website": "http://www.doodle3d.com/",
|
2015-04-24 16:12:48 +02:00
|
|
|
"contact": "develop@doodle3d.com"
|
|
|
|
};
|
|
|
|
|
|
|
|
function sendAPI (url, data, callback) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
$.ajax({
|
2015-05-07 14:09:36 +02:00
|
|
|
url: url,
|
|
|
|
type: "POST",
|
|
|
|
data: data,
|
|
|
|
dataType: "json",
|
|
|
|
timeout: 10000,
|
2015-04-24 16:12:48 +02:00
|
|
|
success: function (response) {
|
|
|
|
if (response.status === "success") {
|
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(response.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.warn(response.msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(function () {
|
2015-05-07 17:27:41 +02:00
|
|
|
console.warn("Failed connecting to " + url);
|
2015-04-24 16:12:48 +02:00
|
|
|
sendAPI(url, data, callback);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAPI (url, callback) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
$.ajax({
|
2015-05-07 14:09:36 +02:00
|
|
|
url: url,
|
|
|
|
dataType: "json",
|
|
|
|
timeout: 5000,
|
2015-04-24 16:12:48 +02:00
|
|
|
success: function (response) {
|
|
|
|
if (response.status === "success") {
|
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(response.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.warn(response.msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).fail(function () {
|
2015-05-07 17:27:41 +02:00
|
|
|
console.warn("Failed connecting to " + url);
|
2015-04-24 16:12:48 +02:00
|
|
|
getAPI(url, callback);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-04-28 14:11:41 +02:00
|
|
|
function downloadFile (file, data) {
|
2015-05-01 10:06:52 +02:00
|
|
|
"use strict";
|
2015-05-17 23:22:27 +02:00
|
|
|
|
2015-05-19 17:15:59 +02:00
|
|
|
var blob = new Blob([data], {type:'text/plain'});
|
|
|
|
|
2015-05-17 23:22:27 +02:00
|
|
|
var button = document.createElement("a");
|
|
|
|
button.download = file;
|
2015-05-19 17:15:59 +02:00
|
|
|
button.href = window.URL.createObjectURL(blob);
|
2015-05-17 23:22:27 +02:00
|
|
|
button.click();
|
2015-05-19 17:15:59 +02:00
|
|
|
}
|