From e34b121c28f3a2806bf4bdfd94430059aa6212cf Mon Sep 17 00:00:00 2001 From: Rick Companje Date: Tue, 20 Jun 2017 21:44:14 +0200 Subject: [PATCH] added some utils --- js/main.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/js/main.js b/js/main.js index 62b3d36..f60daef 100644 --- a/js/main.js +++ b/js/main.js @@ -30,6 +30,7 @@ d3d.util = { parameters: parameters }; }, + getPageParams:function(pageID) { return d3d.pageParams[pageID]; }, @@ -97,8 +98,29 @@ d3d.util = { if (!("autofocus" in document.createElement("input"))) { 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,12 +128,14 @@ 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); if(url.parameters === undefined) { return; } d3d.pageParams[url.hash] = url.parameters; - + // let jQuery mobile navigate to page (providing only the page id so it understands) $.mobile.changePage(url.hash, data.options); // replace the history item with a url including parameters