mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
Refactor tag input handling in VideoTags plugin to simplify code and improve readability
This commit is contained in:
parent
1c21b668f2
commit
08098a8384
1 changed files with 0 additions and 39 deletions
|
@ -237,45 +237,6 @@ class VideoTags extends PluginAbstract {
|
||||||
freeInput: ' . (self::canCreateTag() ? "true" : "false") . '
|
freeInput: ' . (self::canCreateTag() ? "true" : "false") . '
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add event listener for when user tries to add a tag but cannot create new ones
|
|
||||||
' . (!self::canCreateTag() ? '
|
|
||||||
$(\'#inputTags' . $tagTypesId . '\').on(\'beforeItemAdd\', function(event) {
|
|
||||||
// Check if the item being added is a new tag (not in existing list)
|
|
||||||
var existingTags = videoTags' . $tagTypesId . '.get(event.item);
|
|
||||||
if (!existingTags || existingTags.length === 0) {
|
|
||||||
// This is a new tag attempt - show toast and cancel
|
|
||||||
if (typeof avideoToastError === \'function\') {
|
|
||||||
avideoToastError(\'' . __("Only administrators can create new tags") . '\');
|
|
||||||
} else if (typeof toastr !== \'undefined\') {
|
|
||||||
toastr.error(\'' . __("Only administrators can create new tags") . '\');
|
|
||||||
} else {
|
|
||||||
alert(\'' . __("Only administrators can create new tags") . '\');
|
|
||||||
}
|
|
||||||
event.cancel = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Also handle direct input attempts when freeInput is disabled
|
|
||||||
$(\'#inputTags' . $tagTypesId . '\').siblings(\'.bootstrap-tagsinput\').find(\'input\').on(\'keypress\', function(event) {
|
|
||||||
if (event.which === 13 || event.which === 44) { // Enter or comma
|
|
||||||
var inputValue = $(this).val().trim();
|
|
||||||
if (inputValue) {
|
|
||||||
var existingTags = videoTags' . $tagTypesId . '.get(inputValue);
|
|
||||||
if (!existingTags || existingTags.length === 0) {
|
|
||||||
event.preventDefault();
|
|
||||||
if (typeof avideoToastError === \'function\') {
|
|
||||||
avideoToastError(\'' . __("Only administrators can create new tags") . '\');
|
|
||||||
} else if (typeof toastr !== \'undefined\') {
|
|
||||||
toastr.error(\'' . __("Only administrators can create new tags") . '\');
|
|
||||||
} else {
|
|
||||||
alert(\'' . __("Only administrators can create new tags") . '\');
|
|
||||||
}
|
|
||||||
$(this).val(\'\'); // Clear the input
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});' : '') . '
|
|
||||||
|
|
||||||
// Step 3: Preload and fill the input with all tags from the database
|
// Step 3: Preload and fill the input with all tags from the database
|
||||||
var preloadedTags = ' . $tagsJson . ';
|
var preloadedTags = ' . $tagsJson . ';
|
||||||
if(preloadedTags && preloadedTags.length) {
|
if(preloadedTags && preloadedTags.length) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue