如何让 CKeditor 从 Hspace 和 Vspace 切换到正确的 CSS

发布于 2024-09-12 04:30:19 字数 176 浏览 2 评论 0原文

我正在与 CKeditor 合作,无论出于何种原因,他们在 UI 中包含了 Hspace 和 Vspace。允许用户像这样操作他们的图像是一个方便的想法,但这些已经被弃用了。

有谁将CKeditor的Hspace和Vspace转换为CSS,并知道如何解释其转换吗?

我是一个 JavaScript 新手..

I'm working with CKeditor, and for whatever reason, they included Hspace and Vspace in their UI. Convenient idea to allow users to manipulate their images like so, but those are way deprecated.

Has anyone converted CKeditor's Hspace and Vspace to CSS, and know how to explain its conversion?

I am a javascript novice..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↙厌世 2024-09-19 04:30:19

hspacevspace 是以像素为单位的边距。转换应该是直接、即时和简单的。

您希望在哪里进行更正?我对 CKEditor 的来源一无所知,因此我提出了三个选项。

选项 1:在提交时使用正确的 CSS 替换 hspacevspace 属性。这可能会影响以后的可编辑性。

选项 2:在渲染时使用适当的 CSS 替换 hspacevspace 属性。如果您以正确的方式(HTML 解析器)执行此操作,这可能会很慢。

选项 3:在渲染时在客户端用适当的 CSS 替换 hspacevspace 属性。这在 jQuery、Prototype、Mootools 或您正在使用的任何库中应该是微不足道的。


jQuery 来救援!像这样的东西可以工作。

$('img[hspace]').each(function(el){
    var pixels = parseInt($(el).attr('hspace'));
    if(isNaN(pixels) || pixels < 1)
        pixels = 0;
    else
        pixels = pixels / 2
    $(el).css('marginLeft', pixels + 'px')
         .css('marginRight', pixels + 'px')
         .removeAttr('hspace');
});

$('img[vspace]').each(function(el){
    var pixels = parseInt($(el).attr('vspace'));
    if(isNaN(pixels) || pixels < 1)
        pixels = 0;
    else
        pixels = pixels / 2
    $(el).css('marginTop', pixels + 'px')
         .css('marginBottom', pixels + 'px')
         .removeAttr('vspace');
});

hspace and vspace are margins in pixels. The conversion should be direct, immediate and simple.

Where do you want the correction to take place? I don't know anything about CKEditor's source, so that leads me to propose three options.

Option 1: Replace the hspace and vspace attributes with proper CSS at submit time. This might impact editability later.

Option 2: Replace the hspace and vspace attributes with proper CSS at render time. This might be slow if you do it the right way (HTML parser).

Option 3: Replace the hspace and vspace attributes with proper CSS on the client side at render time. This should be trivial in jQuery, Prototype, Mootools, or whatever library you're using.


jQuery to the rescue! Something like this could work.

$('img[hspace]').each(function(el){
    var pixels = parseInt($(el).attr('hspace'));
    if(isNaN(pixels) || pixels < 1)
        pixels = 0;
    else
        pixels = pixels / 2
    $(el).css('marginLeft', pixels + 'px')
         .css('marginRight', pixels + 'px')
         .removeAttr('hspace');
});

$('img[vspace]').each(function(el){
    var pixels = parseInt($(el).attr('vspace'));
    if(isNaN(pixels) || pixels < 1)
        pixels = 0;
    else
        pixels = pixels / 2
    $(el).css('marginTop', pixels + 'px')
         .css('marginBottom', pixels + 'px')
         .removeAttr('vspace');
});
来日方长 2024-09-19 04:30:19

您使用什么版本的 CKEditor?
加载 http://ckeditor.com/demo 并查看该图像的生成源:
style="左边距:10px;右边距:10px;浮动:左;宽度:120px;高度:168px;"所以你不需要做任何事情。

What version of CKEditor are you using?
Load http://ckeditor.com/demo and look at the generated source for that image:
style="margin-left: 10px; margin-right: 10px; float: left; width: 120px; height: 168px;" so you don't have to do anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文