#21812 closed task (blessed) (fixed)
Make custom TinyMCE views easier to implement
Reported by: | koopersmith | Owned by: | azaozz |
---|---|---|---|
Milestone: | 3.5 | Priority: | high |
Severity: | normal | Version: | 3.5 |
Component: | TinyMCE | Keywords: | has-patch |
Focuses: | Cc: |
Description
Currently, adding a custom view to TinyMCE is quite difficult. Given MCE's capability to mark html as non-editable, we should make improving the editor along these lines as easy as possible.
Potential applications include views and interactions for shortcodes, oEmbed, media objects, and more.
See #21390.
Attachments (5)
Change History (37)
#6
@
12 years ago
A very crude first run patch. Still missing some things but the main functionality is there.
#7
@
12 years ago
In 21812-2.patch:
- Added cleanup_callback called when the preview is being removed.
- Fixed creating previews on paste and on inserting content in the editor.
- Fixed lots of bugs.
To-do:
- Better CSS.
- More testing with very big posts and many previews.
Maybe:
- Abstract the calculation of the visible part of a preview and pass the rectangle in the events callbacks (the code currently showing popup buttons on the images).
#8
@
12 years ago
In 21812-3.patch:
- Added scanning/detecting of previews when the user types the "trigger" string (on enter).
- Improved timing/handling for firing the node_callback.
- Moved couple of functions to match the standard TinyMCE plugin structure.
#9
@
12 years ago
In 21812-4.patch:
- Added option for previews that are shown inline controlled by the wrapper tags (either 'div' or 'span').
#10
@
12 years ago
- Keywords has-patch added; needs-patch removed
21812.diff takes the techniques Andrew has been working on and transforms them into an API on the wp
object, namely wp.mce.view
, which acts as a bridge between TinyMCE and Backbone Views.
The patch differs from 21812-4.patch in several ways:
- Blocker divs are not included — we're frequently going to add UI inside the views, so blocking interactions to the view will frequently degrade the experience.
- Fixes several encoding and decoding bugs that caused errors when switching between editors.
- Views are rendered instantly; there is no longer a need to call
setTimeout
.
- There is no scanning on keydown. This should be added in again. I experimented with a few other methods, like scoping to the active node, so this will be worth experimenting with.
- There is currently no way to add a preview for only certain editor instances. This should be implemented as a function on the object passed to
wp.mce.view.add()
.
It's also worth noting that none of the provided patches isolates the replacement text when scanning it with multiple patterns. This could lead to collisions and encoding errors. When scanning, we should progressively split the string to ensure patterns won't collide or overlap.
For an example, this code will identify and replace the string [text]
with the string My test view.
, and record all clicks to the console.
wp.mce.view.add( 'test', { pattern: /\[test\]/g, view: { events: { 'click': 'clicked' }, render: function() { this.$el.text('My test view.'); }, clicked: function() { console.log('I was clicked!'); } } });
#14
follow-up:
↓ 15
@
12 years ago
Not sure if this is the correct ticket, but I'm getting the following error on CPT edit screens that don't have 'editor' in the 'supports' array:
ReferenceError: tinymce is not defined tinymce.onAddEditor.add(function(mce, ed){ post.js (line 703)
#15
in reply to:
↑ 14
@
12 years ago
Replying to scribu:
Not sure if this is the correct ticket, but I'm getting the following error on CPT edit screens that don't have 'editor' in the 'supports' array:
ReferenceError: tinymce is not defined tinymce.onAddEditor.add(function(mce, ed){ post.js (line 703)
From the looks of it, it doesn't seem related. Can you post a stack trace?
#16
follow-up:
↓ 18
@
12 years ago
Uncaught ReferenceError: tinymce is not defined post.js:703 (anonymous function) post.js:703 p.Callbacks.k jquery.js:2 p.Callbacks.l.fireWith jquery.js:2 p.extend.ready jquery.js:2
#21
@
12 years ago
Whether I use the new Beta Media button or the old link, after I insert an image into a post, in Visual mode, I can't switch to Text mode:
Uncaught TypeError: Cannot read property 'width' of undefined mce-view.js:394 wp.media.string.image mce-view.js:394 (anonymous function) media-upload.js:112 T.map.T.collect underscore.min.js:5 r.(anonymous function) backbone.min.js:25 (anonymous function) media-upload.js:111 g.Events.trigger backbone.min.js:9 media.controller.Workflow.Backbone.Model.extend.update media-views.js:122 media.view.Attachment.Library.media.view.Attachment.extend.insert media-views.js:477 p.event.dispatch jquery.js:2 g.handle.h
#23
@
12 years ago
- Resolution set to fixed
- Status changed from reopened to closed
I was playing with add_image_size() and was missing the default image sizes.
False alarm.
#28
@
12 years ago
Small improvement for [22210], we don't need to do this "by hand":
isView : function( node ) { return (/(?:^|\s)wp-view-wrap(?:\s|$)/).test( node.className ); },
Can use ed.dom.hasClass(node, 'wp-view-wrap')
or if it needs regex perhaps this:
isView : function( node ) { return /\bwp-view-wrap\b/.test( node.className ); },
#29
follow-up:
↓ 30
@
12 years ago
[Edit] Sorry, I was a bit trigger happy. Read the whole changeset comment and realised views aren't going into 3.5. Sorry about that.
First time commenter here - I'm not sure if I'm supposed to comment on a fixed ticket, but here goes.
I found that in [22567] the wpviews TinyMCE plugin was deactivated. Wouldn't that make this a non-fixed issue? The plugin is still left in core so I'm assuming there's a plan to reactivate it some time.
#30
in reply to:
↑ 29
@
12 years ago
Replying to lippe:
I found that in [22567] the wpviews TinyMCE plugin was deactivated. Wouldn't that make this a non-fixed issue?
It's still considered as fixed for 3.5.
The plugin is still left in core so I'm assuming there's a plan to reactivate it some time.
Correct. That should happen in a new ticket.
Based on a conversation with azaozz in IRC, this is how we're going to proceed:
On the TinyMCE side, you can create a preview type. Each preview can have multiple instances within MCE. TinyMCE requires that some sort of preview html be provided on render, so we will handle the creation of placeholder divs. The external JS will either immediately replace them, or replace them once their content has loaded (the latter will be especially useful when using AJAX requests).
azaozz is working on this, and barring any blockers, will have a patch later today.