From c4e1b5f7d42ffaf6fd8c931dbb28d562ba53db54 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 4 Nov 2020 10:32:45 +0530 Subject: [PATCH] refactor two mostly-identical functions --- www/common/cryptpad-common.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 8874871d8..ca65ce77b 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -148,20 +148,19 @@ define([ send(); }; - common.setTabHref = function (href) { - var ohc = window.onhashchange; - window.onhashchange = function () {}; - window.location.href = href; - window.onhashchange = ohc; - ohc({reset: true}); - }; - common.setTabHash = function (hash) { - var ohc = window.onhashchange; - window.onhashchange = function () {}; - window.location.hash = hash; - window.onhashchange = ohc; - ohc({reset: true}); - }; + (function () { + var bypassHashChange = function (key) { + return function (value) { + var ohc = window.onhashchange; + window.onhashchange = function () {}; + window.location[key] = value; + window.onhashchange = ohc; + ohc({reset: true}); + }; + }; + common.setTabHref = bypassHashChange('href'); + common.setTabHash = bypassHashChange('hash'); + }()); // RESTRICTED // Settings only