PageSourceSearch

https://iabtechlab.com/wp-content/themes/modality/js/unslider.js?ver=7.1.2

js iabtechlab.com collected 2026-09-24 06:45:59 UTC 6,687 bytes, 251 lines download raw bytes

1/**
2 *   Unslider by @idiot and @damirfoy
3 *   Contributors:
4 *   - @ShamoX
5 *
6 */
7
8(function($, f) {
9	var Unslider = function() {
10		//  Object clone
11		var _ = this;
12
13		//  Set some options
14		_.o = {
15			speed: 500,     // animation speed, false for no transition (integer or boolean)
16			delay: 3000,    // delay between slides, false for no autoplay (integer or boolean)
17			init: 0,        // init delay, false for no delay (integer or boolean)
18			pause: !f,      // pause on hover (boolean)
19			loop: !f,       // infinitely looping (boolean)
20			keys: f,        // keyboard shortcuts (boolean)
21			dots: f,        // display dots pagination (boolean)
22			arrows: f,      // display prev/next arrows (boolean)
23			prev: '←', // text or html inside prev button (string)
24			next: '→', // same as for prev option
25			fluid: f,       // is it a percentage width? (boolean)
26			starting: f,    // invoke before animation (function with argument)
27			complete: f,    // invoke after animation (function with argument)
28			items: '>ul',   // slides container selector
29			item: '>li',    // slidable items selector
30			easing: 'swing',// easing function to use for animation
31			autoplay: true  // enable autoplay on initialisation
32		};
33
34		_.init = function(el, o) {
35			//  Check whether we're passing any options in to Unslider
36			_.o = $.extend(_.o, o);
37
38			_.el = el;
39			_.ul = el.find(_.o.items);
40			_.max = [el.outerWidth() | 0, el.outerHeight() | 0];
41			_.li = _.ul.find(_.o.item).each(function(index) {
42				var me = $(this),
43					width = me.outerWidth(),
44					height = me.outerHeight();
45
46				//  Set the max values
47				if (width > _.max[0]) _.max[0] = width;
48				if (height > _.max[1]) _.max[1] = height;
49			});
50
51
52			//  Cached vars
53			var o = _.o,
54				ul = _.ul,
55				li = _.li,
56				len = li.length;
57
58			//  Current indeed
59			_.i = 0;
60
61			//  Set the main element
62			el.css({width: _.max[0], height: li.first().outerHeight(), overflow: 'hidden'});
63
64			//  Set the relative widths
65			ul.css({position: 'relative', left: 0, width: (len * 100) + '%'});
66			if(o.fluid) {
67				li.css({'float': 'left', width: (100 / len) + '%'});
68			} else {
69				li.css({'float': 'left', width: (_.max[0]) + 'px'});
70			}
71
72			//  Autoslide
73			o.autoplay && setTimeout(function() {
74				if (o.delay | 0) {
75					_.play();
76
77					if (o.pause) {
78						el.on('mouseover mouseout', function(e) {
79							_.stop();
80							e.type === 'mouseout' && _.play();
81						});
82					};
83				};
84			}, o.init | 0);
85
86			//  Keypresses
87			if (o.keys) {
88				$(document).keydown(function(e) {
89					switch(e.which) {
90						case 37:
91							_.prev(); // Left
92							break;
93						case 39:
94							_.next(); // Right
95							break;
96						case 27:
97							_.stop(); // Esc
98							break;
99					};
100				});
101			};
102
103			//  Dot pagination
104			o.dots && nav('dot');
105
106			//  Arrows support
107			o.arrows && nav('arrow');
108
109			//  Patch for fluid-width sliders. Screw those guys.
110			o.fluid && $(window).resize(function() {
111				_.r && clearTimeout(_.r);
112
113				_.r = setTimeout(function() {
114					var styl = {height: li.eq(_.i).outerHeight()},
115						width = el.outerWidth();
116
117					ul.css(styl);
118					styl['width'] = Math.min(Math.round((width / el.parent().width()) * 100), 100) + '%';
119					el.css(styl);
120					li.css({ width: width + 'px' });
121				}, 50);
122			}).resize();
123
124			//  Move support
125			if ($.event.special['move'] || $.Event('move')) {
126				el.on('movestart', function(e) {
127					if ((e.distX > e.distY && e.distX < -e.distY) || (e.distX < e.distY && e.distX > -e.distY)) {
128						e.preventDefault();
129					}else{
130						el.data("left", _.ul.offset().left / el.width() * 100);
131					}
132				}).on('move', function(e) {
133					var left = 100 * e.distX / el.width();
134				        var leftDelta = 100 * e.deltaX / el.width();
135					_.ul[0].style.left = parseInt(_.ul[0].style.left.replace("%", ""))+leftDelta+"%";
136
137					_.ul.data("left", left);
138				}).on('moveend', function(e) {
139					var left = _.ul.data("left");
140					if (Math.abs(left) > 30){
141						var i = left > 0 ? _.i-1 : _.i+1;
142						if (i < 0 || i >= len) i = _.i;
143						_.to(i);
144					}else{
145						_.to(_.i);
146					}
147				});
148			};
149
150			return _;
151		};
152
153		//  Move Unslider to a slide index
154		_.to = function(index, callback) {
155			if (_.t) {
156				_.stop();
157				_.play();
158	                }
159			var o = _.o,
160				el = _.el,
161				ul = _.ul,
162				li = _.li,
163				current = _.i,
164				target = li.eq(index);
165
166			$.isFunction(o.starting) && !callback && o.starting(el, li.eq(current));
167
168			//  To slide or not to slide
169			if ((!target.length || index < 0) && o.loop === f) return;
170
171			//  Check if it's out of bounds
172			if (!target.length) index = 0;
173			if (index < 0) index = li.length - 1;
174			target = li.eq(index);
175
176			var speed = callback ? 5 : o.speed | 0,
177				easing = o.easing,
178				obj = {height: target.outerHeight()};
179
180			if (!ul.queue('fx').length) {
181				//  Handle those pesky dots
182				el.find('.dot').eq(index).addClass('active').siblings().removeClass('active');
183
184				el.animate(obj, speed, easing) && ul.animate($.extend({left: '-' + index + '00%'}, obj), speed, easing, function(data) {
185					_.i = index;
186
187					$.isFunction(o.complete) && !callback && o.complete(el, target);
188				});
189			};
190		};
191
192		//  Autoplay functionality
193		_.play = function() {
194			_.t = setInterval(function() {
195				_.to(_.i + 1);
196			}, _.o.delay | 0);
197		};
198
199		//  Stop autoplay
200		_.stop = function() {
201			_.t = clearInterval(_.t);
202			return _;
203		};
204
205		//  Move to previous/next slide
206		_.next = function() {
207			return _.stop().to(_.i + 1);
208		};
209
210		_.prev = function() {
211			return _.stop().to(_.i - 1);
212		};
213
214		//  Create dots and arrows
215		function nav(name, html) {
216			if (name == 'dot') {
217				html = '<ol class="dots">';
218					$.each(_.li, function(index) {
219						html += '<li class="' + (index === _.i ? name + ' active' : name) + '">' + ++index + '</li>';
220					});
221				html += '</ol>';
222			} else {
223				html = '<div class="';
224				html = html + name + 's">' + html + name + ' prev">' + _.o.prev + '</div>' + html + name + ' next">' + _.o.next + '</div></div>';
225			};
226
227			_.el.addClass('has-' + name + 's').append(html).find('.' + name).click(function() {
228				var me = $(this);
229				me.hasClass('dot') ? _.stop().to(me.index()) : me.hasClass('prev') ? _.prev() : _.next();
230			});
231		};
232	};
233
234	//  Create a jQuery plugin
235	$.fn.unslider = function(o) {
236		var len = this.length;
237
238		//  Enable multiple-slider support
239		return this.each(function(index) {
240			//  Cache a copy of $(this), so it
241			var me = $(this),
242				key = 'unslider' + (len > 1 ? '-' + ++index : ''),
243				instance = (new Unslider).init(me, o);
244
245			//  Invoke an Unslider instance
246			me.data(key, instance).data('key', key);
247		});
248	};
249
250	Unslider.version = "1.0.0";
251})(jQuery, false);

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.