forked from darsain/loremImages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.loremimages.js
55 lines (41 loc) · 1.82 KB
/
jquery.loremimages.js
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
44
45
46
47
48
49
50
51
52
53
54
55
/*!
* jQuery LoremImages v1.0.1
* https://github.com/Darsain/loremImages
*
* LoremIpsum equivalent for populating elements with random images.
* LoremImages is using the http://lorempixel.com service.
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/MIT
*/
;(function($, undefined){
var pluginName = 'loremImages';
// jQuery plugin extension
$.fn[pluginName] = function( width, height, options ){
// Parse options
var o = $.extend( {}, $.fn[pluginName].defaults, options );
// Execute plugin and return this
return this.each(function(i,e){
var container = $(e),
output = '';
for( var i = 0; i < o.count; i++ ){
var LPwidth = width + Math.round( Math.random()*o.randomWidth ),
LPheight = height + Math.round( Math.random()*o.randomHeight ),
url = '//lorempixel.com/'+( o.grey ? 'g/' : '' )+LPwidth+'/'+LPheight+'/'+(o.category ? o.category+'/' : '')+'?'+Math.round( Math.random()*1000 );
output += o.itemBuilder.call( container, i, url, LPwidth, LPheight );
}
container.append(output);
});
};
// Default options
$.fn[pluginName].defaults = {
count: 10, // how many items should be attached
grey: 0, // set to 1 for grey images
randomWidth: 0, // random range for width value. if 'width' is 100 and 'randomWidth' is 50, it'll produce a number in 100-150 range
randomHeight: 0, // random range for height value. if 'height' is 100 and 'randomHeight' is 50, it'll produce a number in 100-150 range
category: 0, // can be: abstract, animals, city, food, nightlife, fashion, people, nature, sports, technics, transport
itemBuilder: function( index, url, width, height ){ // function for generating items, where `this` is jQuery wrapped container
return '<img src="'+url+'" alt="Lorempixel">';
}
};
})(jQuery);