/**
* vars
*/
var confPageFlg = "1";
var mailAdminCc = {};
mailAdminCc[0] = "";
var compAjaxFlg = "";
var reCaptchaKeyPublic = "";
var compFilePath = "/comp/";
var errorFilePath = "err.html";
var formId = "contact_form";
var btnAreaId = "btn_area";
var btnConfId = "btn_conf";
var btnBackId = "btn_back";
var btnCompId = "btn_comp";
var btnConfName = "確認する";
var btnBackName = "戻る";
var btnCompName = "送信する";
var titleClass = "item";
var titleSubClass = "item_sub";
var titleSubStrBefore = "<";
var titleSubStrAfter = ">";
var formElemClass = "form_wrap";
var labelElemCssInitStr = "label_";
var nameName = "name";
var zipName = "zip";
var telName = "tel";
var emailName = "email";
var emailConfName = "email_conf";
var addressName = "address";
var addressNamePart = {};
addressNamePart[0] = "pref";
addressNamePart[1] = "address1";
addressNamePart[2] = "address2";
addressNamePart[3] = "address3";
var addressPartTitle = "住所";
var addName = "add";
var addBoxClass = "add_box";
var addSeparatorClass = "add_separator";
var addLastStr = "_list";
var privacyCheckName = "agree";
var privacyCheckFlg = "1";
var compPageName = "comp_page";
var chkActionName = "form_action";
var actionName = "action";
var inputOnlyClass = "input_only";
var confOnlyClass = "conf_only";
var mailOnlyClass = "mail_only";
var notSendClass = "not_send";
var selectClass = "select";
var compTargetClass = ".contact";
var compMsgStr = "
お問い合わせありがとうございます。 送信完了いたしました。
";
var arraySplitStr = "、";
var programVersion = "2.0.3";
var formHideClass = "form_hide";
var formViewClass = "form_view";
var sendLocalMail = "";
var yubinTopClass = "h-adr";
var yubinCountryClass = "p-country-name";
var yubinZipcodeClass = "p-postal-code";
var yubinPrefClass = "p-region";
var yubinPrefIdClass = "p-region-id";
var yubinAddress1Class = "p-locality";
var yubinAddress2Class = "p-street-address";
var yubinAddress3Class = "p-extended-address";
var programRoot = "/home/ccx2/ccrw.in/public_html/itoh.ccrw.in/wp-content/themes/itoh/mmf";
var dirProgramName = "mmf";
var documentPath = "/wp-content/themes/itoh";
var programPath = "/wp-content/themes/itoh/mmf";
var siteUrl = "https://itoh.ccrw.in/wp-content/themes/itoh";
var pathJsFile = "/wp-content/themes/itoh/mmf/js/";
var pathCssFile = "/wp-content/themes/itoh/mmf/css/";
var pathControllerFile = "/wp-content/themes/itoh/mmf/controller.php";
var pathUploadFileOther = "/wp-content/themes/itoh/mmf/img/file_other.png";
var reCaptchaFormName = "g-recaptcha-response";
var reCaptchaFormClass = "g-recaptcha";
var validClass = {};
validClass["hissu"] = "valid_hissu";
validClass["num"] = "valid_num";
validClass["email"] = "valid_email";
validClass["hiragana"] = "valid_hiragana";
validClass["katakana"] = "valid_katakana";
validClass["tel"] = "valid_tel";
validClass["zip"] = "valid_zip";
validClass["exc"] = "valid_exc";
var validStr = {};
validStr["hissu"] = "必須項目です。";
validStr["num"] = "入力形式が異なります。";
validStr["email"] = "入力形式が異なります。";
validStr["hiragana"] = "入力形式が異なります。";
validStr["katakana"] = "入力形式が異なります。";
validStr["tel"] = "入力内容を確認下さい。";
validStr["zip"] = "入力内容を確認下さい。";
validStr["same"] = "内容が一致していません。";
var elemErrStr = "div";
var errElemIdInitStr = "err_";
var formErrStrClass = "err_str";
var formErrIconClass = "err_icon";
var validFlg = "1";
var formErrClass = "form_err";
var topAjustClass = "";
var topAjustNum = "0";
var errBeforeStr = "※ ";
var errStrColor = "#d93025";
var errFormColor = "#fff0f5";
var addMaxCount = "0";
var uploadDropClass = "file_drop";
var uploadTextClass = "file_text";
var uploadCloseClass = "file_close";
var uploadDragClass = "file_drag";
var uploadSetClass = "file_set";
var uploadPreviewClass = "file_preview";
var uploadFileNameClass = "file_name";
var uploadWidthSize = "300";
var uploadHeightSize = "300";
var uploadAreaStr = "ここにファイルをドロップして下さい";
var uploadAreaColor = "#ddd";
var uploadSetColor = "#eee";
var uploadSetBorderColor = "#f96";
var uploadSetFlg = "";
var tokenName = "token";
var ajaxFlgName = "ajax";
var ajaxValidName = "mode_valid";
var phpMsstrEnableVer = "5.2.1";
var nameNamePart = {};
nameNamePart[1] = "name1";
nameNamePart[2] = "name2";
var zipNamePart = {};
zipNamePart[1] = "zip1";
zipNamePart[2] = "zip2";
var telNamePart = {};
telNamePart[1] = "tel1";
telNamePart[2] = "tel2";
telNamePart[3] = "tel3";
var formObj;
DevelopConsoleLog('version:' + programVersion);
/**
* ページ内動作処理
*/
$(window).on('load', function(){
//$(function() {
InitAction ();
DispConfBtn ();
$(document).on( 'click', '#' + privacyCheckName, function(){
DispConfBtn ();
});
/**
* ページ遷移処理
*/
$(document).on( 'click', '#' + btnConfId, function(){
formObj = GetFormValues ();
$('.' + formErrClass).css({ 'background-color' : '' });
$('#' + formId + ' *').removeClass(formErrClass);
var posFormSelector = ( topAjustClass != '' ? '.' + topAjustClass : '#' + formId );
if ( ValidAll ( formObj ) ) {
ConfPageAction ( formObj );
$('body,html').animate({scrollTop:$( posFormSelector ).offset().top - topAjustNum}, 500, 'swing');
}
else {
//$('body,html').animate({scrollTop:$('.' + formErrClass + ':first').offset().top - topAjustNum}, 500, 'swing');
MoveErrStr();
}
});
$(document).on( 'click', '#' + btnBackId, function(){
BackPageAction ();
var posFormSelector = ( topAjustClass != '' ? '.' + topAjustClass : '#' + formId );
$('body,html').animate({scrollTop:$( posFormSelector ).offset().top - topAjustNum}, 500, 'swing');
});
$(document).on( 'click', '#' + btnCompId, function(){
CompBtnAction();
});
$(
'input,' +
'select,' +
'textarea'
).change(function() {
var targetName = $(this).attr('name');
// 検証処理
ValidOrderAction (targetName);
// 対象が郵便番号
if (
targetName == zipName ||
targetName == zipNamePart[1] ||
targetName == zipNamePart[2]
) {
// 検証処理
ValidOrderAction (addressName);
ValidOrderAction (addressName[0]);
ValidOrderAction (addressName[1]);
ValidOrderAction (addressName[2]);
ValidOrderAction (addressName[3]);
}
if (
targetName == zipNamePart[1] ||
targetName == zipNamePart[2]
) {
// 検証処理
ValidOrderAction (zipNamePart[1]);
ValidOrderAction (zipNamePart[2]);
}
});
//ウインドウがリサイズされたら発動
$(window).resize(function() {
// エラーメッセージ再配置
MoveErrStr();
});
$(
'input[type="tel"],' +
'input[type="email"],' +
'input[type="url"],' +
'input[type="number"]'
).blur(function() {
$(this).val( StrFullToHalf ( $(this).val() ) );
});
var radioChecked = [];
$('input[type="radio"]:checked').each(function(){
var name = $(this).attr('name');
radioChecked.push( name + '_' + $('input[name="' + name + '"]').index(this) );
});
$('input[type="radio"]').click(function(){
var name = $(this).attr('name');
var nameX = $.inArray( name + '_' + $('input[name="' + name + '"]').index(this), radioChecked );
if( nameX >= 0 ) {
$(this).prop( 'checked', false );
radioChecked.splice( nameX, 1);
}
else {
var name = $(this).attr('name');
$('input[name="' + name + '"]').each(function(){
var nameX2 = $.inArray( name + '_' + $('input[name="' + name + '"]').index(this), radioChecked);
if( nameX2 >= 0 ){
radioChecked.splice(nameX2,1);
}
});
radioChecked.push( name + '_' + $('input[name="' + name + '"]').index(this) );
}
});
});
/**
* 各動作用関数群
*/
function ConfPageAction ( formObj ) {
$.each( formObj, function ( name, objVal ) {
FormElemHide ( name );
FormValDispShow ( name, objVal['value'] );
});
FormElemHide();
UpdateFormBtnConf ();
}
function BackPageAction () {
FormElemShow ();
FormValDispHide ();
UpdateFormBtnInput ();
}
// 完了画面処理
function CompPageAction ( formObj ) {
// $('#' + formId).empty();
// $('.' + formHideClass).remove();
FormDelAction();
$('#' + formId).attr('action', pathControllerFile);
SetCompFormHidden (formObj);
// 動作確認テスト
//console.log($('#' + formId));
//console.log($('[name="file_up"]').length);
//return false;
$('#' + formId).submit();
}
function CompAjaxAction ( formObj ) {
$('.' + formHideClass).remove();
$('#' + formId).attr('action', pathControllerFile);
var returnVal = false;
var targetObj = {};
$.each( formObj, function ( name, objVal ) {
//---------------------------------
// 複数要素に連なる項目を個別に対応
//---------------------------------
if ( name == nameNamePart[1] ) {
targetObj[nameName + '[title]'] = objVal.title;
targetObj[nameName + '[value]'] = formObj[nameNamePart[1]].value + ' ' + formObj[nameNamePart[2]].value;
}
else if ( name == zipNamePart[1] ) {
targetObj[zipName + '[title]'] = objVal.title;
targetObj[zipName + '[value]'] = formObj[zipNamePart[1]].value + '-' + formObj[zipNamePart[2]].value;
}
else if ( name == telNamePart[1] ) {
targetObj[telName + '[title]'] = objVal.title;
targetObj[telName + '[value]'] = formObj[telNamePart[1]].value + '-' + formObj[telNamePart[2]].value + '-' + formObj[telNamePart[3]].value;
}
else if ( name == addressNamePart[0] ) {
targetObj[addressName + '[title]'] = addressPartTitle;
targetObj[addressName + '[value]'] = formObj[addressNamePart[0]].value + ' ' + formObj[addressNamePart[1]].value + ' ' + formObj[addressNamePart[2]].value + ' ' + formObj[addressNamePart[3]].value;
}
else if ( objVal.type == 'hidden' ) {
targetObj[name] = objVal.value;
}
else if (
name != nameNamePart[2] &&
name != zipNamePart[2] &&
name != telNamePart[2] &&
name != telNamePart[3] &&
name != emailConfName &&
name != addressNamePart[1] &&
name != addressNamePart[2] &&
name != addressNamePart[3] &&
name != privacyCheckName
) {
targetObj[name + '[title]'] = objVal.title;
if ( CheckValidArray ( objVal.value ) ) {
targetObj[name + '[value]'] = objVal.value.join( arraySplitStr );
}
else {
targetObj[name + '[value]'] = objVal.value;
}
}
});
targetObj[compPageName] = compFilePath;
targetObj[chkActionName] = true;
targetObj['target_selector'] = compTargetClass;
targetObj['target_value'] = compMsgStr;
targetObj[ajaxFlgName] = true;
$.ajax({
url: pathControllerFile,
type: 'POST',
data: targetObj,
dataType: 'json',
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert (XMLHttpRequest + " " + textStatus + " " + errorThrown);
},
success: function( content ) {
if ( content['result'] == true ) {
if ( content['target_selector'] ) {
if ( ! content['target_function'] ) content['target_function'] = 'html';
if ( $.isArray( content['target_selector'] ) ) {
$.each( content['target_selector'], function( i, value ) {
if ( content['target_value'] && content['target_value'][i] != null ) {
$( content['target_selector'][i] )[content['target_function']]( content['target_value'][i] );
}
else {
$( content['target_selector'][i] )[content['target_function']]();
}
});
}
else {
if ( content['target_value'] != null ) {
$(content['target_selector'])[content['target_function']]( content['target_value'] );
}
else {
$(content['target_selector'])[content['target_function']]();
}
}
}
returnVal = true;
}
else if ( content['err_url'] ) {
window.location.href = content['err_url'];
}
}
});
return returnVal;
}
function FormElemShow () {
$('#' + formId + ' *').removeClass(formHideClass);
$('.' + inputOnlyClass).removeClass(formHideClass);
$('.' + confOnlyClass).addClass(formHideClass);
$('.' + mailOnlyClass).addClass(formHideClass);
$('.' + selectClass + '_hidden').addClass(selectClass);
$('.' + selectClass + '_hidden').removeClass(selectClass + '_hidden');
}
function FormElemHide (targetName = '') {
if (targetName) {
$('[name="' + targetName + '"]').addClass(formHideClass);
$('.' + labelElemCssInitStr + targetName).addClass(formHideClass);
$('[name="' + targetName + '"]').parent("label").addClass(formHideClass);
$('[name="' + targetName + '"] + label').addClass(formHideClass);
$('[name="' + targetName + '"][type="file"]').parent('.' + uploadDropClass).addClass(formHideClass);
}
else {
$('.' + inputOnlyClass).addClass(formHideClass);
$('.' + confOnlyClass).removeClass(formHideClass);
$('.' + mailOnlyClass).addClass(formHideClass);
$('.' + selectClass).addClass(selectClass + '_hidden');
$('.' + selectClass).removeClass(selectClass);
}
}
function FormValDispShow ( targetName, addStr ) {
if ( addStr != '' ) {
if (
targetName != privacyCheckName &&
$('[name="' + targetName + '"]').attr('type') !== 'hidden'
) {
if ( $('[name="' + targetName + '"]').attr('type') == 'checkbox' ) {
var addStrArray = addStr.join( arraySplitStr );
if ( $('[name="' + targetName + '"]:first').parent("label") ) {
$('[name="' + targetName + '"]:first').parent("label").after('' + addStrArray + ' ');
}
else {
$('[name="' + targetName + '"]:first').after('' + addStrArray + ' ');
}
}
else if ( $('[name="' + targetName + '"]').attr('type') === 'radio' ) {
$('[name="' + targetName + '"]:first').after('' + addStr + ' ');
if ( $('[name="' + targetName + '"]:first').parent("label") ) {
$('[name="' + targetName + '"]:first').parent("label").after('' + addStr + ' ');
}
else {
$('[name="' + targetName + '"]:first').after('' + addStr + ' ');
}
}
else if ( $('[name="' + targetName + '"]').attr('type') === 'file' ) {
$('[name="' + targetName + '"]').parent('.' + uploadDropClass).after('' + addStr + ' ');
}
else {
$('[name="' + targetName + '"]').after('' + addStr.replace(/\r?\n/g, ' ') + ' ');
}
}
}
}
function FormValDispHide () {
$('.' + formViewClass).remove();
}
function InitAction () {
if (
!$('#' + formId).length &&
$('form').length
) {
$('form').first().attr('id', formId);
}
$('.' + confOnlyClass).addClass(formHideClass);
$('.' + mailOnlyClass).addClass(formHideClass);
}
function UpdateFormBtnInput () {
$('#' + btnCompId).after(function (){
var btnClassName = ( $(this).attr('class') ? 'class="' + $(this).attr('class') + '"' : '' );
if ( $(this).prop('tagName') == 'a' ) {
return '' + btnConfName + ' ';
}
else {
return ' ';
}
});
$('#' + btnBackId).remove();
$('#' + btnCompId).remove();
}
function UpdateFormBtnConf () {
$('#' + btnConfId).after(function (){
var btnClassName = ( $(this).attr('class') ? 'class="' + $(this).attr('class') + '"' : '' );
if ( $(this).prop('tagName') == 'a' ) {
return '' + btnBackName + ' ' +
'' + btnCompName + ' ';
}
else {
return ' ' +
' ';
}
});
$('#' + btnConfId).remove();
}
function DispConfBtn () {
if (
$('#' + privacyCheckName).prop("checked") == true ||
! $('#' + privacyCheckName).length
) {
if ( privacyCheckFlg ) {
$('#' + btnConfId).show();
}
else {
$('#' + btnConfId).prop('disabled', false);
}
}
else {
if ( privacyCheckFlg ) {
if ($('#' + privacyCheckName).hasClass('active')) {
$('#' + btnConfId).show();
}
else {
$('#' + btnConfId).hide();
}
}
else {
$('#' + btnConfId).prop('disabled', true);
}
}
}
/**
* 完了ボタン処理
*/
function CompBtnAction () {
if ( ! compAjaxFlg ) {
CompPageAction ( formObj );
}
else {
CompAjaxAction ( formObj );
var posFormSelector = ( topAjustClass != '' ? '.' + topAjustClass : '#' + formId );
$('body,html').animate({scrollTop:$( posFormSelector ).offset().top - topAjustNum}, 500, 'swing');
}
}
function AjaxAction(sendObj = {}) {
// 返値を初期化
var returnVal = false;
$.ajax({
url: pathControllerFile,
type: 'post',
dataType: 'json',
data: sendObj,
cache: false
})
.then(
// 成功時
function (returnData) {
if (returnData) {
// 検証用
if (returnData['mode_valid']) {
$.each(
returnData['mode_valid'],
function( key, value ) {
$('name="' + key + '"').
DevelopConsoleLog(key + ':' + value);
}
);
}
}
},
// エラー時
function (XMLHttpRequest, textStatus, errorThrown) {
if (XMLHttpRequest) DevelopConsoleLog(XMLHttpRequest);
if (textStatus) DevelopConsoleLog(textStatus);
// if (errorThrown) DevelopConsoleLog(errorThrown);
}
);
}
function SetCompFormHidden (formObj) {
$.each( formObj, function ( name, objVal ) {
//---------------------------------
// 複数要素に連なる項目を個別に対応
//---------------------------------
if ( name == nameNamePart[1] ) {
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: nameName + '[title]',
value: objVal.title,
}
)
);
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: nameName + '[value]',
value: formObj[nameNamePart[1]].value + ' ' + formObj[nameNamePart[2]].value,
}
)
);
}
else if ( name == zipNamePart[1] ) {
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: zipName + '[title]',
value: objVal.title,
}
)
);
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: zipName + '[value]',
value: formObj[zipNamePart[1]].value + '-' + formObj[zipNamePart[2]].value,
}
)
);
}
else if ( name == telNamePart[1] ) {
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: telName + '[title]',
value: objVal.title,
}
)
);
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: telName + '[value]',
value: formObj[telNamePart[1]].value + '-' + formObj[telNamePart[2]].value + '-' + formObj[telNamePart[3]].value,
}
)
);
}
else if ( name == addressNamePart[0] ) {
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: addressName + '[title]',
value: addressPartTitle,
}
)
);
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: addressName + '[value]',
value: formObj[addressNamePart[0]].value +
(formObj[addressNamePart[1]] ? ' ' + formObj[addressNamePart[1]].value : '') +
(formObj[addressNamePart[2]] ? ' ' + formObj[addressNamePart[2]].value : '') +
(formObj[addressNamePart[3]] ? ' ' + formObj[addressNamePart[3]].value : ''),
}
)
);
}
else if ( objVal.type == 'file' ) {
/*
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: name + '[title]',
value: objVal.title,
}
)
);
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: name + '[value]',
value: objVal.value,
}
)
);
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: name + '[data][lastModified]',
value: objVal.data.lastModified,
}
),
$(' ',
{
type: 'hidden',
name: name + '[data][name]',
value: objVal.data.name,
}
),
$(' ',
{
type: 'hidden',
name: name + '[data][size]',
value: objVal.data.size,
}
),
$(' ',
{
type: 'hidden',
name: name + '[data][type]',
value: objVal.data.type,
}
),
$(' ',
{
type: 'hidden',
name: name + '[data][webkitRelativePath]',
value: objVal.data.webkitRelativePath,
}
)
);
*/
}
else if ( objVal.type == 'hidden' ) {
/*
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: name,
value: objVal.value,
}
)
);
*/
if (objVal.title) {
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: name + '[title]',
value: objVal.title,
}
)
);
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: name + '[value]',
value: objVal.value,
}
)
);
}
}
else if (
name != nameNamePart[2] &&
name != zipNamePart[2] &&
name != telNamePart[2] &&
name != telNamePart[3] &&
name != emailConfName &&
name != addressNamePart[1] &&
name != addressNamePart[2] &&
name != addressNamePart[3] &&
name != privacyCheckName &&
$.inArray( notSendClass, objVal.classList ) === -1 &&
!objVal.disabled
) {
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: name + '[title]',
value: objVal.title,
}
)
);
if ( CheckValidArray ( objVal.value ) ) {
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: name + '[value]',
value: objVal.value.join( arraySplitStr ),
}
)
);
}
else {
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: name + '[value]',
value: objVal.value,
}
)
);
}
}
});
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: compPageName,
value: compFilePath,
}
)
);
$('#' + formId).append(
$(' ',
{
type: 'hidden',
name: chkActionName,
value: true,
}
)
);
}
function FormDelAction () {
$('.' + formHideClass).each(function(i, elem) {
// ファイルアップロード
if ($(this).attr('type') == 'file') {
$(this).removeClass(formHideClass);
$(this).show();
}
// ファイルアップロード以外
else {
var targetName = $(this).attr('name');
// 削除
$('[name="' + targetName + '"]').remove();
}
});
}
function GetFormValues () {
var returnObj = new Object();
var mailCount = 1;
$(
'#' + formId + ' input,' +
'#' + formId + ' select,' +
'#' + formId + ' textarea,' +
'.' + mailOnlyClass
).each(function() {
if (
this.type != undefined &&
this.type != 'submit' &&
this.type != 'button' &&
this.type != 'reset'
) {
returnObj[this.name] = new Object();
returnObj[this.name] = GetFormValuesTargetName(this.name);
}
else if (
$(this).hasClass(mailOnlyClass) &&
$(this).attr("class").indexOf(mailOnlyClass) != -1
) {
returnObj[mailOnlyClass + mailCount] = new Object();
returnObj[mailOnlyClass + mailCount] = GetFormValuesTargetMailOnly(mailCount);
mailCount ++;
}
});
return returnObj;
}
function GetFormValuesTargetName (targetName) {
var returnObj = new Object();
var targetSel = $("[name='" + targetName + "']");
var targetTag = targetSel.prop("tagName");
var targetType = targetSel.attr("type");
var targetId = targetSel.attr("id");
var targetClass = targetSel.attr("class");
if (targetTag == 'INPUT') {
if (
targetType == 'text' ||
targetType == 'hidden' ||
targetType == 'tel' ||
targetType == 'email' ||
targetType == 'url' ||
targetType == 'number'
) {
if (
targetType == 'text' ||
targetType == 'hidden'
) {
returnObj['value'] = StrEscapeHTML ( targetSel.val() );
}
else if (
targetType == 'tel' ||
targetType == 'email' ||
targetType == 'url' ||
targetType == 'number'
) {
returnObj['value'] = StrEscapeHTML ( StrFullToHalf ( targetSel.val() ) );
}
returnObj['type'] = targetType;
}
else if (targetType == 'radio') {
returnObj['value'] = StrEscapeHTML ( $('input[name=' + targetName + ']:checked').val() );
returnObj['value'] = ( returnObj['value'] != undefined ? returnObj['value'] : '' );
returnObj['type'] = targetType;
}
else if (targetType == 'checkbox') {
returnObj['value'] = [];
$('input[name=' + targetName + ']:checked').each(function() {
returnObj['value'].push ( StrEscapeHTML ( targetSel.val() ) );
});
returnObj['type'] = targetType;
}
else if (targetType == 'file') {
if (targetSel.val()) {
returnObj['value'] = targetSel.prop('files')[0].name;
// ファイルアップロード用の特別対応
returnObj['data'] = targetSel.prop('files')[0];
//returnObj['data'] = Array.from(targetSel.prop('files')[0]);
}
else {
returnObj['value'] = '';
}
returnObj['type'] = targetType;
}
}
else if (targetTag == 'SELECT') {
returnObj = new Object();
returnObj['value'] = StrEscapeHTML ( targetSel.val() );
returnObj['type'] = 'select';
}
else if (targetTag == 'TEXTAREA') {
returnObj = new Object();
returnObj['value'] = StrEscapeHTML ( targetSel.val() );
returnObj['type'] = 'textarea';
}
returnObj['id'] = targetId;
returnObj['class'] = targetClass;
returnObj['classList'] = (targetClass ? targetClass.split(' ') : '');
returnObj['title'] = targetSel.prevAll('.' + titleClass + ':first').text();
returnObj['disabled'] = targetSel.prop('disabled');
returnObj['err'] = false;
if (returnObj['title'] == '' && targetSel.data(titleClass)) returnObj['title'] = targetSel.data(titleClass);
if (returnObj['title'] == '' && targetSel.data('item')) returnObj['title'] = targetSel.data('item');
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent('.' + titleClass).text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().prevAll('.' + titleClass + ':first').text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().parent('.' + titleClass).text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().parent().prevAll('.' + titleClass + ':first').text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().parent().parent('.' + titleClass).text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().parent().parent().prevAll('.' + titleClass + ':first').text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().parent().parent().parent('.' + titleClass).text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().parent().parent().parent().prevAll('.' + titleClass + ':first').text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().parent().parent().parent().parent('.' + titleClass).text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().parent().parent().parent().parent().prevAll('.' + titleClass + ':first').text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().parent().parent().parent().parent().parent('.' + titleClass).text();
if (returnObj['title'] == '') returnObj['title'] = targetSel.parent().parent().parent().parent().parent().parent().prevAll('.' + titleClass + ':first').text();
if (returnObj['title'] == '' && targetSel.attr('placeholder')) returnObj['title'] = targetSel.attr('placeholder');
if (returnObj['title'] != '') {
var titleSub = targetSel.prevAll('.' + titleSubClass + ':first').text();
if (titleSub == '' && targetSel.data(titleSubClass)) titleSub = targetSel.data(titleSubClass);
if (titleSub == '') titleSub = targetSel.parent('.' + titleSubClass).text();
if (titleSub == '') titleSub = targetSel.parent().prevAll('.' + titleSubClass + ':first').text();
if (titleSub == '') titleSub = targetSel.parent().parent('.' + titleSubClass).text();
if (titleSub == '') titleSub = targetSel.parent().parent().prevAll('.' + titleSubClass + ':first').text();
if (titleSub == '') titleSub = targetSel.parent().parent().parent('.' + titleSubClass).text();
if (titleSub == '') titleSub = targetSel.parent().parent().parent().prevAll('.' + titleSubClass + ':first').text();
if (titleSub == '') titleSub = targetSel.parent().parent().parent().parent('.' + titleSubClass).text();
if (titleSub != '') returnObj['title'] += titleSubStrBefore + titleSub + titleSubStrAfter;
}
if ($.inArray( formErrClass, returnObj['classList'] ) !== -1) {
returnObj['err'] = true;
}
return returnObj;
}
function GetFormValuesTargetMailOnly (targetCount) {
var returnObj = new Object();
var targetSel = $("." + mailOnlyClass).eq((targetCount - 1));
var targetClass = mailOnlyClass;
returnObj['value'] = StrEscapeHTML ( targetSel.text() );
returnObj['type'] = 'mail_only';
returnObj['id'] = targetClass + targetCount;
returnObj['class'] = targetClass;
returnObj['classList'] = (targetClass ? targetClass.split(' ') : '');
returnObj['title'] = targetSel.prevAll('.' + titleClass + ':first').text();
returnObj['err'] = false;
return returnObj;
}
/*
========================================
*/
$(window).on('load', function(){
//$(function() {
// 初期化処理
DevelopInitAction();
});
function DevelopInitAction () {
}
function DevelopCheck () {
formObj = GetFormValues ();
DevelopConsoleLog(formObj);
if (!$('form').length) {
DevelopConsoleLog('◆◆◆エラー◆◆◆:FORMが設定されていません。');
}
if (
$('form').length &&
!$('#' + formId).length
) {
DevelopConsoleLog('◆◆◆エラー◆◆◆:FORMにIDが設定されていません。');
}
if (formObj) {
$.each( formObj, function ( name, objVal ) {
// タイトルが存在しない場合
if (!objVal['title']) {
DevelopConsoleLog('◇◆◇要注意◇◆◇:FORMエレメント名「' + name + '」のタイトルが取得できませんでした。');
}
});
}
if (
!$('#' + btnConfId).length &&
!$('#' + btnCompId).length
) {
DevelopConsoleLog('◆◆◆エラー◆◆◆:確認ボタンIDが未設定です。');
}
//AjaxAction();
}
function DevelopConsoleLog (targetData) {
}
function StrFullToHalf ( str ) {
var returnVal = str.replace( /[A-Za-z0-9-!"#$%&'()=<>,.?_[]{}@^~¥]/g, function(s) {
return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
});
return returnVal;
}
function StrHalfToFull ( str ) {
var returnVal = str.replace( /[A-Za-z0-9!-\/:-@\[-\{-~]/g, function(s) {
return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
});
return returnVal;
}
function StrEscapeHTML ( str = '' ) {
str = str.replace(/&/g, '&');
str = str.replace(//g, '>');
str = str.replace(/"/g, '"');
str = str.replace(/'/g, ''');
return str;
}
function ValidAll ( formObj ) {
// 検証フラグの初期化
validFlg = true;
//-------------------------------
// エラーメッセージを初期化
//-------------------------------
$.each( formObj, function ( name, objVal ) {
ErrInitStr ( errElemIdInitStr + name, name );
// エラーフラグの初期化
objVal['err'] = false;
});
//-------------------------------
// 基本項目の検証
//-------------------------------
$.each( formObj, function ( name, objVal ) {
// CSSがセットがセットされている場合
if (
objVal['class'] != '' &&
objVal['class'] != undefined &&
!objVal['disabled']
) {
$.each( validClass, function ( key, targetVal ) {
if (key != 'exc') {
if (!objVal['err']) {
// 検証処理
errFlg = CheckValid (objVal, key);
// 検証エラー
if (!errFlg) {
ErrAddStr ( errElemIdInitStr + name, validStr[key] );
objVal['err'] = true;
// エラーCSSを追加
ErrAddCss ( name );
// 検証フラグの更新
validFlg = false;
}
}
}
});
}
});
// エラーが存在しない場合
if (validFlg) {
//-------------------------------
// 個別対応の項目の検証
//-------------------------------
// E-mail(確認)
if (
formObj[emailName] &&
formObj[emailName]['value'] != '' &&
formObj[emailConfName] &&
formObj[emailConfName]['value'] != ''
) {
if ( formObj[emailName]['value'] != formObj[emailConfName]['value'] ) {
ErrAddStr ( errElemIdInitStr + emailConfName, validStr['same'] );
formObj[emailConfName]['err'] = true;
validFlg = false;
// エラーCSSを追加
ErrAddCss ( emailName );
}
}
}
// 返り値を返す
return validFlg;
}
function ValidOrderAction (name) {
// エラーフラグを初期化
var errFlg = true;
// Form情報取得
objVal = CheckValidCommon (name);
if (!objVal['disabled']) {
$.each( validClass, function ( key, targetVal ) {
if (
errFlg &&
key != 'exc'
) {
errFlg = CheckValid (objVal, key);
// 検証エラー
if (!errFlg) {
ErrAddStr ( errElemIdInitStr + name, validStr[key] );
objVal['err'] = true;
// エラーCSSを追加
ErrAddCss ( name );
}
}
});
}
// エラーメッセージ再配置
MoveErrStr();
}
function CheckValid (objVal, key) {
// 返値を初期化
var validFlg = true;
// classがセット
if ( objVal['class'] != '' ) {
// エラーCSSがセット
if (objVal['err'] == true) {
// 返値を更新
validFlg = false;
}
// 検証:ベース
else if (
$.inArray( validClass[key], objVal['classList'] ) !== -1 &&
$.inArray( validClass['exc'], objVal['classList'] ) === -1
) {
// 必須
if (
key == 'hissu' &&
! CheckValidHissu(objVal['value'])
) {
// 返値を更新
validFlg = false;
}
// 数字
else if (
key == 'num' &&
! CheckValidNum(objVal['value'])
) {
// 返値を更新
validFlg = false;
}
// ひらがな
else if (
key == 'hiragana' &&
! CheckValidHiragana(objVal['value'])
) {
// 返値を更新
validFlg = false;
}
// カタカナ
else if (
key == 'katakana' &&
! CheckValidKatakana(objVal['value'])
) {
// 返値を更新
validFlg = false;
}
// メールアドレス
else if (
key == 'email' &&
! CheckValidEmail(objVal['value'])
) {
// 返値を更新
validFlg = false;
}
// 電話番号 or FAX
else if (
key == 'tel' &&
! CheckValidTel(objVal['value'])
) {
// 返値を更新
validFlg = false;
}
// 郵便番号
else if (
key == 'zip' &&
! CheckValidZip(objVal['value'])
) {
// 返値を更新
validFlg = false;
}
}
}
// 返値を返す
return validFlg;
}
function CheckValidHissu (val) {
return (val && val.length > 0 ? true : false);
}
function CheckValidNum (val) {
return ($.isNumeric ( val ) ? true : false);
}
function CheckValidHiragana (val) {
return (val.match(/^([ぁ-んー ]+)+$/) ? true : false);
}
function CheckValidKatakana (val) {
return (val.match(/^([ァ-ロワヲンー ]+)+$/) ? true : false);
}
function CheckValidEmail (val) {
return (val.match(/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/) ? true : false);
}
function CheckValidTel (val) {
return (val.match(/^([0-9])+([0-9-])+([0-9])+$/) ? true : false);
}
function CheckValidZip (val) {
return (val.match(/^([0-9-]){3,8}$/) ? true : false);
}
function CheckValidArray (object) {
return ( Object.prototype.toString.call( object ) === '[object Array]' ? true : false );
}
function CheckValidCommon (name) {
// エラー表示 初期化
ErrInitStr ( errElemIdInitStr + name, name );
// Form情報を取得して返す
return GetFormValuesTargetName (name);
}
function MoveErrStr () {
//-----------------------------
// 仕様変更で、再配置処理をしない
return;
//-----------------------------
// エラーメッセージクラス
$('.' + formErrStrClass).each(function() {
// 対象のIDを所得
var targetId = $(this).attr('id');
// 対象のIDからFORMエレメント名を取得
var targetEleName = targetId.slice(errElemIdInitStr.length);
if ( $('[name="' + targetEleName + '"]').length > 1 ) {
// 親要素がlabel
if ( $('[name="' + targetEleName + '"]:first').parent('label').length ) {
// 対象FORMの座標取得
var targetOffset = $("[name='" + targetEleName + "']:first").parent('label').offset();
}
else if ($('[name="' + targetEleName + '"]:first').parent().find('label').length) {
// 対象FORMの座標取得
var targetOffset = $("[name='" + targetEleName + "']:first").parent().find('label').offset();
}
else {
// 対象FORMの座標取得
var targetOffset = $("[name='" + targetEleName + "']:first").offset();
}
}
else {
// ファイルアップロード
if ($("[name='" + targetEleName + "']").parent("." + uploadDropClass).length) {
// 対象FORMの座標取得
var targetOffset = $("[name='" + targetEleName + "']").parent("." + uploadDropClass).offset();
}
else {
// 対象FORMの座標取得
var targetOffset = $("[name='" + targetEleName + "']").offset();
}
}
if (targetOffset) {
// 対象エラーメッセージの座標を再配置
$(this).offset({
top:targetOffset.top - 12,
left:targetOffset.left
});
}
});
}
function ErrInitStr ( targetSelctor, baseSelectorName ) {
if ( ! $('#' + targetSelctor).length ) {
if ( $('[name="' + baseSelectorName + '"]').length > 1 ) {
var targetSel = $('[name="' + baseSelectorName + '"]:last').closest('.' + formElemClass);
}
else {
var targetSel = $('[name="' + baseSelectorName + '"]').closest('.' + formElemClass);
}
targetSel.append('<' + elemErrStr +' id="' + targetSelctor + '" class="' + formErrStrClass + '">' + '' + elemErrStr +'>');
}
$('[name="' + baseSelectorName + '"]').removeClass(formErrClass);
$('[name="' + baseSelectorName + '"]').parent("label").removeClass(formErrClass);
$('[name="' + baseSelectorName + '"]').parent("." + uploadDropClass).removeClass(formErrClass);
$('#' + targetSelctor).text('');
}
function ErrAddCss ( targetName ) {
$('[name="' + targetName + '"]').addClass(formErrClass);
$('[name="' + targetName + '"]').parent("label").addClass(formErrClass);
$('[name="' + targetName + '"]').parent("." + uploadDropClass).addClass(formErrClass);
//$('.' + formErrClass).css({ 'background-color' : errFormColor });
}
function ErrAddStr ( targetSelctor, addStr ) {
if ( addStr != '' ) {
if ( $('#' + targetSelctor).text().length > 0 ) $('#' + targetSelctor).append(' ');
// エラーメッセージ
$('#' + targetSelctor).append('※' + addStr);
// エラーメッセージ(アイコン付き)
// 仕様変更によりコメントアウト
//$('#' + targetSelctor).append(
// ' ',
// addStr
//);
//$('#' + targetSelctor).css({ 'color' : errStrColor });
}
}
/*
========================================
*/
$(window).on('load', function(){
//$(function() {
// 初期化処理
YubinInitAction();
});
function YubinInitAction () {
// 郵便番号自動入力用のタグを生成
YubinAction();
}
function YubinAction () {
if (
$('#' + formId).length &&
(
$('[name="' + zipName + '"]').length ||
(
$('[name="' + zipNamePart[1] + '"]').length &&
$('[name="' + zipNamePart[2] + '"]').length
)
) &&
(
$('[name="' + addressName + '"]').length ||
(
$('[name="' + zipNamePart[1] + '"]').length &&
$('[name="' + zipNamePart[2] + '"]').length
)
)
) {
var yubinbangoJsUrl = 'https://yubinbango.github.io/yubinbango/yubinbango.js';
//console.log(siteUrl + '/' + dirProgramName + '/js/yubinbango.js');
//var includeJs = '';
var includeJs = '';
$('head script:last').after(includeJs);
// TOP
if (! $('.' + yubinTopClass).length) {
$('#' + formId).addClass(yubinTopClass);
}
// 国指定
if (! $('.' + yubinCountryClass).length) {
$('.' + yubinTopClass).prepend('Japan ');
}
// 郵便番号へのクラスの追加
if (! $('.' + yubinZipcodeClass).length) {
if ($('[name="' + zipName + '"]').length) {
$('[name="' + zipName + '"]').addClass(yubinZipcodeClass);
}
else {
$('[name="' + zipNamePart[1] + '"]').addClass(yubinZipcodeClass);
$('[name="' + zipNamePart[2] + '"]').addClass(yubinZipcodeClass);
}
}
// 住所へのクラスの追加
if (! $('.' + yubinAddress1Class).length) {
if (! $('[name="' + addressNamePart[0] + '"]').length) {
if ($('[name="' + addressName + '"]').length) {
$('[name="' + addressName + '"]').addClass(
yubinPrefClass + ' ' +
yubinAddress1Class + ' ' +
yubinAddress2Class + ' ' +
yubinAddress3Class
);
}
else if (
$('[name="' +addressNamePart[1] + '"]').length &&
$('[name="' +addressNamePart[2] + '"]').length
) {
$('[name="' + addressNamePart[1] + '"]').addClass(
yubinPrefClass + ' ' +
yubinAddress1Class + ' ' +
yubinAddress2Class
);
$('[name="' + addressNamePart[2] + '"]').addClass(yubinAddress3Class);
}
}
else {
if ($('[name="' + addressNamePart[0] + '"]').is('input')) {
$('[name="' + addressNamePart[0] + '"]').addClass(yubinPrefClass);
}
else {
$('[name="' + addressNamePart[0] + '"]').addClass(yubinPrefIdClass);
}
if ($('[name="' + addressName + '"]').length) {
$('[name="' + addressName + '"]').addClass(
yubinAddress1Class + ' ' +
yubinAddress2Class + ' ' +
yubinAddress3Class
);
}
else if (
$('[name="' +addressNamePart[1] + '"]').length &&
$('[name="' +addressNamePart[2] + '"]').length
) {
$('[name="' + addressNamePart[1] + '"]').addClass(
yubinAddress1Class + ' ' +
yubinAddress2Class
);
$('[name="' + addressNamePart[2] + '"]').addClass(yubinAddress3Class);
}
else if (
$('[name="' +addressNamePart[1] + '"]').length &&
! $('[name="' +addressNamePart[2] + '"]').length
) {
$('[name="' + addressNamePart[1] + '"]').addClass(
yubinAddress1Class + ' ' +
yubinAddress2Class + ' ' +
yubinAddress3Class
);
}
}
}
if ($('.' + yubinCountryClass).length) {
// 動的要素への対応
//new YubinBango.MicroformatDom();
}
}
}
/*
========================================
*/
$(window).on('load', function(){
// 追加項目の初期化処理
AddInitAction ();
// 追加数変更
$('[name="' + addName + '"]').on('change', function () {
// 追加項目の更新
ChangeAddAction();
});
});
function ChangeAddAction () {
var formObj = GetFormValues ();
var targetNum = GetAddNum();
addMaxCount = (GetAddMax() > addMaxCount ? GetAddMax() : addMaxCount);
var baseList = [];
var nowList = [];
var i = (i ? i : 0);
$.each( formObj, function ( name, objVal ) {
// 追加項目のFORMタイトルが存在
if (name.indexOf(addName + '_') !== -1) {
if (name.indexOf(addLastStr) === -1) {
baseList.push(name);
}
else {
nowList.push(name);
}
}
});
// 追加元データが存在
if (baseList.length > 0) {
// カウントが0以上
if (targetNum > 0) {
for (var num_i = 1; num_i <= targetNum; num_i ++) {
for (var i = 0; i < baseList.length; i ++) {
// 変更後の名称をセット
var editName = (baseList[i] + addLastStr + num_i);
// 追加要素が存在しない
if (!($('[name="' + editName + '"]').length)) {
// 最後の要素
var lastBox = $('.' + addBoxClass).last();
// 後ろに区切り線が存在する場合、区切り線要素をセット
var lastSeparator = lastBox.nextAll('.' + addSeparatorClass);
// 対象の追加項目範囲を取得
if ($('[name="' + baseList[i] + '"]').closest('.' + addBoxClass).length > 0) {
// 対象範囲をセット
var targetBox = $('[name="' + baseList[i] + '"]').closest('.' + addBoxClass);
// 最後に区切り線が存在
if (lastSeparator.length) {
// 要素のコピーを作成して追加処理
lastSeparator.after(targetBox.clone());
}
else {
// 要素のコピーを作成して追加処理
lastBox.after(targetBox.clone());
}
// 要素名を更新
$('[name="' + baseList[i] +'"]').last().attr('name', editName);
// disabled属性を更新
$('[name="' + editName +'"]').prop('disabled', false);
// 追加対象の範囲をセット
var editBox = $('[name="' + editName + '"]').closest('.' + addBoxClass);
// 対象範囲を表示設定
editBox.find('.' + titleClass)
.html(GetAddValFromNum(num_i) + ' ' + editBox.find('.' + titleClass).html());
// 対象範囲を表示設定
editBox.show();
}
}
}
// 区切り線の追加
if (
num_i < targetNum &&
$('.' + addBoxClass).length &&
$('.' + addSeparatorClass).length < num_i
) {
// 区切り線を追加表示
$('.' + addBoxClass + ':visible')
.eq(((targetNum - 1) * baseList.length) - 1)
.after('
');
}
$('.' + addSeparatorClass).eq(targetNum - 1).remove();
}
}
// 更新以降
if (nowList.length > 0) {
// 不要な要素削除
for (var i = 0; i < baseList.length; i ++) {
// 追加更新要素削除
for (var num_i = (targetNum + 1); num_i <= addMaxCount; num_i ++) {
// 変更後の名称をセット
var editName = (baseList[i] + addLastStr + num_i);
// 追加要素の削除
$('[name="' + editName + '"]').closest('.' + addBoxClass).remove();
}
}
}
}
$('.' + addSeparatorClass).show();
}
function AddInitAction () {
var formObj = GetFormValues ();
$.each( formObj, function ( name, objVal ) {
// 追加項目のFORMタイトルが存在
if (
name.indexOf(addName + '_') !== -1 &&
name.indexOf(addLastStr) === -1
) {
// disabled属性を更新
$('[name="' + name + '"]').prop('disabled', true);
// 対象の追加項目範囲を取得
if ($('[name="' + name + '"]').closest('.' + addBoxClass).length > 0) {
// 対象範囲を非表示設定
$('[name="' + name + '"]').closest('.' + addBoxClass).hide();
}
}
});
// 区切り線を非表示設定
$('.' + addSeparatorClass).hide();
}
function GetAddMax () {
returnVal = 0;
tempVal = 0;
if ($('[name="' + addName + '"]').length) {
// 対象エレメント情報を取得
var targetObj = GetFormValuesTargetName(addName);
// プルダウン
if (targetObj['type'] == 'select') {
$('[name="' + addName + '"] option').each(function(index, element){
// 値のみを取得
tempVal = Number(StrFullToHalf($(this).val()).replace(/[^0-9]/g, ''));
returnVal = (returnVal > tempVal ? returnVal : tempVal);
});
}
// その他
else {
$('[name="' + addName + '"]').each(function(index, element){
// 値のみを取得
tempVal = Number(StrFullToHalf($(this).val()).replace(/[^0-9]/g, ''));
returnVal = (returnVal > tempVal ? returnVal : tempVal);
});
}
}
return returnVal;
}
function GetAddNum () {
returnVal = 0;
if ($('[name="' +addName + '"]').length) {
// ラジオボタン
if ($('[name="' +addName + '"]:checked').val()) {
var targetVal = StrFullToHalf($('[name="' +addName + '"]:checked').val());
returnVal = Number(targetVal.replace(/[^0-9]/g, ''));
}
// それ以外
else if ($('[name="' +addName + '"]').val() != '') {
var targetVal = StrFullToHalf($('[name="' + addName + '"]').val());
returnVal = Number(targetVal.replace(/[^0-9]/g, ''));
}
}
return returnVal;
}
function GetAddValFromNum (num) {
returnVal = '';
if ($('[name="' +addName + '"]').length) {
// 追加数の情報を取得
var addData = GetFormValuesTargetName(addName);
// ラジオボタン
if (addData['type'] == 'radio') {
$('[name="' + addName + '"]').each(function(){
var targetVal = StrFullToHalf($(this).val());
if (Number(targetVal.replace(/[^0-9]/g, '')) == num) {
returnVal = $(this).val();
return false;
}
});
}
// プルダウン
else if (addData['type'] == 'select') {
$('[name="' + addName + '"] option').each(function(){
var targetVal = StrFullToHalf($(this).val());
if (Number(targetVal.replace(/[^0-9]/g, '')) == num) {
returnVal = $(this).val();
return false;
}
});
}
// その他
else {
var targetVal = StrFullToHalf($('[name="' + addName + '"]').val());
if (Number(targetVal.replace(/[^0-9]/g, '')) == num) {
returnVal = $('[name="' + addName + '"]').val();
}
}
}
return returnVal;
}
/*
========================================
*/
$(window).on('load', function(){
// 初期化処理
UploadInitAction();
// ファイルドロップエリアをクリック
$('.' + uploadDropClass).on('click', function () {
if (!uploadSetFlg) {
targetFile = $(this).find('input[type="file"]');
targetFile.on('click', function(e){
// イベント伝播を阻止
e.stopPropagation();
});
// 再度クリック
targetFile.click();
// ファイルセット時の処理
targetFile.on('change',function(){
var file = $(this).prop('files')[0];
// テキストエリア更新
$('.' + uploadTextClass).text('ファイル名:' + file.name);
UploadTextAreaReset();
// 削除ボタン設置
UploadAddClosebtn();
// セットクラス追加
$('.' + uploadDropClass).addClass(uploadSetClass);
// セットフラグの更新
uploadSetFlg = true;
});
}
});
// ファイルドラッグ処理
$('.' + uploadDropClass).on('dragenter dragover', function (e) {
e.stopPropagation();
e.preventDefault();
// Class追加
$(this).addClass(uploadDragClass);
});
// ファイルドラッグ処理
$('.' + uploadDropClass).on('dragleave', function (e) {
e.stopPropagation();
e.preventDefault();
// Class追加
$(this).removeClass(uploadDragClass);
});
// ファイルドロップ処理
$('.' + uploadDropClass).on('drop', function (e) {
e.preventDefault();
var file = e.originalEvent.dataTransfer.files;
var inputFile = $(this).find('input[type="file"]');
// 更新途中 2022/08/27
UploadSetTextArea(inputFile);
inputFile[0].files = file;
// テキストエリア更新
$('.' + uploadTextClass).text('ファイル名:' + file[0].name);
UploadTextAreaReset();
// 削除ボタン設置
UploadAddClosebtn();
// セットクラス追加
$('.' + uploadDropClass).addClass(uploadSetClass);
// セットフラグの更新
uploadSetFlg = true;
});
// ファイル削除ボタンをクリック
$(document).on( 'click', '.' + uploadCloseClass, function(){
// データ削除
$(this).parent('.' + uploadDropClass).find('input[type="file"]').val('');
// 初期化処理
UploadInitAction ();
// セットクラス追加
$('.' + uploadDropClass).removeClass(uploadSetClass);
// セットフラグ解除
uploadSetFlg = false;
});
});
function UploadInitAction () {
// enctype属性追加
UploadAddFormEnctype();
// ドラッグ&ドロップエリア生成
UploadCreateDropArea();
}
function UploadAddFormEnctype () {
if (!$('#' + formId).attr('enctype')) {
$('#' + formId).attr('enctype', 'multipart/form-data');
}
}
function UploadCreateDropArea () {
if ($('input[type="file"]').length) {
$('input[type="file"]').each(function(){
var targetExists = ($(this).val().length > 0 ? true : false);
// ファイルがセット済み
if (targetExists) {
if ($(this).parent().hasClass(uploadDropClass)) {
if ($('.' + uploadTextClass).length) {
$('.' + uploadTextClass).text('ファイル名:' + $(this).prop('files')[0].name);
UploadTextAreaReset();
}
// 削除ボタン設置
UploadAddClosebtn();
}
else {
$(this).wrapAll('
');
$(this).parent().append('
');
$(this).hide();
$('.' + uploadTextClass).text('ファイル名:' + $(this).prop('files')[0].name);
UploadTextAreaReset();
// 削除ボタン設置
UploadAddClosebtn();
}
// セットフラグの更新
uploadSetFlg = true;
}
// ファイルが未セット
else {
if (
!$(this).parent().hasClass(uploadDropClass) &&
!$(this).parent().find('.' + uploadTextClass).length
) {
// エリアコメント変数を初期化
var areaText = '';
$(this).wrapAll('
');
// エリアコメントが設定
if ($(this).data('text') !== 'undefined') {
areaText = $(this).data('text');
}
$(this).hide();
$(this).parent().append('
');
}
if ($(this).parent().find('.' + uploadCloseClass).length) {
$(this).parent().find('.' + uploadCloseClass).remove();
}
if ($(this).parent().find('.' + uploadDragClass).length) {
$(this).parent().find('.' + uploadDragClass).removeClass(uploadDragClass);
}
if ($(this).parent().hasClass(uploadSetClass)) {
$(this).parent().removeClass(uploadSetClass);
}
// エリアコメントをセット
$('.' + uploadTextClass).text(areaText ? areaText : uploadAreaStr);
UploadTextAreaReset();
}
});
}
/*
if ($('input[type="file"]').length) {
$('input[type="file"]').each(function(){
var targetExists = ($(this).val().length > 0 ? true : false);
// ファイルがセット済み
if (targetExists) {
if ($(this).parent().hasClass(uploadDropClass)) {
if ($('.' + uploadTextClass).length) {
$('.' + uploadTextClass).text('ファイル名:' + $(this).prop('files')[0].name);
UploadTextAreaReset();
}
// 削除ボタン設置
UploadAddClosebtn();
}
else {
$(this).wrapAll('
');
$(this).parent().append('
');
$(this).hide();
$('.' + uploadTextClass).text('ファイル名:' + $(this).prop('files')[0].name);
UploadTextAreaReset();
// 削除ボタン設置
UploadAddClosebtn();
}
// セットフラグの更新
uploadSetFlg = true;
}
// ファイルが未セット
else {
if (
!$(this).parent().hasClass(uploadDropClass) &&
!$(this).parent().find('.' + uploadTextClass).length
) {
// エリアコメント変数を初期化
var areaText = '';
$(this).wrapAll('
');
// エリアコメントが設定
if ($(this).data('text') !== 'undefined') {
areaText = $(this).data('text');
}
$(this).hide();
$(this).parent().append('
');
}
if ($(this).parent().find('.' + uploadCloseClass).length) {
$(this).parent().find('.' + uploadCloseClass).remove();
}
if ($(this).parent().find('.' + uploadDragClass).length) {
$(this).parent().find('.' + uploadDragClass).removeClass(uploadDragClass);
}
if ($(this).parent().hasClass(uploadSetClass)) {
$(this).parent().removeClass(uploadSetClass);
}
// エリアコメントをセット
$('.' + uploadTextClass).text(areaText ? areaText : uploadAreaStr);
UploadTextAreaReset();
}
});
}
*/
}
function UploadTextAreaReset () {
if ($('.' + uploadTextClass).length) {
$('.' + uploadTextClass).css({
'position': 'absolute',
'top': '50%',
'left': '50%',
'transform': 'translate(-50%, -50%)',
'-webkit-transform': 'translate(-50%, -50%)',
'-ms-transform': 'translate(-50%, -50%)'
});
}
}
function UploadSetTextArea (targetSel) {
if (!targetSel.parent().find('.' + uploadTextClass).length) {
targetSel.wrapAll('
');
}
if (targetSel.val().length > 0) {
targetSel.parent().find('.' + uploadTextClass).text('ファイル名:' + targetSel.prop('files')[0].name);
}
else {
targetSel.parent().find('.' + uploadTextClass).text(targetSel.data('text') !== 'undefined' ? targetSel.data('text') : uploadAreaStr);
}
targetSel.parent().find('.' + uploadTextClass).css({
'position': 'absolute',
'top': '50%',
'left': '50%',
'transform': 'translate(-50%, -50%)',
'-webkit-transform': 'translate(-50%, -50%)',
'-ms-transform': 'translate(-50%, -50%)'
});
}
function UploadAddClosebtn () {
if (!$('.' + uploadCloseClass).length) {
$('.' + uploadTextClass).after('
');
var closeTopPos = $('.' + uploadTextClass).position().top;
closeTopPos -= $('.' + uploadTextClass).css('font-size').replace(/[^0-9.]/g, '') * 2;
var closeLeftPos = $('.' + uploadTextClass).position().left + $('.' + uploadTextClass).width();
$('.' + uploadCloseClass).css({
'top': closeTopPos + 'px',
'left': closeLeftPos + 'px'
});
}
}