#31412 closed enhancement (fixed)
TinyMCE views improvements
Reported by: | iseulde | Owned by: | azaozz |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | |
Component: | TinyMCE | Keywords: | has-patch |
Focuses: | javascript | Cc: |
Description (last modified by )
I'm going to use this ticket to propose some improvements to the mce views API, instead of adding this to #29841.
- Give views the option to display a loader or not. See #29841. We can mark the paragraph and replace it later based on this option. To the user it will look as if nothing happened until there is a match. This is very useful for oEmbed.
- Remove the
wrap
andreplace
options fromsetContent
. - Better edit function. Now it's part of the instance, so no need to look at the node for the encoded text. You can call the function provided to refresh the view, no need to touch the DOM any more. You can see the edit functions of the core views are a lot simpler.
- The gallery and av views now reuse the same edit function.
- Simpler registration.
setContent
will callsetIframes
itself if needed.- Selecting another view will pause all players. We could also limit this to the same view type or a set of view types. This allows us to remove a lot of code.
- Better documentation (though it could be better still).
- Move the main API to the top of the file.
- Wrap the view registration in a separate IIFE. Ideally this should go in a separate file.
- The
render
method is easier to override. - Better detection of already rendered views, so we don't unnecessarily refresh views.
- I added a proper
setLoader
method, just likesetError
. - All options set in
toView
are now added as properties of the instance.
I will do some more testing.
Suggestion are welcome.
Attachments (26)
Change History (55)
#7
@
10 years ago
Hm, there seems to be a tiny memory leak since 4.0 [29615]. editor.on( 'wp-body-class-change', function() {...
.
#12
follow-ups:
↓ 14
↓ 22
@
10 years ago
Left here:
- Above patch (there's a missing check for MutationObserver).
- Encoding issue.
- Media views should pause when switching to the text editor. Previously we did this whenever we could through mejs, but that didn't pause any embeds. I think the best solution is to remove the views when switching (which will destroy any iframes and therefore stop anything that's playing). This is okay since all the views need to be rerendered anyway when switching back to visual (all content is replaced by TinyMCE).
#14
in reply to:
↑ 12
@
10 years ago
Replying to iseulde:
Left here:
- Encoding issue.
As far as I see we will have to do that by hand. It seems it will be better to encode the wpView "text" rather than decode the whole content. If we touch the content we risk breaking double encoding, for example code with &&
in <pre> tags.
- Media views should pause when switching to the text editor. Previously we did this whenever we could through mejs, but that didn't pause any embeds. I think the best solution is to remove the views when switching (which will destroy any iframes and therefore stop anything that's playing). This is okay since all the views need to be rerendered anyway when switching back to visual (all content is replaced by TinyMCE).
Right. The whole content of TinyMCE is reloaded on every switch Text => Visual as we are expecting changes. There is no point in keeping the old "views".
#17
@
10 years ago
Subscribing. I'll update this TinyMCE view/shortcode example once 4.2 RC is out.
https://github.com/dtbaker/wordpress-mce-view-and-shortcode-editor
(I'm using similar code to this in lots of themes so will have to do a big update)
#18
@
10 years ago
I've found a small - somewhat edge case issue with setIframes
. Since this ticket tackles quite a few things - I'm going to post it here.
If you call setIframes
twice in quick succession, then you can end up with the iFrame content being shown twice. This only happens for previews that are sandboxed in an iFrame.
You can replicate this by replacing render()
in the initialize
method of the av view with render( true ); render( true );
I think the reason for this is the timeout in the setIframes
method. content.innerHTML
is reset outside of the callback. Calling it twice in quick succession causes the content to be appended to the content from the first call.
A simple fix is to move content.innerHTML = '';
inside the timeout callback - resetting the content innerHTML each time.
Uploading a patch.
This ticket was mentioned in Slack in #core by johnbillion. View the logs.
10 years ago
#22
in reply to:
↑ 12
@
10 years ago
Left here: patch above from @mattheu and third point in comment above.
We could move that last one to a new ticket.
This ticket was mentioned in Slack in #core-editor by iseulde. View the logs.
10 years ago
#24
@
10 years ago
- Owner set to azaozz
- Resolution set to fixed
- Status changed from new to closed
In 31740:
This ticket was mentioned in Slack in #core by paulschreiber. View the logs.
10 years ago
This ticket was mentioned in Slack in #core-editor by paulschreiber. View the logs.
10 years ago
#27
@
9 years ago
Hey all,
Is there a way to override the default gallery template?
Here is a before/after 4.2 example that I'm struggling with. Surely there's an easier way?
Thanks!
becomes