There are incompatibilities in .indexOf method and the handling of arrays in Microsoft JScript and ECMA javascript - these incompatibilities should be noted as they will have an impact on your javascript code.
I'm not raising this as a bug for Tony to fix it is just something to be noted.
The indexOf() method returns the position of the first occurrence of a specified value in a string.
The ECMA standard javascript allows you to use the indexOf() method on an array so you can search for the occurrence of a string in several array elements.
Code:
var validTypes = [".mpeg", ".mp4", ".mpg", ".flv"];
if (validTypes.indexOf(xtn(filename)) === -1) {
alert("incompatible file type");
} else {
dprint("fileName " + fileName);
// do something
PlayFile(fileName);
}
Unfortunately, JScript arrays have no .IndexOf() method so validTypes cannot be an array of valid suffixes, we have to use our own home-grown validate_filetype function instead.
Code:
var validTypes = ["mpeg", "mp4", "mpg", "flv"];
if (validate_filetype(fileName,validTypes) === true ) {
dprint("fileName " + fileName);
// do something
PlayFile(fileName);
} else {
alert("incompatible file type");
}
Code:
function validate_filetype(fileName,allowed_extensions)
{
for(var i = 0; i < allowed_extensions.length; i++)
{
dprint("allowed_extensions[i] "+ allowed_extensions[i]);
if(allowed_extensions[i]==file_extension.toLowerCase())
{
dprint("return true");
return true; // valid file extension
}
}
//dprint("return false");
return false;
}