From 895d46b2435c1990bed4b64c71d936bfb46cfbc6 Mon Sep 17 00:00:00 2001 From: Mats Mikkel Rummelhoff Date: Tue, 16 Nov 2021 01:04:51 +0100 Subject: [PATCH] Fix JS issues in element editor slideouts and HUDs. Bump to 1.3.1 --- CHANGELOG.md | 7 ++ composer.json | 2 +- .../matrixmate/dist/js/MatrixMate.js | 73 +++++++++++++------ 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae2c0df..ed277b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.3.1 - 2021-11-16 + +### Fixed +- Fixes a JavaScript error that could occur when opening element editor slideouts and HUDs +- Fixes a bug where the entry type switcher would not reload the MatrixMate config in element editor HUDs prior to Craft 3.7.x +- Fixes a bug where MatrixMate could fail to apply the correct config for entry types in element editor slideouts on Craft 3.7.x + ## 1.3.0 - 2021-11-12 ### Fixed diff --git a/composer.json b/composer.json index 496eab5..5974314 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "vaersaagod/matrixmate", "description": "Welding Matrix into shape, mate!", "type": "craft-plugin", - "version": "1.3.0", + "version": "1.3.1", "keywords": [ "craft", "cms", diff --git a/src/assetbundles/matrixmate/dist/js/MatrixMate.js b/src/assetbundles/matrixmate/dist/js/MatrixMate.js index dd632b0..0f99737 100644 --- a/src/assetbundles/matrixmate/dist/js/MatrixMate.js +++ b/src/assetbundles/matrixmate/dist/js/MatrixMate.js @@ -42,36 +42,61 @@ e.target._originalMatrixMateContext = this.settings.context; - this.settings.context = '*'; + var updateEditorContext = $.proxy(function () { - var typeId = (e.target.settings.attributes || {}).typeId; - if (typeId) { - this.settings.context = 'entryType:' + typeId; - return; - } + this.settings.context = '*'; - var groupId = (e.target.settings.attributes || {}).groupId; - if (groupId) { - this.settings.context = 'categoryGroup:' + groupId; - return; - } + var typeId = (e.target.settings.attributes || {}).typeId || null; + if (typeId) { + this.settings.context = 'entryType:' + typeId; + return; + } - var $form = e.target.$form; - var fieldLayoutId = parseInt($form.find('input[type="hidden"][name$="[fieldLayoutId]"]').val(), 10); + var groupId = (e.target.settings.attributes || {}).groupId || null; + if (groupId) { + this.settings.context = 'categoryGroup:' + groupId; + return; + } - if (!fieldLayoutId) { - return; - } + var fieldLayoutId = null; + + if (e.target.slideout) { + var $form = e.target.$body.parent('form.slideout'); + if ($form.length) { + fieldLayoutId = parseInt($form.find('input[type="hidden"][name="fieldLayoutId"]').val(), 10); + } + } else if (e.target.$form) { + fieldLayoutId = parseInt(e.target.$form.find('input[type="hidden"][name$="[fieldLayoutId]"]').val(), 10); + } + + if (!fieldLayoutId) { + return; + } - var fieldsConfig = this.settings.fieldsConfig || []; - for (var fieldHandle in fieldsConfig) { - for (var context in fieldsConfig[fieldHandle]) { - if (fieldLayoutId === (fieldsConfig[fieldHandle][context].fieldLayoutId || null)) { - this.settings.context = context; - return; + var fieldsConfig = this.settings.fieldsConfig || []; + for (var fieldHandle in fieldsConfig) { + for (var context in fieldsConfig[fieldHandle]) { + if (fieldLayoutId === (fieldsConfig[fieldHandle][context].fieldLayoutId || null)) { + this.settings.context = context; + return; + } } } + + }, this); + + updateEditorContext(); + + if (e.target.on) { + if (e.target.slideout) { + e.target.on('updateForm', updateEditorContext); + } else { + e.target.on('endLoading', function () { + Garnish.requestAnimationFrame(updateEditorContext); + }); + } } + }, this) ); // ...and restore the previous context when the HUD closes @@ -748,7 +773,9 @@ }, onMatrixInputInit: function (e) { - this.initField(e.target.$container); + Garnish.requestAnimationFrame($.proxy(function () { + this.initField(e.target.$container); + }, this)); }, onMatrixInputBlockAdded: function (e) {