Web Development with jQuery®

(Elliott) #1

(^364) ❘ CHAPTER 14 SELECTABLE
The following JavaScript makes it possible to select multiple fi les at once by drawing a box.
$.fn.extend({
selectFile : function()
{
this.addClass('finderSelected');
this.each(
function()
{
if ($.inArray($(this), finder.selectedFiles) == -1)
{
finder.selectedFiles.push($(this));
}
}
);
return this;
},
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;
}
});
var finder = {
selectingFiles : false,
selectedFiles : [],
unselectSelected : function()
{
if (this.selectedFiles instanceof Array && this.selectedFiles.length)
{
$(this.selectedFiles).each(
function()
{
$(this).unselectFile();
http://www.it-ebooks.info

Free download pdf