Skip to content

Conversation

@swalahamani
Copy link

This PR introduces a new feature that allows users to customize the behavior of the download button in the Attaches Tool for Editor.js. The feature adds an onClick event handler option to the downloadButton configuration, enabling developers to define specific actions that occur when the download button is clicked.

Key Changes:

  • downloadButton.onClick Configuration: Added a new onClick method in the newly introduced downloadButton configuration, allowing developers to override the default download behavior with custom logic.
  • Custom Event Handling: The onClick method provides access to the click event and file data, offering flexibility to implement additional functionality such as analytics tracking, security checks, custom auth, and user feedback.
  • Backward Compatibility: The default download behavior remains unchanged for existing implementations unless the onClick handler is explicitly specified.

Usage Example:

Developers can now define a custom download action as shown in the following example:

import AttachesTool from '@editorjs/attaches';

var editor = EditorJS({
  tools: {
    attaches: {
      class: AttachesTool,
      config: {
        downloadButton: {
          onClick: function(event, data) {
            event.preventDefault();
            console.log('File download initiated:', data.file.url);
          }
        }
      }
    }
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant