From c96dd0836bc9fa88bfd2a436aa5b77eb5a943320 Mon Sep 17 00:00:00 2001 From: rugk Date: Sun, 5 Feb 2017 21:22:09 +0100 Subject: [PATCH 1/3] Make link clickable again We need to emulate the click and manually trigger a reload if the hash is already shown in the URL. --- js/privatebin.js | 27 +++++++++++++++++++++++++++ js/test.js | 19 +++++++++---------- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 850dfc9..4887e8c 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1121,6 +1121,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { deleteUrl = helper.scriptLocation() + '?pasteid=' + data.id + '&deletetoken=' + data.deletetoken; controller.showStatus(''); controller.errorMessage.addClass('hidden'); + // show new URL in browser bar history.pushState({type: 'newpaste'}, document.title, url); $('#pastelink').html( @@ -1129,6 +1130,11 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { url, url ) + controller.shortenUrl(url) ); + // save newly created element + controller.pasteUrl = $('#pasteurl'); + // and add click event + controller.pasteUrl.click($.proxy(controller.pasteLinkClick, controller)); + var shortenButton = $('#shortenbutton'); if (shortenButton) { shortenButton.click($.proxy(controller.sendToShortener, controller)); @@ -1489,6 +1495,25 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { } }, + /** + * Forces opening the paste if the link does not do this automatically. + * + * This is necessary as browsers will not reload the page when it is + * already loaded (which is fake as it is set via history.pushState()). + * + * @name controller.pasteLinkClick + * @function + * @param {Event} event + */ + pasteLinkClick: function(event) + { + // check if location is (already) correctly shown in URL bar + if (window.location.href === this.pasteUrl.attr('href')) { + // if so we need to load link by reloading the site + location.reload(true); + } + }, + /** * create a new paste * @@ -1689,6 +1714,8 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { this.passwordForm = $('#passwordform'); this.passwordDecrypt = $('#passworddecrypt'); this.pasteResult = $('#pasteresult'); + // this.pasteUrl is saved in sendDataContinue() if/after it is + // actually created this.prettyMessage = $('#prettymessage'); this.prettyPrint = $('#prettyprint'); this.preview = $('#preview'); diff --git a/js/test.js b/js/test.js index 5e4d3c3..b2d5f00 100644 --- a/js/test.js +++ b/js/test.js @@ -91,14 +91,14 @@ describe('helper', function () { jsc.array(jsc.elements(queryString)), 'string', function (schema, address, query, fragment) { - var query = query.join(''), + var queryString = query.join(''), clean = jsdom('', { url: schema.join('') + '://' + address.join('') + - '/?' + query + '#' + fragment + '/?' + queryString + '#' + fragment }), result = $.PrivateBin.helper.pasteId(); clean(); - return query === result; + return queryString === result; } ); }); @@ -111,14 +111,14 @@ describe('helper', function () { jsc.array(jsc.elements(queryString)), jsc.array(jsc.elements(base64String)), function (schema, address, query, fragment) { - var fragment = fragment.join(''), + var fragmentString = fragment.join(''), clean = jsdom('', { url: schema.join('') + '://' + address.join('') + - '/?' + query.join('') + '#' + fragment + '/?' + query.join('') + '#' + fragmentString }), result = $.PrivateBin.helper.pageKey(); clean(); - return fragment === result; + return fragmentString === result; } ); jsc.property( @@ -129,14 +129,14 @@ describe('helper', function () { jsc.array(jsc.elements(base64String)), jsc.array(jsc.elements(queryString)), function (schema, address, query, fragment, trail) { - var fragment = fragment.join(''), + var fragmentString = fragment.join(''), clean = jsdom('', { url: schema.join('') + '://' + address.join('') + '/?' + - query.join('') + '#' + fragment + '&' + trail.join('') + query.join('') + '#' + fragmentString + '&' + trail.join('') }), result = $.PrivateBin.helper.pageKey(); clean(); - return fragment === result; + return fragmentString === result; } ); }); @@ -156,4 +156,3 @@ describe('helper', function () { ); }); }); - diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index b457221..cf41871 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 491be5d..042bc42 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - + From 5c603d09788049be222c8fb4f39c3cc16cdfb476 Mon Sep 17 00:00:00 2001 From: rugk Date: Sun, 5 Feb 2017 21:35:28 +0100 Subject: [PATCH 2/3] Improve comment --- js/privatebin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/privatebin.js b/js/privatebin.js index 4887e8c..3070aad 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1507,7 +1507,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { */ pasteLinkClick: function(event) { - // check if location is (already) correctly shown in URL bar + // check if location is (already) shown in URL bar if (window.location.href === this.pasteUrl.attr('href')) { // if so we need to load link by reloading the site location.reload(true); From 86cd5e1c152d12c114d98d4b7f9277a37b9c334a Mon Sep 17 00:00:00 2001 From: rugk Date: Sun, 5 Feb 2017 22:35:44 +0100 Subject: [PATCH 3/3] Use existing reload function --- js/privatebin.js | 2 +- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 3070aad..86ed9fc 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -1510,7 +1510,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { // check if location is (already) shown in URL bar if (window.location.href === this.pasteUrl.attr('href')) { // if so we need to load link by reloading the site - location.reload(true); + this.reloadPage(event); } }, diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index cf41871..ebace8b 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 042bc42..ce2ea7a 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - +