Ext.menu.Menuインスタンスを呼び出すときに、現在選択されているテキストをDOMから取得しようとすると、現在問題が発生しています。ここに簡単な例を示します。
- 以下のEXTJサンプルを含む標準のHTMLページからテキストを選択して強調表示します
- 右クリックしてコンテンツメニューを呼び出します
- 選択は、コンテキストメニューにバインドされたイベントリスナーから利用できますが、コンテキストメニューからオプションを入力または選択する場合は利用できません。
注:サンプルは現在、コンソールオブジェクトのため、ChromeとFirefoxで動作します
Ext.onReady(function() {
// Context Menu
var menu = Ext.create('Ext.menu.Menu', {
items : [{
text : 'Copy',
handler : function() {
// Selection is not available here
console.log("On Context menu item:" + window.getSelection().toString());
}
}],
listeners : {
mouseenter : function() {
// Selection is not available here
console.log("Enter menu render: " + window.getSelection().toString());
},
activate : function () {
// Selection is still available
console.log("Activate Context menu render:" + window.getSelection().toString());
}
}
});
// Bind to contextmenu event listener
Ext.getDoc().on('contextmenu', function(ev) {
menu.showAt(ev.getXY());
ev.stopEvent();
// Selection is available
console.log("On Context menu :" + window.getSelection().toString());
});
});