Introducing the Selectable Plugin (^) ❘ 369
unselectFile : function()
{
this.removeClass('finderSelected');
var files = this;
if (finder.selectedFiles instanceof Array && finder.selectedFiles.length)
{
finder.selectedFiles = $.grep(
finder.selectedFiles,
function(file, index)
{
return $.inArray(file, files) == -1;
}
);
}
return this;
}
});
The unselectFile() method then returns the fi les that were unselected so that you can potentially
chain method calls together.
You next set up a new object called finder.
var finder = {
The property finder.selectingFiles is used to keep track of whether a selection of fi les is presently
underway using the Selectable plugin. The default value is set to false to indicate that there is no
selection of fi les underway.
The property finder.selectedFiles contains an empty array by default. As you saw with the jQuery
plugins selectFile() and unselectFile(), when one or more fi les are selected, a reference to each
selected node is stored in the selectedFiles property.
selectingFiles : false,
selectedFiles : [],
The method unselectSelected() unselects every fi le node that is presently selected, and then the
property is reset to an empty array. This method is simply a quick and easy way to unselect every fi le.
unselectSelected : function()
{
if (this.selectedFiles instanceof Array && this.selectedFiles.length)
{
$(this.selectedFiles).each(
function()
{
$(this).unselectFile();
}
);
}
http://www.it-ebooks.info
elliott
(Elliott)
#1