From ca51a808035e2b29c5a3168ec5c8afb875b53269 Mon Sep 17 00:00:00 2001 From: rugk Date: Wed, 1 Feb 2017 19:24:56 +0100 Subject: [PATCH] Update the history when a paste is created Fixes https://github.com/PrivateBin/PrivateBin/issues/167 --- js/privatebin.js | 23 +++++++++++++++++++++++ tpl/bootstrap.php | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/js/privatebin.js b/js/privatebin.js index 6ed88f03..5963592a 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1118,6 +1118,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { var deleteUrl = controller.scriptLocation() + '?pasteid=' + data.id + '&deletetoken=' + data.deletetoken; controller.showStatus(''); controller.errorMessage.addClass('hidden'); + history.pushState({type: 'newpaste'}, '', url); $('#pastelink').html( i18n._( @@ -1152,6 +1153,26 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { }); }, + /** + * handle history (pop) state changes + * + * currently this does only handle redirects to the home page. + * + * @name controller.historyChange + * @function + * @param {Event} event + */ + historyChange: function(event) + { + if (event.originalEvent.state === null && // no state object passed + this.scriptLocation() === event.originalEvent.target.location.href && // target location is home page + this.scriptLocation() === window.location.href // and we are not already on the home page + ) { + // redirect to home page + window.location.href = this.scriptLocation(); + } + }, + /** * check if a URL shortener was defined and create HTML containing a link to it * @@ -1619,6 +1640,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { this.passwordModal.on('shown.bs.modal', $.proxy(this.passwordDecrypt.focus, this)); this.passwordModal.on('hidden.bs.modal', $.proxy(this.decryptPasswordModal, this)); this.passwordForm.submit($.proxy(this.submitPasswordModal, this)); + + $(window).on('popstate', $.proxy(this.historyChange, this)); }, /** diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 8938112c..aa61a02b 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - +