Sharepoint 富内容编辑器修改从自定义工具栏按钮添加的 HTML

发布于 2024-08-08 17:35:47 字数 1294 浏览 5 评论 0原文

摘要:我想问的是 - 我们是否以完全错误的方式处理这个问题,或者是否有办法阻止 Sharepoint 或其丰富的编辑器修改添加的 HTML?

我被“扔”进了一个围绕 Sharepoint 2007 的项目(相信我,我对此并不完全满意),所追求的事情之一就是使用丰富内容区域来实现用户输入“丰富内容”,然后向内容添加某些“附加内容”,例如可扩展内容区域、对话框等。

最初的攻击计划是向 Sharepoint 丰富内容编辑器工具栏添加一个自定义按钮,我们将其有代码可以做到这一点,并且它可以工作等等,并将 javascript 事件处理程序附加到某些元素 - 这也可以工作 - 到一个点。

我们正在做的一件事是使用 元素和后续的

<a href="#" class="dialog-trigger">Click me to open the dialog</a>
<div class="dialog-content">
    this is some dialog content etc
</div>

当页面加载时,我们挂钩 .dialog-trigger click 方法,获取 a 元素的同级元素,即 >.dialog-content 并将其设置为对话框。只要您不想编辑任何内容,此操作就“有效”。

我发现,一旦您开始编辑 .dialog-content DIV 中的内容,丰富内容编辑器就会开始修改 HTML,例如,添加列表会添加以下 HTML:

<li><div class=dialog-content>Some list item</div></li>
<li><div class=dialog-content>Some list item 2</div></li>
<li><div class=dialog-content>Another list item</div></li>

正如您可以想象的那样,这破坏了我们正在尝试做的事情。

总结一下我想问的问题 - 我们是否以完全错误的方式解决这个问题,或者是否有办法阻止 Sharepoint 或其丰富的编辑器修改添加的 HTML?

Summary: What I'm trying to ask - are we going about this the completely wrong way, or, is there a way to stop Sharepoint, or its rich editor, from munging the HTML which gets added?

I've been 'dropped' into a project revolving around Sharepoint 2007 (trust me, I'm not entirely pleased about it), and one of the things that is sought after is a way to use a rich-content-area for the users to put in 'rich content' and then add certain 'extras' to the content, such as expandable content areas, dialogs etc.

The initial plan of attack was to add in a custom button to the Sharepoint rich content editor toolbar, which we have code to do this, and it works etc, and attach javascript event handlers to certain elements - which also works - to a point.

One thing we are doing is using an <a> element and a subsequent <div> to setup a dialog (using jQuery UI to do the magic). When the user clicks the 'insert dialog' button the following is inserted into the editor:

<a href="#" class="dialog-trigger">Click me to open the dialog</a>
<div class="dialog-content">
    this is some dialog content etc
</div>

When the page loads we hook onto the .dialog-trigger click method, grab the a element's sibling which is a .dialog-content and set that up as a dialog. This 'works' as long as you don't want to edit anything.

What I have found is that as soon as you start editing the content within the .dialog-content DIV the rich-content editor starts munging the HTML, for example, adding a list adds in the following HTML:

<li><div class=dialog-content>Some list item</div></li>
<li><div class=dialog-content>Some list item 2</div></li>
<li><div class=dialog-content>Another list item</div></li>

As you can imagine, this kind of breaks what we are trying to do.

To summarize what I'm trying to ask - are we going about this the completely wrong way, or, is there a way to stop Sharepoint, or its rich editor, from munging the HTML which gets added?

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

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

发布评论

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

评论(2

千寻… 2024-08-15 17:35:47

如果您只是将 HTML 按原样放入编辑器内容中,您将无法阻止编辑器弄乱您的 HTML。如果您有一些必须保持完整的内容,那么您需要将其存储在其他地方,并在编辑器中为它提供一个占位符,其中包含实际内容的 ID(例如,在 中带有 ID 的占位符图像) alt 属性)。当编辑器保存时,您需要将这些占位符替换为真实的 HTML 内容,反之亦然。

If you're just putting the HTML as it is into the editor content, you won't be able to stop the editor from messing with your HTML. If you have some content that must be kept intact then you need to store it somewhere else and have a placeholder for it in the editor that contains an ID for the actual piece of content (e.g. a placeholder image with the ID in the alt attribute). You'll need to replace such placeholders with the real HTML content when the editor saves and vice versa when the editor loads.

柠北森屋 2024-08-15 17:35:47

我理解您的痛苦,与其他开源解决方案相比,SharePoint 的富文本编辑器并不是最好的。无论如何,也许您可​​以训练您的用户使用预定义的样式?然后使用 JQuery 来做事。

如果您在 CSS 中执行以下操作,

/*.ms-rteCustom-anything else you want*/
/*e.g.*/
.ms-rteCustom-DialogTrigger {
    color:#333333
}

现在共享点编辑器将在样式下显示“DialogTrigger”并将其应用为 div。

或者,从技术上讲,您可以使用另一个编辑器,并使用 SPAPI 或 JQuery + SharePoint Web 服务。

I feel your pain, SharePoint's rich text editor is not the best compared to other open source solutions out there. Anyhow, perhaps you can train your users to use predefined styles? Then use JQuery to do stuff.

If you do the following in your CSS

/*.ms-rteCustom-anything else you want*/
/*e.g.*/
.ms-rteCustom-DialogTrigger {
    color:#333333
}

Now the sharepoint editor will show you "DialogTrigger" under Styles and apply it as a div.

Alternatively, you could technically use another editor and post the data back to SharePoint using SPAPI or JQuery + SharePoint webservices.

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