0

我正在为 Google Closure 提供的编辑器制作自定义插件。该插件使其能够添加一个按钮。

插件的对话框。

我通过在按钮上设置 onclick 遇到问题,其他值设置得很好。

button.innerHTML = event.label;
button.className = event.initialClass;

var extraClasses = event.extraClasses;

if (extraClasses)
{
    button.className += ' ' + extraClasses
}

button.onclick = function() { event.onclick };

有谁知道我做错了什么以及如何解决这个问题?

创建按钮后,它被添加到编辑器SeamlessField。我目前遇到的第二个问题是,在创建按钮后,我的指针在按钮内,我似乎无法将其从那里取出。

创建按钮。

我现在有以下代码来处理这个问题。var 按钮是创建的按钮。按钮包含:<button class="orange">test</button>

// We want to insert the button in place of the user's selection.
// So we restore it first, and then use it for insertion.
this.restoreOriginalSelection();
var range = this.fieldObject.getRange();
button = range.replaceContentsWithNode(button);

// Done making changes, notify the editor.
this.fieldObject.dispatchChange();

// Put the user's selection right after the newly inserted button.
goog.editor.range.placeCursorNextTo(button, false);

// Dispatch selection change event because we just moved the selection.
this.fieldObject.dispatchSelectionChangeEvent();

关于如何解决第二个问题的任何想法?

4

1 回答 1

1

首先,您似乎还没有开始使用 Google Closure 事件代码。将按钮连接到 Google Closure 中的“点击”事件如下:

goog.events.listen(button, goog.events.EventType.CLICK, event.onclick)

如果您想使用 Google Closure 围绕标准 CSS 类和文本 DOM 操作的包装器,您还应该研究goog.dom和命名空间。goog.dom.classes


其次,您是否在 Chrome 中进行测试?如果是这样,您可能在 Webkit 中遇到了范围问题,记录在 Closure 代码本身中: https ://code.google.com/p/closure-library/source/browse/closure/goog/editor/range.js第174章

过去,我通过在有问题<span>的元素(在您的情况下为按钮)之后插入一个空元素作为兄弟元素,并将光标放在旁边来解决这个问题<span>。但是,没有什么可以阻止用户将光标移回您的按钮内。您必须添加更多逻辑以防止用户将光标放在按钮的文本中。

于 2013-08-07T17:56:53.723 回答