XUL 文本框的自定义 onsynctopreference
我想在我的 Firefox 扩展中启用自定义快捷方式。这个想法是,用户只需关注文本框,按下组合键,它就会显示在文本框中并保存到首选项中。但是,我无法让它发挥作用。有了这个 XUL,
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://mozapps/skin/pref/pref.css" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://nextplease/locale/nextplease.dtd">
<prefwindow id="nextpleaseprefs" title="&options.title;" buttons="accept, cancel"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<prefpane id="nextplease.general" label="&options.general.title;" image="chrome://nextplease/skin/Sound Mixer.png">
<preferences>
<preference id="nextkey" name="nextplease.nextkey" type="int"/>
</preferences>
<vbox flex="1">
<hbox align="center">
<label value="&options.general.nextKey;" />
<textbox id="nextkey" flex="1" editable="false"
onkeyup="return nextplease.handleKeySelection(this, event);"
preference-editable="true" preference="nextkey"
onsynctopreference="alert('syncing'); return nextplease.syncKeySelector(this);"/>
</hbox>
</vbox>
</prefpane>
<script type="application/x-javascript" src="chrome://nextplease/content/nextpleaseCommon.js" />
<script type="application/x-javascript" src="chrome://nextplease/content/nextpleaseOptions.js" />
</prefwindow>
onkeyup
中的事件就可以工作了。但是,当我单击“确定”按钮时,我没有看到“正在同步”警报。为什么 onsynctopreference
不起作用?文本框是否不可能具有自定义 onsynctopreference
属性?
I wanted to enable custom shortcuts in my Firefox extension. The idea is that the user just focuses on a textbox, presses key combination, and it's shown in the textbox and saved to a preference. However, I couldn't get it to work. With this XUL
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://mozapps/skin/pref/pref.css" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://nextplease/locale/nextplease.dtd">
<prefwindow id="nextpleaseprefs" title="&options.title;" buttons="accept, cancel"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<prefpane id="nextplease.general" label="&options.general.title;" image="chrome://nextplease/skin/Sound Mixer.png">
<preferences>
<preference id="nextkey" name="nextplease.nextkey" type="int"/>
</preferences>
<vbox flex="1">
<hbox align="center">
<label value="&options.general.nextKey;" />
<textbox id="nextkey" flex="1" editable="false"
onkeyup="return nextplease.handleKeySelection(this, event);"
preference-editable="true" preference="nextkey"
onsynctopreference="alert('syncing'); return nextplease.syncKeySelector(this);"/>
</hbox>
</vbox>
</prefpane>
<script type="application/x-javascript" src="chrome://nextplease/content/nextpleaseCommon.js" />
<script type="application/x-javascript" src="chrome://nextplease/content/nextpleaseOptions.js" />
</prefwindow>
the event in onkeyup
works. But when I click the OK button, I don't see a "syncing" alert. Why isn't onsynctopreference
working? Is it impossible to have custom onsynctopreference
attribute for a textbox?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎很简单,首选项仅在
input
事件(也许还有其他一些事件)上同步,但在keyup
上不同步。It seems the problem was simply that preferences are only synchronized on
input
event (and maybe some others), but not onkeyup
.