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:
parent
313196b2ef
commit
e34b121c28
30
js/main.js
30
js/main.js
@ -30,6 +30,7 @@ d3d.util = {
|
|||||||
parameters: parameters
|
parameters: parameters
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
getPageParams:function(pageID) {
|
getPageParams:function(pageID) {
|
||||||
return d3d.pageParams[pageID];
|
return d3d.pageParams[pageID];
|
||||||
},
|
},
|
||||||
@ -97,8 +98,29 @@ d3d.util = {
|
|||||||
if (!("autofocus" in document.createElement("input"))) {
|
if (!("autofocus" in document.createElement("input"))) {
|
||||||
var target = form.find("input[autofocus]:visible");
|
var target = form.find("input[autofocus]:visible");
|
||||||
target.focus();
|
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) {
|
(function (w) {
|
||||||
@ -106,12 +128,14 @@ d3d.util = {
|
|||||||
// only pagecontainer events contain url's
|
// only pagecontainer events contain url's
|
||||||
// we parse the parameters and store them in a global object
|
// we parse the parameters and store them in a global object
|
||||||
d3d.pageParams = {};
|
d3d.pageParams = {};
|
||||||
|
d3d.pageParams.uuid = d3d.util.getQueryParam("uuid");
|
||||||
|
|
||||||
$.mobile.document.on( "pagebeforechange", function( event, data ) {
|
$.mobile.document.on( "pagebeforechange", function( event, data ) {
|
||||||
if (typeof data.toPage !== "string") { return; }
|
if (typeof data.toPage !== "string") { return; }
|
||||||
var url = d3d.util.parseURL(data.toPage);
|
var url = d3d.util.parseURL(data.toPage);
|
||||||
if(url.parameters === undefined) { return; }
|
if(url.parameters === undefined) { return; }
|
||||||
d3d.pageParams[url.hash] = url.parameters;
|
d3d.pageParams[url.hash] = url.parameters;
|
||||||
|
|
||||||
// let jQuery mobile navigate to page (providing only the page id so it understands)
|
// let jQuery mobile navigate to page (providing only the page id so it understands)
|
||||||
$.mobile.changePage(url.hash, data.options);
|
$.mobile.changePage(url.hash, data.options);
|
||||||
// replace the history item with a url including parameters
|
// replace the history item with a url including parameters
|
||||||
|
Loading…
Reference in New Issue
Block a user