diff --git a/js/privatebin.js b/js/privatebin.js index 9e626e9c..3d8ddd1b 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -866,7 +866,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { { var currentLocation = Helper.baseUri(); if (event.originalEvent.state === null && // no state object passed - event.originalEvent.target.location.href === currentLocation && // target location is home page + event.target.location.href === currentLocation && // target location is home page window.location.href === currentLocation // and we are not already on the home page ) { // redirect to home page @@ -958,6 +958,19 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { }); } + /** + * trigger a history (pop) state change + * + * used to test the UiHelper.historyChange private function + * + * @name UiHelper.mockHistoryChange + * @function + */ + me.mockHistoryChange = function() + { + historyChange($.Event('popstate', {originalEvent: new PopStateEvent('popstate', {state: null}), target: window})); + } + /** * initialize * diff --git a/js/test.js b/js/test.js index bedcd4ac..66752dbd 100644 --- a/js/test.js +++ b/js/test.js @@ -2,7 +2,6 @@ var jsc = require('jsverify'), jsdom = require('jsdom-global'), cleanup = jsdom(), - EventEmitter = require('events'), a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z'], @@ -824,6 +823,8 @@ describe('UiHelper', function () { $.PrivateBin.Helper.reset(); }); + // TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet. + // for now we use a mock function to trigger the event jsc.property( 'returns the URL without query & fragment', jsc.elements(schemas), @@ -832,11 +833,9 @@ describe('UiHelper', function () { 'string', function (schema, address, query, fragment) { var expected = schema + '://' + address.join('') + '/', - clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}), - emitter = new EventEmitter(); + clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}); - $.PrivateBin.UiHelper.init(); - emitter.emit('popstate'); + $.PrivateBin.UiHelper.mockHistoryChange(); var result = window.location.href; clean(); console.log(expected, result); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index c3e1ba4a..b6e75603 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 81d7c1ab..d774d05f 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - +