Class Flavor

Defined in flavors.js

Working with Javascript on the web is famous for browser inconsistencies, to the point where a lot of people think they "hate Javascript" when what they really hate is the inconsistencies across browsers.

XBLinJS has it even worse; not only does it want to work across browsers in the conventional sense, it also wants to work in Mozilla with XUL, and even in non-browser things that use ECMAScript, like Flash, anything that uses the same general DOM event model. This makes merely programming cross-browser look like a piece of cake.

XBLinJS addresses this issue by creating several "flavors" of XBLinJS, as defined in this file. These flavors provide methods that the Widget class uses to perform its work, and does other things like managing constants. (For instance, the Browser flavor of XBLinJS has constants for determining what browser it is running in, whereas the XUL flavor has no need of that, but it may have other constants it wants to use.)

The documentation for this class lays out the complete set of things a Flavor can change, which you should change in sub-classes to create new flavors. If you find that you need things that aren't already in Flavor specifications, please mail the development list on Sourceforge and I will be happy to work with you to pull the additional things out.

This is a reverse template pattern, based on the way Javascript can dynamically choose a super-class to inherit from; this allows you to inherit from Widget, which is cleaner and simpler thing to do than constantly inheriting from "BrowserFlavor", and also means you can switch out flavors without affecting the rest of your code. (Odds are you'll never want to switch from Browser to Flash, but you may want to swap to a browser-specific flavor based on some criteria computed at run time.)

One of the design requirements is that you can leave in extra flavors without causing any errors, so many computations must be wrapped up in functions that will only be executed if that flavor is used. For example, the Browser flavor has constants based on the navigator.userAgent string, but other ECMAScript environments may not have this available at all, requiring either convoluted "if" statements or deferred execution. We have to protect that from execution until we know what environment the user desires. Your own flavors, of course, may do as they please.

This is a "virtual class"; the methods named here are more for the documentation opportunity than the implementation value. When you override these, you do not need to call the superclass, EXCEPT if you happen to override .init, which should generally be called before your own .init, in case you want to override it.

(Note if you're going to create another Flavor that uses real XML like XUL does, it may be good to drop me a line and ask me to extract the XML support into a superclass that you can use without getting the XUL support in the way, such as the event handling.)


Field Summary
 Object flavorConstants
          Constants defined by this flavor.
 Object flavorFixups
          code to run when a flavor is resolved for use
 
Constructor Summary
Flavor ()
            Define a "flavor" of XBLinJS.
 
Method Summary
 void attachHandlerToNode(node, event, handler)
           attaches an event handler to a DOM node
 void createElement(nodeType)
           creates a DOM node
 void getAttributeFrom(node, key)
           Get an attribute from a node, be it Widget or DOM node.
 void getElementsByTagName(tagName, node)
           Wraps the getElementsByTagName, because it can be either document.getElementsByTagName or document.getElementsByTagNameNS.
 void initData(atts)
           copies all constants onto the object
 void setAttributeOn(node, key, value)
           set an attribute on something, either DOM node or Widget

Field Detail

flavorConstants

Object flavorConstants

flavorFixups

Object flavorFixups

Constructor Detail

Flavor

Flavor()

Method Detail

attachHandlerToNode

void attachHandlerToNode(node, event, handler)

createElement

void createElement(nodeType)

getAttributeFrom

void getAttributeFrom(node, key)

getElementsByTagName

void getElementsByTagName(tagName, node)

initData

void initData(atts)

setAttributeOn

void setAttributeOn(node, key, value)


Documentation generated by JSDoc on Tue May 3 17:16:26 2005