$(document).ready(function () { $(".js-share").click(function (e) { e.preventDefault(); var options = { loadingHtml: 'Loading', title: $(this).attr('title'), size: 'mg', url: $(this).attr('href') + "&mfg=" + $(this).data('mfg') + "&sub=" + $(this).data('sub') + "&msg=" + $(this).data('msg') + "&r=" + Math.random(), buttons: false }; eModal.ajax(options).then(ajaxOnShareLoadCallback); }); $(".js-share-save").click(function (e) { e.preventDefault(); if ($(this).data('saved') == '0') { var options = { loadingHtml: 'Loading', title: $(this).attr('title'), size: 'mg', url: $(this).attr('href') + "&mfg=" + $(this).data('mfg') + "&uid=" + $(this).data('uid') + "&price=" + $(this).data('price') + "&r=" + Math.random(), buttons: false }; eModal.ajax(options).then(ajaxOnSaveLoadCallback); } else { unmarked_saved_unit(); } }); $(document).on('hidden.bs.modal', function () { $('.grecaptcha-badge').parent('div').remove(); }); marked_saved_units(); // // $(document).on("hide.bs.modal", ".modal", function(){ // console.log('CLOSING'); // }); }); function ajaxOnShareLoadCallback(event) { // $('.g-recaptcha').each(function (key, val) { // var widgetId = grecaptcha.render('g-recaptcha_' + $(this).data('id'), { // 'sitekey': $(this).data('sitekey'), // 'theme': 'dark' // }); // $(this).data('widgetId', widgetId); $('.js-share-form').parsley(); // }); } function ajaxOnSaveLoadCallback() { // $('.g-recaptcha').each(function (key, val) { // var widgetId = grecaptcha.render('g-recaptcha_' + $(this).data('id'), { // 'sitekey': $(this).data('sitekey'), // 'theme': 'dark' // }); // $(this).data('widgetId', widgetId); $('.js-save-form').parsley(); // }); } function marked_saved_units() { var unit_id = $('#unit_id').val(); var saved_list = $.cookie(location.host); var arr_unit_list = []; if (typeof saved_list != 'undefined') arr_unit_list = saved_list.split('|'); if (jQuery.inArray(unit_id, arr_unit_list) != -1) { $('.js-share-save').data('saved', "1"); $('.js-share-save > span').html('Saved!'); $('.js-save-icon').removeClass('fa-heart-o').addClass('fa-heart'); } } function unmarked_saved_unit() { var unit_id = $('#unit_id').val(); var saved_list = $.cookie(location.host); var arr_unit_list = []; if (typeof saved_list != 'undefined') arr_unit_list = saved_list.split('|'); if (jQuery.inArray(unit_id, arr_unit_list) != -1) { // arr_unit_list.pop(unit_id); arr_unit_list.splice(arr_unit_list.indexOf(unit_id), 1); // console.log(unit_id); // console.log(arr_unit_list); var unit_list = arr_unit_list.join("|"); $.removeCookie(location.host); if (unit_list.substring(0, 1) == '|') { unit_list = unit_list.substring(1); } var expDate = new Date(); expDate.setTime(expDate.getTime() + (365 * 24 * 60 * 60 * 1000)); // add 15 minutes $.cookie(location.host, unit_list, {path: '/', expires: expDate}); $('.js-share-save').data('saved', "0"); $('.js-share-save > span').html('Save'); $('.js-save-icon').removeClass('fa-heart').addClass('fa-heart-o'); } }