Your IP : 216.73.216.95


Current Path : /var/test/www/ooareogundevinitiative/wp-content/themes/pain/assets/js/
Upload File :
Current File : /var/test/www/ooareogundevinitiative/wp-content/themes/pain/assets/js/main.js

!(function($){
	"use strict";
	jQuery(document).ready(function($) {
		//Back top
		function jwsthemeBackTop() {
			$('#jw-backtop').on('click', function() {
				$('html,body').animate({
					scrollTop: 0
				}, 400);
				return false;
			});

			if ($(window).scrollTop() > 300) {
				$('#jw-backtop').addClass('jw-show');
			} else {
				$('#jw-backtop').removeClass('jw-show');
			}

			$(window).on('scroll', function() {

				if ($(window).scrollTop() > 300) {
					$('#jw-backtop').addClass('jw-show');
				} else {
					$('#jw-backtop').removeClass('jw-show');
				}
			});
		}
		jwsthemeBackTop();
		//Date picker
		function jwsthemeDatePicker() {
			if ($('.ro-date-picker').length) {
				$('.ro-date-picker').datepicker();
			}
		}
		jwsthemeDatePicker();
		//useful var
		var $window = $(window);
		var mainMenuHeight = $('#jw-main-menu').height();
		/* Make easing scroll when click a link in page */
		function jwsthemeEasingMoving() {
			var $root = $('html, body');
			$('.jw-demo-select').on('click', function() {
				var href = $.attr(this, 'href');
				$root.animate({
					scrollTop: ($(href).offset().top - mainMenuHeight)
				}, 500, function() {
					window.location.hash = href;
				});
				return false;
			});
		}
		jwsthemeEasingMoving();
		//Video popup
		function jwsthemeheadervideo() {
			$("#jw-play-button").on("click", function(e){
				e.preventDefault();
					$.fancybox({
					'padding' : 0,
					'autoScale': false,
					'transitionIn': 'none',
					'transitionOut': 'none',
					'title': this.title,
					'width': 720,
					'height': 405,
					'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
					'type': 'swf',
					'swf': {
					'wmode': 'transparent',
					'allowfullscreen': 'true'
					}
				});
			});
		}
		jwsthemeheadervideo();
		/* Open the hide mini search */
		function jwsthemeOpenMiniSearchSidebar() {
			$('.jw-share-search-icon > li > a.search-icon').on('click', function() {
				$('#jw_header .widget_search').toggle();
			});
		}
		jwsthemeOpenMiniSearchSidebar()
		/* Open the hide social share */
		function jwsthemeOpenMiniSocialShareSidebar() {
			$('.jw-share-search-icon > li > a.share-icon').on('click', function() {
				$('#jw_header .jw-social-share').toggle();
			});
		}
		jwsthemeOpenMiniSocialShareSidebar();
		/* Open the hide mini cart */
		function jwsthemeOpenMiniCartSidebar() {
			$('.jw_widget_mini_cart .jw-cart-header > a.jw-icon').on('click', function() {
				$('.jw_widget_mini_cart .jw-cart-content').toggle();
			});
		}
		jwsthemeOpenMiniCartSidebar();
		/* Open the hide menu canvas */
		function jwsthemeOpenMenuSidebar() {
			$('.jw-menu-sidebar > a').on('click', function() {
				$('body').toggleClass('jw-menu-canvas-open');
			});
			$('.jw-menu-canvas-overlay').on('click', function() {
				$('body').toggleClass('jw-menu-canvas-open');
			});
		}
		jwsthemeOpenMenuSidebar();
		/* Open the hide menu */
		function jwsthemeOpenMenu() {
			var $navEl = $( '.jw-header-menu ul#nav' ),
				$btnHamburger = $( '#jw-hamburger' ), 
				$closeEl = $( '<a>', { href: '#', class: 'btn-close-menu-mobi', 'html': '<i class="fa fa-times"></i>' } );

			if( $navEl.length > 0 ) $navEl.append( $closeEl );

			$btnHamburger.on('click', function( e ) {
				e.preventDefault();
				$( 'body' ).toggleClass( 'menumobi_active' );
				$( '.jw-menu-list' ).toggleClass('hidden-xs hidden-sm is_menumobi_active');
			});

			$closeEl.on( 'click', function( e ) {
				e.preventDefault();
				$btnHamburger.trigger( 'click' );
			} )
		}
		jwsthemeOpenMenu();
		/* Header Stick */
		function jwsthemeHeaderStick() {
			if($( '.jw-header-v1, .jw-header-v3' ).hasClass( 'jw-header-stick' )) {
				var header_offset = $('#jw_header .jw-header-menu').offset();
			
				if ($(window).scrollTop() > header_offset.top) {
					$('body').addClass('jw-stick-active');
				} else {
					$('body').removeClass('jw-stick-active');
				}

				$(window).on('scroll', function() {
					if ($(window).scrollTop() > header_offset.top) {
						$('body').addClass('jw-stick-active');
					} else {
						$('body').removeClass('jw-stick-active');
					}
				});
				
				$(window).on('load', function() {
					if ($(window).scrollTop() > header_offset.top) {
						$('body').addClass('jw-stick-active');
					} else {
						$('body').removeClass('jw-stick-active');
					}
				});
				$(window).on('resize', function() {
					if ($(window).scrollTop() > header_offset.top) {
						$('body').addClass('jw-stick-active');
					} else {
						$('body').removeClass('jw-stick-active');
					}
				});
			}
		}
		jwsthemeHeaderStick();
		
		/* Header Fixed */
		function jwsthemeHeaderFixed() {
			if($( '.jw-header-v2' ).hasClass( 'jw-header-fixed' )) {
				var header_offset = $('#jw_header .jw-header-menu').offset();
			
				if ($(window).scrollTop() > header_offset.top) {
					$('body').addClass('jw-stick-active');
				} else {
					$('body').removeClass('jw-stick-active');
				}

				$(window).on('scroll', function() {
					if ($(window).scrollTop() > header_offset.top) {
						$('body').addClass('jw-stick-active');
					} else {
						$('body').removeClass('jw-stick-active');
					}
				});
				
				$(window).on('load', function() {
					if ($(window).scrollTop() > header_offset.top) {
						$('body').addClass('jw-stick-active');
					} else {
						$('body').removeClass('jw-stick-active');
					}
				});
				$(window).on('resize', function() {
					if ($(window).scrollTop() > header_offset.top) {
						$('body').addClass('jw-stick-active');
					} else {
						$('body').removeClass('jw-stick-active');
					}
				});
			}
		}
		jwsthemeHeaderFixed();		
		function jwsthemeCountDownClock() {
			$('.jw-countdown-clock').each(function() {
				var countdownTime = $(this).attr('data-countdown');
				$(this).countdown({
					until: countdownTime,
					format: 'DHMS',
					padZeroes: true
				});
			});
		}
		jwsthemeCountDownClock();
		
		/*Count up*/
		function jwsthemeCountUp() {
			if($( ".jw-number" ).length > 0) {
				$('.jw-number').counterUp({
					delay: 10,
					time: 1000
				});
			}
		}
		jwsthemeCountUp();
		/**
         * Add Product Quantity Up Down icon
         */
        $('form.cart .quantity').each(function() {
            $(this).prepend('<span class="qty-minus"><i class="fa fa-minus"></i></span>');
            $(this).append('<span class="qty-plus"><i class="fa fa-plus"></i></span>');
        });
        /* Plus Qty */
        $(document).on('click', '.qty-plus', function() {
            var parent = $(this).parent();
            $('input.qty', parent).val( parseInt($('input.qty', parent).val()) + 1);
        })
        /* Minus Qty */
        $(document).on('click', '.qty-minus', function() {
            var parent = $(this).parent();
            if( parseInt($('input.qty', parent).val()) > 1) {
                $('input.qty', parent).val( parseInt($('input.qty', parent).val()) - 1);
            }
        });
		/* Disable scrolling zoom on maps */
		$('#map').addClass('scrolloff');
		$('.overlay_map').on("mouseup",function(){
			$('#map').addClass('scrolloff'); 
		});
		$('.overlay_map').on("mousedown",function(){
			$('#map').removeClass('scrolloff');
		});
		$("#map").mouseleave(function () { 
			$('#map').addClass('scrolloff');
		});
		/*Shop*/
		$('.woocommerce-info .ro-checkout-title > a').on('click', function(event) {
			$( event.target ).closest('.woocommerce-info').toggleClass('ro-active');
		});
		function eventToggleHandle() {
			var $el = $( '.tb-event-segment' );
			$el.each( function() {
				var $this = $( this ),
					$btnToggle = $( '<span class="btn-event-toggle"><i class="fa fa-minus"></i></span>' );
				
				$this.prepend( $btnToggle );
				$btnToggle.on( 'click', function() {
					$this.toggleClass( 'minus' );
					$( this ).find( 'i' ).toggleClass( 'fa-minus fa-plus' );
				} )
			} )
		}
		eventToggleHandle();
	});
})(jQuery);


