0
0
mirror of https://github.com/Doodle3D/doodle3d-connect.git synced 2024-12-26 02:23:48 +01:00

added some utils

This commit is contained in:
Rick Companje 2017-06-20 21:44:14 +02:00
parent 313196b2ef
commit e34b121c28

View File

@ -30,6 +30,7 @@ d3d.util = {
parameters: parameters
};
},
getPageParams:function(pageID) {
return d3d.pageParams[pageID];
},
@ -98,7 +99,28 @@ d3d.util = {
var target = form.find("input[autofocus]:visible");
target.focus();
}
},
getQueryParam:function(param) {
var result = window.location.search.match(new RegExp("(\\?|&)" + param + "(\\[\\])?=([^&]*)"));
return result ? result[3] : false;
},
formatBytes:function(a,b) {
if (0===a) {
return "0 Bytes";
} else {
var c=1e3,d=b||2,e=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"];
var f=Math.floor(Math.log(a)/Math.log(c));
return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f];
}
},
formatPercentage:function(cur,total) {
console.log("formatPercentage",cur,total);
return Math.round(cur/total*100) + "%";
},
};
(function (w) {
@ -106,6 +128,8 @@ d3d.util = {
// only pagecontainer events contain url's
// we parse the parameters and store them in a global object
d3d.pageParams = {};
d3d.pageParams.uuid = d3d.util.getQueryParam("uuid");
$.mobile.document.on( "pagebeforechange", function( event, data ) {
if (typeof data.toPage !== "string") { return; }
var url = d3d.util.parseURL(data.toPage);