Skip to content

Commit

Permalink
Fix JS issues in element editor slideouts and HUDs. Bump to 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mmikkel committed Nov 16, 2021
1 parent b3517eb commit 895d46b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 24 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
73 changes: 50 additions & 23 deletions src/assetbundles/matrixmate/dist/js/MatrixMate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 895d46b

Please sign in to comment.