XUL:XPath in Overlays

From MozillaWiki
Jump to: navigation, search


Currently, overlaid items are inserted by matching ids. The problem with this is that a lot of chrome does not give ids to elements, making it hard to extensions for example to extend the user interface. It also isn't very flexible - what if I want to overlay something to all menus in a document who have more than 5 menuitems?

Bug on this: https://bugzilla.mozilla.org/show_bug.cgi?id=253147


Since we are dealing with XML, it makes sense to have XPath determine the node[s] that we want to overlay onto.

So rather than defining the overlay like this:

 <menu id="help-menu">
   <menupopup id="help-popup">
     <menuitem id="help-xul" label="Help on XUL" />

It could look like this:

 <overlayitem match="//menupopup[@id='help-popup']">
   <menuitem id="help-xul" label="Help on XUL" />

This also seperates the matching part and the new content, making it easier to see what exactly is being added.

Overlays also allow to finetune the position the content is added to by using position/insertbefore/insertafter. Those could also perhaps support XPath, but that might be overkill.

--Doron 08:28, 7 Mar 2005 (PST)

This may also allow multiple applications of a single overlay element. Also, does XPath support something like "first match only"?

--Eyalroz 22:18, 26 April 2006 (PDT)

Items in a node list can be referenced using the [#] predicate (where # is the one-based node index). So to limit the application of the above overlay to only the first matching element you could use:

 <overlayitem match="//menupopup[@id='help-popup'][1]">
   <menuitem id="help-xul" label="Help on XUL" />

insertbefore/insertafter may not be needed because XPath has:


--Mikecaines 23:14, 26 Nov 10 (ADT)