//------------------------------------------------------------------------- // モーダルフォーム制御スクリプト // var defaultArticleFlg = true; var parentRefrrer = document.referrer; var currentUrl = location.href ; var currentState = history.state; //window.onpopstate = function(event) { // console.log("location: " + document.location + ", state: " + JSON.stringify(event.state)); //}; console.log(parentRefrrer); console.log(currentUrl); console.log(currentState); // 資料請求フォームモーダルオブジェクト作成 if ($('#modal-download').length) { $('#modal-download').iziModal({ width: '100%', iframe: true, iframeHeight: '100vh', iframeURL: '/request-docment/' }); } // お問合わせフォームモーダルオブジェクト作成 if ($('#modal-contact').length) { $('#modal-contact').iziModal({ width: '100%', iframe: true, iframeHeight: '100vh', iframeURL: '/contact/' }); } //------------------------------------------------------------------------- // 資料請求フォーム制御処理 $(function() { var winScrollTop; $('.modal__toggle').on('click', function(){ $('#title').toggleClass("active"); //開いた時、ボタンにクラスを追加 }); //----------------------------- // デフォルトの資料を表示するかどうかの判定 var reqDocumentFlg = $('#EntryDataReqDocumentFlg').val(); if (reqDocumentFlg) { defaultArticleFlg = false; } //----------------------------- console.log(reqDocumentFlg); console.log(defaultArticleFlg); // 親画面からモーダルを開く $('[data-modal="button_download"]').off('click'); $('[data-modal="button_download"]').on('click', function(){ //event.preventDefault(); posi = $(window).scrollTop(); $('body').css({ position: 'fixed', //top: -1 * posi }); $('#modal-download').iziModal('setZindex', 99999); $('#modal-download').iziModal('open'); //$('#modal-download .mclose_contact').addClass("active"); //$('#modal-download .modal_download').addClass("active"); //------------------------------------------ // モーダルが開かれたら処理を行う $('#modal-download iframe.iziModal-iframe').off('load'); $('#modal-download iframe.iziModal-iframe').on('load', function(){ console.log(parentRefrrer); history.replaceState(null, null, parentRefrrer); console.log('download iframe is loaded.'); var modalForm = $('#modal-download iframe.iziModal-iframe').contents(); console.log(modalForm.find('#ModalContents').length); /* if (modalForm.find('#ModalContents').length == 0) { modalForm = ''; return; } */ /* var posi = $(window).scrollTop(); modalForm.find('body').css({ position: 'fixed', top: -1 * posi }); */ //----------------------------- // Google Analytics Event ga('send', 'event', 'fileDLinput', 'click', 'inquiry'); // 親画面のリファラをセット modalForm.find('#parent_refrrer').val(parentRefrrer); if (!$('#config_get_thanks').val()) { modalForm.find('.modal_download').addClass("active"); } modalForm.find('.mclose_download').addClass("active"); modalForm.find('dl.pdf').matchHeight(); // デフォルト資料表示場合の処理 if (defaultArticleFlg) { modalForm.find('#EntryDataReqDocumentSelected' + zeroPadding(1, 2)).val('true'); modalForm.find('#EntryDataReqDocumentSelected' + zeroPadding(2, 2)).val('true'); modalForm.find('#EntryDataReqDocumentSelected' + zeroPadding(3, 2)).val('true'); modalForm.find('#EntryDataReqDocumentSelected' + zeroPadding(4, 2)).val('true'); modalForm.find('#label_pdf_checkbox' + zeroPadding(5, 2)).hide(); modalForm.find('#label_pdf_checkbox' + zeroPadding(6, 2)).hide(); modalForm.find('#label_pdf_checkbox' + zeroPadding(7, 2)).hide(); modalForm.find('#label_pdf_checkbox' + zeroPadding(8, 2)).hide(); modalForm.find('#label_pdf_checkbox' + zeroPadding(9, 2)).hide(); modalForm.find('#label_pdf_checkbox' + zeroPadding(10, 2)).hide(); // カスタムフィールド制御の場合の処理 } else { for (var i = 1; i <= 10; i ++) { if ($('#EntryDataReqDocument' + zeroPadding(i, 2)).val() == 'true') { console.log('EntryDataReqDocument' + zeroPadding(i, 2) + ' = true'); modalForm.find('#EntryDataReqDocumentSelected' + zeroPadding(i, 2)).val('true'); } else{ modalForm.find('#label_pdf_checkbox' + zeroPadding(i, 2)).hide(); } } } modalForm.find('input.input_pdf_checkbox').off('change'); modalForm.find('input.input_pdf_checkbox').on('change', function() { if (modalForm.find('#is_request_document_' + $(this).data('num')).val() == '未') { modalForm.find('#is_request_document_' + $(this).data('num')).val('済'); //----------------------------- // Google Analytics Event ga('send', 'event', 'fileDLchoice', 'click', $(this).data('document_name')); } else { modalForm.find('#is_request_document_' + $(this).data('num')).val('未'); } }); modalForm.find('[data-modal="close_download"]').off('click'); modalForm.find('[data-modal="close_download"]').on('click', function(){ $('body').attr('style', ''); $('html, body').prop({scrollTop: posi}); modalForm.find('.mclose_download').removeClass("active"); modalForm.find('.modal_download').removeClass("active"); $('#modal-download').iziModal('close'); $('#modal-download iframe.iziModal-iframe').off('load'); location.replace(currentUrl); }); modalForm.find('#btn-request-document-pagenext').off('click'); modalForm.find('#btn-request-document-pagenext').on('click', function(){ var isChecked = false; modalForm.find('input.input_pdf_checkbox:checked').each(function(index, element){ isChecked = true; }); if (isChecked) { modalForm.find('.select-document-required-error').text(''); modalForm.find('.modal_download_contact').addClass("active"); modalForm.find('.modal_download').removeClass("active"); } else { modalForm.find('.select-document-required-error').css('font-size', '16px'); modalForm.find('.select-document-required-error').text('* 資料の選択は必須となります'); } }); modalForm.find('#btn-request-document-pageprev').off('click'); modalForm.find('#btn-request-document-pageprev').on('click', function(){ modalForm.find('.modal_download').addClass("active"); modalForm.find('.modal_download_contact').removeClass("active"); }); modalForm.find('#confirm_submit_button').off('click'); modalForm.find('#confirm_submit_button').on('click', function(){ modalForm.find('.modal_download').removeClass("active"); modalForm.find('.modal_download_contact').removeClass("active"); //----------------------------- // Google Analytics Event ga('send', 'event', 'fileDLcompleted', 'click', 'inquiry'); }); if (modalForm.find('#mail_form').length) { $inquiry_items = modalForm.find('#mail_form').find('.inquiry-inner').children('dl'); $inquiry_items.on('click', function (e) { // $(this).find('input, select, textarea').focus(); }); } }); }); // 資料請求フォーム制御処理 ここまで //------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ // お問合わせフォーム制御処理 // 親画面からモーダルを開く $('[data-modal="button_contact"]').off('click'); $('[data-modal="button_contact"]').on('click', function(){ //event.preventDefault(); posi = $(window).scrollTop(); $('body').css({ position: 'fixed', //top: -1 * posi }); $('#modal-contact').iziModal('setZindex', 99999); $('#modal-contact').iziModal('open'); //------------------------------------------ // モーダルが開かれたら処理を行う $('#modal-contact iframe.iziModal-iframe').off('load'); $('#modal-contact iframe.iziModal-iframe').on('load', function(){ console.log(parentRefrrer); history.replaceState(null, null, parentRefrrer); console.log('contact iframe is loaded.'); var modalForm = $('#modal-contact iframe.iziModal-iframe').contents(); console.log(modalForm.find('#ModalContents').length); /* if (modalForm.find('#ModalContents').length == 0) { modalForm = ''; return; } */ /* var posi = $(window).scrollTop(); modalForm.find('body').css({ position: 'fixed', top: -1 * posi }); */ //----------------------------- // Google Analytics Event //ga('send', 'event', 'fileDLinput', 'click', 'inquiry'); // 親画面のリファラをセット modalForm.find('#parent_refrrer').val(parentRefrrer); if (!$('#config_get_thanks').val()) { modalForm.find('.modal_contact').addClass("active"); } modalForm.find('.mclose_contact').addClass("active"); modalForm.find('[data-modal="close_contact"]').off('click'); modalForm.find('[data-modal="close_contact"]').on('click', function(){ $('body').attr('style', ''); $('html, body').prop({scrollTop: posi}); modalForm.find('.mclose_contact').removeClass("active"); modalForm.find('.modal_contact').removeClass("active"); $('#modal-contact').iziModal('close'); $('#modal-contact iframe.iziModal-iframe').off('load'); location.replace(currentUrl); }); modalForm.find('#confirm_submit_button').off('click'); modalForm.find('#confirm_submit_button').on('click', function(){ modalForm.find('.modal_contact').removeClass("active"); //----------------------------- // Google Analytics Event //ga('send', 'event', 'fileDLcompleted', 'click', 'inquiry'); }); if (modalForm.find('#mail_form').length) { $inquiry_items = modalForm.find('#mail_form').find('.inquiry-inner').children('dl'); $inquiry_items.on('click', function (e) { // $(this).find('input, select, textarea').focus(); }); } }); }); // お問合わせフォーム制御処理 ここまで //------------------------------------------------------------------------------------------ }); //------------------------------------------------------------------------- //------------------------------------------------------------------------- // function zeroPadding(num,length){ return ('0000000000' + num).slice(-length); }