Closed
Bug 619897
Opened 14 years ago
Closed 14 years ago
widgets’ onClick property doesn’t forward the event to the function
Categories
(Add-on SDK Graveyard :: General, defect)
Tracking
(Not tracked)
RESOLVED
INVALID
People
(Reporter: flying-sheep, Unassigned)
Details
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13 Build Identifier: i try to get my widget to perform different actions based on the mouse button they are clicked with like so: `if (evt.button === 0) console.log("left button");`. it didn’t work. then i read somewhere that event handlers in the addon sdk give back the widget as first argument, so i tried the following: require("widget").Widget({ label: "", content: "-", onClick: function(w, evt) { console.log(w, evt); } }); when i run this code, however, i get “info: null undefined”, which means, as far as i understand javascript, that only one value is passed in the function, which is “null”. this means that there is a bug in the sdk, which doesn’t give to the onClick handler the click event, but “null” instead. Reproducible: Always
Reporter | ||
Comment 1•14 years ago
|
||
oh, and i tried this with firefox 4.0b7, not with the 3.6 i’m writing this report with. sorry.
Comment 2•14 years ago
|
||
This is intentional in the latest version of the Jetpack SDK. It is required in order to have Jetpack add-ons be able to run outside the main Firefox process. Some info is here: https://wiki.mozilla.org/Labs/Jetpack/Release_Notes/1.0b1#Electrolysis. Instead, you can have a "content script" run in the context of the widget content, that handles click events and passes the relevant information back to your add-on. I wrote a blog post about this here: https://autonome.wordpress.com/2010/11/23/upcoming-changes-to-the-jetpack-widget-api/.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
So, with help from Dietrich's links, I managed to get this working, and thought I'd share my code with anyone who looks at this bug in the future. Here's part of my addon's main.js file: http://pastebin.mozilla.org/908365 It sets up two panel elements and a widget. One of the panel elements is attached directly to the widget. Here's the widget's content script: http://pastebin.mozilla.org/908366 It adds a click event listener to the widget, which can then get information about the click event. It then sends back the event's information to the addon, which then opens the connected panel (though not really "connected" due to bug 616160...) on a left click, and opens the unaffiliated widget on right click (or Shift-Left-click, for our one-mouse-buttoned brethren :) ).
You need to log in
before you can comment on or make changes to this bug.
Description
•