-
Notifications
You must be signed in to change notification settings - Fork 3
/
jquery.cl_gallery.js
executable file
·54 lines (49 loc) · 1.34 KB
/
jquery.cl_gallery.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
/**
* @author Julian Bogdani <jbogdani@gmail.com>
* @copyright 2007-2021 Julian Bogdani
* @license AGPL-3.0; see LICENSE file
* @since Apr 9, 2013
* @example $('ul.cl_gallery').cl_gallery();
*
* Transforms a ul to a image gallery
* <ul data-rel="sth" class="a b c noimg_gallery">
* <li data-img="img_src" data-thumb="thumb_img_src">caption text</li>
* ...
* </ul>
*
* to
*
* <ul class="cl_gallery a b c">
* <li>
* <a href="big_img_src" class="fancybox" rel="sth" title="caption text">
* <img src="thumb_img_src" alt="caption text" />
* </a>
* <div class="caption">caption text</div>
* </li>
* ...
* </ul>
*/
(function( $ ){
$.fn.cl_gallery = function() {
var ul = this;
if (!ul.is(':visible')){
return;
}
ul.removeClass('cl_gallery');
var tmp = $('<ul />').addClass(ul.attr('class'));
$.each(ul.find('li'), function(i, el){
var text = $(el).text(),
oSrc = $(el).data('img'),
thSrc = $(el).data('thumb'),
rel = ul.data('rel'),
id = $(el).data('id');
tmp.append('<li data-id="' + id + '">' +
'<a href="' + oSrc + '" class="fancybox" ' + (rel ? ' rel="' + rel + '"' : '') + ' title="' + text + '">' +
'<img src="' + thSrc + '" alt="' + text + '" />' +
'</a>' +
'<div class="caption">' + text + '</div>' +
'</li>');
});
ul.replaceWith(tmp);
};
})( jQuery );