Commit bccc1584 authored by Sven Franck's avatar Sven Franck

fixed back to home & setting page title based on stored page config

parent c56accc9
...@@ -1654,27 +1654,23 @@ ...@@ -1654,27 +1654,23 @@
* @return {object} HTML fragment * @return {object} HTML fragment
*/ */
// NOTE: we are defaulting to fixed toolbars! // NOTE: we are defaulting to fixed toolbars!
factory.generatePage = function (config, layout) { factory.generatePage = function (spec, layout) {
var page = factory.generateElement( return page = factory.generateElement(
"div", "div",
{ {
"id": config.id, "id": spec.id,
"className": "ui-page " + ("ui-page-theme-" + layout.theme || "") + "className": "ui-page " + ("ui-page-theme-" + layout.theme || "") +
" " + ((layout.fix && layout.fix === false) ? "" : " " + ((layout.fix && layout.fix === false) ? "" :
" ui-page-header-fixed ui-page-footer-fixed") " ui-page-header-fixed ui-page-footer-fixed")
}, { }, {
"data-module": config.id, "data-module": spec.id,
"data-role": "page", "data-role": "page",
"data-url": config.url, "data-url": spec.url,
"data-external-page": true, "data-external-page": true,
"tabindex": 0, "tabindex": 0,
"data-enhanced": true "data-enhanced": true
} }
); );
// set state
return page;
}; };
/* ********************************************************************** */ /* ********************************************************************** */
...@@ -3268,6 +3264,73 @@ ...@@ -3268,6 +3264,73 @@
/* PAGE SETUP */ /* PAGE SETUP */
/* ====================================================================== */ /* ====================================================================== */
/**
* Update a page (which may already be in the DOM)
* @method updatePage
* @param {object} e Event (pagebeforechange)
* @param {object} data Data passed along with this (JQM) event
*/
init.updatePage = function (e, data) {
var page = e.target;
//NOTE: only setting title at the moment
init.fetchPageLayouts("settings", page.id)
.then(function (reply) {
init.setPageTitle(page, util.parseIfNeeded(reply.response[0]));
})
.fail(util.errorHandler);
};
/**
* Set the page title
* @method setPageTitle
* @param {object} page Page
* @param {object} spec Config of page being loaded
*/
init.setPageTitle = function (page, spec) {
var header, title, text, config;
if (page === undefined) {
util.errorHandler({"error": "Set Title: Missing page"});
} else {
// find header
// WARNING: IE8- children() retrieves comments, too
header = document.getElementById("global_header") || page.children()[0];
if (util.testForClass(header.className, "ui-header")) {
title = header.getElementsByTagName("h1")[0];
title.setAttribute("data-i18n", (spec.title_i18n || ""));
title.removeChild(title.childNodes[0]);
title.appendChild(document.createTextNode((spec.title || "\u00A0")));
}
}
};
/**
* Set page bindings
* @method setPageBindings
* @param {object} e Custom event object
*/
init.setPageBindings = function (e) {
$(document)
// disable JQM filters
.find("[data-filter='true']")
.filter(function () {
return this.getAttribute("data-bound") !== true;
})
.each(function (i, element) {
element.setAttribute("data-bound", true);
$(element).on("filterablebeforefilter", function (e) {
e.preventDefault();
});
});
// TODO: FIND local popups!
};
/** /**
* Parse a page for gadgets and run page setup * Parse a page for gadgets and run page setup
* @method parsePage * @method parsePage
...@@ -3276,7 +3339,7 @@ ...@@ -3276,7 +3339,7 @@
*/ */
init.parsePage = function (e, data) { init.parsePage = function (e, data) {
var create, config, raw_url, handle; var create, config, raw_url, handle;
// console.log("pbc")
// TODO:maybe this is the problem??? // TODO:maybe this is the problem???
if (data) { if (data) {
if (data.options.link) { if (data.options.link) {
...@@ -3296,7 +3359,7 @@ ...@@ -3296,7 +3359,7 @@
// console.log(data.options.role === "popup") // console.log(data.options.role === "popup")
// console.log(raw_url === $.mobile.getDocumentUrl()) // console.log(raw_url === $.mobile.getDocumentUrl())
// console.log($.mobile.getDocumentUrl()) // console.log($.mobile.getDocumentUrl())
if (document.getElementById(raw_url.replace("#", "")) || if (document.getElementById(raw_url.split("#").pop()) ||
raw_url === $.mobile.getDocumentUrl() || raw_url === $.mobile.getDocumentUrl() ||
data.options.role === "popup") { data.options.role === "popup") {
// console.log("let JQM go") // console.log("let JQM go")
...@@ -3318,11 +3381,6 @@ ...@@ -3318,11 +3381,6 @@
// $.mobile.navigate.history.initialDst = ""; // $.mobile.navigate.history.initialDst = "";
// } // }
} }
} else {
// once transition done. Update gadgets if going back to page in DOM
if(data.options.fromHashChange) {
init.setPageTitle(data.toPage[0], {});
}
} }
if (e === undefined || handle) { if (e === undefined || handle) {
if (config.deeplink) { if (config.deeplink) {
...@@ -3583,9 +3641,6 @@ ...@@ -3583,9 +3641,6 @@
document.body.appendChild(page); document.body.appendChild(page);
} }
// set title after appending
init.setPageTitle(document.getElementById(config.id), layout);
// JQM treatment // JQM treatment
$(document).enhanceWithin(); $(document).enhanceWithin();
// console.log("CHANGING PAGE") // console.log("CHANGING PAGE")
...@@ -3600,52 +3655,6 @@ ...@@ -3600,52 +3655,6 @@
.fail(util.errorHandler); .fail(util.errorHandler);
}; };
/**
* Set the page title
* @method setTitle
* @param {object} page Page object
* @param {object} layout configuration
*/
init.setPageTitle = function (page, layout) {
var header, title, text = layout.title || page.id;
if (text) {
// WARNING: IE8- children() retrieves comments, too
header = document.getElementById("global_header") ||
page.children()[0];
if (util.testForClass(header.className, "ui-header")) {
title = header.getElementsByTagName("h1")[0];
title.innerHTML = text;
title.setAttribute("data-i18n", (layout.title_i18n || ""));
}
}
};
/**
* Set page bindings
* @method setPageBindings
* @param {object} e Custom event object
*/
init.setPageBindings = function (e) {
$(document)
// disable JQM filters
.find("[data-filter='true']")
.filter(function () {
return this.getAttribute("data-bound") !== true;
})
.each(function (i, element) {
element.setAttribute("data-bound", true);
$(element).on("filterablebeforefilter", function (e) {
e.preventDefault();
});
});
// TODO: FIND local popups!
};
/* ====================================================================== */ /* ====================================================================== */
/* APPLICATION SETUP */ /* APPLICATION SETUP */
...@@ -3820,9 +3829,15 @@ ...@@ -3820,9 +3829,15 @@
init.parsePage(e, data); init.parsePage(e, data);
}) })
// update global elements depending on state
// NOTE: this should work on deeplinks, too, because going back
// to an existing page will still trigger pagebeforeshow
.on("pagebeforeshow", function (e, data) {
init.updatePage(e, data);
})
// clean dynamic pages on hide // clean dynamic pages on hide
// NOTE: alternative would be to hack JQM and call bindRemove on // NOTE: alternative hack JQM and call "bindRemove" on dynamic pages, too
// dynamically generated content/pages, too. Then JQM will remove
.on("pagehide", "div.ui-page", function (e) { .on("pagehide", "div.ui-page", function (e) {
if (this.getAttribute("data-external-page")) { if (this.getAttribute("data-external-page")) {
$(this).page("destroy").remove() $(this).page("destroy").remove()
......
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