npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

elfinder-picker

v2.0.5

Published

Modern ESM file picker for elFinder with auto-injected styles, zero dependencies, and minimal configuration

Readme

elFinder Picker

Enable your website users to select files using elFinder File Browser. You can also use this tool as a file picker module for tinyMCE editor.

Version 2.0 brings modern ESM support, removes jQuery dependency, eliminates global variables, and auto-injects CSS styles for a cleaner integration experience.

Looking for v1.x? If you need the legacy version with jQuery and global variables, see the v1.1.2 documentation on npm.

Demo

Coming soon

Dependencies

Installation

npm

npm i -s elfinder-picker

Yarn

yarn add elfinder-picker

Browser ESM (CDN)

<script type="module">
  import ElFinderPicker from 'https://cdn.jsdelivr.net/npm/elfinder-picker@2/dist/index.mjs';
  // Use the picker
</script>

Usage

Basic Example

import ElFinderPicker from 'elfinder-picker';

// Create a new instance (styles are auto-injected!)
const picker = new ElFinderPicker({
  url: '/path/to/elfinder.html'
});

// Open the picker with a callback that receives the file object
picker.open((file) => {
  console.log('Selected file:', file);
  // file = { url: '...', name: '...', mime: 'image/jpeg' }

  document.getElementById('myInput').value = file.url;
  document.getElementById('fileName').textContent = file.name;
});

// Or open with an initial value (navigates to that file in elFinder)
const currentFile = document.getElementById('myInput').value;
picker.open((file) => {
  document.getElementById('myInput').value = file.url;
}, currentFile);

Configure elFinder

Step 1: Setup Your Main Application

Create your picker instance and use it:

import ElFinderPicker from 'elfinder-picker';

const picker = new ElFinderPicker({ url: '/path/to/elfinder.html' });

// Open the picker and handle file selection
document.getElementById('selectFileBtn').addEventListener('click', () => {
  picker.open((file) => {
    console.log('Selected file:', file.url, file.name, file.mime);
    document.getElementById('fileInput').value = file.url;
  });
});

Step 2: Setup Your elFinder Page

Import and use the provided helper callback (minimal code required):

import { filePickerCallback } from 'elfinder-picker';

// Configure elFinder with the helper
$('#elfinder').elfinder({
  url: '/path/to/elfinder/connector.php',
  getFileCallback: filePickerCallback  // That's it!
});

The helper automatically handles everything for you:

  • ✅ Detects if running in picker mode
  • ✅ Sends file data (URL, name, MIME type) back to the picker
  • ✅ Zero configuration needed

Production Security (Optional)

Restrict postMessage to your specific domain:

import { createFilePickerCallback } from 'elfinder-picker';

const callback = createFilePickerCallback({
  origin: 'https://yourdomain.com'  // Only allow messages to your domain
});

$('#elfinder').elfinder({
  url: '/path/to/elfinder/connector.php',
  getFileCallback: callback
});

TinyMCE Integration

TinyMCE needs different response formats depending on which dialog is open. Use the MIME type to determine how to format the response:

import ElFinderPicker from 'elfinder-picker';

const picker = new ElFinderPicker({ url: '/path/to/elfinder.html' });

tinymce.init({
  selector: '.text-editor',
  height: 350,
  plugins: ['link', 'image', 'media'],
  file_picker_callback: (callback, value, meta) => {
    picker.open((file) => {
      // Format response based on TinyMCE dialog type
      if (meta.filetype === 'image') {
        callback(file.url, { alt: file.name });
      } else if (meta.filetype === 'media') {
        callback(file.url);
      } else {
        // For links/files
        callback(file.url, { text: file.name, title: file.name });
      }
    });
  },
});

You can also use the file's MIME type to make decisions:

file_picker_callback: (callback, value, meta) => {
  picker.open((file) => {
    // Use MIME type to determine file category
    if (file.mime.startsWith('image/')) {
      callback(file.url, { alt: file.name });
    } else if (file.mime.startsWith('video/') || file.mime.startsWith('audio/')) {
      callback(file.url);
    } else {
      callback(file.url, { text: file.name, title: file.name });
    }
  });
}

API Reference

ElFinderPicker Class

Constructor

new ElFinderPicker(config)
  • config.url (string): URL to your elFinder instance

Methods

open(callback, value, meta)

Open the file picker modal

Parameters:

  • callback (Function): Called when a file is selected. Receives a file object:
    {
      url: string,   // Normalized file URL
      name: string,  // File name
      mime: string   // MIME type (e.g., 'image/jpeg', 'application/pdf')
    }
  • value (string, optional): Initial file path to navigate to in elFinder
  • meta (Object, optional): Metadata for TinyMCE compatibility

Example:

// Basic usage
picker.open((file) => {
  console.log(file.url, file.name, file.mime);
});

// With initial value (navigate to specific file)
picker.open((file) => {
  document.getElementById('input').value = file.url;
}, '/uploads/images/current-file.jpg');

// Check file type
picker.open((file) => {
  if (file.mime.startsWith('image/')) {
    // Handle image
  }
});
config(config)

Update picker configuration

  • config.url (string): URL to your elFinder instance
close()

Close the picker modal

destroy()

Remove the picker from DOM and clean up resources

Helper Functions

filePickerCallback(file, fm, options)

Ready-to-use callback for elFinder's getFileCallback. Automatically sends file data (URL, name, MIME type) to the parent picker.

Parameters:

  • file (Object): File object from elFinder
  • fm (Object): elFinder instance
  • options (Object): Optional configuration
    • options.origin (string): Target origin for postMessage (default: '*')

Example:

import { filePickerCallback } from 'elfinder-picker';

$('#elfinder').elfinder({
  url: '/connector.php',
  getFileCallback: filePickerCallback
});

createFilePickerCallback(options)

Creates a configured file picker callback with custom origin for production security

Parameters:

  • options (Object): Configuration options
    • options.origin (string): Target origin for postMessage

Returns: Function compatible with elFinder's getFileCallback

Example:

import { createFilePickerCallback } from 'elfinder-picker';

const callback = createFilePickerCallback({
  origin: 'https://yourdomain.com'
});

$('#elfinder').elfinder({
  url: '/connector.php',
  getFileCallback: callback
});

License

MIT