0

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

The dialog of the plugin.

我具有由设置在按钮上一个onclick问题

,其他值是很好的设定。

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

var extraClasses = event.extraClasses; 

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

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

有没有人知道我在做什么错,我该如何解决这个问题?

创建按钮后,它被添加到编辑器SeamlessField中。我现在有的第二个问题是,在创建按钮后,我的指针位于按钮内部,我似乎无法将它移出。

Created button.

我有如下一段代码在那一刻处理这个。 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(); 

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

回答

1

首先,它看起来不像您已开始使用Google Closure事件代码。按钮接线,在谷歌关闭了“click”事件将如下所示:

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

你也应该调查goog.domgoog.dom.classes命名空间,如果你想使用围绕标准的CSS谷歌封闭的包装类和文本DOM操作。


对于第二,你在Chrome中测试?如果是这样,你可能已经遇到了在Webkit的一系列问题,关闭代码本身中记载: https://code.google.com/p/closure-library/source/browse/closure/goog/editor/range.js#174

我已经插入一个空<span>元素作为出错的元素后,兄弟(在解决此得到过去按钮,在你的情况下),并将光标放在<span>旁边。但是,没有什么能阻止用户将光标移回到按钮中。您必须添加更多逻辑来防止用户将光标放置在按钮的文本中。

相关问题