ContentTools - 如何在挂载/卸载期间保留数据属性

问题描述 投票:0回答:1

我正在项目中使用ContentTools编辑器。 http://getcontenttools.com/我有img标签与data-foo属性。我希望在mount / unmount过程中传递/保留这些属性。目前它们已完全删除。

这是我的示例img标记:

 <img data-foo="SAVEME" class="align-right" height="300" src="/images/pages/demo/click-and-hold-to-drag.png" width="300" >

初始化ContentTools后:

<div class="align-right ce-element ce-element--type-image" style="background-image:url('/images/pages/demo/click-and-hold-to-drag.png');width:300px;height:300px;" data-ce-size="w 300 × h 300"></div>

如您所见,'data-foo =“SAVEME”'现已删除。有没有办法保存数据属性?谢谢

javascript wysiwyg
1个回答
0
投票

一种选择是修补图像mount方法,以便它应用如下数据属性:

var _super = ContentEdit.Image.prototype.mount;

ContentEdit.Image.prototype.mount = function() {
    _super.call(this);
    for (var attrName in this._attributes) {
        if (attrName.startsWith('data-')) {
            this._domElement.setAttribute(attrName, this._attributes[attrName]);
        }
    }
};
© www.soinside.com 2019 - 2024. All rights reserved.