ボタンがクリックされるたびにマウスクリック(マウスアップ)座標を警告する単純な拡張機能を作成しようとしています。(学習の試み)
拡張機能は正常に機能しており、1つの不具合を除いて正しくセットアップされています。
私のXULファイル:
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin/" ?>
<?xml-stylesheet type="text/css"
href="chrome://mouseclick/skin/mouseclick.css" ?>
<!DOCTYPE overlay SYSTEM
"chrome://mouseclick/locale/mouseclick.dtd">
<overlay id = "overlay-id" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript"
src="chrome://mouseclick/content/mouseclick.js" />
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id="mouseclick-button" class="mouseclick-class"
label="&button.label;" tooltiptext="&tooltip.text;"
oncommand = "mouseClick.display();"/>
</toolbarpalette>
<toolbar id="nav-bar">
<toolbarbutton id="mouseclick-button" class="mouseclick-class"
label="&button.label;" tooltiptext="&tooltip.text;"
oncommand = "mouseClick.display();"/>
</toolbar>
</overlay>
私のJSファイル:
if(mouseClick === undefined) {
var mouseClick = {
_x : "not yet clicked" ,
_y : "not yet clicked"
};
}
mouseClick.handler = function(e) {
var x = e.pageX !== undefined ? e.pageX : e.clientX;
var y = e.pageY !== undefined ? e.pageY : e.clientY;
/*A TEST ALERT
alert("(" + x + ", " + y + ")"); // a dummy command for testing
*/
this._x = x;
this._y = y;
};
mouseClick.display = function() {
alert("(" + this._x + ", " + this._y + ")");
};
window.addEventListener("mouseup", mouseClick.handler, false);
この問題は、ドキュメント内の任意の場所、または拡張ボタン以外のウィンドウ内の任意の場所をクリックすると、TESTalertコマンドが正しい座標を警告します。
ただし、ボタンをクリックすると(アラートコマンドを再度トリガーするため)、最初のTESTアラートは正しい座標を返します。
しかし、メインアラート、アラート(not yet clicked, not yet clicked)
。
mouseClick
拡張機能のボタンをクリックするたびにオブジェクトがリセットされるのはなぜですか?