Problem/Motivation

In js/wysiwyg-media.js the media tokens are replaced with real <img> tags so content editors can see the image in the rich text editor.

After clicking "save" button, in some cases (eg when using image2 plugin) there may be multiple classes added to the image tag, and when this happens, if "media-image" is not the *first* class, then the conversion back to Media tokens fails.

Proposed resolution

There are two possible solutions to this:

1) Modify the regular expression used to detect images with media-image class, to allow media-image anywhere inside the class attribute.
2) Convert the plain HTML string to a jQuery object and use a jQuery selector $('img.media-image') to find media placeholder images.

Remaining tasks

Review patch for Solution #1, to determine if this solution is sufficient.

Comments

jwilson3’s picture

Issue summary: View changes
jwilson3’s picture

Status: Active » Needs review
StatusFileSize
new700 bytes

I've opted for solution 1 because the change is a one-liner. It is a little bit complicated to read, but essentially, with the addition of ([^\'"]*?) to the regular expression, I've added the ability for additional classes to appear before the image-media class on the image tag.

jwilson3’s picture

StatusFileSize
new700 bytes

Switched from + to * to allow zero or more characters.

jwilson3’s picture

Title: Media wysiwyg token conversion fails before save if "media-image" class is not first » wysiwyg token not converted on save if media-image is not first class
chris matthews’s picture

Status: Needs review » Closed (outdated)

Closing this issue as outdated. However, if you think this issue is still important, please let us know and we will gladly re-open it for review.
sincerely,
- the Drupal Media Team