XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently April 19th, 2025, 4:55 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: February 19th, 2018, 2:41 am 
Offline
User avatar

Joined: July 29th, 2013, 9:13 am
Posts: 609
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;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: Bing [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Powered by phpBB® Forum Software © phpBB Group