PageSourceSearch

https://turism.drajna.ro/modules/mod_sj_k2_extraslider/assets/js/jcarousel.js

js drajna.ro collected 2026-10-02 14:22:46 UTC 6,259 bytes, 205 lines download raw bytes

1!function ($) {
2	"use strict";
3	var JCarousel = function (element, options) {
4		this.$element = $(element)
5		this.options = options
6		this.options.jslide && this.slide(this.options.jslide)
7		this.options.pause == 'hover' && this.$element.on('mouseenter', $.proxy(this.pause, this)).on('mouseleave', $.proxy(this.cycle, this))
8		this.transition = (function () {
9			var transitionEnd = (function () {
10				var el = document.createElement('bootstrap'),
11				transEndEventNames = {
12					'WebkitTransition' : 'webkitTransitionEnd',
13					'MozTransition' : 'transitionend',
14					'OTransition' : 'oTransitionEnd otransitionend',
15					'transition' : 'transitionend'
16				},
17				name
18				for (name in transEndEventNames) {
19					if (el.style[name] !== undefined) {
20						return transEndEventNames[name]
21					}
22				}
23			}())
24			return transitionEnd && {
25				end : transitionEnd
26			}
27		})()
28	}
29	
30	JCarousel.prototype = {
31		cycle : function (e) {
32			if (!e) this.paused = false
33			if (this.interval){
34				clearInterval(this.interval)
35				this.interval = null
36			}
37			this.options.interval && !this.paused && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
38			return this
39		},
40		to : function (pos) {
41			var $active = this.$element.find('.item.active'),
42			children = $active.parent().children(),
43			activePos = children.index($active),
44			that = this
45			if (pos > (children.length - 1) || pos < 0) return
46			if (this.sliding) {
47				return this.$element.one('jslid', function () {
48					that.to(pos)
49				})
50			}
51			if (activePos == pos) {
52				return this.pause().cycle()
53			}
54			return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos]))
55		},
56		pause : function (e) {
57			if (!e) this.paused = true
58			if (this.$element.find('.next, .prev').length && this.transition.end) {}
59			clearInterval(this.interval)
60			this.interval = null
61			return this
62		},
63		next : function () {
64			if (this.sliding) return
65			return this.slide('next')
66		},
67		prev : function () {
68			if (this.sliding) return
69			return this.slide('prev')
70		},
71		slide : function (type, next) {
72			var $active = this.$element.find('.item.active'),
73			$next = next || $active[type](),
74			isCycling = this.interval,
75			direction = type == 'next' ? 'left' : 'right',
76			fallback = type == 'next' ? 'first' : 'last',
77			that = this
78			
79			this.sliding = true
80			isCycling && this.pause()
81			$next = $next.length ? $next : this.$element.find('.item')[fallback]()
82			if ($next.hasClass('active')) return
83			var e = $.Event('jslide', {
84				relatedTarget : $next[0]
85			})
86			if (this.transition && this.$element.hasClass('slide')) {
87				this.$element.trigger(e)
88				if (e.isDefaultPrevented()) return
89				$next.addClass(type)
90				$next[0].offsetWidth
91				$active.addClass(direction)
92				$next.addClass(direction)
93				this.$element.one(this.transition.end, function () {
94					$next.removeClass([type, direction].join(' ')).addClass('active')
95					$active.removeClass(['active', direction].join(' '))
96					that.sliding = false
97					setTimeout(function () {
98						that.$element.trigger('jslid')
99					}, 0)
100				})
101			} else {
102				this.$element.trigger(e)
103				if (e.isDefaultPrevented()) return
104				if (this.options.pager){ $(this.options.pager).removeClass('sel').eq( $next.index() ).addClass('sel'); }
105				var that = this, end = 0, endFn = function () {
106					$active.removeClass('active')
107					$next.addClass('active')
108					$active.attr('style', null)
109					$next.attr('style', null)
110					that.sliding = false
111					that.$element.trigger('jslid')
112				},
113				chk4end = function () {
114					end++;
115					if (end == 2) {
116						endFn();
117					}
118				},
119				nextCss = {
120					display : 'block',
121					width : '100%',
122					position : 'absolute',
123					top : 0,
124					left : '100%'
125				},
126				nextOpt = {
127					left : '0'
128				},
129				actiOpt = {
130					left : '-100%'
131				},
132				commOpt = {
133					duration : 800,
134					complete : chk4end
135				};
136				if (this.$element.hasClass('slide')) {
137					if (type == 'prev') {
138						nextCss.left = '-100%';
139						actiOpt.left = '100%';
140					} else if (type == 'next') {}
141					
142				} else {
143					nextCss.left = 0;
144					nextCss.opacity = 0;
145					nextOpt = {
146						opacity : 1
147					}
148					actiOpt = {
149						opacity : 0
150					}
151				}
152				$next.css(nextCss).animate(nextOpt, commOpt);
153				$active.animate(actiOpt, commOpt);
154			}
155			isCycling && this.cycle()
156			return this
157		}
158	}
159	
160	$.fn.jcarousel = function (option) {
161		return this.each(function () {
162			var $this = $(this),
163				data = $this.data('jcarousel'),
164				options = $.extend({}, $.fn.jcarousel.defaults, typeof option == 'object' && option),
165				action = typeof option == 'string' ? option : options.jslide
166			if (!data) $this.data('jcarousel', (data = new JCarousel(this, options)))
167			if (typeof action == 'number') data.to(action)
168			else if (action) data[action]()
169			else if (options.interval) data.cycle()
170		})
171	}
172	
173	$.fn.jcarousel.defaults = {
174		interval : 5000,
175		pause : 'hover'
176	}
177	
178	$.fn.jcarousel.Constructor = JCarousel
179	
180	$(function () {
181		$('body').on('click.jcarousel.data-api', '[data-jslide]', function (e) {
182			var $this = $(this), href,
183				$target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')),
184				options = !$target.data('modal') && $.extend({}, $target.data(), $this.data())
185			$target.jcarousel(options)
186			e.preventDefault()
187		});
188		$('[data-start-jcarousel]').each(function(){
189			var $this = $(this), options = options = !$this.data('modal') && $.extend({}, $this.data());
190			$this.jcarousel(options);
191			$this.bind('jslide', function(e){
192				var index = $(this).find(e.relatedTarget).index();
193				$('[data-jslide]').each(function(){
194					var $nav = $(this), $navData = $nav.data(), href, $target = $($nav.attr('data-target') || (href = $nav.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, ''));
195					if ( !$target.is($this) ) return;
196					if (typeof $navData.jslide == 'number' && $navData.jslide==index){
197						$nav.addClass('sel');
198					} else {
199						$nav.removeClass('sel');
200					}
201				});				
202			});
203		});
204	})
205}(window.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.