jQuery(document).ready(function($){
// disable any cart attributes that have a class of "CartDisabled"
jQuery('.gform_wrapper .CartDisabled input').attr('disabled','disabled');
// remove disabled attribute when the form is submitted
jQuery('form.cart').submit(function() {
if (jQuery('.gform_wrapper .CartDisabled input') && jQuery('.gform_wrapper .CartDisabled input').is(':disabled')) jQuery('.gform_wrapper .CartDisabled input').removeAttr('disabled');
});
// if the hidden field "SCImage" is populated, then put that value in HTML field
if (jQuery('.gform_wrapper #input_1_5').length) {
jQuery('.gform_wrapper #field_1_3').html('
');
}
});
/**
* Initial search -- simply display first three results from array
*/
function sponsor_child_search(category, SearchGender, SearchCommunity, SearchAge, SearchId) {
var ajaxFilePath = '/wp-content/themes/Avada-Child-Theme/ajax/sponsor_child_search1.php';
var date = new Date();
var jSponsorChildSearchResults = jQuery('#SponsorChildSearchResults');
if (SearchId == 'HOL ID #') SearchId = '';
var QS = '&SearchGender=' + escape(SearchGender) + '&SearchCommunity=' + escape(SearchCommunity) + '&SearchAge=' + escape(SearchAge) + '&SearchId=' + escape(SearchId);
jQuery.ajax({
url: ajaxFilePath + '?category=' + category + '&r=' + date.getTime() + QS
}).success(function (results) {
//alert(results);
jSponsorChildSearchResults.html(results).waitForImages(function() {
jSponsorChildSearchResults.fadeIn('slow');
});
//jQuery('#SponsorChildSearchResults').html(results);
}).error(function (xhr, status, error) {
//var ErrorText = eval("(" + xhr.responseText + ")");
var ErrorText = '
There was an error while getting the updated results. Please try again.
';
jSponsorChildSearchResults.html(ErrorText);
jSponsorChildSearchResults.fadeIn('slow');
})
}
/**
* Update search results -- display next three results from array
*/
function update_sponsor_child_search(category, srs) {
var jSponsorChildSearchResults = jQuery('#SponsorChildSearchResults');
var resultsHeight = jSponsorChildSearchResults.height() + 'px';
jQuery('#SponsorChildSearchContainer').css('min-height', resultsHeight)
// scroll to top of search results div
jQuery('#SponsorChildSearchTop').ScrollTo({
duration: 500,
callback: function () {
// hide old results
jSponsorChildSearchResults.fadeOut(500, function () {
// perform AJAX call to reload search results
var ajaxFilePath = '/wp-content/themes/Avada-Child-Theme/ajax/sponsor_child_search2.php';
var date = new Date();
var QS = '&category=' + category + '&SearchResultsStart=' + srs;
jQuery.ajax({
url: ajaxFilePath + '?r=' + date.getTime() + QS
}).success(function (results) {
// wait for images to fully load, and then display results
jSponsorChildSearchResults.html(results).waitForImages(function () {
jSponsorChildSearchResults.fadeIn(500);
});
}).error(function (xhr, status, error) {
//var ErrorText = eval("(" + xhr.responseText + ")");
//var ErrorText = '
There was an error while getting the updated results. Please try again.
';
//jSponsorChildSearchResults.html(ErrorText);
})
});
}
});
}
/**
* Home search results -- send qs to sponsor page and have results show there
*/
function home_sponsor_child_search() {
var date = new Date();
var SearchGender = jQuery('#SponsorChildSearchGender').val();
var SearchCommunity = jQuery('#SponsorChildSearchCommunity').val();
var SearchAge = jQuery('#SponsorChildSearchAge').val();
var SearchId = jQuery('#SponsorChildSearchId').val();
if (SearchId == 'undefined' || SearchId == 'HOL ID #') SearchId = '';
var QS = '&SearchGender=' + escape(SearchGender) + '&SearchCommunity=' + escape(SearchCommunity) + '&SearchAge=' + escape(SearchAge) + '&SearchId=' + escape(SearchId);
document.location = '/sponsor/?r=' + date.getTime() + QS;
}
/**
* Custom search results -- start over and display first three results from array
*/
function custom_sponsor_child_search() {
var jSponsorChildSearchResults = jQuery('#SponsorChildSearchResults');
var resultsHeight = jSponsorChildSearchResults.height() + 'px';
jQuery('#SponsorChildSearchContainer').css('min-height', resultsHeight);
// scroll to top of search results div
jQuery('#SponsorChildSearchTop').ScrollTo({
duration: 500,
callback: function () {
// hide old results
jSponsorChildSearchResults.fadeOut(500, function () {
// perform AJAX call to reload search results
var ajaxFilePath = '/wp-content/themes/Avada-Child-Theme/ajax/sponsor_child_search3.php';
var date = new Date();
var SearchGender = jQuery('#SponsorChildSearchGender').val();
var SearchCommunity = jQuery('#SponsorChildSearchCommunity').val();
var SearchAge = jQuery('#SponsorChildSearchAge').val();
var SearchId = jQuery('#SponsorChildSearchId').val();
if (SearchId == 'HOL ID #') SearchId = '';
var QS = '&SearchGender=' + escape(SearchGender) + '&SearchCommunity=' + escape(SearchCommunity) + '&SearchAge=' + escape(SearchAge) + '&SearchId=' + escape(SearchId);
jQuery.ajax({
url: ajaxFilePath + '?r=' + date.getTime() + QS
}).success(function (results) {
// wait for images to fully load, and then display results
jSponsorChildSearchResults.html(results).waitForImages(function () {
jSponsorChildSearchResults.fadeIn(500);
});
}).error(function (xhr, status, error) {
//var ErrorText = eval('(' + xhr.responseText + ')');
var ErrorText = '
There was an error while getting the updated results. Please try again.
';
jSponsorChildSearchResults.html(ErrorText);
jSponsorChildSearchResults.fadeIn('slow');
})
});
}
});
}
function add_sponsor_child_to_cart(name, age, classification, id) {
var QS = '&SCName=' + escape(name) + '&SCAge=' + escape(age) + '&SCClassification=' + escape(classification) + '&SCImage=' + escape(id);
if (2 == 1) {
// perform AJAX call to reload search results
var ajaxFilePath = '/wp-content/themes/Avada-Child-Theme/ajax/add_sponsored_child_to_cart.php';
var date = new Date();
jQuery.ajax({
url: ajaxFilePath + '?r=' + date.getTime() + QS
}).success(function (results) {
alert('Success!');
}).error(function (xhr, status, error) {
var ErrorText = eval("(" + xhr.responseText + ")");
alert(ErrorText);
})
} else {
if (classification == 'Kelly\'s House') {
productId = 948;
productURL = '/product/kellys-house-sponsorship/';
} else if (classification == 'Oasis de Eden') {
productId = 947;
productURL = '/product/oasis-de-eden-sponsorship/';
} else {
productId = 946;
productURL = '/product/child-sponsorship/';
}
//document.location = '/cart/?add-to-cart=' + productId + QS;
document.location = productURL + '?' + QS
}
}
/**
* in case search form gets submitted, this will make sure it works
*/
function custom_sponsor_child_search_submit(opt) {
jQuery('#SponsorChildSearchTop').ScrollTo({
duration: 500,
callback: function () {
// hide old results
jQuery('#SponsorChildSearchResults').fadeOut(500, function () {
if (opt == 0) {
document.SponsorChildSearchForm.submit();
} else {
return true;
}
});
}
});
}
/********************************************************/
/* Wait for images jQuery plugin so AJAX content doesn't show until all images for the page have downloaded. */
/********************************************************/
/*! waitForImages jQuery Plugin 2015-06-02 */
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){var b="waitForImages";a.waitForImages={hasImageProperties:["backgroundImage","listStyleImage","borderImage","borderCornerImage","cursor"],hasImageAttributes:["srcset"]},a.expr[":"]["has-src"]=function(b){return a(b).is('img[src][src!=""]')},a.expr[":"].uncached=function(b){return a(b).is(":has-src")?!b.complete:!1},a.fn.waitForImages=function(){var c,d,e,f=0,g=0,h=a.Deferred();if(a.isPlainObject(arguments[0])?(e=arguments[0].waitForAll,d=arguments[0].each,c=arguments[0].finished):1===arguments.length&&"boolean"===a.type(arguments[0])?e=arguments[0]:(c=arguments[0],d=arguments[1],e=arguments[2]),c=c||a.noop,d=d||a.noop,e=!!e,!a.isFunction(c)||!a.isFunction(d))throw new TypeError("An invalid callback was supplied.");return this.each(function(){var i=a(this),j=[],k=a.waitForImages.hasImageProperties||[],l=a.waitForImages.hasImageAttributes||[],m=/url\(\s*(['"]?)(.*?)\1\s*\)/g;e?i.find("*").addBack().each(function(){var b=a(this);b.is("img:has-src")&&j.push({src:b.attr("src"),element:b[0]}),a.each(k,function(a,c){var d,e=b.css(c);if(!e)return!0;for(;d=m.exec(e);)j.push({src:d[2],element:b[0]})}),a.each(l,function(c,d){var e,f=b.attr(d);return f?(e=f.split(","),void a.each(e,function(c,d){d=a.trim(d).split(" ")[0],j.push({src:d,element:b[0]})})):!0})}):i.find("img:has-src").each(function(){j.push({src:this.src,element:this})}),f=j.length,g=0,0===f&&(c.call(i[0]),h.resolveWith(i[0])),a.each(j,function(e,j){var k=new Image,l="load."+b+" error."+b;a(k).one(l,function m(b){var e=[g,f,"load"==b.type];return g++,d.apply(j.element,e),h.notifyWith(j.element,e),a(this).off(l,m),g==f?(c.call(i[0]),h.resolveWith(i[0]),!1):void 0}),k.src=j.src})}),h.promise()}});
/********************************************************/
/* jQuery.ScrollTo plugin */
/********************************************************/
(function (name, context, definition) {
if (typeof module != 'undefined' && module.exports) module.exports = definition();
else if (typeof define == 'function' && define.amd) define(definition);
else context[name] = definition();
})('jquery-scrollto', this, function(){
// Prepare
var jQuery, $, ScrollTo;
jQuery = $ = window.jQuery || require('jquery');
// Fix scrolling animations on html/body on safari
$.propHooks.scrollTop = $.propHooks.scrollLeft = {
get: function(elem,prop) {
var result = null;
if ( elem.tagName === 'HTML' || elem.tagName === 'BODY' ) {
if ( prop === 'scrollLeft' ) {
result = window.scrollX;
} else if ( prop === 'scrollTop' ) {
result = window.scrollY;
}
}
if ( result == null ) {
result = elem[prop];
}
return result;
}
};
$.Tween.propHooks.scrollTop = $.Tween.propHooks.scrollLeft = {
get: function(tween) {
return $.propHooks.scrollTop.get(tween.elem, tween.prop);
},
set: function(tween) {
// Our safari fix
if ( tween.elem.tagName === 'HTML' || tween.elem.tagName === 'BODY' ) {
// Defaults
tween.options.bodyScrollLeft = (tween.options.bodyScrollLeft || window.scrollX);
tween.options.bodyScrollTop = (tween.options.bodyScrollTop || window.scrollY);
// Apply
if ( tween.prop === 'scrollLeft' ) {
tween.options.bodyScrollLeft = Math.round(tween.now);
}
else if ( tween.prop === 'scrollTop' ) {
tween.options.bodyScrollTop = Math.round(tween.now);
}
// Apply
window.scrollTo(tween.options.bodyScrollLeft, tween.options.bodyScrollTop);
}
// jQuery's IE8 Fix
else if ( tween.elem.nodeType && tween.elem.parentNode ) {
tween.elem[ tween.prop ] = tween.now;
}
}
};
// jQuery ScrollTo
ScrollTo = {
// Configuration
config: {
duration: 400,
easing: 'swing',
callback: undefined,
durationMode: 'each',
offsetTop: 0,
offsetLeft: 0
},
// Set Configuration
configure: function(options){
// Apply Options to Config
$.extend(ScrollTo.config, options||{});
// Chain
return this;
},
// Perform the Scroll Animation for the Collections
// We use $inline here, so we can determine the actual offset start for each overflow:scroll item
// Each collection is for each overflow:scroll item
scroll: function(collections, config){
// Prepare
var collection, $container, container, $target, $inline, position, containerTagName,
containerScrollTop, containerScrollLeft,
containerScrollTopEnd, containerScrollLeftEnd,
startOffsetTop, targetOffsetTop, targetOffsetTopAdjusted,
startOffsetLeft, targetOffsetLeft, targetOffsetLeftAdjusted,
scrollOptions,
callback;
// Determine the Scroll
collection = collections.pop();
$container = collection.$container;
$target = collection.$target;
containerTagName = $container.prop('tagName');
// Prepare the Inline Element of the Container
$inline = $('').css({
'position': 'absolute',
'top': '0px',
'left': '0px'
});
position = $container.css('position');
// Insert the Inline Element of the Container
$container.css({position:'relative'});
$inline.appendTo($container);
// Determine the top offset
startOffsetTop = $inline.offset().top;
targetOffsetTop = $target.offset().top;
targetOffsetTopAdjusted = targetOffsetTop - startOffsetTop - parseInt(config.offsetTop,10);
// Determine the left offset
startOffsetLeft = $inline.offset().left;
targetOffsetLeft = $target.offset().left;
targetOffsetLeftAdjusted = targetOffsetLeft - startOffsetLeft - parseInt(config.offsetLeft,10);
// Determine current scroll positions
containerScrollTop = $container.prop('scrollTop');
containerScrollLeft = $container.prop('scrollLeft');
// Reset the Inline Element of the Container
$inline.remove();
$container.css({position:position});
// Prepare the scroll options
scrollOptions = {};
// Prepare the callback
callback = function(event){
// Check
if ( collections.length === 0 ) {
// Callback
if ( typeof config.callback === 'function' ) {
config.callback();
}
}
else {
// Recurse
ScrollTo.scroll(collections,config);
}
// Return true
return true;
};
// Handle if we only want to scroll if we are outside the viewport
if ( config.onlyIfOutside ) {
// Determine current scroll positions
containerScrollTopEnd = containerScrollTop + $container.height();
containerScrollLeftEnd = containerScrollLeft + $container.width();
// Check if we are in the range of the visible area of the container
if ( containerScrollTop < targetOffsetTopAdjusted && targetOffsetTopAdjusted < containerScrollTopEnd ) {
targetOffsetTopAdjusted = containerScrollTop;
}
if ( containerScrollLeft < targetOffsetLeftAdjusted && targetOffsetLeftAdjusted < containerScrollLeftEnd ) {
targetOffsetLeftAdjusted = containerScrollLeft;
}
}
// Determine the scroll options
if ( targetOffsetTopAdjusted !== containerScrollTop ) {
scrollOptions.scrollTop = targetOffsetTopAdjusted;
}
if ( targetOffsetLeftAdjusted !== containerScrollLeft ) {
scrollOptions.scrollLeft = targetOffsetLeftAdjusted;
}
// Check to see if the scroll is necessary
if ( $container.prop('scrollHeight') === $container.width() ) {
delete scrollOptions.scrollTop;
}
if ( $container.prop('scrollWidth') === $container.width() ) {
delete scrollOptions.scrollLeft;
}
// Perform the scroll
if ( scrollOptions.scrollTop != null || scrollOptions.scrollLeft != null ) {
$container.animate(scrollOptions, {
duration: config.duration,
easing: config.easing,
complete: callback
});
}
else {
callback();
}
// Return true
return true;
},
// ScrollTo the Element using the Options
fn: function(options){
// Prepare
var collections, config, $container, container;
collections = [];
// Prepare
var $target = $(this);
if ( $target.length === 0 ) {
// Chain
return this;
}
// Handle Options
config = $.extend({},ScrollTo.config,options);
// Fetch
$container = $target.parent();
container = $container.get(0);
// Cycle through the containers
while ( ($container.length === 1) && (container !== document.body) && (container !== document) ) {
// Check Container for scroll differences
var containerScrollTop, containerScrollLeft;
containerScrollTop = $container.css('overflow-y') !== 'visible' && container.scrollHeight !== container.clientHeight;
containerScrollLeft = $container.css('overflow-x') !== 'visible' && container.scrollWidth !== container.clientWidth;
if ( containerScrollTop || containerScrollLeft ) {
// Push the Collection
collections.push({
'$container': $container,
'$target': $target
});
// Update the Target
$target = $container;
}
// Update the Container
$container = $container.parent();
container = $container.get(0);
}
// Add the final collection
collections.push({
'$container': $('html'),
// document.body doesn't work in firefox, html works for all
// internet explorer starts at the beggining
'$target': $target
});
// Adjust the Config
if ( config.durationMode === 'all' ) {
config.duration /= collections.length;
}
// Handle
ScrollTo.scroll(collections,config);
// Chain
return this;
}
};
// Apply our extensions to jQuery
$.ScrollTo = $.ScrollTo || ScrollTo;
$.fn.ScrollTo = $.fn.ScrollTo || ScrollTo.fn;
// Export
return ScrollTo;
});