These Forums Are Going Away!

These forums are currently read-only, but will be going away entirely in mid-august. All active discussion has moved elsewhere. Visit the Songbird Developers Google Group for developer topics, and Get Satisfaction for everything else.

XBL and <observes>

Hello,

another problem here :-(.
I'm in love with the "sb-player-*-button" solution, because it implements stack of buttons and uses observers to manage them. I love this solution because in the css i set the image property for "on and off" button so I don't need to change this property via Dom when the button changes its state.

I tried to implement this solution creating a brand new button to manage a filter/nofilter button I've created, but "sb-player-*-button" use the "dataremote" observer type and i coldn't use it because (obviously) there's no dataremote to bind when mediaPage changes.

I decided to use a classical broadcaster/observer solution but i needed to write my own observer to implement the "inverted" attribute like in the dataremote type.

In the logic I hide one of the buttons so the other is shown, it works when Songbird runs the first time but when i register the observer to the broadcaster:


this._broadcaster = document.getElementById(this.getAttribute("broadcaster_id"))
this_broadcaster.addEventListener("DomAttrModified",onChange,false)

when the event is fired i lose the control over the object and all previuos reference, so i couldn't access the broadcaster or the parentNode of the observer anymore, and i couldn't switch the hidden attribute of buttons, so nothing works.

The implementation is very similar to the one provided by the implementation of sb-player-shuffle-button and observes type="dataremote", so I don't think it's necessary to paste my source code.

Thank you

Matt Says:   

Hi Ventuno,

Cool!

Let me make sure I understand the problem:

* Regular tag, updated by some code that monitors the media page
* New that monitors a broadcaster element
* Two-state button that shows/hides using the new observer

Sounds like it should work.

What do you mean "lose control"? Have you tried stepping through it with the JS debugger?

I think I'll need to see some of the code or try running it to be of any help. Can you drop by irc.mozilla.org#songbird (via http://wiki.songbirdnest.com/Developer_Center/Articles/Advoc... if you like) or send me a link to some code in http://pastebin.mozilla.org/?

ventuno Says:   

The most part of the code is (of course) a copy-paste of the observes type="dataremote".
There are some parts I don't use but I decided to keep them in the source.

observes type="two-state"

mediapages-button

I had to create the "elem" attribute because if I use the traditional "element" the observes works just like a common observes and ignores other attributes.
As you can see the code to change the mediapage from "playlistPage.xul" to "playlistPage.xul?useFilters=true", isn't embedded yet, but i was writing the code step by step and trying to make the show/hide two state button work first.
(The code is written and works very well for a toggle button wich changes it's background image/label via Dom).

What's going wrong is that the first time the code runs (when songbird starts), the alert shows me the value of the "elem" attribute, but when I run the change() method (clicking on the stack) the DomAttrModified event is fired but the alert is empty (""), trying to access to other elements it returns "undefined" or similar.

Sorry for my buggy english, 21.

ventuno Says:   

I met Matt days ago on the songbird channel on irc.mozilla.org, we had a conversation and he solved my problem, here's the solution.

What happens is that using


this._broadcaster.addEventListener('DOMAttrModified',this.onDataChanged, false)

passes only the onDataChanged() function and not the entire object (due of js interpretation of "this").
There are two solutions, the first:

var element = this;
broadcaster.addEventListener("DOMAttrModified", function() { element.onDataChanged() }, true)

and the second:

broadcaster.addEventListener("DOMAttrModified", this, true);

and implement the handleEvent() method in the object wich need this:

<implementation type="application/x-javascript" implements="nsIDOMEventListener">

to work correctly.

He also gave me this links, very useful for me:

http://hq.songbirdnest.com:8080/source/
http://lxr.mozilla.org/mozilla/
http://developer.mozilla.org/en/docs/A_re-introduction_to_Ja...

Sorry for my buggy english, 21.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Keep me posted!

Sign up to be notified of new releases & important updates.


Get a Songbird Tshirt

Songbird Buttons


Get Songbird
Get Songbird
Get Songbird
Get Songbird


More buttons for your blog...