/* main */
!( function( $ ) {
	'use strict';

	var main_api = function() {
		this.init();
	}

	main_api.prototype = {
		init: function() {
			// stickyMenu
			this.stickyMenu();

			// mobiMenuHandle
			this.mobiMenuHandle();

			// comboWidgets
			this.comboWidgets();

			// chritable donate - ajax loadform
			this.chariableDonateAjaxLoadform();

			// event manager booking - ajax loadform
			this.eventManagerBookingAjaxLoadform();
		},
		stickyMenu: function() {
			$( '[data-sticky-menu]' ).each( function() {
				var $this = $( this ),
					infoEl = { top: $this.offset().top, height: $this.innerHeight() },
					scrollTop = 0;

				$( window ).on( {
					'scroll.stickyMenu': function() {
						scrollTop = $( this ).scrollTop();
						if( scrollTop >= ( infoEl.top + infoEl.height ) ) {
							$this.addClass( 'sticky-menu' );
						} else {
							$this.removeClass( 'sticky-menu' );
						}
					}
				} )
			} )
		},
		mobiMenuHandle: function() {
			var self = this;

			$( '.btn-toggle-menu-mobi' ).each( function() {
				var $this = $( this ),
					$selectorElem = $( $this.attr( 'href' ) ),
					$btnClose = $( '<a>', {
						href 	: '#',
						class 	: 'btn-close-menu-mobi',
						html 	: '<i class="ion-close-round"></i>'
					} );

				$selectorElem.append( $btnClose );

				$this.on( 'click', function( e ) {
					e.preventDefault();
					$selectorElem.toggleClass( 'is-open' );
				} )

				$btnClose.on( 'click', function( e ) {
					e.preventDefault();
					$selectorElem.toggleClass( 'is-open' );
				} )
			} )
		},
		comboWidgets: function() {
			var self = this;

			// widget_jw_combowigets
			$( '.widget_jw_combowigets' ).on( 'click', '.jwwg-icon', function( e ) {
				e.preventDefault();

				var $this = $( this ),
					container_class = $this.data( 'container' );

				setTimeout( function() {
					$( container_class ).toggleClass( 'is-open' );
					$( 'html' ).toggleClass( container_class.replace( '.', '' ) + '-open' );

					if( ! $( container_class ).hasClass( 'is-open' ) ) {
						setTimeout( function() {
							$( window ).trigger( 'resize' );
						}, 600 )
					}
				}, 10 )
			} )

			$( '.jwwg-container-menu-off-canvas' ).on( 'click', function( e ) {
				if( $( e.target ).hasClass( 'is-open' ) ) {
					$( '.jwwg-menu-off-canvas .jwwg-icon' ).click();
				}
			} )
            
			// jwwg_cart
			this.jwwg_cart = function() {

				var self = this;

				this.callback = function() {
					if( ! $( window ).data( 'jwwg_cart.minicartUpdate' ) ) {
						$( window ).data( 'jwwg_cart.minicartUpdate', function( obj ) {
							$( '.cart-data', '.jwwg-cart .jwwg-icon' ).html( obj.cart_count );
							$( '.jwwg-container-cart', '.jwwg-cart' ).html( obj.cart_template );
						} )
					}
				}
				this.callback();

				this.updateMinicart = function() {
		            // ask server for updated data
		            $.ajax( {
		            	type: 'POST',
		                url: main_object.ajax_url,
		                data: { action: 'jwsthemes_mode_minicart_update' },
		                success: function( data ) {
		                    
		                    try{
		                    	var cart_obj = JSON.parse( data );
		                    	$( window ).data( 'jwwg_cart.minicartUpdate' ).call( this, cart_obj );
		                    }catch ( e ) {
		                    	console.log( 'result updateMinicart: ', e );
		                    }
		                },
		                error: function( e ) {
		                	console.log( 'updateMinicart: ', e );
		                }
		            } );
		        }
		        this.updateMinicart();

		        // auto update after 30s
		        setInterval( function() { self.updateMinicart() }, 1000 * 30 );


		        // ajaxComplete
		        $( document ).ajaxComplete( function( event, xhr, ajaxOpts ) {
		            // check for WP e-Commerce "empty_cart" action
		            if ( 'data' in ajaxOpts && ( ajaxOpts.data.indexOf( 'action=empty_cart' ) != -1 || ajaxOpts.data.indexOf( 'product_id' ) != -1 ) ) 
		            {
		                self.updateMinicart();
		            }
		        });

				$( document ).on( 'wpsc_fancy_notification', function( event ) {
		            self.updateMinicart();
		        });
			}
			//this.jwwg_cart(); // use jwwg_cart()

			// remove product ajax
			this.removeProductAjax = function() {
				$( '.jwwg-container-cart' ).on( 'click', '.remove', function( e ) {
					e.preventDefault();

					var $this = $( this ),
						$itemWrap = $this.parent( 'li.mini_cart_item' ),
						pid = $this.data( 'product_id' );

					// add class jw-ajax-handle
					$itemWrap.addClass( 'jw-ajax-handle' );

					$.ajax( {
						type: 'POST',
						url: main_object.ajax_url,
						data: { action: 'jwsthemes_remove_product_minicart', product_id: pid },
						success: function( data ) {
							self.updateMinicart();
						},
						error: function( e ) {
							console.log( 'remove product ajax: ', e );
						}
					} )
				} )
			}
			this.removeProductAjax();
		},
        
		chariableDonateAjaxLoadform: function() {
			var self = this;

			$( 'body' ).on( 'click.charitableAjaxLoadform', '.charitable-donate-ajax-loadform', function( e ) {
				e.preventDefault();

				var $this = $( this ),
					campaign_id = $this.data( 'campaign-id' ),
					campaign_title = $this.data( 'campaign-title' ),
					campaign_img = $this.data( 'campaign-img' ),
					$modal = self.bearsModal();

				$.ajax( {
					type: 'POST',
					url: main_object.ajax_url,
		            data: { action: 'get_donation_form', campaign_id: campaign_id },
					success: function( result ) {
						console.log( result );
						try{
							if( result.success != true ) return;

							// show container 
							$modal
							.trigger( 'buildHeader', [campaign_img, campaign_title] )
							.trigger( 'updateContent', [result.data] )
							.trigger( 'showContainer' );

							CHARITABLE.PaymentMethodSelection.init();
						} catch( e ) { console.log( e ) }
					},
					error: function( e ) {
						console.log( e );
					}
				} )
			} )
		},
		eventManagerBookingAjaxLoadform: function() {
			var self = this;

			self.eventManagerBookingFormHandle = function( $form, callback ) {
				$form.on( 'submit', function( e ) {
					e.preventDefault();

					var $this = $( this ),
						formdata = $this.serialize();

					$this.find( '.em-booking-buttons' ).addClass( 'ajax-loading' );

					$.ajax({
						url: main_object.ajax_url,
						data: formdata,
						dataType: 'jsonp',
						type:'POST',
						success : function( response ) {

							$this.parent().find( '.em-booking-message' ).remove();
							$this.find( '.em-booking-buttons' ).removeClass( 'ajax-loading' );
							if( response.result ){
								$this.before( '<div class="em-booking-message em-booking-success">'+ response.message + '</div>' );
							}else{
								$this.before( '<div class="em-booking-message em-booking-error">'+ response.message + response.errors +'</div>' );
							}

							// callback
							if( callback ) callback.call( this, response )
						},
						error: function( e ) {
							console.log( e );
						}
					});
				} )
			}

			$( 'body' ).on( 'click.eventManagerAjaxLoadform', '.event-manager-ajax-loadform', function( e ) {
				e.preventDefault();

				var $this = $( this ),
					event_id = $this.data( 'event-id' ),
					event_title = $this.data( 'event-title' ),
					event_img = $this.data( 'event-img' ),
					redirect_to = $this.data( 'redirect-to' ),
					$modal = self.bearsModal();

				$.ajax( {
					type: 'POST',
					url: main_object.ajax_url,
					data: { action: 'jwstheme_eventManagerBook_form', event_id: event_id },
					dataType: 'json',
					success: function( result ) {
						// console.log( result );	
						try{
							$modal
							.trigger( 'buildHeader', [event_img, event_title] )
							.trigger( 'updateContent', [result.data] )
							.trigger( 'showContainer' );

							if( $modal.find( 'input[name="redirect_to"]' ).length > 0 )
								$modal.find( 'input[name="redirect_to"]' ).val( redirect_to )

							// booking form submit
							self.eventManagerBookingFormHandle( $modal.find( 'form[name="booking-form"]' ), function() {
								$modal.trigger( 'scrollTop' );
							} );

						} catch( e ) { console.log( e ) }
					},
					error: function( e ) {
						console.log( e )
					}
				} )
			} )
		},
		bearsModal: function( callback ) {
			var modal_temp = '';

			modal_temp = 	'<div class="bears-modal-wral">';
			modal_temp += 	'	<div class="bears-modal-container">';
			modal_temp += 	'		<div class="bears-modal-container-inner">';
			modal_temp += 	'			<a href="#!" class="close-modal"><i class="fa fa-times"></i></a>';
			modal_temp += 	'			<div class="modal-body"></div>';
			modal_temp += 	'		</div>';
			modal_temp += 	'	</div>';
			modal_temp += 	'</div>';

			// modal elem
			var $modal_elem =  $( modal_temp );

			// body is modal
			$( 'body' ).addClass( 'bears-modal-is-open' );

			// loading success
			$modal_elem.on( {
				'buildHeader': function( e, image, title ) {
					var header_temp = '';
					header_temp += '<div class="header-modal" style="background: url('+ image +') no-repeat center center / cover, #333">';
					header_temp += '	<h3 class="title">'+ title +'</h3>';
					header_temp += '</div>';

					$modal_elem.find( '.modal-body' ).before( header_temp );
				},
				'showContainer': function() { 
					$( this ).addClass( 'is-show' ); 
				},
				'closeModal': function() { 
					$( this ).addClass( 'is-close' );

					setTimeout( function() {
						$( 'body' ).removeClass( 'bears-modal-is-open' );
						$modal_elem.remove();
					}, 500 )
				},
				'updateContent': function( e, container ) {
					$( this ).find( '.modal-body' ).html( container );
				},
				'click': function( e ) {
					var $target = $( e.target );
					if(  $target.hasClass( 'bears-modal-wral' ) ) $( this ).trigger( 'closeModal' )

				},
				'scrollTop': function() {
					$( this ).animate( {
						scrollTop: 0
					}, 200 )
				}	
			} )

			$modal_elem.find( 'a.close-modal' ).on( 'click', function( e ) {
				e.preventDefault();
				$modal_elem.trigger( 'closeModal' );
			} )

			// append body
			$( 'body' ).append( $modal_elem )

			// callback
			if( callback ) callback.call( this, $modal_elem );

			// return Elem
			return $modal_elem;
		}
	}

	function effectFadeInFadeOutWhenRedirect() {
		// delegate all clicks on "a" tag (links)
		$(document).on("click", "a[data-smooth-link]", function () {

		    // get the href attribute
		    var newUrl = $(this).attr("href");

		    // veryfy if the new url exists or is a hash
		    if (!newUrl || newUrl[0] === "#") {
		        // set that hash
		        location.hash = newUrl;
		        return;
		    }

		    // now, fadeout the html (whole page)
		    $("html").fadeOut(function () {
		        // when the animation is complete, set the new location
		        location = newUrl;
		    });

		    // prevent the default browser behavior.
		    return false;
		});
	}

	/* DOM Ready */
	$( function() {

		// use main_api()
		new main_api();

		// use effectFadeInFadeOutWhenRedirect()
		effectFadeInFadeOutWhenRedirect();
	} )
} )( jQuery )