Web Development with jQuery®

(Elliott) #1

(^74) ❘ CHAPTER 3 EVENTS
.removeClass('finderIconSelected');
$('span.finderDirectoryNameSelected')
.removeClass('finderDirectoryNameSelected');
$('span.finderFileNameSelected')
.removeClass('finderFileNameSelected');
$(this).find('div.finderIcon')
.addClass('finderIconSelected');
$(this).find('div.finderDirectoryName span')
.addClass('finderDirectoryNameSelected');
$(this).find('div.finderFileName span')
.addClass('finderFileNameSelected');
}
);
The event handler is given some new code to deal with the semantics of having fi les in addition to
directories.
$('div#finderFiles div.finderNode:first')
.trigger('click');
The event is triggered on the fi rst

element with the class name finderNode.
Next, you set up a variable to keep track of whether the additional fi les have been added to the
entire collection of fi les and folders, which tests whether an element has to exist for a persistent
event handler to get applied.
var addedAdditionalFiles = false;
Technically, these new elements do exist in the DOM, but they do not exist within the
element
that acts as a container for directory and fi le nodes, and thus, the requisite events associated with
fi le and directory nodes are not yet applied.
$('body').dblclick(
function()
{
if (addedAdditionalFiles)
{
return;
}
$('div#finderAdditionalFiles > div.finderFile').each(
function()
{
$('div#finderFiles').append(
$(this).clone()
);
}
);
http://www.it-ebooks.info