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

Add Custom Download Button Click Handler to Attaches Tool #75

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

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