I'm having trouble with the following code in media_wysiwyg.filter.js:

      // Re-build the macros in case any element has changed in the editor.
      $('.media-element', content).each(function(i, element) {
        var markup = Drupal.media.filter.outerHTML($(element));
          macro = Drupal.media.filter.create_macro($(element));

        // Store the macro => html for more efficient rendering in
        // replaceTokenWithPlaceholder().
        Drupal.settings.tagmap[macro] = markup;
        // Replace the media element with its macro.
        content = content.replace(markup, macro);
      });

It's not replacing the placeholder with the media tag because the markup variable isn't identical to the html in the original content. For example I can add a single placeholder for a video as an image preview and the markup variable will be:

<img alt="ug0ifwslG84" class="media-element file-full" data-file_info="%7B%22fid%22:%2224384%22,%22view_mode%22:%22full%22,%22fields%22:%7B%22format%22:%22full%22,%22field_video_caption%5Bund%5D%5B0%5D%5Bvalue%5D%22:%22%22,%22field_trending_score%5Bund%5D%5B0%5D%5Bradioactivity_energy%5D%22:%220%22,%22field_trending_score%5Bund%5D%5B0%5D%5Bradioactivity_timestamp%5D%22:%221396445177%22%7D,%22type%22:%22media%22%7D" src="http://localhost:90/sites/default/files/styles/wide_medium/public/media-youtube/ug0ifwslG84.jpg?itok=Jl98_8QZ" typeof="foaf:Image" height="169" width="300">

But the content variable will be:

<p><img alt="ug0ifwslG84" class="media-element file-full" data-file_info="%7B%22fid%22:%2224384%22,%22view_mode%22:%22full%22,%22fields%22:%7B%22format%22:%22full%22,%22field_video_caption%5Bund%5D%5B0%5D%5Bvalue%5D%22:%22%22,%22field_trending_score%5Bund%5D%5B0%5D%5Bradioactivity_energy%5D%22:%220%22,%22field_trending_score%5Bund%5D%5B0%5D%5Bradioactivity_timestamp%5D%22:%221396445177%22%7D,%22type%22:%22media%22%7D" height="169" src="http://localhost:90/sites/default/files/styles/wide_medium/public/media-youtube/ug0ifwslG84.jpg?itok=Jl98_8QZ" typeof="foaf:Image" width="300"></p>

Note the placement of the height attribute in each. The html is equivalent but it doesn't match when replace is called.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jmuzz’s picture

Status: Active » Needs review
FileSize
1.28 KB

Here's a fix that works by converting content into a jQuery object and using jQuery's replaceWith function.

jmuzz’s picture

FileSize
1.29 KB

That solution caused errors when the content was empty.

jmuzz’s picture

FileSize
1.27 KB

Fixed a bug described at https://drupal.org/node/2236115 .

drclaw’s picture

I believe the issue you're experiencing will be fixed by #2126755: Improve Media's WYSIWYG Macro handling

I'm not familiar enough with this to judge whether or not this is a duplicate, however.

Chris Matthews’s picture

Status: Needs review » Closed (outdated)
Related issues: +#2126755: Improve Media's WYSIWYG Macro handling

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