Problem/Motivation
While testing #2159403: Make CKEditor plugin system modular and clean I came across the issue that the code worked in Chrome but didn't in FF and IE.
Whenever I toggled to the source view of the CKEditor I didn't see the token but still the placeholder of the inserted media. Which also means when the content was saved the placeholder instead the token was saved.
I could locate the issue for this behaviour in Drupal.media.filter.replacePlaceholderWithToken()
(media/modules/media_wysiwyg/js/media_wysiwyg.filter.js
).
The function iterated over all media-elements found by jQuery and uses the output of Drupal.media.filter.outerHTML()
to do a search replace operation in the content.
Unfortunately Drupal.media.filter.outerHTML()
doesn't always return an exact representation of the HTML that's contained in the content. This happens due the fact that some browsers seem to alter the return of innerHTML
.
An example is this code:
<img alt="" class="media-element file-default" data-file_info="%7B" height="160" src="dummy_image.jph" typeof="foaf:Image" width=" 260">
which is returned as:
<img alt="" class="media-element file-default" data-file_info="%7B" src="dummy_image.jph" typeof="foaf:Image" height="160" width=" 260">
Even if "just" the order of the attributes is changed this makes a search / replace operation useless.
Code to test the effect: jQuery('<div>').html(jQuery('<img alt="" class="media-element file-default" data-file_info="%7B" height="160" src="dummy_image.jph" typeof="foaf:Image" width=" 260">')).html()
Proposed resolution
Instead looping over the found elements and use a separated replacement function we can use jQuery.replaceWith()
.
Tests with Chrome, FF and IE where successful so far.
Remaining tasks
Reviews needed.
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#8 | media-browser-incompatibilities-2164823-8.patch | 1.42 KB | das-peter |
Comments
Comment #1
valross.nu CreditAttribution: valross.nu commentedWe had a bug as described in Wysiwyg embeds breaks in Firefox and IE.
Bug occured as you pointed out in IE and FF.
Test results
Before patch applied
Opera(W8) 12.16 OK
Firefox (W8) 26.0 FAIL
Chrome (W8) 31.0.1650.63 OK
IE9 (W7 VM) FAIL
IE10 (W7 VM) FAIL
IE11 (W8) FAIL
Safari (W8) 5.1.7 OK
After patch applied
Opera (W8) 12.16 OK
Firefox (W8) 26.0 OK
Chrome (W8) 31.0.1650.63 OK
IE9 (W7 VM) OK
IE10 (W7 VM) OK
IE11 (W8) OK
Safari(W8) 5.1.7 OK
Test conclusion
Testing confirms that patch does solve the issue!
Thank you for posting this issue with the patch!
Comment #2
das-peter CreditAttribution: das-peter commented@valross.nu Aaaaawesome, thanks for testing and reporting so detailed :)
Comment #3
kaidjohnson CreditAttribution: kaidjohnson commented@das-peter - this is a much cleaner solution than one I was working on. I've added it to a slightly broader topic because it covers a piece of the issue at hand. Closing this one out as a duplicate of #2126755: Improve Media's WYSIWYG Macro handling as we should (and have) consolidate our work on a single thread.
Comment #4
Marty2081 CreditAttribution: Marty2081 commentedIn our case the provided patch results in a "TypeError: this.cloneNode is not a function" JS error in some cases. I guess that that is because there can be content that does not have any media-element items in it and therefore "this" will be the "window" object instead of a media-element.
I changed the code into the following to solve this (probably there is a cleaner way to do this?):
Comment #5
sylus CreditAttribution: sylus commentedI am going to reopen this as addresses an immediate bug and I see no reference of this code in the others issue patch which doesn't correct the problem.
Comment #6
kaidjohnson CreditAttribution: kaidjohnson commented@sylus - the reference to this patch being included in the work from #2126755: Improve Media's WYSIWYG Macro handling can be found here: https://drupal.org/comment/8361293#comment-8361293. All subsequent patches on that thread include the approach used here.
Comment #7
kaareSo … closing.
Comment #8
das-peter CreditAttribution: das-peter commentedRe-opening since #2126755 doesn't show the progress I was hoping for and this patch provides a ready to go solution for an existing problem.
@Marty2081 I'm not sure if I understand the issue but apparently it fixed the error for you and the behaviour still is as required - so the latest patch incorporates your enhancements.
Comment #9
rooby CreditAttribution: rooby commentedI think this patch is still useful at least for now.
In the version of the module I am running this is an issue that needs addressing.
Once #2126755: Improve Media's WYSIWYG Macro handling is fully finished then this issue likely not be relevant (at least once they have addressed the problem mentioned in #97 & #99 of that issue).
Comment #10
rooby CreditAttribution: rooby commentedThanks for this patch, it fixes the problem described in my current module versions:
* media 7.x-2.0-alpha3+77-dev
* file_entity 7.x-2.0-alpha3+17-dev
* ckeditor 7.x-1.13+22-dev
However it is not compatible with the the latest versions:
* media 7.x-2.0-alpha3+90-dev
* file_entity 7.x-2.0-alpha3+17-dev
* ckeditor 7.x-1.14+2-dev
In newer versions of the media module I don't ever see the
[[{fid...}]]
tokens. Only ever the image markup.Based on #97 & #99 of #2126755: Improve Media's WYSIWYG Macro handling I'm assuming that this newer problem will be fixed there.
If it does not I will reopen #2279749: Media in WYSIWYG no longer shows rendered entity as this issue is really for a different problem.
Unfortunately I don't see this patch being committed due to the recent media changes (so not marking RTBC), however this patch will still remain useful to users running older versions.
Comment #11
dasjo#8 works for me thanks!
Comment #12
Kevin P Davison CreditAttribution: Kevin P Davison commented#8 seems to resolve an issue we have with Firefox where upon save, the image(s) are shown in the wrong view mode. We've tested this with media 7.x-2.0-alpha3+29-dev, and we'd love to see this problem fixed. Does the patch need to be re-rolled, or did something fundamentally change since then? Thank you!
Comment #13
rooby CreditAttribution: rooby commentedThe module has changed since then, so this patch is no longer relevant for the latest dev version.
It is however very useful for those of us running slightly older versions.
Hopefully when #2126755: Improve Media's WYSIWYG Macro handling is finished this issue will be redundant.
Comment #14
LittleRedHen CreditAttribution: LittleRedHen commentedThe patch at https://www.drupal.org/node/2832384#comment-11814293 should correct this issue as well. It uses the $.replaceWith approach suggested in the original issue, and is rolled against the latest 2.x-dev branch.
Comment #15
joseph.olstadComment #16
joseph.olstadI marked it as duplicate, but could very well have been marked as 'closed outdated'.