CoreFiles by mySites.guru
plugin.js53 lines, 2,104 bytes, from Joomla_6.2.0-alpha3-Alpha-Full_Package.zip
Raw History Compare with 6.2.0-alpha2
md5
49a37bfb6af82db84018603141ef9d77
sha1
be8669bef53049ff5f8063c9798a1d8032a0351b
sha256
b36aa1b7b8ca800caf21848330fa697e2f5e66f46b4bee223fb68dcdaf04dc16
/**
 * @copyright  (C) 2026 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

/**
 * Connects the "browse" button of TinyMCE's image, media and link dialogs to Joomla pickers
 * registered on Joomla.editorFilePickers. The dialog filetypes are 'image', 'media' and 'file'
 * (the link dialog).
 *
 * Register a picker for all editors, keyed by filetype:
 *   Joomla.editorFilePickers.image = (meta) => Promise<{ url, alt?, text? } | null>;
 * Override it for a single editor, keyed by the editor id:
 *   Joomla.editorFilePickers[editorId] = { image: (meta) => ... };
 *
 * The resolved url is inserted; the image/media dialogs read { alt }, the link dialog reads
 * { text }. The browse button is only shown for filetypes this editor can serve (global pickers
 * plus its own overrides). A file_picker_callback or file_picker_types set by a developer on the
 * editor options wins over this plugin.
 */
window.tinymce.PluginManager.add('jfilepicker', editor => {
  const registry = Joomla.editorFilePickers || {};
  const types = [...new Set([...Object.keys(registry).filter(key => typeof registry[key] === 'function'), ...Object.keys(registry[editor.id] || {})])];

  // Nothing registered, or the developer supplied their own picker: do nothing
  if (!types.length || editor.options.isSet('file_picker_callback')) {
    return {};
  }
  if (!editor.options.isSet('file_picker_types')) {
    editor.options.set('file_picker_types', types.join(' '));
  }
  editor.options.set('file_picker_callback', (cb, value, meta) => {
    const pickers = Joomla.editorFilePickers || {};
    const picker = (pickers[editor.id] || {})[meta.filetype] || pickers[meta.filetype];
    if (!picker) {
      return;
    }
    picker(meta).then(result => {
      if (result && result.url) {
        cb(result.url, {
          alt: result.alt || '',
          text: result.text || ''
        });
      }
    });
  });
  return {
    getMetadata: () => ({
      name: 'Joomla file picker',
      url: 'https://www.joomla.org/'
    })
  };
});

The same content is in 10 releases, Joomla 6.2.0-alpha3 to 6.3.0-alpha1. See them all, or every version of this file.