PageSourceSearch

https://mphtj.gov.my/modules/mod_news_pro_gk5/interface/scripts/engine.jquery.js

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

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.