PageSourceSearch

https://gobernacionloja.gob.ec/wp-content/themes/Sitio-33/js/responsiveCarousel.js

js gobernacionloja.gob.ec collected 2026-10-05 03:41:33 UTC 14,845 bytes, 420 lines download raw bytes

1/*! responsiveCarousel.JS - v1.2.0
2 * http://basilio.github.com/responsiveCarousel
3 *
4 * Copyright (c) 2013 Basilio Cáceres <[email protected]>;
5 * Licensed under the MIT license */
6
7;(function($){
8	"use strict";
9	$.fn.responsiveCarousel = function(args){
10                var md = new MobileDetect(window.navigator.userAgent);
11                
12                    
13		var defaults, obj;
14		defaults = {
15			infinite : false,
16			visible : 1,
17			speed : 'fast',
18			overflow : false,
19			autoRotate : false,
20			navigation : $(this).data('navigation'),
21			itemMinWidth : 0,
22			itemEqualHeight : false,
23			itemMargin : 0,
24			itemClassActive : 'crsl-active',
25			imageWideClass : 'wide-image',
26			// Use to build grid system - carousel : false
27			carousel : true
28		};
29                
30                if(md.mobile()){
31                    defaults.infinite = true;
32                }
33		return $(this).each( function(){
34			// Set Object
35			obj = $(this);
36
37			// Extend
38			if( $.isEmptyObject(args) === false )
39				$.extend( defaults, args );
40			if( $.isEmptyObject( $(obj).data('crsl') ) === false )
41				$.extend( defaults, $(obj).data('crsl') );
42
43
44			// Touch detection
45			defaults.isTouch = 'ontouchstart' in document.documentElement || navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i) ? true : false ;
46
47			obj.init = function(){
48				// Set some default vars
49				defaults.total = $(obj).find('.crsl-item').length;
50				defaults.itemWidth = $(obj).outerWidth();
51				defaults.visibleDefault = defaults.visible;
52
53				// Touch Defaults
54				defaults.swipeDistance = null;
55				defaults.swipeMinDistance = 100;
56				defaults.startCoords = {};
57				defaults.endCoords = {};
58
59				// .crsl-items
60				$(obj).css({ width: '100%' });
61				// .crls-item
62				$(obj).find('.crsl-item').css({ position: 'relative', float: 'left', overflow: 'hidden', height: 'auto' });
63				// .crsl-item > images with full width
64				$(obj).find('.'+defaults.imageWideClass).each( function(){
65					$(this).css({ display: 'block', width: '100%', height: 'auto' });
66				});
67				// .crsl-item > iframes (videos)
68				$(obj).find('.crsl-item iframe').attr({ width: '100%' });
69
70
71				// Declare the item ative
72				if( defaults.carousel )
73					$(obj).find('.crsl-item:first-child').addClass(defaults.itemClassActive);
74
75				// Move last element to begin for infinite carousel
76				if( defaults.carousel && defaults.infinite && ( defaults.visible < defaults.total ) )
77					$(obj).find('.crsl-item:first-child').before( $('.crsl-item:last-child', obj) );
78
79				// if defaults.overflow
80				if( defaults.overflow === false ){
81					$(obj).css({ overflow: 'hidden' });
82				} else {
83					$('html, body').css({ 'overflow-x': 'hidden' });
84				}
85
86				$(obj).trigger('initCarousel', [defaults, obj]);
87
88				// Preload if it`s neccesary
89				obj.testPreload();
90
91				// This configure and margins and variables when document is ready,
92				// loaded and window is resized
93				obj.config();
94
95				// Init AutoRotate
96				obj.initRotate();
97
98				// Trigger Clicks
99				obj.triggerNavs();
100
101			};
102
103			obj.testPreload= function(){
104				if( $(obj).find('img').length > 0 ){
105					var totalImages = $(obj).find('img').length, i = 1;
106					$(obj).find('img').each( function(){
107						obj.preloadImage(this, i , totalImages);
108						i++;
109					});
110				} else {
111					$(obj).trigger('loadedCarousel', [defaults, obj]);
112				}
113			};
114
115			obj.preloadImage = function(image, i, totalImages){
116				var new_image = new Image(), attributes = {};
117				attributes.src = ( $(image).attr('src') !== undefined ? image.src : '' );
118				attributes.alt = ( $(image).attr('alt') !== undefined ? image.alt : '' );
119				$(new_image).attr( attributes );
120				$(new_image).on('load', function(){
121					// Trigger first image loaded as init Loading action
122					if( i === 1 )
123						$(obj).trigger('loadingImagesCarousel', [defaults, obj]);
124					// Trigger last image loaded as loaded complete action
125					if( i === totalImages )
126						$(obj).trigger('loadedImagesCarousel', [defaults, obj]);
127				});
128			};
129
130			// Base Configuration:
131			obj.config = function(){
132				// Width Item
133				defaults.itemWidth = Math.floor( ( $(obj).outerWidth() - ( defaults.itemMargin * ( defaults.visibleDefault - 1 ) ) ) / defaults.visibleDefault );
134				if( defaults.itemWidth <= defaults.itemMinWidth ){
135					defaults.visible = Math.floor( ( $(obj).outerWidth() - ( defaults.itemMargin * ( defaults.visible - 1 ) ) ) / defaults.itemMinWidth ) === 1 ?
136						Math.floor( $(obj).outerWidth() / defaults.itemMinWidth ) :
137						Math.floor( ( $(obj).outerWidth() - defaults.itemMargin ) / defaults.itemMinWidth );
138					defaults.visible = defaults.visible < 1 ? 1 : defaults.visible;
139					defaults.itemWidth = defaults.visible === 1 ? Math.floor( $(obj).outerWidth() ) : Math.floor( ( $(obj).outerWidth() - ( defaults.itemMargin * ( defaults.visible - 1 ) ) ) / defaults.visible );
140				} else {
141					defaults.visible = defaults.visibleDefault;
142				}
143
144				if( defaults.carousel ){
145					// Normal use - Global carousel variables
146					// Set Variables
147					obj.wrapWidth = Math.floor( ( defaults.itemWidth + defaults.itemMargin ) * defaults.total );
148					obj.wrapMargin = obj.wrapMarginDefault = defaults.infinite && defaults.visible < defaults.total ? parseInt( ( defaults.itemWidth + defaults.itemMargin ) * -1, 10 ) : 0 ;
149					// Move last element to begin for infinite carousel
150					if( defaults.infinite && ( defaults.visible < defaults.total ) && ( $(obj).find('.crsl-item.'+defaults.itemClassActive).index() === 0 ) ){
151						$(obj).find('.crsl-item:first-child').before( $('.crsl-item:last-child', obj) );
152						obj.wrapMargin = obj.wrapMarginDefault = parseInt( ( defaults.itemWidth + defaults.itemMargin ) * -1, 10 );
153					}
154					// Modify width & margin to .crsl-wrap
155					$(obj).find('.crsl-wrap').css({ width: obj.wrapWidth+'px', marginLeft: obj.wrapMargin });
156				} else {
157					// Excepcional use
158					// responsiveCarousel might be use to create grids!
159					obj.wrapWidth = $(obj).outerWidth();
160					$(obj).find('.crsl-wrap').css({ width: obj.wrapWidth+defaults.itemMargin+'px' });
161					$('#'+defaults.navigation).hide();
162				}
163
164				$(obj).find('.crsl-item').css({ width: defaults.itemWidth+'px', marginRight : defaults.itemMargin+'px' });
165
166				// Equal Height Configuration
167				obj.equalHeights();
168
169				// Condition if total <= visible
170				if( defaults.carousel ){
171					if( defaults.visible >= defaults.total ){
172						defaults.autoRotate = false;
173						$('#'+defaults.navigation).hide();
174					} else {
175						$('#'+defaults.navigation).show();
176					}
177				}
178			};
179
180			// Equal Heights
181			obj.equalHeights = function(){
182				if( defaults.itemEqualHeight !== false ){
183					var tallest = 0;
184					$(obj).find('.crsl-item').each( function(){
185						$(this).css({ 'height': 'auto' });
186						if ( $(this).outerHeight() > tallest ){ tallest = $(this).outerHeight(); }
187					});
188					$(obj).find('.crsl-item').css({ height: tallest+'px' });
189                                        $('#nav-programas a').css({ height: tallest+'px' });
190				}
191				return true;
192			};
193
194			obj.initRotate = function(){
195				// Set AutoRotate Interval
196				if( defaults.autoRotate !== false ){
197					obj.rotateTime = window.setInterval( function(){
198						obj.rotate();
199					}, defaults.autoRotate);
200				}
201			};
202
203			obj.triggerNavs = function(){
204				// Previous / Next Navigation
205				$('#'+defaults.navigation).delegate('.previous, .next', 'click', function(event){
206					// Prevent default
207					event.preventDefault();
208					// Prepare execute
209					obj.prepareExecute();
210					// Previous & next action
211					if( $(this).hasClass('previous') && obj.testPrevious(obj.itemActive) ){
212						obj.previous();
213					} else if( $(this).hasClass('next') && obj.testNext() ){
214						obj.next();
215					} else {
216						return;
217					}
218				});
219			};
220
221			// Prepare Execute
222			obj.prepareExecute = function(){
223				// Stop rotate
224				if( defaults.autoRotate ){
225					clearInterval(obj.rotateTime);
226				}
227				// Prevent Animate Event
228				obj.preventAnimateEvent();
229				// Active
230				obj.itemActive = $(obj).find('.crsl-item.'+defaults.itemClassActive);
231				return true;
232			};
233
234			obj.preventAnimateEvent = function(){
235				if( $(obj).find('.crsl-wrap:animated').length > 0 ){
236					return false;
237				}
238			};
239
240			// Rotate Action
241			obj.rotate = function(){
242				// Prevent Animate Event
243				obj.preventAnimateEvent();
244				// Active
245				obj.itemActive = $(obj).find('.crsl-item.'+defaults.itemClassActive);
246				obj.next();
247				return true;
248			};
249
250			obj.testPrevious = function(active){
251				return $('.crsl-wrap', obj).find('.crsl-item').index(active) > 0;
252			};
253			obj.testNext = function(){
254				return ( !defaults.infinite &&
255					obj.wrapWidth >= (
256						( ( defaults.itemWidth + defaults.itemMargin ) * ( defaults.visible + 1 ) ) - obj.wrapMargin
257					)
258				) || defaults.infinite;
259			};
260
261			// Previous Animate
262			obj.previous = function(){
263				obj.wrapMargin = defaults.infinite ? obj.wrapMarginDefault + $(obj.itemActive).outerWidth(true) : obj.wrapMargin + $(obj.itemActive).outerWidth(true);
264				var prevItemIndex = $(obj.itemActive).index();
265				var newItemActive = $(obj.itemActive).prev('.crsl-item');
266				var action = 'previous';
267				// Trigger Begin Carousel Move
268				$(obj).trigger('beginCarousel', [defaults, obj, action]);
269				// Animate
270				$(obj).
271					find('.crsl-wrap').
272					animate({ marginLeft: obj.wrapMargin+'px' }, defaults.speed, function(){
273						// Active
274						$(obj.itemActive).removeClass(defaults.itemClassActive);
275						$(newItemActive).addClass(defaults.itemClassActive);
276						if( defaults.infinite ){
277							$(this).css({ marginLeft: obj.wrapMarginDefault }).find('.crsl-item:first-child').before( $('.crsl-item:last-child', obj) );
278						} else {
279							if( obj.testPrevious(newItemActive) === false )
280								$( '#'+defaults.navigation ).find('.previous').addClass('previous-inactive');
281							if( obj.testNext() )
282								$( '#'+defaults.navigation ).find('.next').removeClass('next-inactive');
283						}
284						// Trigger Carousel Exec
285//						$(this).trigger('endCarousel', [defaults, obj, action]);
286					});
287			};
288
289			// Next Animate
290			obj.next = function(){
291				obj.wrapMargin = defaults.infinite ? obj.wrapMarginDefault - $(obj.itemActive).outerWidth(true) : obj.wrapMargin - $(obj.itemActive).outerWidth(true);
292				var nextItemIndex = $(obj.itemActive).index();
293				var newItemActive = $(obj.itemActive).next('.crsl-item');
294				var action = 'next';
295				// Trigger Begin Carousel Move
296				$(obj).trigger('beginCarousel', [defaults, obj, action]);
297				// Animate
298				$(obj).
299					find('.crsl-wrap').
300					animate({ marginLeft: obj.wrapMargin+'px' }, defaults.speed, function(){
301						// Active
302						$(obj.itemActive).removeClass(defaults.itemClassActive);
303						$(newItemActive).addClass(defaults.itemClassActive);
304						if( defaults.infinite ){
305							$(this).css({ marginLeft: obj.wrapMarginDefault }).find('.crsl-item:last-child').after( $('.crsl-item:first-child', obj) );
306						} else {
307							if( obj.testPrevious(newItemActive) )
308								$( '#'+defaults.navigation ).find('.previous').removeClass('previous-inactive');
309							if( obj.testNext() === false )
310								$( '#'+defaults.navigation ).find('.next').addClass('next-inactive');
311						}
312						// Trigger Carousel Exec
313//						$(this).trigger('endCarousel', [defaults, obj, action]);
314					});
315			};
316
317			var mouseHover = false, current;
318			$(window).on('mouseleave', function(event){
319				// Detect current
320				if (event.target) current = event.target;
321				else if (event.srcElement) current = event.srcElement;
322				// Detect mouseover
323				if( ( $(obj).attr('id') && $(current).parents('.crsl-items').attr('id') === $(obj).attr('id') ) || ( $(current).parents('.crsl-items').data('navigation') === $(obj).data('navigation') ) ){
324					mouseHover = true;
325				} else {
326					mouseHover = false;
327				}
328				// False
329				return false;
330			});
331
332			$(window).on('keydown', function(event){
333				if( mouseHover === true ){
334					// Previous & next action
335					if( event.keyCode === 37 ){
336						// Prepare execute
337						obj.prepareExecute();
338						// Previous
339						obj.previous();
340					} else if( event.keyCode === 39 ){
341						// Prepare execute
342						obj.prepareExecute();
343						// Next
344						obj.next();
345					}
346				}
347				return;
348			});
349
350			if( defaults.isTouch ){
351				$(obj).on('touchstart', function(e){
352					$(obj).addClass('touching');
353					defaults.startCoords.pageX = defaults.endCoords.pageX = e.originalEvent.targetTouches[0].pageX;
354					defaults.startCoords.pageY = defaults.endCoords.pageY = e.originalEvent.targetTouches[0].pageY;
355					$('.touching').on('touchmove',function(e){
356						defaults.endCoords.pageX = e.originalEvent.targetTouches[0].pageX;
357						defaults.endCoords.pageY = e.originalEvent.targetTouches[0].pageY;
358						if( Math.abs( parseInt( defaults.endCoords.pageX-defaults.startCoords.pageX, 10 ) ) > Math.abs( parseInt( defaults.endCoords.pageY-defaults.startCoords.pageY, 10 ) ) ){
359							e.preventDefault();
360							e.stopPropagation();
361						}
362					});
363				}).on('touchend', function(e){
364					e.preventDefault();
365					e.stopPropagation();
366					defaults.swipeDistance = defaults.endCoords.pageX - defaults.startCoords.pageX;
367					if( defaults.swipeDistance >= defaults.swipeMinDistance ){
368						// swipeLeft
369						obj.previous();
370					} else if( defaults.swipeDistance <= - defaults.swipeMinDistance ){
371						// swipeRight
372						obj.next();
373					}else{
374                                            console.log("TAP");
375                                            window.location.href = event.srcElement.href;
376                                            
377                                        }
378					$('.touching').off('touchmove').removeClass('touching');
379				});
380			}
381
382			$(obj).on('loadedCarousel loadedImagesCarousel', function(){
383				// Trigger window onload EqualHeights
384				obj.equalHeights();
385			});
386
387			// Create method to resize element
388			$(window).on('carouselResizeEnd', function(){
389				// This configure and margins and variables when document is ready,
390				// loaded and window is resized
391				if( defaults.itemWidth !== $(obj).outerWidth() )
392					obj.config();
393
394			});
395
396			// Carousel General Detection
397			$(window).ready( function(){
398				// Trigger Prepare Event Carousel
399				$(obj).trigger('prepareCarousel', [defaults, obj]);
400				// Init some defaults styles
401				obj.init();
402				// ResizeEnd event
403				$(window).on('resize', function(){
404					if( this.carouselResizeTo ) clearTimeout(this.carouselResizeTo);
405					this.carouselResizeTo = setTimeout(function(){
406						$(this).trigger('carouselResizeEnd');
407					}, 10);
408				});
409			});
410
411			$(window).load( function(){
412				// Preload if it`s neccesary
413				obj.testPreload();
414				// This configure and margins and variables when document is ready,
415				// loaded and window is resized
416				obj.config();
417			});
418		});
419	};
420})(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.