Dosiero demo: TinyMCE 8

Demo only. Everything you upload is visible to every other visitor of this demo, and is deleted again within minutes. Actions are logged, including your IP address. Do not upload anything private, unlawful, or that you are not entitled to share.

TinyMCE 8 loaded from the jsDelivr CDN, which serves the npm package. Since version 7 TinyMCE is GPL and the editor stays disabled without license_key — 'gpl' is the value that accepts those terms, see the TinyMCE documentation. No base_url is needed: the editor finds its skins and plugins next to the script it was loaded from.

Note that Tiny's own CDN is a different thing: https://cdn.tiny.cloud/1/no-api-key/tinymce/8/tinymce.min.js loads, but covers the editor with a “Finish setting up — add your API key” panel. That channel is keyed by an account, not by accepting the GPL, so license_key: 'gpl' does not unlock it.

The file manager opens in a new window, which a popup blocker can stop. The browser allows window.open() only while it is still handling a user gesture, so open() must be reached synchronously from the click — never after an await. Even then some blockers refuse, and the click then appears to do nothing; the browser shows a blocked-popup icon in the address bar. If that is not acceptable for your integration, use mode: 'iframe' and render the manager into a dialog of your own.

Integration

TinyMCE calls file_picker_callback when the user presses the browse button in the image, link or media dialog, and hands you a callback to return the chosen URL to. The whole integration is therefore opening Dosiero and passing the selection back. This is the code this page runs:

<script type="module">
    import {Dosiero} from '/dosiero/dosiero.min.mjs';

    document.addEventListener('DOMContentLoaded', () => {
        tinymce.init({
            selector: '.tinymce',
            license_key: 'gpl',
            plugins: 'image link media',
            toolbar: 'image link media',

            file_picker_callback: function (callback, value, meta) {
                new Dosiero({
                    mode: 'window',
                    endpoint: window.location.origin + '/endpoint/index.php',
                    onSelectFile: function (files) {
                        // the manager allows multiple selection, an editor wants one file
                        for (let file of files) {
                            if (file.type === 'file') {
                                callback(file.url, {alt: file.name, title: file.name});
                                break;
                            }
                        }
                    },
                }).open();
            }
        });
    });
</script>

The second argument of callback fills the remaining fields of the dialog: alt is used by the image dialog, title by the link dialog. The meta parameter says which dialog asked — meta.filetype is image, file or media — so different dialogs can be pointed at different storages.

Self-hosted instead of the CDN

Install the package and serve it yourself. The editor then needs base_url, because it is loaded from a path that does not match the layout it expects — everything else, including license_key, stays as it is above.

npm install --save tinymce
<script src="/node_modules/tinymce/tinymce.min.js"></script>

tinymce.init({
    selector: '.tinymce',
    base_url: '/node_modules/tinymce',
    license_key: 'gpl',
    // …the rest unchanged
});

That path assumes tinymce/ has been copied into the public assets — which is what this demo does with Dosiero itself: npm run build copies its dist/ into www/dosiero/, so node_modules stays out of the webroot entirely.

back