Commit 56c2b3a7 authored by Sven Franck's avatar Sven Franck

renderjs: fixed handling of loading same page in JQM

parent fbc0ea18
......@@ -143,8 +143,9 @@ define([
// @method initializeRenderJs
//
priv.initializeRenderJs = function () {
// TODO: remove if possible
// TODO: try to call "create" earlier (FOUC on first time load)
var setFalse = false;
// TODO: try to live without all bindings... in renderjs 2
priv.doc.on('pagebeforeshow', 'div.ui-page', function () {
var page = $(this);
// need to call this every time a page is shown...
......@@ -152,30 +153,55 @@ define([
RenderJs.bindReady(function () {
var gadget = RenderJs.GadgetIndex.getGadgetById(page.attr('id'));
if (gadget.isEnhanced() === false) {
page.trigger("create");
gadget.setEnhanced(true);
}
});
})
.on('pageremove', 'div.ui-page', function () {
.on('pagebeforehide', 'div.ui-page', function(e, data) {
// pagebeforehide triggers before remove and data includes the new
// page being loaded. This means we can override clearing the gadgetIndex
// in case we are going to a page that has already been loaded. Instead
// we setReady to false.
var page = $(this),
pageId = page.attr('id'),
nextPageId = data.nextPage.attr('id'),
pageGadget = RenderJs.GadgetIndex.getGadgetById(pageId);
if (nextPageId === pageId) {
// renderJs will try to parse the page before pageremove fires, so
// if we don't set all gadgets on this page to false, renderJs does
// nothing...
if (page.attr("data-gadget") !== undefined) {
pageGadget.setReady(false);
pageGadget.setEnhanced(false);
}
// also, set all gadgets on this page to false
setFalse = true;
}
})
.on('pageremove', 'div.ui-page', function (e, data) {
var page = $(this),
pageId = page.attr('id'),
pageGadget;
// remove gadgets when removing pages,
// but not if we are doing a same page transition...
page.find("div[data-gadget]").each(function (i, el) {
var gadget = $(el);
if (gadget.is('.main-interactor') === false && !setFalse) {
RenderJs.GadgetIndex.getGadgetById(gadget.attr('id')).remove();
}
});
// if the page is a gadget itself, it needs to be reset here
if (page.attr("data-gadget") !== undefined) {
pageGadget = RenderJs.GadgetIndex.getGadgetById(page.attr('id'));
if (page.attr("data-gadget") !== undefined && !setFalse) {
pageGadget = RenderJs.GadgetIndex.getGadgetById(pageId);
pageGadget.setReady(false);
RenderJs.GadgetIndex.unregisterGadget(pageGadget);
}
// remove gadgets when removing pages
page.find("div[data-gadget]").each(function (i, el) {
var regularGadget = $(el);
if (regularGadget.is('.main-interactor') === false) {
RenderJs.GadgetIndex.getGadgetById(regularGadget.attr('id')).remove();
}
});
setFalse = false;
})
};
......
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