This project is archived and is in readonly mode.

#284 ✓resolved
Olivier

Asset.images improvement

Reported by Olivier | March 16th, 2010 @ 03:27 PM | in 1.2.5.1

Hi,

On Asset.images, the index returned by the onProgress method is not correct if you have several times the same image source passed.
This often happens when you have for default image for profil, ...

I think the class could be improved.
The object don't need to recalculate the index with sources.indexOf(source) since you can directly ask it earlier in the map function.
Like that, it should be a bit faster and more accurate. See the changes in the code below :

var Asset = {
    // code for javascript, css ...
    images: function(sources, options){
        options = $merge({
            onComplete: $empty,
            onProgress: $empty,
            onError: $empty,
            properties: {}
        }, options);
        
        sources = $splat(sources);
    
        var images = [];
        var counter = 0;
    
        return new Elements(sources.map(function(source, index){ // index parameter added
            
            return Asset.image(source, $extend(options.properties, {
                
                onload: function(){
                    options.onProgress.call(this, counter, index); // use index instead of sources.indexOf(source)
                    
                    counter++;
                    if (counter == sources.length) options.onComplete();
                },
                
                onerror: function(){
                    options.onError.call(this, counter, index); // use index instead of sources.indexOf(source)
                    
                    counter++;
                    if (counter == sources.length) options.onComplete();
                }
            }));
        }));
    }
};

Let me know, if it is correct...

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The MooTools Extensions

People watching this ticket

Pages