Skip to content

Commit

Permalink
Redirect back to the active tab
Browse files Browse the repository at this point in the history
  • Loading branch information
mmikkel committed May 17, 2021
1 parent 5cc71de commit 56849dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
Expand Down
4 changes: 3 additions & 1 deletion src/resources/cpfieldinspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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"]');
Expand Down

0 comments on commit 56849dd

Please sign in to comment.