Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HFP-3989 H5P-3599 Hide buttons based on min/max setting #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions vertical-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,24 @@ H5PEditor.VerticalTabs = (function ($) {
'role': 'tablist',
'class': 'h5p-ul'
}).appendTo($inner);
H5PEditor.createButton('add-entity', H5PEditor.t('core', 'addEntity', {':entity': entity}), function () {

var $buttonAddEntity = H5PEditor.createButton('add-entity', H5PEditor.t('core', 'addEntity', {':entity': entity}), function () {
if (list.addItem()) {
$tabs.children(':last').trigger('open');
toggleOrderButtonsState();
updateButtons();
}
}, true).appendTo($inner);
}, true);
$buttonAddEntity.appendTo($inner);

var $forms = $('<div/>', {
'class': 'h5p-vtab-forms'
}).appendTo($wrapper);

// Once all items have been added we toggle the state of the order buttons
list.once('changeWidget', function () {
toggleOrderButtonsState();
updateButtons();
});
}

Expand Down Expand Up @@ -129,6 +134,29 @@ H5PEditor.VerticalTabs = (function ($) {
toggleOrderButtonsState();
};

/**
* Update buttons.
*
* @private
*/
var updateButtons = function () {
if (typeof list.getConfig !== 'function') {
return; // Might be older core version
}

// Show remove buttons if more tabs than min
if (typeof list.getConfig().min === 'number') {
$tabs.find('.vtab-remove-wrapper')
.toggle((list.getValue() || []).length > list.getConfig().min);
}

// Show add button if less tabs than max
if (typeof list.getConfig().max === 'number') {
$buttonAddEntity
.toggle((list.getValue() || []).length < list.getConfig().max);
}
};

/**
* Decode HTML entities
* @param {String}
Expand Down Expand Up @@ -415,6 +443,7 @@ H5PEditor.VerticalTabs = (function ($) {
$tab.remove();
$form.remove();
reindexLabels();
updateButtons();
});

// Create form wrapper
Expand Down