Created
April 17, 2014 13:53
-
-
Save kdimatteo/10985171 to your computer and use it in GitHub Desktop.
Ember Image Cache with ActiveModelSerializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//todo: memory hit with this loop? | |
//todo: check for valid file names (or use a "cacheThisKey" setting in the model?) | |
DS.ActiveModelSerializer.reopen({ | |
createImageCaches: function(hash){ | |
window.imageCache = window.imageCache || []; | |
var imageKeys = ['url', 'photo_url', 'image_url', 'image']; | |
for(var k in hash){ | |
if(imageKeys.contains(k)){ | |
var i = new Image(); | |
i.src = hash[k]; | |
window.imageCache.push(i); | |
} | |
}; | |
}, | |
normalize: function(type, hash, prop) { | |
this.normalizeLinks(hash); | |
this.createImageCaches(hash); | |
return this._super(type, hash, prop); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment