Ajax Control Toolkit HTML 编辑器自定义问题?

发布于 2024-08-18 02:26:04 字数 197 浏览 8 评论 0原文

如何更改 ACT HTML 编辑器的默认设置? 我想使用“选定的粗体按钮”或默认使用 rtl 方向而不是 ltr 来加载编辑器。
我怎样才能做到这一点? 我重写了 FillTopToolbar() 方法来添加自定义按钮,但我不知道如何更改默认设置。
因为选择了默认 ltr,我想将其更改为 rtl。

How to Change default setting for ACT HTML Editor? I want to load editor with for example Selected Bold Button or with rtl direction instead of ltr defaultly.
How can I perform that?
I overrided FillTopToolbar() method to add Custom buttons but I dont Know how to change default settings.
as Default ltr is selected I want to change it to rtl.

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

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

发布评论

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

评论(2

っ左 2024-08-25 02:26:04

我编辑了答案以纠正一些问题

HTMLEditor 不提供使用服务器端代码设置这些按钮状态的方法。尽管在客户端上,它通过使用 Sys.Application.load Event。如果您在初始化程序之后、用户与 UI 交互之前运行代码,则可以在该事件处理程序中设置您想要设置的任何属性。

这是设置粗体按钮和 RTL 按钮状态所需的代码。如果您想更改其他按钮的状态,可以从这里获取:

// Attach a handler to the load event.
Sys.Application.add_load(myOnLoadLoader);

function myOnLoadLoader() {
    //This will run JUST after ALL code that was set to run during the load event has run
    window.setTimeout(myOnLoad, 0);
}

function myOnLoad() {
    var editor = $find('<% =editor.ClientID %>');
    var toolbar = editor.get_changingToolbar();
    var toolbarButtons = toolbar.get_buttons();
    for (var i = 0; i < toolbarButtons.length; i++) {
        var toolbarButton = toolbarButtons[i];
        if (toolbarButton instanceof AjaxControlToolkit.HTMLEditor.ToolbarButton.Rtl ||
        toolbarButton instanceof AjaxControlToolkit.HTMLEditor.ToolbarButton.Bold) {
            toolbarButton.set_activeEditPanel(editor.get_editPanel());
            toolbarButton.callMethod();
        }
    }
}

Sys(以及 Sys.Application)是来自 ASP.Net AJAX javascript 的命名空间(由于 ScriptManager 添加的文件您添加到您的页面)。如果您使用此功能,则需要确保此行 Sys.Application.add_load(myOnLoad); 在 ASP.Net AJAX 文件加载后运行。您可以通过多种方式执行此操作:

  1. 将此脚本添加到页面中低于 scriptManager 的位置。
  2. 将脚本移至单独的 JS 文件中,然后使用 ScriptManager 加载它(推荐)。

如果将脚本移至单独的文件中,您会注意到 var editor = $find('<% =youreditor.ClientID %>'); 不再有效。这是因为 javascript 文件不会解析服务器标记并将其替换为服务器端值(如 aspx 页面那样)。所以这里有问题的部分是 <% =youreditor.ClientID %>

要解决这个问题,您需要执行以下操作:

将其添加到您的 aspx 标记中(在 head 部分中):

<script language="javascript">
    var myEditorId = '<%= youreditor.ClientID %>';
</script>

所以它看起来像这样:(

<head runat="server">
    <script language="javascript">
        var myEditorId = '<%= youreditor.ClientID %>';
    </script>
<title></title>
</head>

如果您使用的是母版页,您只需在 ScriptManager 下面添加 script 标记即可在你的页面中)

并在你的 JS 文件中,将其替换

var editor = $find('<% =youreditor.ClientID %>');

为此

var editor = $find(myEditorId);

I edited my answer to correct some things

The HTMLEditor doesn't provide a way to set the state of those buttons using serverside code. Although, on the client, it initializes by using Sys.Application.load Event. If you ran your code after their initializers, but before the user will interact with the UI, you could then set whatever properties you want to set in that event handler.

Here is the code you need to set the bold button and the rtl buttons states. You can take it from here if you want to change the states of other buttons:

// Attach a handler to the load event.
Sys.Application.add_load(myOnLoadLoader);

function myOnLoadLoader() {
    //This will run JUST after ALL code that was set to run during the load event has run
    window.setTimeout(myOnLoad, 0);
}

function myOnLoad() {
    var editor = $find('<% =editor.ClientID %>');
    var toolbar = editor.get_changingToolbar();
    var toolbarButtons = toolbar.get_buttons();
    for (var i = 0; i < toolbarButtons.length; i++) {
        var toolbarButton = toolbarButtons[i];
        if (toolbarButton instanceof AjaxControlToolkit.HTMLEditor.ToolbarButton.Rtl ||
        toolbarButton instanceof AjaxControlToolkit.HTMLEditor.ToolbarButton.Bold) {
            toolbarButton.set_activeEditPanel(editor.get_editPanel());
            toolbarButton.callMethod();
        }
    }
}

Sys (and therefore Sys.Application) is a namespace that comes from the ASP.Net AJAX javascript (file(s) that are added thanks to the ScriptManager that you add to your page). If you use this, you need to be sure that this line Sys.Application.add_load(myOnLoad); runs after the ASP.Net AJAX files load. You can do this a couple of ways:

  1. Add this script lower in the page than the scriptManager.
  2. Move your script into a separate JS file, and use the ScriptManager to load it (recommended).

If you move your script into a separate file, you'll notice that var editor = $find('<% =youreditor.ClientID %>'); no longer works. That is because javascript files do not parse out server tags and replace them with the server side value (as aspx pages do). So the part that is a problem here is <% =youreditor.ClientID %>.

To fix that, here is what you do:

Add this to your aspx markup (in the head section):

<script language="javascript">
    var myEditorId = '<%= youreditor.ClientID %>';
</script>

So it looks something like this:

<head runat="server">
    <script language="javascript">
        var myEditorId = '<%= youreditor.ClientID %>';
    </script>
<title></title>
</head>

(If you are using a Master Page, you'll just add the script tag below the ScriptManager in your page)

And in your JS file, replace this

var editor = $find('<% =youreditor.ClientID %>');

with this

var editor = $find(myEditorId);
半山落雨半山空 2024-08-25 02:26:04

您需要使用 CSS 来执行此操作,因为编辑器控件本身不支持 RTL。以下 CSS 将方向设置为 rtl -

div
{
    direction:rtl;
}

HTML 编辑器的默认样式可以在 Editor.css 文件中找到。

You will need to do this using CSS as the editor control doesn't support rtl natively. The following CSS will set direction to rtl -

div
{
    direction:rtl;
}

The default styles for the HTML editor can be found in the Editor.css file.

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