Drag and Drop to reposition FoxyTunes

About

FoxyTunes is an extension which allows you to control any media player from within the browser.

This article describes a technique that allows the user to interactively reposition the FoxyTunes widget anywhere in the browser using Drag and Drop.

It doesn't go deep into the exact technical details, but is more like a guided tour of the FoxyTunes repositioning code which is open.

The need

In the first public version of FoxyTunes, the widget was positioned on the status bar. Its position was to the left of the "Updates" panel and couldn't be changed.

I received a few requests from people that wanted to be able to reposition the FoxyTunes widget on the status bar. They pointed me to the excellent WeatherFox extension that allowed this.

In the WeatherFox options dialog, there are two combo-boxes - one for the main position of the widget (status bar, toolbar etc.) and one for the exact position (to the left of the "Updates" panel, to the right of the main menu etc.).

I loved the idea, but wanted to make this process more interactive and user friendly. Naturally, drag and drop came to mind.

First steps

Mozilla has a very good support for drag and drop. Basically elements can register to events that signal that the user has started the drag, that the element is being dragged over other element and then dropped.

These events are: draggesture, dragover, dragenter, dragexit and dragdrop.

The idea is: FoxyTunes widget registers for the draggesture event that signals drag start. It also registeres all its potential targets (status bar, toolbars etc.) for the other events.

Starting the drag session

FoxyTunes has an element which has a ondraggesture event handler defined. When the user starts dragging this element, the event handler does the following:

  1. It installs the dragover, dragexit and dragdrop events for all the elements that can host the FoxyTunes widget. This includes the status bar and all the toolbars/toolboxes (all the toolboxes can be found using the document.getElementsByTagName('toolbox') command).
  2. It starts the drag and drop session.

During the session

When the user drags the FoxyTunes widget over one of its valid targets, its ondragover event handler gets called. The event handler checks which specific child element is being dragged over and marks this element with a red line, so the user can see where exactly the widget will be positioned if he releases the mouse button. This element is remembered in a global variable for exactly that case.

When the mouse leaves an element the dragexit event handler gets called. All it does in this case is to clear the active target mark set by the ondragover event handler.

When the user finally releases the mouse button over a valid target, the ondragdrop event handler gets called. The handler checks which element got the event so it knows before or after which element to insert the FoxyTunes widget. The parent of this element should be a status bar or a toolbar and it should become the new parent of FoxyTunes.

Now we have all the information needed to reposition the FoxyTunes widget. First, foxytunesWidget.parentNode.removeChild(foxytunesWidget) is used to remove FoxyTunes from its previous parent. Then, something like newParentElement.insertBefore(foxytunesWidget, insertBeforeElement) can be used to insert it to its new position.

At this stage we can remove the event handlers we registered for the potential drop targets.

Final touches

From now on, we want FoxyTunes to appear at its new location. To achieve this, we remember the two elements we got in the drop event handler - the new parent and the new sibling element that FoxyTunes will appear before. Every time FoxyTunes is started, it is removed from its default location and inserted into its new saved location.

Another problem I've encountered is that the FoxyTunes widget is in fact a statusbarpanel element, and when dragged to the toolbox it can be rendered incorrectly with some themes. To solve this, I use a little DOM programming to re-wrap FoxyTunes in a toolbaritem element.

Links and Resources


Get Firefox

Comments

Jose Mesquita wrote:
Help me.
I have been trying to see some clips in my
ISP homepage "http://www.sapo.pt/" but I couldn't.
Javaconsole tels me this:

Warning: Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
Source File: http://xl.sapo.pt/mframe_video.html?cid=Xz00100&mid=1&arid=516027&p=index.html
Line: 24


Error: Player.controls has no properties
Source File: http://xl.sapo.pt/mframe_video.html?cid=Xz00100&mid=1&arid=516027&p=index.html
Line: 25

I am a novice in Firefox and Foxy Tunes.

I am portuguese and my english istn't very good.
Grateful if You can help me.

Jose Mesquita
09-Oct-2004 19:25:25

Neil Phillips wrote:
Just installed Firefox 1.0 - drag'n'drop of FoxyTunes appears to have broken?!
10-Nov-2004 06:27:08

anonymous wrote:
Sorry it does work - finger trouble!! Keep up the good work with Foxytunes!
10-Nov-2004 06:31:58

NiTiN wrote:
after i reposition the foxytunes player to a spot i desire, it just won;t stay there after a restart of firefox... because after a restart the player is back on it's 'old' spot(where i DON't want it...)

what could cause this kind of thing, and, more important, how can it be fixed?
26-Nov-2004 16:09:42

Michael wrote:
Great Program! See if you can come up with visulizations like Window Media Player or Real Player. That would be cool. Great Job on this program. I rate it 9/10!
13-Feb-2005 15:47:48

MissM wrote:
I realize that the new firefox is beta (v1.5 Beta 1) ..... When I opened firefox after upgrading, foxy tunes ended up in the right hand corner, I tried to drag it to the menu bar (beside Help) and the icon disappearred, but the arrows stayed in the bottom right corner.. I realize its a firefox issue, but I wanted to give you a heads up, on the issue. I LUV Fox Tunes!!!!!
09-Sep-2005 06:59:07

ez2055 wrote:
HOW CAN I REMOVE FOXY TUNES FROM MY COMPUTER!
12-Nov-2005 22:27:29

JT RYAN wrote:
I changed Foxy Tunes from status bar to toolbar (did Toolbars\customize\add new toolbar then dragged FT from status bar to new toolbar). Every 20 mins or so FT shifts back into the status bar. Why and fix to keep permanently in toolbar?

Thanks
05-Dec-2005 18:42:16

JKForde wrote:
Hi, si there any way of repositioning the navigation toolbar to the right of the menu toolbar - i have a lot of empty space on the menu toolbar and just want to free up some vertical space!

thanks
08-Feb-2006 11:29:25

anonymous wrote:
how do I uninstall foxy tunes from my computer. It states: Mozilla FireFox does not support a Netscape format
17-Apr-2006 16:51:31

Colin wrote:
Good design!
http://dlsrhqqm.com/pbze/jxvk.html | http://elldgtcs.com/cbbl/mrwu.html
24-Sep-2006 09:28:53

anonymous wrote:
http://www.iosart.com/firefox/foxytunes_articles/dragAndDropReposition.html
FoxyTunes - Drag and Drop to reposition
02-Apr-2007 13:14:05

Janice wrote:
how to uninstall foxy? COz my foxy can't read Chinese words. that's useless for me. I am in Toronto and my computer was bought in Toronto either. WHat can i do ?
24-Nov-2006 03:53:27

sosta wrote:
need foxy t6unes in english
13-Jan-2007 19:33:16

dobias wrote:
Need instructions to remove foxy tunes.
27-Feb-2007 15:50:26
Comments closed