PageSourceSearch

https://www.revistacec.com/templates/gk_technews/js/gk.scripts.js

js revistacec.com collected 2026-10-02 23:12:00 UTC 19,155 bytes, 612 lines download raw bytes

1// IE checker
2function gkIsIE() {
3	var myNav = navigator.userAgent.toLowerCase();
4	return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;
5}
6// jQuery Cookie plugin
7jQuery.cookie = function (key, value, options) {
8    // key and at least value given, set cookie...
9    if (arguments.length > 1 && String(value) !== "[object Object]") {
10        options = jQuery.extend({}, options);
11        if (value === null || value === undefined) {
12            options.expires = -1;
13        }
14        if (typeof options.expires === 'number') {
15            var days = options.expires, t = options.expires = new Date();
16            t.setDate(t.getDate() + days);
17        }
18
19        value = String(value);
20
21        return (document.cookie = [
22            encodeURIComponent(key), '=',
23            options.raw ? value : encodeURIComponent(value),
24            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
25            options.path ? '; path=' + options.path : '',
26            options.domain ? '; domain=' + options.domain : '',
27            options.secure ? '; secure' : ''
28        ].join(''));
29    }
30    // key and possibly options given, get cookie...
31    options = value || {};
32    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
33    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
34};
35//
36jQuery(document).ready(function() {	
37	// smooth anchor scrolling
38	if(!(jQuery('#gkMainbody').find('.subpage').length && jQuery('#gkMainbody').find('.subpage').hasClass('edit'))) {
39		jQuery('a[href*="#"]').on('click', function (e) {
40	        e.preventDefault();
41	        if(this.hash !== '' && this.hash.indexOf('carousel') === -1) {
42	            var target = jQuery(this.hash);
43	            
44	            if(this.hash !== '' && this.href.replace(this.hash, '') == window.location.href.replace(window.location.hash, '')) {    
45	                if(target.length && this.hash !== '#') {
46	                    jQuery('html, body').stop().animate({
47	                        'scrollTop': target.offset().top
48	                    }, 1000, 'swing', function () {
49	                        if(this.hash !== '#') {
50	                            window.location.hash = target.selector;
51	                        }
52	                    });
53	                } else if(this.hash !== '' && this.href.replace(this.hash, '') !== '') {
54	                	window.location.href = this.href;
55	                }
56	            } else if(this.hash !== '' && this.href.replace(this.hash, '') !== '') {
57	            	window.location.href = this.href;
58	            }
59	        }
60	    });
61    }
62    
63    // Social icons
64    jQuery('.item-social-icons').click(function() {
65    	jQuery(this).toggleClass('open');
66    	jQuery(this).parent().toggleClass('social-open');
67    });
68    
69    // Footer popup menu
70    jQuery('#gkFooterNavPopup .micon').click(function() {
71    	jQuery(this).parent().toggleClass('open');
72    });
73    
74    jQuery('#gkFooterNavPopup').find('.gk-footer-popup a').click(function() {
75    	jQuery('#gkFooterNavPopup').removeClass('open');
76    });
77    
78    jQuery('#gkFooterNavPopup').find('.gk-footer-popup').click(function() {
79    	jQuery('#gkFooterNavPopup').removeClass('open');
80    });
81    
82    // Search button
83    jQuery('#gkSearch .micon').click(function() {
84    	jQuery('#gkSearch .micon').parent().toggleClass('open');	
85    });
86    
87	// K2 font-size switcher fix
88	if(jQuery('#fontIncrease').length > 0 && jQuery('.itemIntroText').length > 0) {
89		jQuery('#fontIncrease').click(function() {
90			jQuery('.itemIntroText').attr('class', 'itemIntroText largerFontSize');
91		});
92		
93		jQuery('#fontDecrease').click( function() {
94			jQuery('.itemIntroText').attr('class', 'itemIntroText smallerFontSize');
95		});
96	}
97	
98	// login popup
99	if(jQuery('#gkUser .micon').length && jQuery('#gk-login-submenu').length) {
100		var submenu = jQuery('#gk-login-submenu');
101		
102		jQuery('#gkUser .micon').click(function() {			
103			if(jQuery('#gkUser').hasClass('gk-open')) {
104				jQuery('#gkUser').removeClass('gk-open');
105				
106				setTimeout(function() {
107					submenu.css('display', 'none');	
108				}, 350);
109			} else {
110				submenu.css('display', 'block');
111				
112				setTimeout(function() {
113					jQuery('#gkUser').addClass('gk-open');
114				}, 50);	
115			}
116		});
117	}
118	
119	// Social icons
120	if(jQuery('.gk-social-icons').length) {
121		var social_icons = jQuery('.gk-social-icons');
122		social_icons.click(function() {
123			var item = jQuery(this);
124			
125			if(!item.attr('data-click-block') || item.attr('data-click-block') == '') {
126				if(item.hasClass('clicked')) {
127					item.removeClass('show');
128					setTimeout(function() {
129						item.removeClass('clicked');
130						item.attr('data-click-block', '');
131					}, 350);		
132				} else {
133					item.addClass('clicked');
134					item.attr('data-click-block', 'true');
135					
136					setTimeout(function() {
137						item.addClass('show');
138					}, 50);
139					
140					setTimeout(function() {
141						item.attr('data-click-block', '');
142					}, 300);
143				}
144			}
145		});
146	}
147	
148	// Fix for the containers width
149	if(jQuery('#gkBg').outerHeight() < jQuery(window).outerHeight()) {
150		if(!jQuery(document.body).hasClass('error-page')) {
151			jQuery('#gkBg').css('min-height', jQuery(window).outerHeight() + "px");
152		}
153	}
154	
155	jQuery(window).resize(function() {
156		if(!jQuery(document.body).hasClass('error-page')) {
157			if(jQuery('#gkBg').outerHeight() < jQuery(window).outerHeight()) {
158				jQuery('#gkBg').css('min-height', jQuery(window).outerHeight() + "px");
159			}
160		}
161	});
162	
163	// PhotoSwipe script
164	var initPhotoSwipeFromDOM = function(gallerySelector) {
165	    // parse slide data (url, title, size ...) from DOM elements 
166	    // (children of gallerySelector)
167	    var parseThumbnailElements = function(el) {
168	        var thumbElements = jQuery(el).find('a'),
169	            numNodes = thumbElements.length,
170	            items = [],
171	            figureEl,
172	            linkEl,
173	            size,
174	            item;
175	
176	        thumbElements.each(function(i, link) {
177	            link = jQuery(link);
178	            size = link.attr('data-size').split('x');
179	
180	            // create slide object
181	            item = {
182	                src: link.attr('href'),
183	                w: parseInt(size[0], 10),
184	                h: parseInt(size[1], 10)
185	            };
186	
187	            if(link.attr('data-title') || link.attr('data-desc')) {
188	                item.title = '';
189	                
190	                if(link.attr('data-title')) {
191	                	item.title += '<h3>' + link.attr('data-title') + '</h3>';
192	                }
193	                
194	                if(link.attr('data-desc')) {
195	                	item.title += '<span>' + link.attr('data-desc') + '</span>';
196	                }
197	            }
198	
199	            item.msrc = link.find('img').first().attr('src');
200	            item.el = link; // save link to element for getThumbBoundsFn
201	            // Detect the data-order attribute
202	            if(
203	            	jQuery(window).outerWidth() > jQuery(document.body).attr('data-mobile-width') &&
204	            	link.attr('data-order')
205	            ) {
206	            	items[parseInt(link.attr('data-order'), 10) - 1] = item;
207	            } else {
208	            	items.push(item);
209	            }
210	        });
211	
212	        return items;
213	    };
214	
215	    // find nearest parent element
216	    var closest = function closest(el, fn) {
217	        return el && ( fn(el) ? el : closest(el.parentNode, fn) );
218	    };
219	
220	    // triggers when user clicks on thumbnail
221	    var onThumbnailsClick = function(e) {
222	        e.preventDefault();	
223	        // find root element of slide
224	        var clickedListItem = closest(e.target, function(el) {
225	            return (el.tagName && el.tagName.toUpperCase() === 'A');
226	        });
227	
228	        if(!clickedListItem) {
229	            return;
230	        }
231	
232	        // find index of clicked item by looping through all child nodes
233	        // alternatively, you may define index via data- attribute
234	        var clickedGallery = jQuery(clickedListItem).parents('.gk-gallery'),
235	            childNodes = clickedGallery.find('a'),
236	            numChildNodes = childNodes.length,
237	            nodeIndex = 0,
238	            index;
239	
240	        for (var i = 0; i < numChildNodes; i++) {
241	            if(childNodes[i] === clickedListItem) {
242	                index = nodeIndex;
243	                break;
244	            }
245	            nodeIndex++;
246	        }
247
248			if(
249				jQuery(window).outerWidth() > jQuery(document.body).attr('data-mobile-width') &&
250				clickedListItem.hasAttribute('data-order')
251			) {
252				index = parseInt(clickedListItem.getAttribute('data-order'), 10) - 1;
253			}
254
255	        if(index >= 0) {
256	            // open PhotoSwipe if valid index found
257	            openPhotoSwipe( index, clickedGallery );
258	        }
259	        return false;
260	    };
261	
262	    // parse picture index and gallery index from URL (#&pid=1&gid=2)
263	    var photoswipeParseHash = function() {
264	        var hash = window.location.hash.substring(1),
265	        params = {};
266	
267	        if(hash.length < 5) {
268	            return params;
269	        }
270	
271	        var vars = hash.split('&');
272	        for (var i = 0; i < vars.length; i++) {
273	            if(!vars[i]) {
274	                continue;
275	            }
276	            var pair = vars[i].split('=');  
277	            if(pair.length < 2) {
278	                continue;
279	            }           
280	            params[pair[0]] = pair[1];
281	        }
282	
283	        if(params.gid) {
284	            params.gid = parseInt(params.gid, 10);
285	        }
286	
287	        if(!params.hasOwnProperty('pid')) {
288	            return params;
289	        }
290	        params.pid = parseInt(params.pid, 10);
291	        return params;
292	    };
293	
294	    var openPhotoSwipe = function(index, galleryElement, disableAnimation) {
295	        var pswpElement = document.querySelectorAll('.pswp')[0],
296	            gallery,
297	            options,
298	            items;
299	
300	        items = parseThumbnailElements(galleryElement);
301	
302	        // define options (if needed)
303	        options = {
304	            index: index,
305	            showHideOpacity: true,
306	            hideAnimationDuration: 0,
307	            showAnimationDuration: 0,
308	            
309	
310	            // define gallery index (for URL)
311	            galleryUID: jQuery(galleryElement).attr('data-pswp-uid'),
312	
313	            getThumbBoundsFn: function(index) {
314	                // See Options -> getThumbBoundsFn section of documentation for more info
315	                var thumbnail = items[index].el.find('img').first(), // find thumbnail
316	                    rect = {
317	                    	"left": thumbnail.offset().left, 
318	                    	"top": thumbnail.offset().top,
319	                    	"width": thumbnail.outerWidth()
320	                    }; 
321	                return {x:rect.left, y:rect.top, w:rect.width};
322	            }
323	
324	        };
325	
326	        if(disableAnimation) {
327	            options.showAnimationDuration = 0;
328	        }
329	
330	        // Pass data to PhotoSwipe and initialize it
331	        gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
332	        gallery.init();
333	    };
334	
335	    // loop through all gallery elements and bind events
336	    var galleryElements = jQuery(gallerySelector);
337	
338	    for(var i = 0, l = galleryElements.length; i < l; i++) {
339	        galleryElements[i].setAttribute('data-pswp-uid', i+1);
340	        galleryElements[i].onclick = onThumbnailsClick;
341	    }
342	
343	    // Parse URL and open gallery if it contains #&pid=3&gid=1
344	    var hashData = photoswipeParseHash();
345	    if(hashData.pid > 0 && hashData.gid > 0) {
346	        openPhotoSwipe( hashData.pid - 1 ,  galleryElements[ hashData.gid - 1 ], true );
347	    }
348	};
349	
350	// execute above function if the gallery elements exists
351	if(jQuery('.gk-gallery').length) {
352		initPhotoSwipeFromDOM(jQuery('.gk-gallery'));
353	}
354	
355	// Newsletter popup
356	var newsletter_submit = jQuery('#gk-newsletter-submit');
357	
358	if(newsletter_submit.length) {
359		newsletter_submit.click(function() {
360			jQuery.cookie('gk-newsletter-popup', 1, { expires: 30, path: '/' });
361		});
362		
363		jQuery('#gk-newsletter-popup-close').click(function(e) {
364			e.preventDefault();
365			
366			jQuery.cookie('gk-newsletter-popup', 1, { expires: 30, path: '/' });
367			jQuery('#gk-newsletter-popup').addClass('hidden-popup');
368		});
369	}
370	
371	// Social sharing popups
372    var Config = {
373        Link: ".icon-share-popup",
374        Width: 500,
375        Height: 500
376    };
377 
378    // add handler links
379    var slink = document.querySelectorAll(Config.Link);
380    for (var a = 0; a < slink.length; a++) {
381        slink[a].onclick = gkPopupHandler;
382    }
383 
384    // create popup
385    function gkPopupHandler(e) {
386        e = (e ? e : window.event);
387        var t = (e.target ? e.target : e.srcElement);
388        // popup position
389        var px = Math.floor(((screen.availWidth || 1024) - Config.Width) / 2),
390            py = Math.floor(((screen.availHeight || 700) - Config.Height) / 2);
391        // open popup
392        var link_href = t.href ? t.href : t.parentNode.href;
393        var popup = window.open(link_href, "social", 
394            "width="+Config.Width+",height="+Config.Height+
395            ",left="+px+",top="+py+
396            ",location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1");
397        if (popup) {
398            popup.focus();
399            if (e.preventDefault) e.preventDefault();
400            e.returnValue = false;
401        }
402 
403        return !!popup;
404	}
405	
406	// NSP Switch UI
407	jQuery('.nsp-switch-ui').each(function(i, ui) {
408		ui = jQuery(ui);
409		
410		var firstBtn = jQuery(ui.find('i')[0]);
411		var secondBtn = jQuery(ui.find('i')[1]);
412		var arts = ui.parent().find('.nspArt');
413		
414		var minHeight = jQuery(arts[0]).find('.gkArtContentWrap').outerHeight();
415		
416		function nspSwitchUIHelper(art, delay, finalOpacity) {
417			setTimeout(function() {
418				art.css('opacity', finalOpacity);
419			}, delay);
420		}
421		
422		firstBtn.click(function() {
423			var cols = firstBtn.attr('data-cols');
424			
425			for(var j = 0; j < arts.length; j++) {
426				var art = jQuery(arts[j]);
427				nspSwitchUIHelper(art, 0, 0);
428			}
429			
430			setTimeout(function() {
431				for(var j = 0; j < arts.length; j++) {
432					arts[j] = jQuery(arts[j]);
433					arts[j].attr('class', 'nspArt nspCol' + cols);
434					arts[j].find('.gkArtContentWrap').css('min-height', minHeight + "px");
435					arts[j].css('clear', 'none');
436				}
437				
438				setTimeout(function() {
439					for(var j = 0; j < arts.length; j++) {
440						var art = jQuery(arts[j]);
441						nspSwitchUIHelper(art, 0, 1);
442					}
443				}, 300);
444			}, 350);
445		});
446		
447		secondBtn.click(function() {
448			var cols = secondBtn.attr('data-cols');
449			
450			for(var j = 0; j < arts.length; j++) {
451				var art = jQuery(arts[j]);
452				nspSwitchUIHelper(art, 0, 0);
453			}
454			
455			setTimeout(function() {
456				for(var j = 0; j < arts.length; j++) {
457					arts[j] = jQuery(arts[j]);
458					arts[j].attr('class', 'nspArt nspHorizontal nspCol' + cols);
459					arts[j].find('.nspImageWrapper').css('background-image', 'url(' + arts[j].find('.nspImageWrapper img').attr('src') + ')');
460					arts[j].find('.gkArtContentWrap').css('min-height', arts[j].find('img').outerHeight() + "px");
461					arts[j].css('clear', 'none');
462				}
463				
464				setTimeout(function() {
465					for(var j = 0; j < arts.length; j++) {
466						var art = jQuery(arts[j]);
467						nspSwitchUIHelper(art, 0, 1);
468					}
469				}, 300);
470			}, 350);
471		});
472	});
473});
474
475// Newsletter display
476jQuery(window).load(function() {
477	var newsletter = jQuery('#gk-newsletter-popup');
478	
479	if(newsletter.length) {
480		switch (newsletter.attr('data-display')) {
481		  	case 'direct':
482				setTimeout(function() {
483					newsletter.removeClass('hidden-popup');
484				}, 1000);
485				break;
486			case 'after_time':
487				setTimeout(function() {
488					newsletter.removeClass('hidden-popup');
489				}, newsletter.attr('data-time') * 1000);
490				break;
491			case 'after_scroll': 
492				var win = jQuery(window);
493				var destination = newsletter.attr('data-scroll');
494				
495				var newsletter_scroll = function() {
496					if(win.scrollTop() >= destination) {
497						newsletter.removeClass('hidden-popup');
498						jQuery(window).off('scroll', newsletter_scroll);
499					}
500				};
501				
502				jQuery(window).on('scroll', newsletter_scroll);
503				break;
504		}
505	}
506});
507
508// Reviews
509jQuery(window).load(function() {
510	jQuery('.gk-review-sum-value').each(function(i, sum) {		
511		if(
512			!jQuery(sum).parent().hasClass('gk-content-title') &&
513			!jQuery(sum).parent().hasClass('gk-review-sum')
514		) {
515			var circle = new ProgressBar.Circle(sum, {
516			    color: '#07c958',
517			    strokeWidth: 4,
518			    trailWidth: 4,
519			    duration: 1500,
520			    easing: 'easeInOut'
521			});
522			
523			circle.animate(jQuery(sum).attr('data-final'));
524		}
525	});
526});
527
528// Slideshow
529jQuery(document).ready(function() {
530	jQuery('.gk-slideshow').each(function(i, slideshow) {
531		slideshow = jQuery(slideshow);
532		var interval = parseInt(slideshow.attr('data-interval'), 10);
533		var autoanimation = interval === 0;
534		var current = 0;
535		var prev = slideshow.find('.gk-slideshow-prev');
536		var next = slideshow.find('.gk-slideshow-next');
537		var counter = slideshow.find('.gk-slideshow-counter');
538		var title = slideshow.find('.gk-slideshow-title');
539		var slides = slideshow.find('.gk-slideshow-img');
540		
541		prev.click(function(e) {
542			e.preventDefault();
543			current = (current === 0) ? slides.length - 1 : current - 1;			
544			slides.removeClass('gk-active');
545			slides[current].addClass('gk-active');
546			title.text(jQuery(slides[current]).attr('data-title'));
547			counter.text((current + 1) + ' / ' + counter.attr('data-max'));
548		});
549		
550		next.click(function(e) {
551			e.preventDefault();
552			current = (current === slides.length - 1) ? 0 : current + 1;			
553			slides.removeClass('gk-active');
554			slides[current].addClass('gk-active');
555			title.text(jQuery(slides[current]).attr('data-title'));
556			counter.text((current + 1) + ' / ' + counter.attr('data-max'));
557		});
558		
559		if(interval > 0) {
560			gkSlideshowAutoAnim(interval, next);
561		}
562	});
563	
564	function gkSlideshowAutoAnim(interval, next) {
565		setTimeout(function() {
566			next.trigger('click');
567			gkSlideshowAutoAnim(interval, next);
568		}, interval);
569	}
570});
571
572// Page preloader
573var ignore_onbeforeunload = false;
574var preloader_state = true;
575
576jQuery(document).ready(function() {
577	if(jQuery(document.body).hasClass('preloader-disabled')) {
578 		preloader_state = false;
579 	}
580
581	jQuery('a').on('click',function(){
582		if(jQuery(this).attr('href').substr(0,7) === 'mailto:') {
583	    	ignore_onbeforeunload = true;
584	    } else {
585	    	ignore_onbeforeunload = false;
586	    }
587	});
588});
589
590jQuery(window).load(function() {
591	if(preloader_state && jQuery('#gk-page-preloader').length > 0) {
592		var preloader = jQuery('#gk-page-preloader');
593		setTimeout(function() {
594			preloader.addClass('gk-to-hide');
595			
596			setTimeout(function() {
597				preloader.addClass('gk-hidden');
598			}, 500);
599		}, 500);
600	}
601});
602
603jQuery(window).on('beforeunload', function() {
604	if(preloader_state && !ignore_onbeforeunload && jQuery('#gk-page-preloader').length > 0) {
605		var preloader = jQuery('#gk-page-preloader');
606		preloader.removeClass('gk-hidden');
607		
608		setTimeout(function() {
609			preloader.removeClass('gk-to-hide');
610		}, 25);
611	}
612});

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.