Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipage hash #2

Open
wants to merge 2 commits into
base: multipage-hash
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Task List Page
-->

<div data-role="page" id="task-list-page">
<div data-role="page" id="task-list-page" data-url="task-list-page">

<div data-role="header">
<select id="task-sortby" data-role="select" data-mini="true">
Expand Down Expand Up @@ -83,7 +83,7 @@ <h2 data-i18n="header.tasks">
{{#if tasks}}
{{#tasks}}
<li>
<a href="#task-detail-page?id={{this._id}}" data-jio-id="{{this._id}}" class="task-detail-link">
<a href="#task-detail-page/{{this._id}}" data-jio-id="{{this._id}}" class="task-detail-link">
{{this.title}}
<p>{{sanitize this.description 100}}</p>
<p>
Expand All @@ -110,7 +110,7 @@ <h3 data-i18n="tasks.noresult">No results found.</h3>
Project List Page
-->

<div data-role="page" id="project-list-page" data-external-page="true">
<div data-role="page" id="project-list-page" data-url="project-list-page" data-external-page="true">

<div data-role="header">
<a href="#" data-role="button" data-rel="back"
Expand Down Expand Up @@ -192,7 +192,7 @@ <h2 class="ui-mini">{{@key}} <span class="ui-li-count">{{this.task_count}}</span
-->


<div data-role="page" id="task-detail-page" data-external-page="true">
<div data-role="page" id="task-detail-page" data-url="task-detail-page" data-external-page="true">

<div data-role="header">
<a href="#" data-role="button" data-rel="back"
Expand Down Expand Up @@ -330,7 +330,7 @@ <h2 data-i18n="header.details">
-->


<div data-role="page" id="settings-page" data-external-page="true">
<div data-role="page" id="settings-page" data-url="settings-page" data-external-page="true">
<div data-role="header">
<a href="#" data-role="button" data-rel="back"
data-icon="arrow-l" data-mini="true"
Expand Down Expand Up @@ -420,7 +420,7 @@ <h2 data-i18n="header.settings">
-->


<div data-role="page" id="storage-list-page" data-external-page="true">
<div data-role="page" id="storage-list-page" data-url="storage-list-page" data-external-page="true">
<div data-role="header">
<a href="#" data-role="button" data-rel="back"
data-icon="arrow-l" data-mini="true"
Expand Down Expand Up @@ -501,7 +501,7 @@ <h2 data-i18n="header.storage">
-->


<div data-role="page" id="storage-detail-page" data-external-page="true">
<div data-role="page" id="storage-detail-page" data-url="storage-detail-page" data-external-page="true">
<div data-role="header">
<a href="#" data-role="button" data-rel="back"
data-icon="arrow-l" data-mini="true"
Expand Down
87 changes: 33 additions & 54 deletions modules/taskman.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,32 +809,6 @@ $(document).on('mobileinit', function () {
* *
**************************/



// helper
var testForString = function (search_string, full_string, nowrap) {
var s = nowrap ? "" : " ";
return (s + full_string + s).indexOf(s + search_string + s) > -1;
};

// get Active page = last page in DOM
var getPage = function (url) {
var i, kid, kids = document.body.children;

// reverse, because in JQM last page is the active page!
for (i = kids.length - 1; i >= 0; i -= 1) {
kid = kids[i];

if (testForString("ui-page", kid.className)) {
if (url === undefined || kid.getAttribute("data-url") === url) {
return kid;
}
}
}
return undefined;
};


var parseHashParams = function (hash) {
var pos = hash.indexOf('?'),
s = pos > -1 ? hash.substr(pos + 1) : '',
Expand All @@ -853,14 +827,12 @@ $(document).on('mobileinit', function () {
};
};



// This parses a link.
var parseLink = function (url) {
var hash, clean_hash, decode, root;
var parseLink = parseLink = function (url) {
var i, hash, path, clean_hash, decode, root;

hash = $.mobile.path.parseUrl(url.replace($.mobile.dialogHashKey, "")).hash.replace("#", "");
decode = /^[^\/]*%[^\/]*$/.test(hash);
decode = /^[^\/]*%2[^\/]*$/.test(hash);

// decode (allowing URI encoded identifiers)
if (decode) {
Expand All @@ -870,24 +842,17 @@ $(document).on('mobileinit', function () {
}

if (clean_hash === "") {
root = getPage().getAttribute("data-url");
console.log(root);
root = document.querySelector("div.ui-page-active").getAttribute("data-url");
return {
"data_url": root,
// for JSBIN
"no_hash": true
"data_url": root
};
}


// check for mode
var hp = parseHashParams(clean_hash);

console.log('url: ', hp.url);
console.log('params: ', hp.params);
path = clean_hash.split("/");

return {
"data_url": hp.url,
"data_url": clean_hash
};
};

Expand All @@ -897,17 +862,20 @@ $(document).on('mobileinit', function () {
// b) Stop me, stop JQM > we are already on the correct page
// c) I go, JQM stops > generate page because it's not in DOM
var parsePage = function (e, data) {
var page, base, config, raw_url, handle, clean_url, parsed_url, first, link, spec;
var page, base, config, raw_url, handle, clean_url, parsed_url, first, link, spec, encoded;

spec = data || {"options": {}};
link = spec.options.link || [{}];
raw_url = link[0].href || spec.toPage || window.location.href;

if (typeof raw_url === "string") {
if (data && data.options.reverse) {
raw_url = window.decodeURIComponent(raw_url);
}
config = parseLink(raw_url);

if (e) {
page = document.getElementById(raw_url.split("#").pop());
page = document.querySelector("div[data-url='" + window.encodeURIComponent(config.data_url) + "']");
base = page ? page.getAttribute("data-external-page") : null;
first = $.mobile.firstPage[0].getAttribute("data-url") === config.data_url;

Expand All @@ -917,7 +885,7 @@ $(document).on('mobileinit', function () {
}

// stop us and stop JQM
if ((getPage(config.data_url) && base !== null)) {
if (page && base !== null) {
e.preventDefault();
return;
}
Expand Down Expand Up @@ -946,18 +914,30 @@ $(document).on('mobileinit', function () {
}
}

var stopTheBin = config && config.no_hash;

// fetch pageIndex and trigger loading of page with view
if ((e === undefined || handle) && stopTheBin === undefined) {
var encoded = window.encodeURIComponent(config.data_url.split("?")[0]);
console.log('changepage:', encoded);
if (e === undefined || handle) {
encoded = window.encodeURIComponent(config.data_url.split("?")[0]);
page = document.querySelector("div[data-url='" + config.data_url.split("/")[0] + "']");

// update the data-url of existing page to include id, so it can be found
if (page) {
page.setAttribute("data-url", encoded);
}
$.mobile.changePage("#" + encoded);
}
};

$(document).on("pagebeforechange", function (e, data) {
parsePage(e, data);
})

$(document).on("pagebeforehide", function (e, data) {
var page = document.querySelector("div.ui-page-active");

// since we manipulated data-url, we now need to set it back
if (page.id !== page.getAttribute("data-url")) {
page.setAttribute("data-url", page.id);
}
});


Expand Down Expand Up @@ -1125,7 +1105,6 @@ $(document).on('mobileinit', function () {
*/
$(document).on('click', '.task-detail-link', function () {
page_parameter_box = {task_id: $(this).data('jio-id')};
$.mobile.navigate('#task-detail-page');
});


Expand Down Expand Up @@ -1291,7 +1270,7 @@ $(document).on('mobileinit', function () {
*/
$(document).on('click', '#settings-edit-storage', function () {
page_parameter_box = {storage_id: $('#storage-form input:radio[name=storage]:checked').val()};
$.mobile.navigate('#storage-detail-page');
$.mobile.changePage('#storage-detail-page');
});


Expand Down Expand Up @@ -1373,7 +1352,7 @@ $(document).on('mobileinit', function () {
then(function (response) {
Logger.debug('Updated storage %s', response.id);
Logger.debug(' status %s (%s)', response.status, response.statusText);
$.mobile.navigate('#storage-list-page');
$.mobile.changePage('#storage-list-page');
});
}).fail(displayError);
});
Expand All @@ -1393,7 +1372,7 @@ $(document).on('mobileinit', function () {
Logger.debug('Deleted storage %o:', response.id);
Logger.debug(' status %s', response.status);
setSelectedStorage(default_storage_id);
$.mobile.navigate('#storage-list-page');
$.mobile.changePage('#storage-list-page');
});
}).fail(displayError);
});
Expand Down