Reference Guide

facebook FBML Reference Guide Page 151 of 159
Textbox selections have been implemented with the methods getSelection and setSelection. getSelection returns
an object with properties start and end which correspond to the W3C-style attributes selectionStart and
selectionEnd. setSelection takes two arguments, start and end (optional). This abstraction was added because
Internet Explorer does not support selectionStart and selectionEnd. Since it is quicker in IE to retrieve both
values together, they were coupled together into a single getter and setter. This function should work the same in
all browsers with no extra work from you.
Creating FBML Elements
You can also use createElement to create FBML elements, although this is currently limited to fb:swf. Once it's
created, it works just like any other DOM object does, however, once it is attached to the DOM you cannot
move it and obj.getElementsByTagName('fb:swf') does not work.
var newSwf = document.createElement('fb:swf');
Events
Events can be added to FBJS DOM objects using the W3C-style addEventListener method. The third parameter,
useCapture, is not supported. removeEventListener is also supported. In addition to the W3C event methods,
we've also added listEventListeners and purgeEventListeners.
listEventListeners(eventName)
Returns an array of handles of all events that have been added to this event. Events that were added in FBML
using the on<event> attributes will also be included
purgeEventListeners(eventName)
Removes all event listeners for a given event. This also removes events that were added as attributes in FBML.
Event handlers are called with one parameter, which is an object with information about the event. In the case of
event handlers added as attributes, this object will be accessible through the "event" variable (just as it is in
regular JavaScript). The event will have attributes target, type, pageX, pageY, ctrlKey, keyCode, metaKey, and
shiftKey. It also implements two methods:
stopPropagation
Prevents this event from propagating to any more elements further up in the DOM.
preventDefault
Cancels the default behavior of this event without stopping propagation. For instance, preventDefault on an
onfocus event will prevent that element from getting focus.
getId on event object of a listener function
When using the getId() method inside an event listener function on the event object, the following syntax may
be used to retrieve the ID of the object that fired the event:
<div id="firedByDescription"></div>
<div id="foo"></div>
<div id="bar"></div>
<script>
//disclaimer: sample code block meant only to demonstrate functionality
function myEventHandler(evt) {
//we'll use this div later to drop stuff into it
firedByDescription = document.getElementById('firedByDescription');
if (evt.type == 'mouseout') {
//if the event is a mouseout, empty out the description div, and exit the event listener
www.yapish.com