Implemented Allow reading preview URL directly from <xf:editor

TickTackk

Well-known member
From my understanding, at this moment add-on developers will have to do weird hacks to make different editor rows have their own preview url if the parent form already has a data-preview-url set.

From my quick testing changing:
JavaScript:
        isPreviewAvailable: function($textarea)
        {
            if (!$textarea.closest('form').data('preview-url'))
            {
                return false;
            }

            if ($textarea.data('preview') === false)
            {
                return false;
            }

            return true;
        },
to
JavaScript:
        isPreviewAvailable: function($textarea)
        {
            if (!$textarea.data('preview-url') && !$textarea.closest('form').data('preview-url'))
            {
                return false;
            }

            if ($textarea.data('preview') === false)
            {
                return false;
            }

            return true;
        },

and

JavaScript:
                        var $form = ed.$oel.closest('form'),
                            href = $form.data('preview-url'),
                            formData = XF.getDefaultFormData($form);
to
JavaScript:
                        var $form = ed.$oel.closest('form'),
                            href = ed.$oel.data('preview-url') ? ed.$oel.data('preview-url') : $form.data('preview-url'),
                            formData = XF.getDefaultFormData($form);
In js/xf/editor.js.

This will allow developers to have this:
HTML:
    <xf:editorrow name="first_editor" data-min-height="200"
                  label="{{ phrase('xy_first_editor') }}"
                  data-preview-url="{{ link_type('public', 'my-route/get-preview-for-first-editor') }}" />
    
    <xf:editorrow name="other_editor" data-min-height="200"
                      label="{{ phrase('xy_other_editor') }}"
                      data-preview-url="{{ link_type('public', 'my-route/get-preview-for-other-editor') }}" />
And both editors should (theoretically) get preview from the data-preview-url argument.
 
Upvote 7
This suggestion has been implemented. Votes are no longer accepted.
This is a required change IMO, as my eCommerce add-on has multiple pages with multiple rich text editors.

Given how easy this change is, it would be amazing if I could take advantage of the fancy preview system in the new editor.
 
Top Bottom