gpt4 book ai didi

twitter-bootstrap - 如何将响应类添加到 ckeditor 图像对话框?

转载 作者:行者123 更新时间:2023-12-02 01:28:45 24 4
gpt4 key购买 nike

我有一个带有 CK 编辑器的网站面包师。如果没有插入任何类,我想让图像自动具有“img-responsive”类。如何?我可以这样做吗

我找不到这个的字典http://docs.cksource.com/CKEditor_3.x/Howto/Default_Field_Values每个输入的名称是什么等等?而 html 源代码不会显示这一点。

最佳答案

很久以前我也遇到过同样的问题。我可能复制粘贴了大部分代码,并自己做了一些小修改。它的代码有点长,它将 img-responsive 类添加到所有添加的图像。

 CKEDITOR.replace('editor1');
CKEDITOR.on('instanceReady', function(ev) {

//resp. images for bootstrap 3
ev.editor.dataProcessor.htmlFilter.addRules(
{
elements:
{
$: function(element) {
// Output dimensions of images as width and height
if (element.name == 'img') {
var style = element.attributes.style;
//responzive images

//declare vars
var tclass = "";
var add_class = false;

tclass = element.attributes.class;

//console.log(tclass);
//console.log(typeof (tclass));

if (tclass === "undefined" || typeof (tclass) === "undefined") {
add_class = true;
} else {
//console.log("I am not undefined");
if (tclass.indexOf("img-responsive") == -1) {
add_class = true;
}
}

if (add_class) {
var rclass = (tclass === undefined || typeof (tclass) === "undefined" ? "img-responsive" : tclass + " " + "img-responsive");
element.attributes.class = rclass;
}

if (style) {
// Get the width from the style.
var match = /(?:^|\s)width\s*:\s*(\d+)px/i.exec(style),
width = match && match[1];

// Get the height from the style.
match = /(?:^|\s)height\s*:\s*(\d+)px/i.exec(style);
var height = match && match[1];

if (width) {
element.attributes.style = element.attributes.style.replace(/(?:^|\s)width\s*:\s*(\d+)px;?/i, '');
element.attributes.width = width;
}

if (height) {
element.attributes.style = element.attributes.style.replace(/(?:^|\s)height\s*:\s*(\d+)px;?/i, '');
element.attributes.height = height;
}
}
}



if (!element.attributes.style)
delete element.attributes.style;

return element;
}
}
});
});

关于twitter-bootstrap - 如何将响应类添加到 ckeditor 图像对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35334816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com