/* arya */ $(document).ready(function () { arya.init(); }); var arya = { mode: '', optionsGlobal: optionsGlobal, optionsCampaign: optionsCampaign, options: {}, campaign_stats: campaign_stats, campaign_stats_last_donators: campaign_stats_last_donators, context_lang: context_lang, pageTypeRender: '', preloader: function () { var _arya_preloader = _arya_preloader || 1000; $('body').prepend('
\
\
\
\
\
\
\
'); setTimeout(function () { $('#loader').fadeOut('slow', function () { // Animation complete. arya.adaptHeight(); }); }, _arya_preloader); $('#type-b').addClass('loaded'); }, adaptHeight: function () { if (typeof Steps != 'undefined') { Steps.adapted_height || ($('#step-1 .step-content').children().wrapAll('
'), $('#step-2 .step-content').children().wrapAll('
'), $("#step-3 .step-content").children().wrapAll('
'), $(window).load(Steps.adaptHeight)), Steps.adapted_height = !0; var e = $('#step-1 .height_adaptor').height(), t = $('#step-2 .height_adaptor').height(), a = $('#step-3 .height_adaptor').height(), i = Math.max(e, t, a); $('.step-content').height(i); } }, init: function () { // init options from global or campaigns arya.initThemeOptions(); }, start: function () { arya.pageTypeRender(); arya.stepsRender(); arya.placeholders(); arya.step1(); arya.step2(); arya.step3(); arya.stepInfos(); arya.initWidgets(); arya.amountsRender(); $('body').bind('change_amount', arya.changeAMount); if ($('#greetings').length > 0) { $('body').addClass('thanks-page'); } arya.preloader(); aryaAmounts.init(); arya.initCssOptions(); arya.initVar() if (arya.amount_in_valid == '1') { arya.btnRender(); } arya.colorAdjust(); setTimeout(function () { arya.sizing(); }, 2000); }, initThemeOptions: function () { arya.options = { 'KFJEi9kava0x5LjA0SMy': '', 'active_theme': '', 'font': '', 'font_title': '', 'wedge': '', 'donation_grid': '', 'one_column_mobile': '', 'widgets_footer': '', 'widgets_header': '', 'widgets_progress_bar_goal': '', 'widgets_progress_bar_text': '', 'widgets_last_donors': '', 'widgets_last_donors_filter': '', 'widgets_last_donors_text': '', 'widgets_cookies_banner': '', 'widgets_cookies_banner_text': '', '--main-action-color': '', '--main-action-color-lighter': '', '--description-color': '', '--information-color': '', '--column-background-color': '', '--banner-color': '', '--banner-color-darker': '' }; if (arya.optionsCampaign['active_theme'] == '1' && (arya.optionsCampaign['overload_theme'] == '1' || typeof arya.optionsGlobal['active_theme'] == 'undefined')) { arya.mode = 'campaign'; } else if (arya.optionsGlobal['active_theme'] == '1') { arya.mode = 'global'; } else { arya.mode = 'off'; } arya.setTheme(arya.mode); }, setTheme: function (mode) { switch (mode) { case 'global': $('body').addClass('arya'); //console.log(' theme global ON'); $.each(arya.optionsGlobal, function (key, value) { arya.options[key] = arya.optionsGlobal[key]; }); arya.options['widgets_last_donors_text'] = arya.optionsGlobal['widgets_last_donors_text_' + arya.context_lang]; arya.options['widgets_progress_bar_text'] = arya.optionsGlobal['widgets_progress_bar_text_' + arya.context_lang]; arya.options['widgets_cookies_banner_text'] = arya.optionsGlobal['widgets_cookies_banner_text_' + arya.context_lang]; console.log('ARYA GLOBAL'); arya.start(); break; case 'campaign': $('body').addClass('arya'); //console.log(' OVERLOAD theme campagne ON'); $.each(arya.optionsCampaign, function (key, value) { arya.options[key] = arya.optionsCampaign[key]; }); arya.options['widgets_last_donors_text'] = arya.optionsCampaign['widgets_last_donors_text_' + arya.context_lang]; arya.options['widgets_progress_bar_text'] = arya.optionsCampaign['widgets_progress_bar_text_' + arya.context_lang]; arya.options['widgets_cookies_banner_text'] = arya.optionsCampaign['widgets_cookies_banner_text_' + arya.context_lang]; console.log('ARYA CAMPAIGN'); arya.start(); break; case 'off': console.log('ARYA OFF'); return; break; default: console.log('ARYA OFF'); } }, initCssOptions: function () { let root = document.documentElement; root.style.setProperty('--main-action-color', arya.options['--main-action-color']); root.style.setProperty('--main-action-color-lighter', utils.lightenDarkenColor(arya.options['--main-action-color'], 35)); root.style.setProperty('--border-radius', arya.options['wedge'] + 'px'); root.style.setProperty('--description-color', arya.options['--description-color']); root.style.setProperty('--information-color', arya.options['--information-color']); root.style.setProperty('--column-background-color', arya.options['--column-background-color']); root.style.setProperty('--banner-color', arya.options['--banner-color']); root.style.setProperty('--banner-color-darker', utils.lightenDarkenColor(arya.options['--banner-color'], -45)); if( arya.options['font'] != ''){ WebFont.load({ google: { families: [arya.options['font'] + ':300,700'] } }); } if( arya.options['font_title'] != ''){ WebFont.load({ google: { families: [arya.options['font_title'] + ':300,700'] } }); } $('body').css('font-family', arya.options['font']); $('#type-b.arya h1, #type-b.arya h2, #type-b.arya h3, #type-b.arya h4, #type-b.arya h5, #type-b.arya h6').css('font-family', arya.options['font_title']); if (typeof Step3 != 'undefined') { Step3.select('h4').css('font-family', arya.options['font_title']); } }, initVar: function () { if (typeof amount_in_valid_text != 'undefined' && amount_in_valid_text != '') { arya.amount_btn_text = amount_in_valid_text; } else { if (typeof Step3 != 'undefined') { arya.amount_btn_text = Step3.select('.payment-submit .button').first().val(); } } if (typeof amount_in_valid != 'undefined') { arya.amount_in_valid = amount_in_valid; } }, initWidgets: function () { if (arya.options['widgets_last_donors'] == 'true' && arya.pageTypeRender == 'form_page') { arya.widgets_last_donors(); }; if (arya.options['widgets_header'] == '3' && arya.pageTypeRender == 'form_page') { arya.widgets_progress_bar(); }; if (arya.options['one_column_mobile'] == 'true') { arya.oneColumn(); }; if (arya.options['widgets_cookies_banner'] == 'true') { arya.widgets_cookiesBanner(); }; }, changeAMount: function () { arya.adaptHeight(); arya.sizing(); arya.UpdateCreditCardType(); }, widgets_cookiesBanner: function () { if (Cookies.get('cookies_accepted') != 'true') { $('#container').prepend('
' + arya.options['widgets_cookies_banner_text'] + 'ok
'); $('#cookiesBanner .close').on('click', function () { $('#cookiesBanner').slideUp('slow', function () { // Animation complete. Cookies.set('cookies_accepted', 'true'); }); }); } }, pageTypeRender: function(){ if( typeof Thanks == 'undefined' && typeof Steps == 'undefined'){ arya.pageTypeRender = 'annexes_pages'; $('body').addClass('annexes_pages'); $('body #main').wrapInner('
'); $('body #footer').wrapInner(''); } else if( typeof Thanks != 'undefined'){ arya.pageTypeRender = 'thanks_page'; $('body').addClass('thanks_page'); } else { arya.pageTypeRender = 'form_page'; } }, stepsRender: function () { if (typeof $('body').attr('id') == 'undefined') { $('body').attr('id', 'type-b'); } if ($('#lang').length > 0) { $('body').addClass('i18n'); } if (arya.options['widgets_header'] == 2 || arya.options['widgets_header'] == 3) { $('body').addClass('header-banner'); } $('body.annexes_pages #header').wrapInner('
'); //radio & checkbox $('[name=iscompany]').after(''); $('[type=checkbox][name^=reserved_]').each(function (index, el) { $(this).after(''); $(this).attr('id', $(this).attr('name')); }); $('input[type=radio]').each(function (index, el) { var id = $(this).parent().attr('for'); $(this).attr('id', id); }); $.getScript('https://libs.iraiser.eu/libs/forms/select2/js/select2.full.min.js', function (data, textStatus, jqxhr) { if (typeof Step3 != 'undefined') { Step3.select('#cardmonth, #cardyear').select2({ minimumResultsForSearch: Infinity }); } $('#step-2 select').select2({ minimumResultsForSearch: Infinity }); $('#step-1 select').select2({ minimumResultsForSearch: Infinity }); }); if ($('#lang form#form_lang').length > 0) { $('[name=lang] option').each(function (index, el) { var label = $(this).text(); var link = $(this).val(); $('#lang').append('' + label + ' '); }); $('[name=lang]').hide(); } else if ($('#lang p').length > 0) { var lang = $('#lang p a').detach(); $('#lang p').addClass('duo').html(lang); } $('#powered img').attr({ 'src': 'https://libs.iraiser.eu/images/pictos/powered_by_white.png?v=2', 'width': '150px', 'height': '' }); }, placeholders: function () { $('p[name^=reserved_]').each(function () { var input = $(this).find(':input'); var type; if (input.is('textarea')) { type = 'textarea'; } else if (input.is('select')) { type = 'select'; } else { type = input.attr('type'); } switch (type) { case 'text': var placeholder = $(this).find('.reserved_title').text().trim(); if (placeholder.length > 38) { placeholder = placeholder.substring(0, 38); placeholder += '...' } placeholder += $(this).find('.required').text(); input.attr('placeholder', placeholder); $(this).find('label').hide(); break; case 'textarea': var placeholder = $(this).find('.reserved_title').text().trim(); placeholder += $(this).find('.required').text(); input.attr('placeholder', placeholder); $(this).find('label').hide(); break; case 'tel': /* var placeholder = $(this).find('.reserved_title').text(); if(placeholder.length > 19){ placeholder = placeholder.substring(0, 19); } placeholder + ' : ' +input.attr('placeholder'); placeholder += $(this).find('.required').text(); input.attr('placeholder', placeholder); */ $(this).find('label').hide(); break; case 'select': var input = $(this).find(':input'); if ($(this).find('.required').length > 0) { var requiredClassicField = 1; } var placeholder = $(this).find('.reserved_title').text().trim(); if (requiredClassicField > 0) { placeholder += '*'; } if (input.find('option').first().val() == '') { input.find('option').first().text(placeholder); } else { input.prepend('') } $(this).find('label').hide(); break; default: return; } }); //STEP2 classic $('#c-email,#c-isc-inf,#c-fname,#c-lname,#c-addr1,#c-addr2,#c-pcode,#c-city').each(function () { var input = $(this).find(':input'); if ($(this).find('.required').length > 0) { var requiredClassicField = 1; } var clone = $(this).find('label').clone(true) .find('span').remove() .end() var placeholder = clone.text().trim(); if (placeholder.length > 38) { placeholder = placeholder.substring(0, 38); placeholder += '...' } if (requiredClassicField > 0) { placeholder += '*'; } input.attr('placeholder', placeholder); if ($(this).attr('id') != 'c-email') { $(this).find('label').hide(); } else { $(this).find('label').text(''); } }); $('#c-email label[for=email]').html('') //SELECT $('#c-civ').each(function () { var input = $(this).find(':input'); if ($(this).find('.required').length > 0) { var requiredClassicField = 1; } var clone = $(this).find('label').clone(true) .find('span').remove() .end() var placeholder = clone.text().trim(); if (requiredClassicField > 0) { placeholder += '*'; } input.find('option').first().text(placeholder); $(this).find('label').hide(); }); $('#c-country').find('label').hide(); // CREDIT CARD if (typeof Step3 != 'undefined') { Step3.select('#card-number, #card-scode').each(function () { var input = $(this).find(':input'); if ($(this).find('.required').length > 0) { var requiredClassicField = 1; } var clone = $(this).find('label').clone(true) .find('span').remove() .end() var placeholder = clone.text().trim(); if (placeholder.length > 38) { placeholder = placeholder.substring(0, 38); placeholder += '...' } if (requiredClassicField > 0) { placeholder += '*'; } input.attr('placeholder', placeholder); if ($(this).attr('id') != 'c-email') { $(this).find('label').hide(); } else { $(this).find('label').text(''); } }); Step3.select('#card-expiry span:first-child').hide(); } }, step1: function () { if (arya.options['donation_grid'] == 1) { if (typeof Step1 != 'undefined') { $('#step-1 .bloc').wrapAll('
'); $('.tabs').prepend(''); $('#step-1 .bloc h3').each(function (index, el) { var frequency = $(this).parents('.bloc').attr('id'); if (index == 0) { $(this).appendTo('.tabs ul.tabs_menu').wrap('
  • '); } else { $(this).appendTo('.tabs ul.tabs_menu').wrap('
  • '); } }); if ($('.tabs_menu li').length == 1) { $('.tabs_menu').addClass('single_frequency'); } arya.tabs(); $('#step-1 #or').siblings('.unit ').hide(); $('#step-1 #or').remove(); if (Step1.active_tax_reduction < 1) { $('.tax-info').hide(); } $('#step-1 .height_adaptor').append('
    '); } } }, step2: function () { $('#step-2 .step2_head.step2_connect_block').wrapInner(''); }, step3: function () { if (typeof Step3 != 'undefined') { arya.brand(); //différenciation des cas foldable et simple /* $('#payment_mode-paypal, #payment_mode-check,#payment_mode-apple_pay-once,#payment_mode-google_pay-once').addClass('simple'); $('#payment_mode-paypal, #payment_mode-apple_pay-once').addClass('simple'); */ //gestion des cas simples Step3.select('.payment_mode.simple').each(function(){ var title = $(this).find('h4').text(); $(this).find('.button').attr('value', title); }); // gestion des cas foldable Step3.select('.payment_mode:not(.simple)').each(function(){ $(this).find('h4').click(function(){ var paymentMode = $(this).parent(); var paymentModeBody = $(this).siblings('.payment_body'); if(paymentModeBody.is(':hidden')){ paymentMode.addClass('active'); }else{ paymentMode.removeClass('active'); } paymentModeBody.slideToggle('fast', function() { // Animation complete. }); }); }); /* Step3.select('.payment_mode:not(.simple):not(:first-of-type)').each(function(){ $(this).find('.payment_body').slideUp(); }); */ Step3.select('.payment_mode:not(.simple) .payment_body').each(function(){ $(this).hide(); }); Step3.select('.payment_mode:not(.simple):first-of-type').each(function(){ $(this).addClass('active'); $(this).find('.payment_body').show(); }); // à nettoyer //Step3.select('[name=cardtype]').after(''); //Step3.select('#payment_mode-ogone-pm [name=pm]').after(''); Step3.select('#card-type').append('
    '); Step3.select('[name=cardtype]').change(function (event) { $('#card-type li').removeClass('selected'); $(this).parents('li').addClass('selected'); }); // security info $('#security-info').prepend('\ \ \ \ \ \ \ \ \ \ '); /*clear*/ $('#step-3 .step-content').append('
    '); /*fix particular case*/ Step3.select('[name=cardtype]').change(function () { arya.adaptHeight(); }) arya.UpdateCreditCardType(); } }, brand: function(){ var paypalSVG = ''; var amazonPaySVG = ''; var googlePaySVG = ''; var applePaySVG = ''; var mobilePaySVG = ''; var satisPaySVG = ''; /* if (typeof Step3 != 'undefined') { if( $('#payment_mode-paypal').length >0 ){ $('#payment_mode-paypal .payment_head .payment_mode_title').html($('#payment_mode-paypal .payment_head .payment_mode_title').html().replace('Paypal', paypalSVG)); } if( $('#payment_mode-apple_pay-once').length >0 ){ $('#payment_mode-apple_pay-once .payment_head .payment_mode_title').html($('#payment_mode-apple_pay-once .payment_head .payment_mode_title').html().replace('Apple Pay', applePaySVG)); } if( $('#payment_mode-google_pay-once').length >0 ){ $('#payment_mode-google_pay-once .payment_head .payment_mode_title').html($('#payment_mode-google_pay-once .payment_head .payment_mode_title').html().replace('Google Pay', googlePaySVG)); } //$('#payment_mode-paypal .payment_head .payment_mode_title').html($('#payment_mode-amazon .payment_head .payment_mode_title').html().replace('Paypal', amazonPaySVG)); //$('#payment_mode-paypal .payment_head .payment_mode_title').html($('#payment_mode-paypal .payment_head .payment_mode_title').html().replace('Paypal', googlePaySVG)); //$('#payment_mode-paypal .payment_head .payment_mode_title').html($('#payment_mode-paypal .payment_head .payment_mode_title').html().replace('Paypal', mobilePaySVG)); //$('#payment_mode-paypal .payment_head .payment_mode_title').html($('#payment_mode-paypal .payment_head .payment_mode_title').html().replace('Paypal', satisPaySVG)); } */ }, paymentMode: function(){ }, UpdateCreditCardType: function(){ if( $('#cardnumber').length > 0 && typeof $('#cardnumber') != 'undefined' ){ var elID = '#cardnumber'; var cleave = new Cleave(elID, { creditCard: true, delimiter: '', onCreditCardTypeChanged: function (type) { console.log('card number change'); $(elID).removeClass(); $(elID).addClass(type); if( $(elID).parents('.payment_body').find('[name=cardtype][value='+type+']').length > 0 ){ $(elID).parents('.payment_body').find('#card-number').removeClass('nocard'); $(elID).parents('.payment_body').find('[name=cardtype][value='+type+']').click(); }else { $(elID).parents('.payment_body').find('#card-number').addClass('nocard'); } } }); } }, stepInfos: function () { if (arya.options['widgets_footer'] == 1) { $('body').addClass('footer-detach') $('#main').after('
    '); $('#step-1 .step-info').appendTo('#bottom .container').addClass('step-info-1'); $('#step-2 .step-info').appendTo('#bottom .container').addClass('step-info-2'); $('#step-3 .step-info').appendTo('#bottom .container').addClass('step-info-3'); $('#bottom').append('
    '); } if (arya.options['widgets_footer'] == 2) { $('body').addClass('footer-column'); } }, colorAdjust: function(){ if (typeof Step3 != 'undefined') { utils.adjustTextColor(Step3.select('.payment_head')); } if (typeof $('.donors') != 'undefined' && $('.donors').length > 0 ) { utils.adjustTextColor($('.donors')); } if (typeof $('.step-title') != 'undefined' && $('.step-title').length > 0 ) { utils.adjustTextColor($('.step-title')); } if (typeof $('.step-info') != 'undefined' && $('.step-info').length > 0 ) { utils.adjustTextColor($('.step-info')); } if (typeof $('#form-info') != 'undefined' && $('#form-info').length > 0 ) { utils.adjustTextColor($('#form-info')); } if (typeof $('#lang') != 'undefined' && $('#lang').length > 0 ) { utils.adjustTextColor($('#lang')); } //utils.adjustTextColor($('#last_donors_banner')); }, sizing: function () { $('.step-info').css('height', 'auto'); var stepInfoHeight = 0; $('.step-info').each(function () { if (stepInfoHeight < $(this).outerHeight()) { stepInfoHeight = $(this).outerHeight(); } }) $('.step-info').css('height', stepInfoHeight + 'px'); }, oneColumn: function () { if ( device.mobile() ) { console.log('mobile detected and one column active'); $('body').addClass('one-column one-column-single-step'); $('#form-info').insertBefore($('#main_wrapinner')); } }, widgets_last_donors: function () { $('#container').prepend('
    '); $.each(arya.campaign_stats_last_donators, function (index, value) { var prenom = arya.campaign_stats_last_donators[index].firstname; var ville = arya.campaign_stats_last_donators[index].city; var montant = parseFloat(arya.campaign_stats_last_donators[index].total) / 100; var text = arya.options['widgets_last_donors_text']; if (text.includes('$n')) { text = text.replace('$n', prenom); } if (text.includes('$a')) { text = text.replace('$a', montant); } if (text.includes('$v')) { text = text.replace('$n', ville); } if( typeof arya.options['widgets_last_donors_filter'] == 'undefined' ) { $('#last_donors_banner').append('
    ' + text + '
    '); }else if( Number.isInteger( parseFloat(arya.options['widgets_last_donors_filter'])) && parseFloat(montant) > parseFloat(arya.options['widgets_last_donors_filter'])){ $('#last_donors_banner').append('
    ' + text + '
    '); } }); var height = $('#last_donors_banner').outerHeight(); window.setInterval(function () { var lastDonorElem = $('#last_donors_banner .donors:first-child'); lastDonorElem.css('margin-top', '-' + height + 'px'); setTimeout(donorLoop, 1000); function donorLoop() { lastDonorElem.appendTo($('#last_donors_banner')); lastDonorElem.css('margin-top', '0'); } }, 4000); }, widgets_progress_bar: function () { var currentPercent; if (isNaN(parseFloat(arya.campaign_stats['sum']))) { currentPercent = 0; } else { if (parseFloat(arya.campaign_stats['sum'])/100 > parseFloat(arya.options['widgets_progress_bar_goal'])) { currentPercent = 100; } else { currentPercent = parseFloat(arya.campaign_stats['sum'])/100 * 100 / parseFloat(arya.options['widgets_progress_bar_goal']); } } arya.options['widgets_progress_bar_text'] = arya.options['widgets_progress_bar_text'].replace('%c', arya.campaign_stats['count']/100 ); arya.options['widgets_progress_bar_text'] = arya.options['widgets_progress_bar_text'].replace('%m' , arya.campaign_stats['sum']/100+' €' ) $('#type-b').addClass('widget-progressbar'); $('#type-b #header').append('
    \
    \ ' + arya.options['widgets_progress_bar_text'] + '\
    \
    \
    \
    \
    \
    \
    \ \ '+arya.options['widgets_progress_bar_goal']+' €\
    \
    '); setTimeout(function () { $('#widget_progress_bar .current').animate({ width: currentPercent + '%' }, 2000) $('#widget_progress_bar .percent').each(function () { $(this).prop('Counter', 0).animate({ Counter: Math.round(currentPercent) }, { duration: 2000, easing: 'swing', step: function (now) { $(this).text(Math.ceil(now) + '%'); } }); }); }, 2000); }, amountsRender: function () { $('.amount .radio-desc').each(function (index, el) { var id = $(this).attr('id'); var parent = $(this).parent(); $(this).find('li').each(function (index, el) { $(this).find('div').removeClass('size1of2'); var parentClass = $(this).parent('ul').attr('id'); console.log(parentClass); $(this).attr('data-detail', 'tabs_' + index + '_' + parentClass); var image = $(this).find('img').attr('src'); if (typeof image != 'undefined') { image = image.replace('pricelist_item', 'origin'); $(this).find('img').remove(); var text = $(this).find('p').html(); $(this).find('p').remove(); if (text.length > 0) { text = '

    ' + text + '

    '; } var block = '
    ' + text + '
    '; parent.after(block); } else { var text = $(this).find('p').text(); $(this).find('p').remove(); if (text.length > 0) { text = '

    ' + text + '

    '; } var block = '
    ' + text + '
    '; parent.after(block); } }); }); /* $('.free-amount').each(function(index, el) { var el = $(this).find('label').clone(); el.find('span').remove(); var text = el.text(); $(this).find('input[name^=famount]').attr('placeholder', text); }); */ }, btnRender: function () { arya.btnChange(); $('body').bind('change_amount', arya.btnChange); }, btnChange: function () { console.log('function : btnChange'); if (typeof Step1 != 'undefined') { var amount = Step1.getDonation().amount; } else { var amount = ''; } if (typeof Step3 != 'undefined') { Step3.select('.payment-submit .button').val(arya.amount_btn_text + ' ' + amount / 100 + ' €'); } }, tabs: function () { if (typeof Step1 != 'undefined') { $('.tabs').tabs({ activate: function (event, ui) { var item = ui.newTab; ui.newPanel.addClass('active-panel'); ui.oldPanel.removeClass('active-panel'); ui.oldPanel.addClass('inactive-panel'); ui.newPanel.removeClass('inactive-panel'); var amount = Common.getDonation().amount; var frequency = Common.getDonation().frequency; if (item.attr('id') == 'regular-item') { Step1.set_donation({ amount: amount, frequency: 'regular' }); } else if (item.attr('id') == 'once-item') { Step1.set_donation({ amount: amount, frequency: 'once' }); } arya.adaptHeight(); }, beforeActivate: function (event, ui) { } }); var amount = Step1.getDonation().amount; var frequency = Step1.getDonation().frequency; if (amount != '0') { if ($('.tabs .ui-tabs-panel:first').attr('id') == frequency) { $('.tabs').tabs('option', 'active', 0); } else { $('.tabs').tabs('option', 'active', 1); } } } }, } var aryaAmounts = { init: function () { if (typeof Step1 == 'undefined') { return } else { //console.log('----init'); aryaAmounts.donationInit(); aryaAmounts.donationWatch(); aryaAmounts.donationControl(); } }, donationInit: function () { //console.log('----donationInit'); aryaAmounts.donationRender(); }, donationRender: function () { console.log('----donationRender'); aryaAmounts.donationRenderReset(); var amount = Step1.getDonation().amount; var frequency = Step1.getDonation().frequency; if (frequency == 'once') { aryaAmounts.donationRenderOnce(); } else { aryaAmounts.donationRenderRegular(); } // free amounts $('[name^=famount-]').each(function (index, el) { if ($(this).val() > 0) { $(this).addClass('active'); $(this).parent().addClass('active'); } }); // grilles de dons $('#once .amount [type=radio]:checked').siblings('span').addClass('active'); $('#regular .amount [type=radio]:checked').siblings('span').addClass('active'); $('#once .amount [type=radio]:checked').parent().addClass('active'); $('#regular .amount [type=radio]:checked').parent().addClass('active'); $('#once .amount [type=radio]:checked').parents('li').addClass('active'); $('#regular .amount [type=radio]:checked').parents('li').addClass('active'); // show description $('.detail').hide(); console.log('hide all .detail'); $('.detail[id=' + $('.amount [type=radio]:checked').parents('li').attr('data-detail') + ']').show(0, '', function () { arya.adaptHeight(); }); /* console.log($('.amount [type=radio]:checked').attr('id')); console.log($('.amount [type=radio]:checked').parents('li').attr('data-detail')); */ }, donationWatch: function () { //console.log('----donationWatch'); $('body').bind('change_amount', aryaAmounts.donationChangeAmount); }, donationChangeAmount: function () { //console.log('----donationChangeAmount'); aryaAmounts.donationRender(); }, donationRenderReset: function () { //console.log('----donationRenderReset'); $('.free-amount label, [name^=famount-], .amount [name^=amount-], .amount ul li label, .amount ul li span, .amount ul li').removeClass('active inactive'); $('.detail').hide(); }, donationRenderOnce: function () { //console.log('----donationRenderOnce'); $('#once').addClass('active-panel').removeClass('inactive-panel'); $('#regular').addClass('inactive-panel').removeClass('active-panel'); $('body').removeClass('ira-regular').addClass('ira-once'); }, donationRenderRegular: function () { //console.log('----donationRenderRegular'); $('#regular').addClass('active-panel').removeClass('inactive-panel'); $('#once').addClass('inactive-panel').removeClass('active-panel'); $('body').removeClass('ira-once').addClass('ira-regular'); }, donationControl: function () { //console.log('----donationControl'); $('[name^=famount-] , .amount [name^=amount-], .amount ul li label, .amount ul li span').one('click', function (event) { /* Act on the event */ console.log('click detected - one'); aryaAmounts.donationRender(); }); } } var utils = { lightenDarkenColor: function (col, amt) { var usePound = false; if (col[0] == '#') { col = col.slice(1); usePound = true; } var num = parseInt(col, 16); var r = (num >> 16) + amt; if (r > 255) r = 255; else if (r < 0) r = 0; var b = (num & 0x0000FF) + amt; if (b > 255) b = 255; else if (b < 0) b = 0; var g = ((num >> 8) & 0x00FF) + amt; if (g > 255) g = 255; else if (g < 0) g = 0; return (usePound ? "#" : "") + ('00000' + (b | (g << 8) | (r << 16)).toString(16)).slice(-6); }, adjustTextColor : function (element) { // Get the element's background color var bgColor = element.css('background-color'); //console.log(element.get()[0].innerHTML+' bgColor = '+bgColor); console.log(' bgColor = '+bgColor); // Call lightOrDark function to get the brightness (light or dark) var brightness = utils.lightOrDark(bgColor); // If the background color is dark, add the light-text class to it if (brightness == 'dark') { element.addClass('light-text'); } else { element.addClass('dark-text'); } }, lightOrDark : function(color) { // Check the format of the color, HEX or RGB? if (color.match(/^rgb/)) { // If HEX --> store the red, green, blue values in separate variables color = color.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/); var r = color[1]; var g = color[2]; var b = color[3]; } else { // If RGB --> Convert it to HEX: http://gist.github.com/983661 color = +("0x" + color.slice(1).replace( color.length < 5 && /./g, '$&$&' )); r = color >> 16; g = color >> 8 & 255; b = color & 255; } // HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html var hsp = Math.sqrt( 0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b) ); // Using the HSP value, determine whether the color is light or dark console.log(hsp); if (hsp > 200) { console.log('light'); return 'light'; } else { console.log('dark'); return 'dark'; } } }