Fix for Firefox/Safari ignoring initial srcset attribute
authorAlexander Ebert <ebert@woltlab.com>
Fri, 23 Sep 2016 15:25:40 +0000 (17:25 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 23 Sep 2016 15:25:40 +0000 (17:25 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabSmiley.js

index 3b82fdc12ab52f7d75ef02f81d2909a1be36fcf0..5fb8c2544ca656ff1b7169dd1af04ab0f01ee75e 100644 (file)
@@ -1,6 +1,8 @@
 $.Redactor.prototype.WoltLabSmiley = function() {
        "use strict";
        
+       var _index = 0;
+       
        return {
                init: function() {
                        require(['EventHandler'], (function(EventHandler) {
@@ -11,7 +13,18 @@ $.Redactor.prototype.WoltLabSmiley = function() {
                _insert: function(data) {
                        this.buffer.set();
                        
-                       this.insert.html(data.img.cloneNode().outerHTML);
+                       var id = 'wscSmiley_' + this.uuid + '_' + _index++;
+                       
+                       var smiley = data.img.cloneNode();
+                       smiley.id = id;
+                       this.insert.html(smiley.outerHTML);
+                       
+                       // Firefox and Safari tend to ignore the `srcset` attribute, all though
+                       // it is clearly present in the DOM. Overwriting the element with itself
+                       // is somehow fixing that issue, yay!
+                       smiley = elById(id);
+                       //noinspection SillyAssignmentJS
+                       smiley.outerHTML = smiley.outerHTML;
                }
        }
 };