From 08098a8384b7646b9cf2c5f8dee4e19b59e9b352 Mon Sep 17 00:00:00 2001 From: Daniel Neto Date: Fri, 18 Jul 2025 15:02:28 -0300 Subject: [PATCH] Refactor tag input handling in VideoTags plugin to simplify code and improve readability --- plugin/VideoTags/VideoTags.php | 39 ---------------------------------- 1 file changed, 39 deletions(-) diff --git a/plugin/VideoTags/VideoTags.php b/plugin/VideoTags/VideoTags.php index 9368466e85..cba1887f8b 100644 --- a/plugin/VideoTags/VideoTags.php +++ b/plugin/VideoTags/VideoTags.php @@ -237,45 +237,6 @@ class VideoTags extends PluginAbstract { 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 var preloadedTags = ' . $tagsJson . '; if(preloadedTags && preloadedTags.length) {