PageSourceSearch

https://chernomorets.bg/modules/mod_news_pro_gk5/interface/scripts/engine.jquery.js

js chernomorets.bg collected 2026-10-03 02:28:08 UTC 10,507 bytes, 370 lines download raw bytes

1/**
2* Main script file
3* @package News Show Pro GK5
4* @Copyright (C) 2009-2012 Gavick.com
5* @ All rights reserved
6* @ Joomla! is Free Software
7* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
8* @version $Revision: GK5 1.0 $
9**/
10
11jQuery.noConflict();
12
13jQuery(window).on('load', function() {
14	jQuery(document).find('.nspMain').each(function(i, module) {	
15		if(!jQuery(module).hasClass('activated')) {
16			new NSP5(module);
17		}
18	});
19});
20
21var NSP5 = function(module) {
22	// init class fields
23	this.init_fields(module);
24	// init the interface
25	this.init_interface();
26};
27
28NSP5.prototype = {
29	// class fields
30	animation: true,
31	anim_arts: false,
32	anim_lists: false,
33	arts: null,
34	arts_block_width: 0,
35	arts_current: 0,
36	arts_pages: null,
37	arts_per_page: null,
38	config: null,
39	hover_anim: null,
40	links: null,
41	links_block_width: 0,
42	links_pages: null,
43	links_pages_amount: null,
44	links_current: 0,
45	modInterface: null,
46	module: null,
47	// touch events properties
48	swipe_max_time: 500, // in ms
49	swipe_min_move: 30, // in px
50	//
51	init_fields: function(module) {
52		// the most important class field ;)
53		this.module = jQuery(module);
54		this.module.addClass('activated');
55		// rest of the fields
56		this.config = jQuery.parseJSON(this.module.attr('data-config').replace(/'/g,"\""));
57		this.arts = this.module.find('.nspArt');
58		this.arts_pages = this.module.find('.nspArtPage');
59		this.arts_per_page = this.config['news_column'] * this.config['news_rows'];
60		this.hover_anim = this.module.hasClass('hover');
61		this.links = (this.module.find('.nspLinkScroll1')) ? this.module.find('.nspLinkScroll1 li') : [];
62		this.links_pages = this.module.find('.nspList');
63		this.links_pages_amount = Math.ceil(Math.ceil(this.links.length / this.config['links_amount']) / this.config['links_columns_amount']);
64		this.modInterface = { 
65			top: this.module.find('.nspTopInterface'), 
66			bottom: this.module.find('.nspBotInterface')
67		};
68		this.pages_amount = Math.ceil(this.arts.length / this.arts_per_page);
69	},
70	init_interface: function() {
71		var $this = this;
72		// arts
73		if(this.arts.length > 0){
74			this.arts_block_width = 100;
75		}
76		// events
77		this.module.mouseenter(function() {
78			if(!$this.module.hasClass('onhover')) {
79				$this.module.addClass('onhover');
80			}
81		});
82		//
83		this.module.mouseleave(function() {
84			if($this.module.hasClass('onhover')) {
85				$this.module.removeClass('onhover');
86			}
87		});
88		// links
89		if(this.links.length > 0){
90			this.links_block_width = 100;
91		}
92		// top interface
93		this.nsp_art_list(0, 'top');
94		this.nsp_art_list(0, 'bottom');
95		//
96		if(this.modInterface.top && this.modInterface.top.find('.nspPagination')){
97			this.modInterface.top.find('.nspPagination li').each(function(i, item){
98				if($this.hover_anim == 'mouseenter') {
99					jQuery(item).mouseenter(function(){
100						$this.arts_anim(i);
101					});	
102				}else {
103					jQuery(item).click(function(e){
104						e.preventDefault();
105						$this.arts_anim(i);
106					});	
107				}
108			});
109		}
110		//
111		if(this.modInterface.top && this.modInterface.top.find('.nspPrev')){
112			this.modInterface.top.find('.nspPrev').click(function(e){
113				e.preventDefault();
114				$this.arts_anim('prev');
115			});
116			
117			this.modInterface.top.find('.nspNext').click(function(e){
118				e.preventDefault();
119				$this.arts_anim('next');
120			});
121		}
122		// bottom interface
123		if(this.modInterface.bottom && this.modInterface.bottom.find('.nspPagination')){
124			this.modInterface.bottom.find('.nspPagination li').each(function(i, item){
125				if($this.hover_anim == 'mouseenter') {
126					jQuery(item).mouseenter(function(){
127						$this.lists_anim(i);
128					});	
129				}else {
130					jQuery(item).click(function(e){
131						e.preventDefault();
132						$this.lists_anim(i);
133					});	
134				}
135			});
136		}
137		//
138		if(this.modInterface.bottom && this.modInterface.bottom.find('.nspPrev')){
139			this.modInterface.bottom.find('.nspPrev').click(function(e){
140				e.preventDefault();
141				$this.lists_anim('prev');
142			});
143			
144			this.modInterface.bottom.find('.nspNext').click(function(e){
145				e.preventDefault();
146				$this.lists_anim('next');
147			});
148		}
149		//
150		if(this.module.hasClass('autoanim')){
151			setTimeout(function(){
152				$this.nsp_gk5_autoanim();
153			},$this.config['animation_interval']);
154		}
155		// Touch events for the articles
156		var arts_wrap = this.module.find('.nspArts');
157		if(arts_wrap) {		
158			var arts_pos_start_x = 0;
159			var arts_pos_start_y = 0;
160			var arts_time_start = 0;
161			var arts_swipe = false;
162			
163			arts_wrap.bind('touchstart', function(e) {
164				arts_swipe = true;
165				var touches = e.originalEvent.changedTouches || e.originalEvent.touches;
166	
167				if(touches.length > 0) {
168					arts_pos_start_x = touches[0].pageX;
169					arts_pos_start_y = touches[0].pageY;
170					arts_time_start = new Date().getTime();
171				}
172			});
173			
174			arts_wrap.bind('touchmove', function(e) {
175				var touches = e.originalEvent.changedTouches || e.originalEvent.touches;
176				
177				if(touches.length > 0 && arts_swipe) {
178					if(
179						Math.abs(touches[0].pageX - arts_pos_start_x) > Math.abs(touches[0].pageY - arts_pos_start_y)
180					) {
181						e.preventDefault();
182					} else {
183						arts_swipe = false;
184					}
185				}
186			});
187						
188			arts_wrap.bind('touchend', function(e) {
189				var touches = e.originalEvent.changedTouches || e.originalEvent.touches;
190				
191				if(touches.length > 0 && arts_swipe) {									
192					if(
193						Math.abs(touches[0].pageX - arts_pos_start_x) >= $this.swipe_min_move && 
194						new Date().getTime() - arts_time_start <= $this.swipe_max_time
195					) {					
196						if(touches[0].pageX - arts_pos_start_x > 0) {
197							$this.arts_anim('prev');
198						} else {
199							$this.arts_anim('next');
200						}
201					}
202				}
203			});
204		}
205		// Touch events for the links
206		var links_wrap = this.module.find('.nspLinksWrap');
207		if(links_wrap) {	
208			var links_pos_start_x = 0;
209			var links_pos_start_y = 0;
210			var links_time_start = 0;
211			var links_swipe = false;
212			
213			links_wrap.bind('touchstart', function(e) {
214				links_swipe = true;
215				var touches = e.originalEvent.changedTouches || e.originalEvent.touches;
216	
217				if(touches.length > 0) {
218					links_pos_start_x = touches[0].pageX;
219					links_pos_start_y = touches[0].pageY;
220					links_time_start = new Date().getTime();
221				}
222			});
223			
224			links_wrap.bind('touchmove', function(e) {
225				var touches = e.originalEvent.changedTouches || e.originalEvent.touches;
226				
227				if(touches.length > 0 && links_swipe) {
228					if(
229						Math.abs(touches[0].pageX - links_pos_start_x) > Math.abs(touches[0].pageY - links_pos_start_y)
230					) {
231						e.preventDefault();
232					} else {
233						links_swipe = false;
234					}
235				}
236			});
237						
238			links_wrap.bind('touchend', function(e) {
239				var touches = e.originalEvent.changedTouches || e.originalEvent.touches;
240				
241				if(touches.length > 0 && links_swipe) {									
242					if(
243						Math.abs(touches[0].pageX - links_pos_start_x) >= $this.swipe_min_move && 
244						new Date().getTime() - links_time_start <= $this.swipe_max_time
245					) {					
246						if(touches[0].pageX - links_pos_start_x > 0) {
247							$this.lists_anim('prev');
248						} else {
249							$this.lists_anim('next');
250						}
251					}
252				}
253			});
254		}
255		this.afterInit();
256	},
257	//
258	nsp_art_list: function(i, pos){
259		var num  = (i !== null) ? i : (pos == 'top') ? this.arts_current : this.links_current;
260		
261		if(this.modInterface[pos] && this.modInterface[pos].find('.nspPagination')){
262			var pagination = this.modInterface[pos].find('.nspPagination');
263			pagination.find('li').attr('class', '');
264			jQuery(pagination.find('li')[num]).attr('class', 'active');
265		}
266	},
267	//
268	arts_anim: function(dir) {
269		if(!this.anim_arts) {
270			var $this = this;
271			this.anim_arts = true;
272			jQuery(this.arts_pages[this.arts_current]).removeClass('active');
273			
274			if(dir == 'next') {
275				this.arts_current = (this.arts_current == this.pages_amount - 1) ? 0 : this.arts_current + 1;
276			} else if(dir == 'prev') {
277				this.arts_current = (this.arts_current == 0) ? this.pages_amount - 1 : this.arts_current - 1;
278			} else {
279				this.arts_current = dir;
280			}
281            $this.beforeAnim();
282			//		
283			jQuery($this.module.find('.nspArtScroll2')).animate({
284				'margin-left': (-1 * this.arts_current * this.arts_block_width) + "%"
285			}, $this.config['animation_speed']);
286			
287			setTimeout(function() {
288				jQuery($this.arts_pages[$this.arts_current]).addClass('active');
289			}, this.config['animation_speed'] * 0.5);
290			
291			setTimeout(function() {
292				$this.anim_arts = false;
293				$this.afterAnim();
294			}, this.config['animation_speed']);
295			
296			this.nsp_art_list(this.arts_current, 'top');
297			this.animation = false;
298			setTimeout(function(){
299				$this.animation = true;
300			}, this.config['animation_interval'] * 0.8);
301		}
302	},
303	//
304	lists_anim: function(dir) {
305		if(!this.anim_lists) {
306			var $this = this;
307			this.anim_lists = true;
308			
309			for(var x = 0; x < this.config['links_columns_amount']; x++) {
310				var item = this.links_pages[this.links_current * this.config['links_columns_amount'] + x];
311				if(item) {
312					jQuery(item).removeClass('active');
313				}
314			}
315			
316			if(dir == 'next') {
317				this.links_current = (this.links_current == this.links_pages_amount - 1) ? 0 : this.links_current + 1;
318			} else if(dir == 'prev') {
319				this.links_current = (this.links_current == 0) ? this.links_pages_amount - 1 : this.links_current - 1;
320			} else {
321				$this.links_current = dir;
322			}
323			
324			$this.beforeAnim();
325			
326			setTimeout(function() {
327				for(var x = 0; x < $this.config['links_columns_amount']; x++) {
328					var item = $this.links_pages[$this.links_current * $this.config['links_columns_amount'] + x]; 
329					if(jQuery(item).length) {
330						jQuery(item).addClass('active');
331					}
332				}
333			}, this.config['animation_speed'] * 0.5);
334			//
335			setTimeout(function() {
336				$this.anim_lists = false;
337				$this.afterAnim();
338			}, this.config['animation_speed']);
339			//
340			jQuery($this.module.find('.nspLinkScroll2')).animate({
341				'margin-left': (-1 * this.links_current * this.links_block_width) + "%"
342			}, $this.config['animation_speed']);
343			
344			this.nsp_art_list(null, 'bottom');
345		}
346	},
347	//
348	nsp_gk5_autoanim: function() {
349		var $this = this;
350		//
351		if(!this.module.hasClass('onhover')) {
352			this.arts_anim('next');
353		}
354		//
355		setTimeout(function() {
356			$this.nsp_gk5_autoanim();
357		}, $this.config['animation_interval']);
358	},
359	beforeAnim: function() {
360	    // support callback after animation
361	    
362	},
363	afterAnim: function() {
364	    // support callback after animation
365	    
366	},
367	afterInit: function() {
368	    // support callback after init interface
369	}
370};

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.