2014-02-24 11:26:30 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Doodle3D project (http://doodle3d.com).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, Doodle3D
|
|
|
|
* This software is licensed under the terms of the GNU GPL v2 or later.
|
|
|
|
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
|
|
|
|
*/
|
2013-10-02 17:24:40 +02:00
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
var d3d = {};
|
|
|
|
d3d.util = {
|
|
|
|
// Helper function that splits a URL just the way we want it
|
|
|
|
parseURL:function(url) {
|
|
|
|
var parsed = $.mobile.path.parseUrl( url );
|
|
|
|
var hashParts = parsed.hash.split( "?" );
|
2014-05-01 18:37:29 +02:00
|
|
|
var parameters;
|
2014-04-24 12:46:26 +02:00
|
|
|
// Assemble query parameters object from the query string
|
|
|
|
if (hashParts.length > 1) {
|
2014-05-01 18:37:29 +02:00
|
|
|
parameters = {};
|
2014-05-01 22:53:54 +02:00
|
|
|
jQuery.each(hashParts[1].split( "&" ), function( index, value ) {
|
2014-04-24 12:46:26 +02:00
|
|
|
var pair = value.split( "=" );
|
|
|
|
if ( pair.length > 0 && pair[ 0 ] ) {
|
|
|
|
parameters[ pair[ 0 ] ] =
|
2014-04-25 16:52:02 +02:00
|
|
|
( pair.length > 1 ? decodeURIComponent(pair[ 1 ]) : true );
|
2014-04-24 12:46:26 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
parsed: parsed,
|
|
|
|
hash: ( hashParts.length > 0 ? hashParts[ 0 ] : "" ),
|
|
|
|
parameters: parameters
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getPageParams:function(pageID) {
|
|
|
|
return d3d.pageParams[pageID];
|
|
|
|
},
|
|
|
|
replaceURLParameters:function(href,parameters){
|
|
|
|
//console.log("replaceURLParameters: ",href,parameters);
|
|
|
|
href = href.split("?")[0];
|
|
|
|
var i = 0;
|
|
|
|
jQuery.each(parameters, function (key,value) {
|
2014-04-25 16:22:55 +02:00
|
|
|
value = encodeURIComponent(value);
|
2014-04-24 12:46:26 +02:00
|
|
|
href += (i===0)? "?" : "&";
|
|
|
|
href += key+"="+value;
|
|
|
|
i++;
|
2014-02-24 11:26:30 +01:00
|
|
|
});
|
2014-04-24 12:46:26 +02:00
|
|
|
return href;
|
|
|
|
},
|
|
|
|
showLoader:function(autoHide) {
|
|
|
|
setTimeout(function(){
|
2014-05-07 15:18:27 +02:00
|
|
|
var loader = $.mobile.loading('show'); //.addClass("fadePrepare");
|
|
|
|
loader.addClass("fadeIn");
|
|
|
|
/*setTimeout(function() {
|
|
|
|
loader.addClass("fadeIn");
|
|
|
|
},500);*/
|
2014-04-24 12:46:26 +02:00
|
|
|
if(autoHide) {
|
|
|
|
setTimeout(function() {
|
|
|
|
$.mobile.loading('hide');
|
|
|
|
},1000);
|
|
|
|
}
|
|
|
|
}, 1);
|
|
|
|
},
|
|
|
|
hideLoader:function() {
|
|
|
|
$.mobile.loading('hide');
|
2014-05-01 22:53:54 +02:00
|
|
|
},
|
|
|
|
getFormData:function(form) {
|
|
|
|
var formData = {};
|
|
|
|
jQuery.each(form.serializeArray(), function(index,field) {
|
|
|
|
formData[field['name']] = field['value'];
|
|
|
|
});
|
|
|
|
return formData;
|
2014-05-07 15:18:08 +02:00
|
|
|
},
|
|
|
|
enableRefreshPrevention:function() {
|
|
|
|
$(document).on("keydown",d3d.util.preventRefresh);
|
|
|
|
},
|
|
|
|
disableRefreshPrevention:function() {
|
|
|
|
$(document).off("keydown",d3d.util.preventRefresh);
|
|
|
|
},
|
|
|
|
preventRefresh:function(event) {
|
|
|
|
if((event.which === 82 && (event.ctrlKey || event.metaKey)) || // ctrl+r
|
|
|
|
event.which === 116) { // F5
|
|
|
|
console.log("d3d.util.preventRefresh");
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
disableLeaveWarning:function() {
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
},
|
|
|
|
enableLeaveWarning:function(warning) {
|
|
|
|
if(warning === undefined) {
|
|
|
|
warning = "Are you sure you want to leave?";
|
|
|
|
}
|
|
|
|
window.onbeforeunload = function() {
|
|
|
|
console.log("WARNING:"+warning);
|
|
|
|
return warning;
|
|
|
|
};
|
2014-04-24 12:46:26 +02:00
|
|
|
}
|
|
|
|
};
|
2014-02-14 15:49:12 +01:00
|
|
|
|
2014-04-24 12:46:26 +02:00
|
|
|
(function (w) {
|
2014-05-01 18:37:29 +02:00
|
|
|
//$(function () {
|
|
|
|
//to get to url parameters we need the url
|
|
|
|
// only pagecontainer events contain url's
|
|
|
|
// we parse the parameters and store them in a global object
|
|
|
|
$.mobile.document.on( "pagebeforechange", function( event, data ) {
|
|
|
|
//console.log("pagebeforechange");
|
2014-04-24 12:46:26 +02:00
|
|
|
//console.log(" event: ",event);
|
|
|
|
//console.log(" data: ",data);
|
2014-05-01 18:37:29 +02:00
|
|
|
//d3d.pageParams[pageID]
|
|
|
|
//console.log(" data.toPage: ",data.toPage);
|
|
|
|
if (typeof data.toPage !== "string") { return; }
|
2014-04-24 12:46:26 +02:00
|
|
|
|
2014-05-01 22:53:54 +02:00
|
|
|
console.log("pagebeforechange, data: ",data);
|
2014-05-01 18:37:29 +02:00
|
|
|
var url = d3d.util.parseURL(data.toPage);
|
2014-04-24 12:46:26 +02:00
|
|
|
//console.log(" url: ",url);
|
2014-05-01 18:37:29 +02:00
|
|
|
//console.log(" url.hash: ",url.hash);
|
|
|
|
if(url.parameters === undefined) { return; }
|
2014-04-24 12:46:26 +02:00
|
|
|
if(!d3d.pageParams) { d3d.pageParams = {}; }
|
|
|
|
d3d.pageParams[url.hash] = url.parameters;
|
2014-05-01 18:37:29 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
window.history.replaceState(null, null, url.parsed.href);
|
|
|
|
// make sure that the parameters are not removed from the visible url
|
|
|
|
event.preventDefault();
|
2013-09-27 12:31:55 +02:00
|
|
|
});
|
2014-04-24 12:46:26 +02:00
|
|
|
})(window);
|