make browser history buttons work with ajax calls in /display and /hq
This commit is contained in:
parent
0325efeb35
commit
159d6469fd
@ -47,20 +47,25 @@ class Hq extends \Zotlabs\Web\Controller {
|
|||||||
$r = q("SELECT mid FROM item
|
$r = q("SELECT mid FROM item
|
||||||
WHERE uid = %d
|
WHERE uid = %d
|
||||||
AND mid = parent_mid
|
AND mid = parent_mid
|
||||||
$item_normal
|
|
||||||
ORDER BY created DESC
|
ORDER BY created DESC
|
||||||
limit 1",
|
limit 1",
|
||||||
local_channel()
|
local_channel()
|
||||||
);
|
);
|
||||||
$item_hash = 'b64.' . base64url_encode($r[0]['mid']);
|
|
||||||
|
|
||||||
if(!$item_hash) {
|
if(!$r[0]['mid']) {
|
||||||
\App::$error = 404;
|
\App::$error = 404;
|
||||||
notice( t('Item not found.') . EOL);
|
notice( t('Item not found.') . EOL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$item_hash = 'b64.' . base64url_encode($r[0]['mid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(strpos($item_hash,'b64.') === 0)
|
||||||
|
$decoded = @base64url_decode(substr($item_hash,4));
|
||||||
|
if($decoded)
|
||||||
|
$item_hash = $decoded;
|
||||||
|
|
||||||
$updateable = false;
|
$updateable = false;
|
||||||
|
|
||||||
if(! $update) {
|
if(! $update) {
|
||||||
@ -101,11 +106,6 @@ class Hq extends \Zotlabs\Web\Controller {
|
|||||||
|
|
||||||
$target_item = null;
|
$target_item = null;
|
||||||
|
|
||||||
if(strpos($item_hash,'b64.') === 0)
|
|
||||||
$decoded = @base64url_decode(substr($item_hash,4));
|
|
||||||
if($decoded)
|
|
||||||
$item_hash = $decoded;
|
|
||||||
|
|
||||||
$r = q("select id, uid, mid, parent_mid, thr_parent, verb, item_type, item_deleted, item_blocked from item where mid like '%s' limit 1",
|
$r = q("select id, uid, mid, parent_mid, thr_parent, verb, item_type, item_deleted, item_blocked from item where mid like '%s' limit 1",
|
||||||
dbesc($item_hash . '%')
|
dbesc($item_hash . '%')
|
||||||
);
|
);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
var notifications_parent;
|
var notifications_parent;
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
notifications_parent = $('#notifications_wrapper')[0].parentElement.id;
|
notifications_parent = $('#notifications_wrapper')[0].parentElement.id;
|
||||||
$('.notifications-btn').click(function() {
|
$('.notifications-btn').click(function() {
|
||||||
@ -13,6 +14,11 @@
|
|||||||
$('#navbar-collapse-2').removeClass('show');
|
$('#navbar-collapse-2').removeClass('show');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.onpopstate = function(e) {
|
||||||
|
if(e.state !== null)
|
||||||
|
getData(e.state.b64mid, '');
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
{{if $module == 'display' || $module == 'hq'}}
|
{{if $module == 'display' || $module == 'hq'}}
|
||||||
@ -20,8 +26,14 @@
|
|||||||
var b64mid = $(this).data('b64mid');
|
var b64mid = $(this).data('b64mid');
|
||||||
var notify_id = $(this).data('notify_id');
|
var notify_id = $(this).data('notify_id');
|
||||||
var path = $(this)[0].pathname.substr(1,7);
|
var path = $(this)[0].pathname.substr(1,7);
|
||||||
|
var stateObj = { b64mid: b64mid };
|
||||||
|
|
||||||
console.log(path);
|
{{if $module == 'display'}}
|
||||||
|
history.pushState(stateObj, '', 'display/' + b64mid);
|
||||||
|
{{/if}}
|
||||||
|
{{if $module == 'hq'}}
|
||||||
|
history.pushState(stateObj, '', 'hq/' + b64mid);
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{if $module == 'hq'}}
|
{{if $module == 'hq'}}
|
||||||
if(b64mid !== 'undefined' && path !== 'pubstre') {
|
if(b64mid !== 'undefined' && path !== 'pubstre') {
|
||||||
@ -31,25 +43,29 @@
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
$('.thread-wrapper').remove();
|
if(! page_load) {
|
||||||
|
|
||||||
if(! page_load)
|
|
||||||
$(this).fadeOut();
|
$(this).fadeOut();
|
||||||
|
getData(b64mid, notify_id);
|
||||||
bParam_mid = b64mid;
|
}
|
||||||
mode = 'replace';
|
|
||||||
page_load = true;
|
|
||||||
{{if $module == 'hq'}}
|
|
||||||
hqLiveUpdate(notify_id);
|
|
||||||
{{else}}
|
|
||||||
liveUpdate();
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
if($('#notifications_wrapper').hasClass('fs'))
|
if($('#notifications_wrapper').hasClass('fs'))
|
||||||
$('#notifications_wrapper').prependTo('#' + notifications_parent).removeClass('fs');
|
$('#notifications_wrapper').prependTo('#' + notifications_parent).removeClass('fs');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
function getData(b64mid, notify_id) {
|
||||||
|
$('.thread-wrapper').remove();
|
||||||
|
bParam_mid = b64mid;
|
||||||
|
mode = 'replace';
|
||||||
|
page_load = true;
|
||||||
|
{{if $module == 'hq'}}
|
||||||
|
hqLiveUpdate(notify_id);
|
||||||
|
{{/if}}
|
||||||
|
{{if $module == 'display'}}
|
||||||
|
liveUpdate();
|
||||||
|
{{/if}}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user