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>旁邊。但是,沒有什麼能阻止用戶將光標移回到按鈕中。您必須添加更多邏輯來防止用戶將光標放置在按鈕的文本中。

相關問題