(function( window, document, req_version, callback, $, script, done, readystate ){ if ( !($ = window.jQuery) || req_version > $.fn.jquery || callback( $ ) ) { script = document.createElement( 'script' ); script.type = 'text/javascript'; script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/' + req_version + '/jquery.min.js'; script.onload = script.onreadystatechange = function() { if ( !done && ( !( readystate = this.readyState ) || readystate == 'loaded' || readystate == 'complete' ) ) { console.log(window.jQuery); callback( window.jQuery, done = 1 ); window.jQuery( script ).remove(); } }; document.head.appendChild( script ); } })( window, document, '3.5.1', function( $, L ) { '$:nomunge, L:nomunge'; // Used by YUI compressor. (function( window, document, req_version, callback, $, script, done, readystate ){ if ( !(typeof $.ui != 'undefined') || req_version > $.fn.jquery || callback( $ ) ) { script = document.createElement( 'script' ); script.type = 'text/javascript'; script.src = 'https://code.jquery.com/ui/' + req_version + '/jquery-ui.min.js'; script.onload = script.onreadystatechange = function() { if ( !done && ( !( readystate = this.readyState ) || readystate == 'loaded' || readystate == 'complete' ) ) { callback($.noConflict(1), done = 1 ); var link = $("",{ rel: "stylesheet", type: "text/css", href: "https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" }); $('head').append(link); $( script ).remove(); } }; document.head.appendChild( script ); } })( window, document, '1.12.1', function( $, L ) { '$:nomunge, L:nomunge'; var amplyMatchingCompany; var amplyFormString; var amplyMatchData = {}; var amplyCompanyToken = false; var waitBindings; function amplyGetMatch(type = 'id', id) { console.log("Get Match"); $.ajax({ type: "GET", url: 'http://giveamply.com/api/donation/' + type + '/' + id + '/results', success: (data) => { amplyMatchData = data.donation; if (typeof data.companyToken != 'undefined') amplyCompanyToken = data.companyToken; amplyProcessResults(data) }, error: function (data) { console.log(data); } }); } function amplyInjectSearch(platform) { switch(platform) { case 'online-express': injectOnlineExpress(); break; } } function amplyWaitFor() { for (let i = 0; i < waitBindings[0].length; i++) { if (!document.getElementById(waitBindings[0][i]) || !document.getElementById(waitBindings[0][i]).value) { setTimeout(amplyWaitFor, 500); return; } } amplySubmitMatch(waitBindings[0], waitBindings[1]); } function htmlToElement(html) { var template = document.createElement('template'); html = html.trim(); // Never return a text node of whitespace as the result template.innerHTML = html; return template.content.firstChild; } /* global $ */ function injectOnlineExpress(){ setTimeout(injectOnlineExpress,1000); if (document.getElementById('amplyMatchInput') == null && (document.getElementById('bboxdonation_btnSecurePayment') !== null || document.getElementById('bboxmembership_btnSecurePayment') !== null)) { $('#amply-root').show(); let emailField = $('#bboxdonation_billing_divEmail'); amplyFormString = 'bboxdonation'; if (document.getElementById('bboxdonation_btnSecurePayment') == null) { emailField = $('#bboxmembership_billing_divEmail'); amplyFormString = 'bboxmembership'; } let cSearch = emailField.clone(); cSearch.attr("id", "cSearch"); cSearch.children('label').attr('for', "amplyMatchInput"); cSearch.children('label').html('Employer'); cSearch.children('label').attr('id', "amplyCompanylbl"); cSearch.children('input').attr('id', "amplyMatchInput"); cSearch.children('input').attr('name', "amplyMatchInput"); cSearch.children('input').attr("autocomplete", "off"); cSearch.children('input').attr("data-lpignore", "true"); cSearch.children('input').attr("data-form-type", "other"); cSearch.children('input').attr("type", "text"); cSearch.children('input').attr('value', ''); if (amplyMatchingCompany) { cSearch.value = amplyMatchingCompany; } else cSearch.value = ""; cSearch.children('input').attr('required', ""); emailField.after(cSearch); document.getElementById('amplyMatchInput').removeAttribute('required'); amplyCreateAutocomplete(); document.getElementById(amplyFormString + '_btnSecurePayment').addEventListener('click', gatherOnlineExpressData); document.getElementById(amplyFormString + '_btnSubmit').addEventListener('click', gatherOnlineExpressData); // addding tooltip to search-box. document.getElementById("amplyMatchInput").parentElement.append(htmlToElement(`
Once you enter your employers name, we will check to see if they have a matching gift program that could double or even triple your contribution.
i
`)); document.getElementById("cSearch").append(htmlToElement(` `)); } } function gatherOnlineExpressData() { amplyMatchingCompany = document.getElementById('amplyMatchInput').value; amplyMatchData = { "donor_name": document.getElementById(amplyFormString + '_billing_txtFirstName').value + " " + document.getElementById(amplyFormString + '_billing_txtLastName').value, "donor_email": document.getElementById(amplyFormString + '_billing_txtEmail').value, "donor_phone": document.getElementById(amplyFormString + '_billing_txtPhone').value, "address_street": document.getElementById(amplyFormString + '_billing_billingAddress_txtAddress').value, "address_city": document.getElementById(amplyFormString + '_billing_billingAddress_txtCity').value, "address_state": document.getElementById(amplyFormString + '_billing_billingAddress_ddState').value, "address_zip": document.getElementById(amplyFormString + '_billing_billingAddress_txtZip').value, "company_name": document.getElementById('amplyMatchInput').value, }; waitBindings = [[amplyFormString + '_hdnBBCheckoutTransactionID', amplyFormString + '_hdnBBCheckoutAmount'], ['transaction_id', 'amount']]; setTimeout(amplyWaitFor,500); } function amplySubmitMatch(waitFields = [], waitKeys = []) { for (let i = 0; i < waitFields.length; i++) { amplyMatchData[waitKeys[i]] = document.getElementById(waitFields[i]).value; } // if (!amplyMatchData.company_name) { // $('#companySearch').show(); // amplyCreateAutocomplete(); // return; // } if (typeof amplyMatchData.id != 'undefined' && amplyMatchData.id && amplyCompanyToken) { amplyMatchData._token = "90bMkGIklqFNToQkrIiAI2l1khVdqAlE8UMqUqHf"; amplyMatchData.company = amplyMatchData.company_name; $.ajax({ type: "POST", url: 'http://giveamply.com/api/enter-company/' + amplyCompanyToken, data: amplyMatchData, success: (data) => { amplyProcessResults(data); }, error: function (data) { console.log(data); } }); } else { $.ajax({ type: "POST", url: 'http://giveamply.com/api/v1/widget/8123/donation', data: amplyMatchData, success: (data) => { amplyProcessResults(data); }, error: function (data) { console.log(data); } }); } } function amplyProcessResults(data) { $("#amply-root").html(data.donation.match_steps.html); if ((typeof data.code != 'undefined' && data.code == '023') || (typeof data.donation != 'undefined' && data.donation.id != null && data.donation.status_id == 23)) { console.log("company Show"); $('#companySearch').show(); amplyCreateAutocomplete(true); return; } if (typeof data.donation == 'undefined' || typeof data.donation.match_steps.iMatchable == 'undefined' || !data.donation.match_steps.iMatchable) { console.log("No Instant Match Available"); return; } if (data.donation.status_id !== 25 && data.donation.status_id !== 6) { $('#step1Button').attr('href','http://giveamply.com/donation/' + data.donation.id + '/confirm/donor?web_confirm=true'); $('#step1Button').html(data.donation.match_steps.step2.text); } else { $('#step1Button').hide(); } if (data.donation.status_id == 4 || data.donation.status_id == 3) { $('#isSubmitted').show(); } else { $('#isNotSubmitted').show(); if (data.donation.status_id !== 8) $('#step1Confirm').show(); $('#donationThanksMsg').html(data.donation.match_steps.thanksMsg); } $('#donationDetails').show(); if (data.donation.status_id == 8) { $('#coRep').show(); $('#contactName').html(data.donation.company.contact_name); $('#contactEmail').html(data.donation.company.contact_email); $('#contactPhone').html(data.donation.company.contact_phone); } if (typeof data.donation.match_steps.step1 != 'undefined' && data.donation.match_steps.step1.url) { $('#step1').show(); $('#step1Link').html(data.donation.match_steps.step1.text); $('#step1Link').attr('href', data.donation.match_steps.step1.url); } $('#donationAmount').html(data.donation.amount); $('#donationTransactionId').html(data.donation.transaction_id); } function amplyCreateAutocomplete(andPost = false) { var amplyGlobalTerm = ''; var amplyChoices = {}; var xhr; var amplyMatchInputId = "#amplyMatchInput"; if (andPost) amplyMatchInputId = "#amplySearchRetry"; console.log($(amplyMatchInputId)); $(amplyMatchInputId).autocomplete({ minLength: 3, source: function (term, response){ try { xhr.abort(); } catch (e){} amplyGlobalTerm = term.term; xhr = $.getJSON('http://giveamply.com/search/company-name/' + term.term + '?exclude=false&other=true', [], function (data){ amplyChoices.raw = data['names']; amplyChoices.array = []; for (let i = 0; i < amplyChoices.raw.length; i++) { let choice = amplyChoices.raw[i]; if (choice.name !== "Other") { let alias = choice.name.toLowerCase() !== choice.company.name.toLowerCase(); amplyChoices.array.push({'value': choice.name,'name': choice.name,'company_id': choice.company_id, 'label': choice.name + (alias ? " (alias)" : ''), 'alias': alias, 'company': choice.company}); } else { amplyChoices.array.push({'value': term.term, 'label': choice.name, 'alias': false, 'company': term.term}); } } response(amplyChoices.array); }); }, select: function( event, ui ) { console.log(ui.item.name); console.log(ui.item); amplyMatchData.company_name = ui.item.name; if (andPost) amplySubmitMatch(); } }) .autocomplete( "instance" )._renderItem = function( ul, item ) { var searchMask = amplyGlobalTerm; var regEx = new RegExp(searchMask, "ig"); let listElement = $( "
" ) .append( "" + item.label.replace(regEx, function(a,b){ return '' + a + '' }) + "" ) .appendTo( ul ); if(item.alias) { listElement.attr("title", "Alias For " + item.company.name); } return listElement; }; $($(amplyMatchInputId).autocomplete("instance").menu.element).css({"max-height": "230px", "overflow-x": "auto"}); } function addCheckbox(amplyInputId, value){ let checkbox = $(''); let label = $(''); $('#' + amplyInputId).hide(); checkbox.on('click', () => { $('#' + amplyInputId).toggle(); $('#' + amplyInputId).prev().toggle(); }); $('#' + amplyInputId).prev().before(checkbox).before(label); $('#' + amplyInputId).prev().hide(); // Holding var amplyInputId = null; /*global amplyMatchingData */ if(document.getElementById('amplyMatchInput')) { amplyInputId = "amplyMatchInput"; } else if(typeof amplyMatchingData != 'undefined') { amplyInputId = amplyMatchingData.field_id; if (amplyMatchingData.opt_in) { addCheckbox(amplyInputId, amplyMatchingData.opt_in_text) } } } console.log('online-express'); amplyInjectSearch('online-express'); } , $); } );