From 56849dd5a795896c0bf4871bc9b20467cc696ce1 Mon Sep 17 00:00:00 2001 From: Mats Mikkel Rummelhoff Date: Mon, 17 May 2021 21:47:21 +0200 Subject: [PATCH] Redirect back to the active tab --- CHANGELOG.md | 3 +++ src/controllers/DefaultController.php | 4 ++++ src/resources/cpfieldinspect.js | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index efdbd1d..980a4db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed - Fixes click behaviour for the cogwheel when holding down the Cmd/Ctrl key or the middle mouse button to open field settings in a new browser tab. Resolves #17 +### Improved +- CP Field Inspect now redirects back to the active field layout tab. Resolves #20 + ## 1.2.4 - 2021-01-27 ### Fixed diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php index ad50d57..b64fe7e 100644 --- a/src/controllers/DefaultController.php +++ b/src/controllers/DefaultController.php @@ -35,6 +35,10 @@ public function actionGetRedirectHash(): Response if ($queryString) { $redirectTo .= "?{$queryString}"; } + $hashbang = \parse_url($url, PHP_URL_FRAGMENT); + if ($hashbang) { + $redirectTo .= "#{$hashbang}"; + } return $this->asJson([ 'data' => Craft::$app->getSecurity()->hashData($redirectTo), ]); diff --git a/src/resources/cpfieldinspect.js b/src/resources/cpfieldinspect.js index f6808d1..688a250 100644 --- a/src/resources/cpfieldinspect.js +++ b/src/resources/cpfieldinspect.js @@ -47,7 +47,7 @@ livePreviewPoller(); // Poll for address bar change - var url = window.location.href; + var url = null; this.addressBarChangeInterval = setInterval(function () { var newUrl = window.location.href; if (newUrl === url) { @@ -57,6 +57,7 @@ try { Craft.postActionRequest('cp-field-inspect/default/get-redirect-hash', { url: url }, $.proxy(function (response) { this.data.redirectUrl = response.data || this.data.redirectUrl || null; + console.log('set redirect url', this.data.redirectUrl); }, _this)); } catch (error) { console.error(error); @@ -98,6 +99,7 @@ setPathAndRedirect: function () { var redirectTo = Craft.getLocalStorage(this.settings.redirectKey); + console.log({ redirectTo }); if (redirectTo) { var $actionInput = $('input[type="hidden"][name="action"]').filter(this.settings.actionInputKeys.join(',')); var $redirectInput = $('input[type="hidden"][name="redirect"]');