PageSourceSearch

https://www.htmmedico.com.sg/wp-content/themes/medicare/js/misc.js?ver=6.3.12

js htmmedico.com.sg collected 2026-10-02 22:54:14 UTC 17,888 bytes, 539 lines download raw bytes

1'use strict';
2
3window.addEventListener("pageshow", function(evt){
4        if(evt.persisted){
5        setTimeout(function(){
6            window.location.reload();
7        },10);
8    }
9}, false);
10
11window.onunload = function(){};
12
13window.bt_loaded = false;
14
15(function( $ ) {
16
17	function bt_video_resize() {
18		$( 'iframe' ).not( '.twitter-tweet' ).not( '.instagram-media' ).not( "[src*='soundcloud']" ).each(function() {
19			if ( ! $( this ).parent().hasClass( 'boldPhotoBox' ) ) {
20				$( this ).css( 'width', '100%' );
21				$( this ).css( 'height', $( this ).width() * 9 / 16 );
22			}
23		});
24		
25		$( 'embed' ).each(function() {
26			if ( ! $( this ).parent().hasClass( 'boldPhotoBox' ) ) {
27				$( this ).css( 'width', '100%' );
28				$( this ).css( 'height', $( this ).width() * 9 / 16 );
29			}
30		});	
31	}
32	
33	/* position on screen */
34
35	jQuery.fn.isOnScreen = function( delta ) {
36		var element = this.get( 0 );
37		if ( element == undefined ) return false;
38		if( delta == undefined ) delta = 50;
39		var bounds = element.getBoundingClientRect();
40		return bounds.top + delta < window.innerHeight && bounds.bottom > 0;
41	}
42
43	$( document ).ready(function() {
44
45		$('.btDropdownSelect, .wpcf7-select').fancySelect({forceiOS: true});
46		
47		bt_video_resize();
48		
49		$( '.btSidebar select, select.orderby' ).fancySelect().on('change.fs', function() {
50			$(this).trigger('change.$');
51		});
52		
53		if ( $( '.btGhost' ).length > 0 ) {
54			$( 'body' ).append( $( '.btGhost' ) );
55			$( 'body' ).addClass( 'btHasGhost' );
56		}
57		
58		$( '.btQuoteSlider' ).wrap( '<div class="btQuoteWrapper"></div>' );
59
60		$( '.btHasGhost .btGhostSliderThumb a' ).on( 'click', function( e ) {
61			// e.preventDefault();
62			$( '.single-portfolio .btGhost' ).removeClass( 'btRemoveGhost' );
63			$( '.btHasGhost .btGhostSliderThumb' ).removeClass( 'btMarkedImage' );
64			bt_disable_scroll();
65			$( '.btGhost .slick-slider' ).slick( 'slickGoTo', $( this ).closest( '.btGhostSliderThumb' ).data( 'order-num' ) );
66		});
67		
68		if ( $( window ).scrollTop() > 0 || $( 'html' ).hasClass( 'no-csstransforms3d' ) ) {
69			$( '.btGhost' ).addClass( 'btRemoveGhost' );
70		}
71		
72		window.bt_theme_loaded = false;
73		
74		window.bt_disable_scroll = function() {
75			window.onmousewheel = document.onmousewheel = function() {
76				if ( window.bt_theme_loaded ) {
77					$( '.btCloseGhost' ).trigger( 'click' );
78				}
79				if ( ! window.bt_theme_loaded || ! window.bt_theme_allow_scroll ) {
80					// return false;
81				}
82			};
83			$( window ).on( 'DOMMouseScroll', function( e ) {
84				if ( window.bt_theme_loaded ) {
85					$( '.btCloseGhost' ).trigger( 'click' );
86				}			
87				if ( ! window.bt_theme_loaded || ! window.bt_theme_allow_scroll ) {
88					// e.preventDefault();
89				}
90			});		
91		}
92		
93		window.bt_enable_scroll = function() {
94			window.onmousewheel = document.onmousewheel = null;
95		}
96		
97		var articleWithGhost = $( '.btPostOverlay' ).length > 0;
98		
99		if ( $( '.btRemoveGhost' ).length == 0 && $( '.btGhost' ).length > 0  ) {
100			window.bt_theme_allow_scroll = false;
101			bt_disable_scroll();
102		}
103		
104		btAnimateRows();
105		if ( ! $( 'body' ).hasClass( 'impress-enabled' ) ) {
106			$( window ).scroll(function() {
107				btAnimateRows();
108			});
109		}
110
111	});
112
113	$( window ).load(function() {
114		window.bt_theme_loaded = true;
115		
116		// remove preloader
117		$( '#btPreloader' ).addClass( 'removePreloader' );
118		
119		// trigger custom load event
120		setTimeout( function() { $( window ).trigger( 'btload' ); window.bt_loaded = true; }, 1000 );
121
122		//close mobile menu on # item click
123		
124		$('.btMenuVertical nav ul.menu a').on( 'click', function() {
125			$('.btVerticalMenuTrigger').trigger( 'click' );
126		});
127                
128		/*$( '.btCartWidgetIcon' ).off('click').on( 'click', function ( e ) {
129			$(this).parent().parent().toggleClass( 'on' );
130			$('body').toggleClass( 'btCartDropdownOn' );
131		});*/
132		
133		initRefreshCart();
134		
135	});
136	
137	$( window ).resize(function() {
138		bt_video_resize();
139	});
140	
141
142	
143	// lazy image load
144	window.bt_bb_lazy_load_images = function() {
145		var $elems = $( 'img.btLazyLoadImage:not(.btLazyLoaded)' );
146		//console.log($elems);
147		$elems.each(function() {
148			var $elm = $(this);
149			//console.log($elm);
150			if ( $elm.isOnScreen( -200 ) ) {
151				$elm.addClass( 'btLazyLoaded' );
152				//console.log($elm.data( 'image_src' ));
153				$elm.attr( 'src', $elm.data( 'image_src' ));
154			}
155		});
156		var $elems = $( '.btLazyLoadBackground:not(.btLazyLoaded)' );
157		$elems.each(function() {
158			var $elm = $(this);
159			if ( $elm.isOnScreen( -200 ) ) {
160				$elm.addClass( 'btLazyLoaded' );
161				$elm.css( 'background-image', 'url(' + $elm.data( 'background_image_src' ) + ')' );
162			}
163		});
164	}
165
166	/* Animate elements */
167
168	function btAnimateRows() {
169		var winheight = $( window ).height();
170		var fullheight = $( document ).height();
171		var $elems = $( 'body:not(.btPageTransitions) .rowItem.animate:not(.animated), body:not(.btPageTransitions) .headline .animate, article.animate' ).not( '.slided .animate' );
172		// classic animations
173		$elems.each(function() {
174			var $elm = $( this );
175			if ( 
176			( $elm.isOnScreen() && ! $( 'body' ).hasClass( 'impress-enabled' ) ) ||
177			( $elm.isOnScreen() && $( 'body' ).hasClass( 'impress-enabled' ) && $elm.closest( '.boldSection' ).hasClass( 'active' ) )
178			) {
179				$elm.addClass( 'animated' );
180			}
181		});
182		bt_bb_lazy_load_images();
183	}
184
185	$( window ).on( 'btload', function() {
186		// autoplay
187		if ( $( 'li.btAnimNavNext' ).length && $( 'body' ).data( 'autoplay' ) > 0 ) {
188			window.bt_autoplay_interval = setInterval( function(){ $( 'li.btAnimNavNext' ).trigger( 'click' ); }, $( 'body' ).data( 'autoplay' ) );
189		}		
190	});
191	
192	$( window ).on( 'bt_section_animation_out', function( e, el ) {
193		$( el ).find( '.rowItem.animated' ).removeClass( 'animated' );
194	});
195	
196	$( window ).on( 'bt_section_animation_end', function( e, el ) {
197		$( el ).find( '.rowItem.animate' ).addClass( 'animated' );
198	});		
199
200	$( document ).ready(function() {
201		
202		var dropdown = $( 'select.fancified' );
203		dropdown.each(function( index ) {
204			function onCatChange() {
205				if ( $( this )[0].options[ $( this )[0].selectedIndex ].value > 0  ) {
206					$( this ).closest( 'form' )[0].submit();
207				}
208			}
209			function onSelectChange() {
210				if ( $( this )[0].options[ $( this )[0].selectedIndex ].value !== '' ) {
211				document.location.href = $( this )[0].options[ $( this )[0].selectedIndex ].value
212				}
213			}
214
215			if($( this )[0].name  == 'archive-dropdown'){
216				$( this )[0].onchange = onSelectChange;
217			} else {
218				$( this )[0].onchange = onCatChange;
219			}
220		});			
221
222		var doc = document.documentElement;
223		doc.setAttribute('data-useragent', navigator.userAgent);
224
225		// basic functions
226
227		if ( ! String.prototype.startsWith ) {
228			String.prototype.startsWith = function(searchString, position) {
229				position = position || 0;
230				return this.lastIndexOf(searchString, position) === position;
231			};
232		}
233
234		if ( ! String.prototype.endsWith ) {
235			String.prototype.endsWith = function(searchString, position) {
236				var subjectString = this.toString();
237				if (position === undefined || position > subjectString.length) {
238					position = subjectString.length;
239				}
240				position -= searchString.length;
241				var lastIndex = subjectString.indexOf(searchString, position);
242				return lastIndex !== -1 && lastIndex === position;
243			};
244		}
245
246		/* scroll handlers */
247
248		function scrollPage() {
249			var fromTop = $( this ).scrollTop();
250			$( '.btCloseGhost' ).trigger( 'click' );
251		}
252
253		function scrollPageTo( val ) {
254			val = parseInt( val );
255			$( 'body, html' ).animate({ scrollTop: val + 'px' }, 500 );
256		}
257
258		function scrollPageToId(id) {
259			if ( $( id ).length == 0 ) return false;
260			var topOffset = $( id ).offset().top;
261			if ( stickyEnabled && topOffset > stickyOffset ) {
262				topOffset -= $( '.mainHeader' ).height();
263				
264			}
265			$( 'html, body' ).animate({ scrollTop: topOffset }, 500);
266		}
267
268		/* init scroll listener */
269
270		window.addEventListener( 'scroll', scrollPage );
271	 	
272		// delay click to allow on page leave screen
273
274		$( document ).on( 'click', 'a', function() {
275			if ( ! $( this ).hasClass( 'lightbox' ) && ! $( this ).hasClass( 'add_to_cart_button' ) ) {
276				var href = $( this ).attr( 'href' );
277				if ( href !== undefined ) {
278					if ( location.href.split('#')[0] != href.split('#')[0] && ! href.startsWith( '#' ) && ! href.startsWith( 'mailto' )  && ! href.startsWith( 'callto' ) )  {
279						if ( $( this ).attr( 'target' ) != '_blank' && ! href.endsWith( '#respond' )) {
280							if ( $( '#btPreloader' ).length ) {
281								$( '#btPreloader' ).removeClass( 'removePreloader' );
282								setTimeout( function() { window.location = href }, 1500 );
283								return false;
284							}
285						}
286					} else if ( href != "#" ) {
287						if( $(this).parent().parent().attr('class') != 'tabsHeader' ) scrollPageToId( href );
288						return false;
289					}
290				}
291			}
292		});
293
294		// Vertical alignment fix
295
296		$( '.rowItem.btTopVertical, .rowItem.btMiddleVertical, .rowItem.btBottomVertical' ).parent().addClass( 'btTableRow' );
297
298		/* Footer widgets count and column set */
299
300		$( '#boldSiteFooterWidgetsRow' ).children().addClass( 'rowItem col-md-' + 12 / $( '#boldSiteFooterWidgetsRow' ).children().length + ' col-sm-12' );
301
302		// Gallery slider info bar toggler
303
304		$( '.btGetInfo' ).on( 'click', function (){
305			$(this).toggleClass( 'on' ).next().toggleClass( 'open' );
306			return false;
307		});	
308
309		// Close gallery slider
310
311		$( '.btCloseGhost' ).on('click', function () {
312			if ( ! $( '.btGhost' ).hasClass( 'btRemoveGhost' ) ) {
313				$( '.btGhost' ).addClass( 'btRemoveGhost' );
314				$( window ).trigger( 'resize' );
315				var pos = $( this ).parent().find( '.slick-slider' ).first().slick( 'slickCurrentSlide' );
316				var num_slides = $( this ).parent().find( '.slick-slider' ).find( '.slick-slide' ).length;
317				var thumbs = $( '.btGridGallery' ).first().find( '.btGhostSliderThumb' );
318				if ( thumbs.length > 0 ) {
319					var num_thumbs = thumbs.length;
320					if ( num_slides > num_thumbs && pos > 0 ) {
321						$( thumbs[ pos - 1 ] ).addClass( 'btMarkedImage' );
322						$( 'html, body' ).animate({
323							scrollTop: $( thumbs[ pos - 1 ] ).offset().top + $( thumbs[ pos - 1 ] ).height() * .5 - window.innerHeight * 0.5
324						}, 0 );
325					} else if ( num_slides == num_thumbs ) {
326						$( thumbs[ pos ] ).addClass( 'btMarkedImage' );
327						$( 'html, body' ).animate({
328							scrollTop: $( thumbs[ pos ] ).offset().top + $( thumbs[ pos ] ).height() * .5 - window.innerHeight * 0.5
329						}, 0 );
330					}
331				}
332				setTimeout( function() { window.bt_theme_allow_scroll = true; $( '.btMarkedImage' ).removeClass( 'btMarkedImage' ) }, 800 );
333				return false;
334			}
335		});
336		
337		// magnific-popup grid gallery
338		
339		$( '.tilesWall.lightbox' ).each(function() {
340			$( this ).find( 'a' ).magnificPopup({
341				type: 'image',
342				// other options
343				gallery:{
344					enabled:true
345				},
346				closeMarkup:'<button class="mfp-close" type="button"><i class="mfp-close-icn">&times;</i></button>',
347				image: {
348					titleSrc: 'data-title'
349				},
350				closeBtnInside:false		
351			});
352		});
353
354		// magnific-popup product gallery
355		$( 'body.single-product .product .images' ).each(function() {
356			$( this ).find( 'a' ).magnificPopup({
357				type: 'image',
358				// other options
359				callbacks: {
360					beforeClose: function() {
361						var photo = $( this.st.el ).closest( '.bpgPhoto' );
362						photo.removeClass( 'out-top' );
363						photo.removeClass( 'out-right' );
364						photo.removeClass( 'out-bottom' );
365						photo.removeClass( 'out-left' );						
366					}
367				},
368				gallery:{
369					enabled:true
370				},
371				closeMarkup:'<button class="mfp-close" type="button"><i class="mfp-close-icn">&times;</i></button>',
372				image: {
373					titleSrc: 'data-title'
374				},
375				closeBtnInside:false		
376			});
377		});
378
379		// Google Map with info pane
380		$('.btGoogleMapsContent').parent().addClass('wInfoPane');
381
382		// Info over Google map slide
383		$('.btInfoPaneToggler').on( 'click', function(){
384			$(this).parent().toggleClass('closed');
385		});
386
387		// Photo with icon over it
388		$('.btTextCenter').each(function(){
389			if($(this).next().is('.btIconsHalfHoverPosition, .btIconsFullHoverPosition')){
390				$(this).addClass('wIconOver');
391			}
392		});
393
394		// FancySelect overflow hidden issue
395		$('.btDropdownSelect').closest('.rowItem').addClass('btOverOthers');
396
397		// Checkboxes
398
399		/*$('input[type=checkbox]').parent().addClass('wCheckBox');
400		$('input[type=checkbox]input:checked').parent().addClass('checked');
401
402		$('input[type=checkbox]').change(function () {
403			$(this).parent().toggleClass('checked');
404		});*/
405
406		// Radios
407
408		/*$('input[type=radio]').parent().addClass('wRadio');
409		$('input[type=radio]input:checked').parent().addClass('on');
410
411		$('input[type=radio]').on( 'click', function () {
412			$('input:not(:checked)').parent().removeClass('on');
413			$('input:checked').parent().addClass('on');
414		});*/
415
416		/* Date inpu wrapper */
417		$('form.wpcf7-form input[type=date]').wrap('<span class="btDateTypeInput"></span>');
418                
419                // remove preloader
420		if(!$( 'body' ).hasClass( 'btRemovePreloader' )) {
421                    $( 'body' ).addClass( 'btRemovePreloader' );
422                }
423                
424                initPreloader();
425                
426	});
427        
428        function initPreloader() {
429            $('body.bodyPreloader').off('click').on( 'click', 'a', function() {  
430                var href = $( this ).attr( 'href' );
431				if ( href !== undefined ) {
432					if ( href.startsWith( 'tel' ) ){
433						setTimeout( function() { window.location = href }, 750 );
434						return false;
435					}
436											
437					if ( 
438							href !== undefined && 
439							! href.startsWith( 'tel' ) &&
440							! href.startsWith( '#' ) && 
441							! href.startsWith( 'mailto' ) &&  
442							! href.startsWith( 'callto' ) && 
443							! $( this ).hasClass( 'lightbox' ) && 
444							! $( this ).hasClass( 'add_to_cart_button' ) && 
445							$( this ).attr( 'target' ) != '_blank'
446					) {   
447							$( 'body' ).removeClass( 'btRemovePreloader' );
448							$( '#btPreloader' ).removeClass( 'removePreloader' );
449							setTimeout( function() { window.location = href }, 750 );
450							return false;
451					}
452				}
453            });
454		}
455        
456	
457})( jQuery );
458
459function bt_swipedetect( el, callback ) {
460  
461    var touchsurface = el,
462    swipedir,
463    startX,
464    startY,
465    distX,
466    distY,
467    threshold = 150, //required min distance traveled to be considered swipe
468    restraint = 100, // maximum distance allowed at the same time in perpendicular direction
469    allowedTime = 300, // maximum time allowed to travel that distance
470    elapsedTime,
471    startTime,
472    handleswipe = callback || function( swipedir ) {}
473  
474    touchsurface.addEventListener( 'touchstart', function( e ) {
475        var touchobj = e.changedTouches[0];
476        swipedir = 'none';
477        //dist = 0;
478        startX = touchobj.pageX;
479        startY = touchobj.pageY;
480        startTime = new Date().getTime(); // record time when finger first makes contact with surface
481        //e.preventDefault();
482    }, false );
483  
484    touchsurface.addEventListener( 'touchmove', function( e ) {
485       // e.preventDefault(); // prevent scrolling when inside DIV
486    }, false );
487  
488    touchsurface.addEventListener( 'touchend', function( e ) {
489        var touchobj = e.changedTouches[0];
490        distX = touchobj.pageX - startX;// get horizontal dist traveled by finger while in contact with surface
491        distY = touchobj.pageY - startY; // get vertical dist traveled by finger while in contact with surface
492
493        elapsedTime = new Date().getTime() - startTime; // get time elapsed
494        if ( elapsedTime <= allowedTime ) { // first condition for awipe met
495            if ( Math.abs( distX ) >= threshold && Math.abs( distY ) <= restraint ) { // 2nd condition for horizontal swipe met
496                swipedir = ( distX < 0 ) ? 'left' : 'right'; // if dist traveled is negative, it indicates left swipe
497            } else if ( Math.abs( distY ) >= threshold && Math.abs( distX ) <= restraint ) { // 2nd condition for vertical swipe met
498                swipedir = ( distY < 0 ) ? 'up' : 'down'; // if dist traveled is negative, it indicates up swipe
499            }
500        }
501
502        handleswipe( swipedir );
503        //e.preventDefault();
504    }, false );
505}
506
507function initRefreshCart() {
508		jQuery( '.cart-contents' ).each(function() {
509			bt_refresh_cart();
510		});
511		var cart_node = jQuery( '.widget_shopping_cart' )[0];
512		if ( cart_node !== undefined ) {
513			var config = { attributes: true, childList: true, subtree: true };
514			var callback = function( mutationsList, observer ) {
515				// for ( var mutation of mutationsList ) {
516				for (var index = 0; index < mutationsList.length; index) {
517					var mutation = mutationsList[index];
518					if ( mutation.type == 'childList' ) {
519						jQuery( '.btCartWidgetIcon' ).off( 'click' ).on( 'click', function ( e ) { jQuery( this ).parent().parent().toggleClass( 'on' ); jQuery('body').toggleClass( 'btCartDropdownOn' ); });
520						jQuery( '.verticalMenuCartToggler' ).off( 'click' ).on( 'click', function ( e ) { jQuery( this ).closest( '.widget_shopping_cart_content' ).removeClass( 'on' ); jQuery('body').removeClass('.btCartDropdownOn'); });
521					}
522					index++;
523				}
524			};
525			var observer = new MutationObserver( callback );
526			observer.observe( cart_node, config );
527		}
528	}
529
530function bt_refresh_cart() {
531	jQuery( '.btCartWidgetIcon' ).off('click').on( 'click', function ( e ) {
532		jQuery(this).parent().parent().toggleClass( 'on' );
533		jQuery('body').toggleClass( 'btCartDropdownOn' );
534	});
535	jQuery('.verticalMenuCartToggler').off('click').on( 'click', function() {
536		jQuery(this).closest('.widget_shopping_cart_content').removeClass('on');
537		jQuery('body').removeClass('.btCartDropdownOn');
538	});
539}

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.