PageSourceSearch

https://argenbio.org/templates/theme3136/js/jquery.fancybox-thumbs.js

js argenbio.org collected 2026-10-02 06:41:40 UTC 6,280 bytes, 234 lines download raw bytes

1 /*!
2 * Thumbnail helper for fancyBox
3 * version: 1.0.7 (Mon, 01 Oct 2012)
4 * @requires fancyBox v2.0 or later
5 *
6 * Usage:
7 *     $(".fancybox").fancybox({
8 *         helpers : {
9 *             thumbs: {
10 *                 width  : 50,
11 *                 height : 50
12 *             }
13 *         }
14 *     });
15 *
16 */
17(function ($) {
18	//Shortcut for fancyBox object
19	var F = $.fancybox;
20
21	//Add helper object
22	F.helpers.thumbs = {
23		defaults : {
24			width    : 50,       // thumbnail width
25			height   : 50,       // thumbnail height
26			position : 'bottom', // 'top' or 'bottom'
27			source   : function ( item ) {  // function to obtain the URL of the thumbnail image
28				var href;
29
30				if (item.element) {
31					href = $(item.element).find('img').attr('src');
32				}
33
34				if (!href && item.type === 'image' && item.href) {
35					href = item.href;
36				}
37
38				return href;
39			}
40		},
41
42		wrap  : null,
43		list  : null,
44		width : 0,
45
46		init: function (opts, obj) {
47			var that = this,
48				list,
49				thumbWidth  = opts.width,
50				thumbHeight = opts.height,
51				thumbSource = opts.source;
52
53			//Build list structure
54			list = '';
55
56			for (var n = 0; n < obj.group.length; n++) {
57				list += '<li draggable="false" style="width:' + thumbWidth + 'px;height:' + thumbHeight + 'px;"></li>';
58			}
59
60			this.wrap = $('<div id="fancybox-thumbs"></div>').addClass(opts.position).appendTo('body');
61			this.list = $('<ul>' + list + '</ul>').appendTo(this.wrap);
62
63			//Load each thumbnail
64			$.each(obj.group, function (i) {
65				var href = thumbSource( obj.group[ i ] );
66
67				if (!href) {
68					return;
69				}
70
71				$("<img />").load(function () {
72					var width  = this.width,
73						height = this.height,
74						widthRatio, heightRatio, parent;
75
76					if (!that.list || !width || !height) {
77						return;
78					}
79
80					//Calculate thumbnail width/height and center it
81					widthRatio  = width / thumbWidth;
82					heightRatio = height / thumbHeight;
83
84					parent = that.list.children().eq(i);
85
86					if (widthRatio >= 1 && heightRatio >= 1) {
87						if (widthRatio > heightRatio) {
88							width  = Math.floor(width / heightRatio);
89							height = thumbHeight;
90
91						} else {
92							width  = thumbWidth;
93							height = Math.floor(height / widthRatio);
94						}
95					}
96
97					$(this).css({
98						width  : width,
99						height : height,
100						top    : Math.floor(thumbHeight / 2 - height / 2),
101						left   : Math.floor(thumbWidth / 2 - width / 2)
102					});
103
104					parent.width(thumbWidth).height(thumbHeight);
105
106					$(this).hide().appendTo(parent).fadeIn(300);
107					$('<div class=holder />').appendTo(parent)
108
109				}).attr({'src': href,'draggable':'false'});
110			});
111
112			//Set initial width
113			this.width = thumbWidth;
114			if(this.width * (obj.group.length)>$(window).width()){
115				left = Math.floor($(window).width() * 0.5 - (obj.index * this.width + this.width * 0.5))
116				if(left>0){
117					left=0
118				}
119				if(left<($(window).width()-this.width * (obj.group.length))){
120					left = $(window).width()-this.width * (obj.group.length)
121				}
122				this.list.css('left', left);
123			}
124			this.list.width(this.width * (obj.group.length))
125          $('#fancybox-thumbs ul li').bind('click', function(){
126            var el = $(this);
127            $.fancybox.jumpto(el.index());
128            return false;
129          })
130          $pep = $('#fancybox-thumbs ul')
131          if($pep.width()>$(window).width()){
132            $pep.pep({
133              start: function(){
134                $('#fancybox-thumbs ul li').unbind('click');
135              },
136              stop: function(){
137                setTimeout(function(){
138                $('#fancybox-thumbs ul li').bind('click', function(){
139                  var el = $(this);
140                  $.fancybox.jumpto(el.index());
141                  return false;
142                })
143              },100)
144              },
145              axis: 'x',
146              useCSSTranslation: false,
147              shouldPreventDefault: false,
148              constrainTo: [0, 0, 0, ($pep.width() - $("#fancybox-thumbs").width()) * -1]  
149            });
150          }
151          $(window).resize(function(){
152            if($pep.width()>$(window).width()){
153              $pep.pep({
154                start: function(){
155                  $('#fancybox-thumbs ul li').unbind('click');
156                },
157                stop: function(){
158                  setTimeout(function(){
159                  $('#fancybox-thumbs ul li').bind('click', function(){
160                    var el = $(this);
161                    $.fancybox.jumpto(el.index());
162                    return false;
163                  })
164                },100)
165                },
166                axis: 'x',
167                useCSSTranslation: false,
168                shouldPreventDefault: false,
169                constrainTo: [0, 0, 0, ($pep.width() - $("#fancybox-thumbs").width()) * -1]  
170              });
171            }
172            else{
173              $.pep.unbind($pep);
174              $pep.css({position:'relative',left:0})
175            }
176          })
177		},
178
179		beforeLoad: function (opts, obj) {
180			//Remove self if gallery do not have at least two items
181			if (obj.group.length < 2) {
182				obj.helpers.thumbs = false;
183
184				return;
185			}
186
187			//Increase bottom margin to give space for thumbs
188			obj.margin[ opts.position === 'top' ? 0 : 2 ] += ((opts.height) + 15);
189		},
190
191		afterShow: function (opts, obj) {
192			//Check if exists and create or update list
193			if (this.list) {
194				this.onUpdate(opts, obj);
195
196			} else {
197				this.init(opts, obj);
198			}
199
200			//Set active element
201			this.list.children().removeClass('active').eq(obj.index).addClass('active');
202		},
203
204		//Center list
205		onUpdate: function (opts, obj) {
206			if (this.list){	
207				this.width = this.list.children().eq(0).outerWidth(true);
208				if (this.width * (obj.group.length)>$(window).width()) {
209					left = Math.floor($(window).width() * 0.5 - (obj.index * this.width + this.width * 0.5))
210					if(left > 0) {
211						left = 0
212					}
213					if(left<($(window).width()-this.width * (obj.group.length))){
214						left = $(window).width()-this.width * (obj.group.length)
215					}
216					this.list.stop(true).animate({
217						'left': left
218					}, 150);
219				}
220			}
221		},
222
223		beforeClose: function () {
224			if (this.wrap) {
225				this.wrap.remove();
226			}
227
228			this.wrap  = null;
229			this.list  = null;
230			this.width = 0;
231		}
232	}
233
234}(jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.