Commit ce04d5f3 authored by Sven Franck's avatar Sven Franck

enabled deeplinks by overwriting inital page in JQM history on deeplinks

parent 6ede497b
...@@ -3629,10 +3629,9 @@ ...@@ -3629,10 +3629,9 @@
init.fetchPageLayouts("settings", page.id) init.fetchPageLayouts("settings", page.id)
.then(function (reply) { .then(function (reply) {
init.setPageTitle(page, util.parseIfNeeded(reply.response[0])); init.setPageTitle(page, util.parseIfNeeded(reply.response[0]));
if (!page.querySelectorAll("div.ui-content")[0] if (!page.querySelectorAll("div.ui-content")[0]
.getAttribute("data-bound")) { .getAttribute("data-bound")) {
return init.setPageElements({}, reply, undefined); return init.setPageElements({"id":page.id}, reply, undefined);
} }
}) })
.fail(util.errorHandler); .fail(util.errorHandler);
...@@ -3724,7 +3723,7 @@ ...@@ -3724,7 +3723,7 @@
* @param {object} data Data passed along with this (JQM) event * @param {object} data Data passed along with this (JQM) event
*/ */
init.parsePage = function (e, data) { init.parsePage = function (e, data) {
var create, config, raw_url, handle; var create, config, raw_url, handle, clean_url, parsed_url;
// TODO:maybe this is the problem??? // TODO:maybe this is the problem???
if (data) { if (data) {
...@@ -3741,10 +3740,6 @@ ...@@ -3741,10 +3740,6 @@
config = util.parseLink(raw_url); config = util.parseLink(raw_url);
if (e) { if (e) {
// console.log(document.getElementById(raw_url.replace("#", "")))
// console.log(data.options.role === "popup")
// console.log(raw_url === $.mobile.getDocumentUrl())
// console.log($.mobile.getDocumentUrl())
if (document.getElementById(raw_url.split("#").pop()) || if (document.getElementById(raw_url.split("#").pop()) ||
raw_url === $.mobile.getDocumentUrl() || raw_url === $.mobile.getDocumentUrl() ||
data.options.role === "popup") { data.options.role === "popup") {
...@@ -3761,10 +3756,19 @@ ...@@ -3761,10 +3756,19 @@
e.preventDefault(); e.preventDefault();
} }
} else { } else {
// if ($.mobile.navigate.history.initialDst && location.hash !== "") { // HACK: overwrite JQM history, so deeplinks are correctly handled
// console.log("CLEANUP - set initialDst to ") if ($.mobile.navigate.history.initialDst && location.hash !== "") {
// $.mobile.navigate.history.initialDst = "";
// } // this is the inital page (not) loaded, but stored as initial page!
clean_url = location.href.split("#")[0];
parsed_url = $.mobile.path.parseUrl(clean_url);
// overwrite :-)
$.mobile.navigate.history.stack[0].hash = "";
$.mobile.navigate.history.stack[0].url = clean_url;
$.mobile.path.documentUrl = parsed_url;
$.mobile.path.documentBase = parsed_url;
}
} }
} }
if (e === undefined || handle) { if (e === undefined || handle) {
...@@ -3829,18 +3833,16 @@ ...@@ -3829,18 +3833,16 @@
gadgets = layout.children || page.querySelectorAll("[data-gadget-id]"); gadgets = layout.children || page.querySelectorAll("[data-gadget-id]");
console.log(gadgets)
// NOTE: this may include local header/footer/panel/popups // NOTE: this may include local header/footer/panel/popups
// TODO: beware of target when adding the above! should not be content // TODO: beware of target when adding the above! should not be content
// TODO: bundle into a single DOM operation! // TODO: bundle into a single DOM operation!
for (i = 0; i < gadgets.length; i += 1) { for (i = 0; i < gadgets.length; i += 1) {
gadget = gadgets[i]; gadget = gadgets[i];
console.log(gadget)
baggage = { baggage = {
"layout": gadget, "layout": gadget,
"id": gadget.id || gadget.getAttribute("data-gadget-id") "id": gadget.id || gadget.getAttribute("data-gadget-id")
}; };
console.log("SET BAGGAGE TO:" + baggage.id)
if (create !== false) { if (create !== false) {
baggage.constructor = gadget.type || gadget.getAttribute("data-gadget-type"); baggage.constructor = gadget.type || gadget.getAttribute("data-gadget-type");
} }
...@@ -3882,7 +3884,6 @@ ...@@ -3882,7 +3884,6 @@
// TODO: remove when not needed anymore // TODO: remove when not needed anymore
if (create !== false) { if (create !== false) {
// 3. Test for data in JIO // 3. Test for data in JIO
console.log("testing for "+baggage.type)
return init.testForSampleData({ return init.testForSampleData({
"storage": "items", "storage": "items",
"type": baggage.type, "type": baggage.type,
...@@ -3902,13 +3903,6 @@ ...@@ -3902,13 +3903,6 @@
"baggage": baggage "baggage": baggage
}); });
} }
// TODO: I thought we would need to purge here, in case we start
// on deeplink and fetch single record, based on deeplink, but I
// guess we don't... check why this makes a transition from deeplink
// to firstpage work
console.log("CRAP")
console.log(reply.response)
return {"baggage": baggage};
} }
return {"baggage": baggage}; return {"baggage": baggage};
}) })
...@@ -3926,8 +3920,6 @@ ...@@ -3926,8 +3920,6 @@
return {"baggage": baggage}; return {"baggage": baggage};
}) })
.then(function(reply) { .then(function(reply) {
console.log("DONE")
console.log(reply)
var baggage = reply.baggage; var baggage = reply.baggage;
if (create === false) { if (create === false) {
...@@ -3953,7 +3945,6 @@ ...@@ -3953,7 +3945,6 @@
}) })
.then(function(reply) { .then(function(reply) {
var parsed, baggage = reply.baggage; var parsed, baggage = reply.baggage;
console.log("FOO, why is it not working...");
// single item query // single item query
// TODO: more levels? how to generalize and not only search by _id? // TODO: more levels? how to generalize and not only search by _id?
...@@ -3968,19 +3959,14 @@ ...@@ -3968,19 +3959,14 @@
baggage.state.query.limit = baggage.store_limit; baggage.state.query.limit = baggage.store_limit;
delete baggage.store_limit; delete baggage.store_limit;
} else { } else {
console.log("So we update or create and set query");
baggage.state.query = init.generateQueryObject( baggage.state.query = init.generateQueryObject(
baggage.config.initial_query, baggage.type, '_id', baggage.value baggage.config.initial_query, baggage.type, '_id', baggage.value
); );
console.log("What is the initial query")
console.log(baggage.config.initial_query)
} }
// new item, no query! // new item, no query!
if (baggage.config.mode) { if (baggage.config.mode) {
return {"baggage": baggage}; return {"baggage": baggage};
} else { } else {
console.log("fetch items....:");
console.log(baggage.state.query)
return util.fetchData({ return util.fetchData({
"storage": "items", "storage": "items",
"query": baggage.state.query, "query": baggage.state.query,
...@@ -3990,7 +3976,6 @@ ...@@ -3990,7 +3976,6 @@
}) })
.then(function(reply) { .then(function(reply) {
var baggage = reply.baggage, selector; var baggage = reply.baggage, selector;
console.log("we are done fetching shit, let's make some content");
// append gadget to wrapping div // append gadget to wrapping div
element = factory.map_gadgets[baggage.constructor]( element = factory.map_gadgets[baggage.constructor](
...@@ -4006,16 +3991,12 @@ ...@@ -4006,16 +3991,12 @@
// NOTE: in case of update, element will be the section to update // NOTE: in case of update, element will be the section to update
// not the gadget/fragment, so we need to find the gadget // not the gadget/fragment, so we need to find the gadget
// NOTE: in case of forms, we find the form! // NOTE: in case of forms, we find the form!
console.log("we have an element")
console.log(element)
console.log("do we have a selector")
selector = element.querySelector("#" + baggage.id) || selector = element.querySelector("#" + baggage.id) ||
document.getElementById(baggage.config.form) || document.getElementById(baggage.config.form) ||
element; element;
console.log(selector)
baggage.state.gadget = selector; baggage.state.gadget = selector;
} }
// round up and store state on gadget // round up and store state on gadget
baggage.state.constructor = baggage.constructor; baggage.state.constructor = baggage.constructor;
delete baggage.constructor; delete baggage.constructor;
...@@ -4034,9 +4015,6 @@ ...@@ -4034,9 +4015,6 @@
) )
.enhanceWithin(); .enhanceWithin();
} else { } else {
console.log("appending element")
console.log(target)
console.log(element)
target.appendChild(element); target.appendChild(element);
} }
delete baggage; delete baggage;
...@@ -4047,9 +4025,8 @@ ...@@ -4047,9 +4025,8 @@
// once the loop is done, we assemble and return the whole thing // once the loop is done, we assemble and return the whole thing
return RSVP.all(promises) return RSVP.all(promises)
.then(function() { .then(function() {
console.log("ALL SET")
// set a flag on target to indicate it has been enhanced // set a flag on target to indicate it has been enhanced
target.setAttribute("data-bound",true); target.setAttribute("data-bound", true);
// append, initialize and enhance new page // append, initialize and enhance new page
if (create === true) { if (create === true) {
...@@ -4069,9 +4046,6 @@ ...@@ -4069,9 +4046,6 @@
} else { } else {
// populate existing page and enhance // populate existing page and enhance
if (gadgets.length > 0 && create === undefined) { if (gadgets.length > 0 && create === undefined) {
console.log("PAGE")
console.log(page)
console.log(target)
$(page).empty().append(target).enhanceWithin(); $(page).empty().append(target).enhanceWithin();
} }
} }
...@@ -4406,7 +4380,7 @@ ...@@ -4406,7 +4380,7 @@
/* ====================================================================== */ /* ====================================================================== */
init.contentLoaded(window, function () { init.contentLoaded(window, function () {
// TODO: don't // HACK: don't!
localStorage.clear(); localStorage.clear();
init init
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment