suhaibkhan / messageResource.js

Javascript library for loading and using message resource property files.
MIT License
22 stars 22 forks source link

Problem with Internet Explorer 8 #6

Closed DanieleAlessandro closed 9 years ago

DanieleAlessandro commented 9 years ago

Hi there, I used messageResource in a project and I recently found out that it doesn't work in Internet Explorer 8. I also found where the problem is: in the init method square bracket are used to read a character in a particular position inside a string. Old versions of IE don't support this syntax. The correct way to do that should be the charAt method of strings: http://www.w3schools.com/jsref/jsref_charAt.asp

The code for init method should be changed in this way:

            init : function(config){

                config = config || {};

                // append '/' to file path if not exists
                filePath = config.filePath || '';
                if (filePath && filePath.charAt(filePath.length - 1) !== '/'){
                    filePath = filePath + '/';
                }

                // prepend '.' to file extension if not exists
                fileExtension = config.fileExtension || DEFAULT_EXTENSION;
                if (fileExtension.charAt(0) !== '.'){
                    fileExtension = '.' + fileExtension;
                }

                // configure default locale
                config.defaultLocale = getValidLocale(config.defaultLocale);
                defaultLocale = config.defaultLocale;
                currentLocale = config.defaultLocale;

                // configure file name resolver
                fileNameResolver = config.fileNameResolver || defaultFileNameResolver;

                // custom ajax function
                ajaxFunction = config.ajaxFunction || ajaxGet;

                // enable or disable debug mode
                debugMode = config.debugMode || false;

                // all configurations are valid
                validConfiguration = true;
            },
DanieleAlessandro commented 9 years ago

I found out other similar problems with IE: even the save function use square brackets on a string:

if (line === '' || line[0] === '#'){ 

Another problem is the use of the trim method of strings. It isn't supported by IE, it should be defined. Here you can find some information: http://stackoverflow.com/questions/2308134/trim-in-javascript-not-working-in-ie

suhaibkhan commented 9 years ago

Updated IE compatibility issue fixes in the code.