Opened 11 years ago
Closed 11 years ago
#27389 closed task (blessed) (fixed)
MCE Views for Audio/Video
Reported by: | wonderboymusic | Owned by: | azaozz |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.9 |
Component: | Media | Keywords: | has-patch commit dev-reviewed |
Focuses: | javascript | Cc: |
Description
Turns out, you can render players in TinyMCE. This was not easy.
Attachments (27)
Change History (64)
This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.
11 years ago
#3
@
11 years ago
27389.3.diff has many improvements:
- Previously, if you had the same shortcode in your post twice, it would only get rendered once. Fixed that.
- When rendering a
wp.mce.View
, the current node context is passed to aready
event, so when you do have multiple shortcodes that are equal, you know which one you are dealing with. - For videos in the editor, force
preload="none"
- will let the video play immediately. Any of the otherpreload
values cause the spinner to appear for many seconds. This defies logic.
#7
@
11 years ago
I tested this on every browser with every supported audio/video type: 27389.5.diff
tl;dr MediaElement's Plugin Bridge (Flash/Silverlight) and TinyMCE do not intermingle well.
Subsequently, I added an isCompatible
method to whitelist types that MEjs should parse, otherwise replace with a placeholder and bail.
#8
@
11 years ago
posted a screenshot that shows intermingling of supported/unsupported videos in TinyMCE. What sucks: almost every type plays just fine in the media modal. I think there is something in the global space that doesn't translate from the MEjs bridge to TinyMCE - the errors propagate from the JS VM though, not from the app #yay
This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.
11 years ago
#18
@
11 years ago
27389.7.diff is a refresh against all of the code churn. Does not take [27544] into account yet.
#20
@
11 years ago
- Resolution set to fixed
- Status changed from new to closed
New tickets for specific bugs.
This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.
11 years ago
This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.
11 years ago
#24
@
11 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
There are at least 2 patches that will need to be applied - one is the timeout on initial page load, the other is related to cut-copy-paste-undo and memory leaks
#25
@
11 years ago
27389.combined.diff combines the patches. As far as memory management goes, TinyMCE itself leaks memory. My initial profiling (empty-editor.png) was done against an empty Visual editor, each additional profile was done by going from Visual-Text-Visual then taking another snapshot. The second set of snapshots (one-audio.png) was done with one audio player in the editor. I did some other tests with 21 players in the editor and the ratios were the same.
My code in the patch ensures that MediaElement's cleanup routine is run on every player when TinyMCE rebuilds itself, even when multiple players are bound to the same view - this happens when duplicate shortcodes exists. I tested this with 20 players, 7 being the exact same.
On page load, the players are initialized after a 500ms timeout to ensure that the stylesheets are loaded. Subsequent builds happen after a 10ms refresh. The broken looking players in FF were due to a race condition with the editor stylesheet.
The patch also contains @gcorne's view refresh fixes in wp.mce.View
#26
@
11 years ago
A change to the UndoManager
was committed upstream that adds the additional context to the BeforeAddUndo
hook that will allow us to prevent undo steps from being added when the body of a wpview
changes and some sort of action triggers TinyMCE to attempt to add an undo level.
#27
follow-up:
↓ 28
@
11 years ago
27389.combined.3.diff cleans up all player instances in a view when the view refreshes and the first new player is being parsed.
Since we are blowing away the inner DOM for MCE views when transition away from Visual or Undo-ing, this is necessary to clean up MEjs cruft from previously created players. They all have to be done at once to prevent extras from leaking - say you go from Visual tab to Text, delete a shortcode, and then tab back to Visual, we don't want orphaned and unbound player instances.
This is a joy to debug. Patch also removes the TinyMCE changes which are forthcoming from upstream.
#28
in reply to:
↑ 27
@
11 years ago
Replying to wonderboymusic:
There is no need to use jQuery inside the editor (TinyMCE includes Sizzle too). This bit:
_.each( tinymce.editors, function( editor ) { var doc; if ( editor.plugins.wpview ) { doc = editor.getDoc(); size += $( doc ).find( '[data-wpview-text="' + self.encodedText + '"]' ).length; } } );
would be better as:
_.each( tinymce.editors, function( editor ) { if ( editor.plugins.wpview ) { size += editor.dom.select( '[data-wpview-text="' + self.encodedText + '"]' ).length; } } );
Also self.encodedText
can be quite long, might slow down or even break the selector? If you need to count only specific views, perhaps select all views first with views = editor.dom.select( '[data-wpview-text]' );
then loop over them and count only the specific views by matching the attribute value with editor.dom.getAttrib( viewNode, 'data-wpview-text' ) === self.encodedText
.
#29
@
11 years ago
Thinking about this more: would it be better to have a "global" unbind event triggered in wpview? Seems the three events that force DOM rebuilding in the editor are undo
, redo
, and loadContent
. We can easily fire an view.unbind()
on these.
#30
@
11 years ago
An unbind
event would negate a lot of the code in my patch, which is a good thing. All of the memory cleanup could happen in the same place, before ready
fires.
Once that is exposed, I can refactor my patch.
This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.
11 years ago
#32
@
11 years ago
27389-unbind-02.patch looks good, @wonderboymusic could you confirm it works as expected.
#33
@
11 years ago
27389.9.diff adds a few of the things from my patch that are still necessary.
- Need to set a longer timeout on initial page load to avoid the race condition with the editor stylesheet setting content width
- Need to push players onto a stack, a single view can render multiple instances if the shortcode is duplicated. Thus, the
unbind
routine needs to iterate and remove and then reset.
Everything looks good, and this approach is much cleaner. John Resig envisioned code-heroes/cowboys like you two when he wrote Secrets of a JavaScript Ninja.
This ticket was mentioned in IRC in #wordpress-dev by wonderboymusic. View the logs.
11 years ago
#35
@
11 years ago
- Keywords commit added
27389.9.diff looks good. 27389.10.diff just adds couple more inline comments.
This bent my brain in half: 27389.2.diff
data-wpview-text
attr is updated, the views are refreshed, and the specific type of media'srender
method is called to remove the player and re-add itwp.media.audio|video
'sshortcode
method is now calledupdate
, which is more semantically representative.ready
event when awp.mce.View
is constructedready
handlers forwp.mce.audio|video.View
for when the page initially loads so we have a reference to the view's root element