5
<title>RequireJS image plugin</title>
6
<meta name="viewport" content="width=device-width, initial-scale=1">
10
<h1>RequireJS image plugin</h1>
11
<p>Note that <code>waitSeconds</code> should be large enough to load all the images, otherwise module may timeout.</p>
12
<p>Use this plugin only on specific cases and make sure you set a large <a href="http://requirejs.org/docs/api.html#config">waitSeconds</a> (default is 7 seconds).</p>
15
<li>Image paths are relative to the HTML file by default.</li>
16
<li>Support absolute paths as well.</li>
17
<li>Appending <code>!bust</code> to the file name will avoid caching the image.</li>
18
<li>Appending <code>!rel</code> to the file name will load image realtive to baseUrl or module path.</li>
19
<li>It will always return the same image object unless you use the <code>!bust</code> flag, so you may need to clone the image element before inserting it multiple times into the same document.</li>
23
<script src="../lib/require.js"></script>
26
waitSeconds : 45, //should be enough to load images
28
image : '../src/image' //alias to plugin
33
'image!img/lol_cat.jpg',
34
'image!http://30.media.tumblr.com/tumblr_lgd1neNYSL1qbwkzvo1_500.jpg',
35
'image!img/bike.jpg!bust',
36
'image!img/bike.jpg!bust',
37
'image!img/lol_cat.jpg',
39
], function(cat, awesome, bike1, bike2, sameCat, relative){
40
var wrapper = document.getElementById('wrapper');
42
//add loaded images to the document!
43
//returns an Image object..
44
wrapper.appendChild(awesome);
45
wrapper.appendChild(cat);
47
//requireJS will return same image object unless you use `!bust`
49
var sameBike = document.createElement('div');
50
sameBike.innerHTML = 'Is same bike cat? : '+ (bike1 === bike2);
51
wrapper.appendChild(sameBike);
53
wrapper.appendChild(bike1);
54
wrapper.appendChild(bike2);
56
var sameLol = document.createElement('div');
57
sameLol.innerHTML = 'Is same lol cat? : '+ (cat === sameCat);
58
wrapper.appendChild(sameLol);
60
//so we need to "deep-clone" the Element to be able
61
//to insert it multiple times into the same document
63
//wrapper.appendChild(sameCat.cloneNode(true)); //insert a clone of the image
64
wrapper.appendChild(sameCat);//swap image position
66
relative.init(wrapper);