meuble (owner)

Revisions

gist: 139217 Download_button fork
public
Public Clone URL: git://gist.github.com/139217.git
Embed All Files: show embed
JavaScript #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// An image preloader without using Image class nor document.images
// Built for a Facebook environment where those two are forbiden. May not work in a regular web page.
// Just change
 
function Preloader(options) {
var defaultSettings = {
preloaderID: "preloader_id",
container: document.body
};
 
this.settings = this.extend(defaultSettings, options || {});
this.buildPreloader();
};
 
Preloader.prototype = {
extend: function(destination, source) {
for (var property in source)
destination[property] = source[property];
return destination;
},
 
// Prepare the preloader. Just a IMG html element hidden with css.
buildPreloader: function(preloaderId) {
var image = document.createElement('IMG')
.setId(this.settings.preloaderId)
.setStyle({display: 'none'});
this.settings.container.appendChild(image);
},
 
// Update de src attribute of our hidden tag with the passing url.
// Having the src updated will make the tag to load the image.
preloadPic: function(imageUrl) {
var preloader = document.getElementById(this.settings.preloaderId);
if (preloader) {
preloader.setSrc(imageUrl);
// Don't know why, setting the src make the picture visible.
// Have to hide it again.
preloader.setStyle({display: 'none'});
}
}
 
};