/************************ ** common.js [Write file text] ************************/ $(function () { // lock control var lock_html = ''; lock_html += '\n'; $("body").append(lock_html); // message control var msg_html = ''; msg_html += '\n'; $("body").append(msg_html); $("#proccess_msg").css({ position: "fixed", bottom: "10px", right:"10px" }); // Enterで更新禁止 $("input").keypress(function (ev) { if ((ev.which && ev.which === 13) || (ev.keyCode && ev.keyCode === 13)) { return false; } else { return true; } }); // スクロールのオフセット値 var offsetY = -10; // スクロールにかかる時間 var time = 500; // ページ内リンクのみを取得 try { $('a[href^=#]').click(function () { // 移動先となる要素を取得 var target = $(this.hash); if (!target.length) return; // 移動先となる値 var targetY = target.offset().top + offsetY; // スクロールアニメーション $('html,body').animate({ scrollTop: targetY }, time, 'swing'); // ハッシュ書き換えとく window.history.pushState(null, null, this.hash); // デフォルトの処理はキャンセル return false; }); } catch (e) { console.log(e.message);} // FullScreen $(".FullScreen-ON").show(); $(".FullScreen-OFF").hide(); }); function alert_delay(msg, delay) { if (!delay) delay = 100; setTimeout(function () { alert(msg); }, delay); } /************ Open and Close ************/ // WOpen function WOpen(url, name, w, h) { if (!(w) && !(h)) { w = Math.round(screen.width * 0.99); h = Math.round(screen.height * 0.95); window.open(url, name, 'width=' + String(w) + ', height=' + String(h) + ', left=0, top=0, menubar=no, toolbar=no, scrollbars=yes, location=no, status=no, resizable=yes'); } else if (!(w)) { w = Math.round(screen.width * 0.99); window.open(url, name, 'width=' + String(w) + ', height=500, left=0, top=0, menubar=no, toolbar=no, scrollbars=yes, location=no, status=no, resizable=yes'); } else { window.open(url, name, 'width=' + String(w) + ', height=' + String(h) + ', menubar=no, toolbar=no, scrollbars=yes, location=no, status=no, resizable=yes'); } } // WClose function WClose() { var nvua = navigator.userAgent; if (nvua.indexOf('MSIE') >= 0) { if (nvua.indexOf('MSIE 5.0') == -1) { top.opener = ''; } } else if (nvua.indexOf('Gecko') >= 0) { top.name = 'CLOSE_WINDOW'; wid = window.open('', 'CLOSE_WINDOW'); } top.close(); //(window.open('', '_top').opener = top).close(); return false; } // TimerLink function TimerLink(ms, lnk) { setTimeout(function () { window.top.location.href(lnk); }, ms); } // FullScreen function FullScreen(e) { if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) { // current working methods if (document.documentElement.requestFullscreen) { document.documentElement.requestFullscreen(); } else if (document.documentElement.msRequestFullscreen) { document.documentElement.msRequestFullscreen(); } else if (document.documentElement.mozRequestFullScreen) { document.documentElement.mozRequestFullScreen(); } else if (document.documentElement.webkitRequestFullscreen) { document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); } $(".FullScreen-ON").hide(); $(".FullScreen-OFF").show(); } else { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.webkitExitFullscreen) { document.webkitExitFullscreen(); } $(".FullScreen-ON").show(); $(".FullScreen-OFF").hide(); } } /************ Auto Setting ************/ // Auto Watch // $(".watch") $(function () { // watch function var wf = (function (obj) { if (obj) { // make time string now = new Date(); year = now.getYear(); month = now.getMonth() + 1; day = now.getDate(); hour = now.getHours(); minute = now.getMinutes(); second = now.getSeconds(); if (year < 1000) { year += 1900 } if (hour < 10) { hour = '0' + hour } if (minute < 10) { minute = '0' + minute } if (second < 10) { second = '0' + second } // disp switch ($(obj).prop("tagName").toUpperCase()) { case "INPUT": case "TEXTAREA": $(obj).val(year + '/' + month + '/' + day + ' ' + hour + ':' + minute + ':' + second); break; default: $(obj).html(year + '/' + month + '/' + day + ' ' + hour + ':' + minute + ':' + second); break; } } }); // watch class $(".watch").each(function () { var target = this; setInterval(function () { wf(target); }, 1000); }); }); // Auto Image Opacity // $("a img, input[type=image]") $(function () { $("a img, input[type=image]").each(function () { if ($(this).hasClass("noalpha")) { //NA } else { // focus and hover $(this).focus(function () { $(this).blur(); }).hover( function () { // mouseover $(this).css({ "opacity": "0.7" }); } , function () { // mouseout $(this).css({ "opacity": "1" }); } ); } }); }); /************ Validation ************/ // check date type function IsDate(text) { if ((new Date(text)) === null) return false; if ((new Date(text)) == 'NaN') return false; if ((new Date(text)) == 'Invalid Date') return false; return true; } function IsNumber(str) { return !Number.isNaN(parseInt(str)); // if (str.match(/[^0-9]+/)) { // return false; // } // return true; } function IsDecimal(str) { if (parseFloat(str)) { return true; } else { return false; } } function IsMail(str) { if (!(str)) { return true; } else if (!str.match(/^[A-Za-z0-9]+[\w-\.-]+@[\w\.-]+\.\w{2,}$/)) { return false; } return true; } /************ 日付関係 ************/ function ToDay() { myDate = new Date(); theDate = myDate.getDate(); theFyear = myDate.getFullYear(); theYear = myDate.getYear(); theMonth = myDate.getMonth() + 1; return theFyear + "/" + theMonth + "/" + theDate; } function addDate(date1Str, days) { if (IsDate(date1Str)) { var date1 = new Date(date1Str); // パラメータで取得した日数を加算 date1.setDate(date1.getDate() + Number(days)); // Date型を(YYYY/MM/DD)形式へ成型して返却 return [date1.getFullYear(), date1.getMonth() + 1, date1.getDate()].join('/'); } else { return date1Str; } } function addMonth(date1Str, months) { if (IsDate(date1Str)) { var date1 = new Date(date1Str); // パラメータで取得した月数を加算 var resultDate = new Date(date1.getTime()); resultDate.setMonth(date1.getMonth() + months); // Date型を(YYYY/MM/DD)形式へ成型して返却 return [resultDate.getFullYear(), resultDate.getMonth() + 1, resultDate.getDate()].join('/'); } else { return date1Str; } } function DateInterval(date1, date2) { if ((IsDate(date1)) && (IsDate(date2))) { var d1 = new Date(date1); var d2 = new Date(date2); return Math.ceil((d2 - d1) / (60 * 60 * 24 * 1000)); } else { return -1; } } function GetBirthday(datevalue) { var d1 = ConvertDate2(datevalue); var d2 = ConvertDate2(ToDay()); if (d1) { d1 = d1.replace(/\//g, ""); d2 = d2.replace(/\//g, ""); d1 = parseInt(d1); d2 = parseInt(d2); return parseInt((d2 - d1) / 10000); } return 0; } function DateString(date, format) { if (IsDate(date)) { date = new Date(date); if (!format) format = 'yyyy-MM-dd hh:mm:ss.fs'; format = format.replace(/yyyy/g, date.getFullYear()); format = format.replace(/MM/g, ('0' + (date.getMonth() + 1)).slice(-2)); format = format.replace(/dd/g, ('0' + date.getDate()).slice(-2)); format = format.replace(/hh/g, ('0' + date.getHours()).slice(-2)); format = format.replace(/mm/g, ('0' + date.getMinutes()).slice(-2)); format = format.replace(/ss/g, ('0' + date.getSeconds()).slice(-2)); if (format.match(/fs/g)) { var milliSeconds = ('00' + date.getMilliseconds()).slice(-3); var length = format.match(/fs/g).length; for (var i = 0; i < length; i++) format = format.replace(/S/, milliSeconds.substring(i, i + 1)); } return format; } else if ($.isNumeric(date)) { try { if (date.substr(8, 2) + date.substr(10, 2) + date.substr(12, 2)) { date = date.substr(0, 4) + "/" + date.substr(4, 2) + "/" + date.substr(6, 2) + " " + date.substr(8, 2) + ":" + date.substr(10, 2) + ":" + date.substr(12, 2); } else { date = date.substr(0, 4) + "/" + date.substr(4, 2) + "/" + date.substr(6, 2); } return DateString(date, format); } catch (e) { return date; } } else { return date; } } /************ オブジェクト情報 ************/ // Target Focus And Scroll function ControlToFocus(ctl) { if (ctl) { //Focus $(ctl).focus(); //Scroll var t = parseInt(GetTop(ctl)); $(window).scrollTo(0, (t + 30)); if (t > 150) { $(window).scrollTo(0, (t - 150)); } else { $(window).scrollTo(0, 0); } } } // Get Control Position Left function GetLeft(obj) { return $(obj).offset().left; } // Get Control Position Top function GetTop(obj) { return $(obj).offset().top; } // Get Control Heigth function GetHeight(obj) { return $(obj).height(); } // Get Control Width function GetWidth(obj) { return $(obj).width(); } // Set Control Position Left function SetLeft(obj, val) { $(obj).offset({ top: GetTop(obj), left: val }); } // Set Control Position Top function SetTop(obj, val) { $(obj).offset({ top: val, left: GetLeft(obj) }); } // Set Control Heigth function SetHeight(obj, val) { $(obj).height(val); } // Set Control Width function SetWidth(obj, val) { $(obj).width(val); } // Set Position function SetPosition(obj, left, top) { $(obj).offset({ top: top, left: left }); } function NumberCommaSplit(str) { var num = new String(str).replace(/,/g, ""); while (num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2"))); return num; } /************ Loading ************/ function Loading_Start() { $("#lock").show(); } function Loading_Exit() { $("#lock").hide(); } /************ Popup Information ************/ function Pop_Save() { $("#proccess_msg").html(''); $("#proccess_msg").show(); setTimeout(function () { $("#proccess_msg").hide(); }, 3000); } function Pop_Remove() { $("#proccess_msg").html(''); $("#proccess_msg").show(); setTimeout(function () { $("#proccess_msg").hide(); }, 3000); } function Pop_Error(msg) { $("#proccess_msg").html(''); $("#proccess_msg").show(); setTimeout(function () { $("#proccess_msg").hide(); }, 3000); } function Pop_Message(msg) { $("#proccess_msg").html(''); $("#proccess_msg").show(); setTimeout(function () { $("#proccess_msg").hide(); }, 3000); } /************ Browser Support ************/ function Browser() { var ua = {}; ua.name = window.navigator.userAgent.toLowerCase(); ua.isIE = (ua.name.indexOf('msie') >= 0 || ua.name.indexOf('trident') >= 0); ua.isiPhone = ua.name.indexOf('iphone') >= 0; ua.isiPod = ua.name.indexOf('ipod') >= 0; ua.isiPad = ua.name.indexOf('ipad') >= 0; ua.isiOS = (ua.isiPhone || ua.isiPod || ua.isiPad); ua.isAndroid = ua.name.indexOf('android') >= 0; ua.isTablet = (ua.isiPad || (ua.isAndroid && ua.name.indexOf('mobile') < 0)); if (ua.isIE) { ua.verArray = /(msie|rv:?)\s?([0-9]{1,})([\.0-9]{1,})/.exec(ua.name); if (ua.verArray) { ua.ver = parseInt(ua.verArray[2], 10); } } if (ua.isiOS) { ua.verArray = /(os)\s([0-9]{1,})([\_0-9]{1,})/.exec(ua.name); if (ua.verArray) { ua.ver = parseInt(ua.verArray[2], 10); } } if (ua.isAndroid) { ua.verArray = /(android)\s([0-9]{1,})([\.0-9]{1,})/.exec(ua.name); if (ua.verArray) { ua.ver = parseInt(ua.verArray[2], 10); } } return ua; } /************ エレメントからの値操作 ************/ function SetValue(ctl, val) { var ret = ''; try { //JQueryに変換 if (ctl.tagName) ctl = $(ctl); //タグに応じた取得方法 if (ctl) { switch (ctl[0].tagName.toUpperCase()) { case "DIV": case "SPAN": if (ctl.find("input").length > 0) { ctl.find("input").each(function () { switch ($(this).attr("type").toUpperCase()) { case "RADIO": if ($(this).val() == val) { $(this).prop("checked", true); } break; case "CHECKBOX": var vals = val.split(","); $("input[name='" + ctl.attr("name") + "']").each(function () { $(this).prop("checked", false); for (i = 0; i < vals.length; i++) { if ($(this).val() == vals[i]) { $(this).prop("checked", true); } } }); break; default: break; } }); } else { ctl.html(val); } break; case "A": ctl.html(val); break; case "INPUT": switch (ctl.attr("type").toUpperCase()) { case "RADIO": $("input[name='" + ctl.attr("name") + "']").each(function () { if ($(this).val() == val) { $(this).prop("checked", true); } else { $(this).prop("checked", false); } }); break; case "CHECKBOX": var vals = val.split(","); $("input[name='" + ctl.attr("name") + "']").each(function () { $(this).prop("checked", false); for (i = 0; i < vals.length; i++) { if ($(this).val() == vals[i]) { $(this).prop("checked", true); } } }); break; default: ctl.val(val); break; } break; case "TEXTAREA": ctl.val(val); break; case "SELECT": if (ctl.attr("class").indexOf("select2-offscreen") > -1) { ctl.val(val); ctl.select2(); } else { ctl.val(val); } break; } } } catch (e) { alert(e); } return true; } function GetValue(ctl) { var ret = ''; try { //JQueryに変換 if (ctl.tagName) ctl = $(ctl); //タグに応じた取得方法 if (ctl) { switch (ctl[0].tagName.toUpperCase()) { case "DIV": case "SPAN": if (ctl.find("input").length > 0) { ctl.find("input").each(function () { switch ($(this).attr("type").toUpperCase()) { case "RADIO": if ($(this).prop("checked")) { ret = $(this).val(); } break; case "CHECKBOX": if ($(this).prop("checked")) { if (ret) ret += ","; ret += $(this).val(); } break; default: break; } }); } else { ret = ctl.html(); } break; case "A": ret = ctl.html(); break; case "INPUT": switch (ctl.attr("type").toUpperCase()) { case "RADIO": $("input[name='" + ctl.attr("name") + "']").each(function () { if ($(this).prop("checked")) { ret = $(this).val(); } }); break; case "CHECKBOX": $("input[name='" + ctl.attr("name") + "']").each(function () { if ($(this).prop("checked")) { if (ret) ret += ","; ret += $(this).val(); } }); break; case "DATE": if (IsDate(ctl.val())) { ret = DateString(ctl.val(), "yyyyMMdd"); } break; default: ret = ctl.val(); break; } break; case "TEXTAREA": ret = ctl.val(); break; case "SELECT": ret = ctl.val(); break; } } } catch (e) { alert(e); } return ret; } function GetID(ctl) { var ret = ''; try { //JQueryに変換 if (ctl.tagName) ctl = $(ctl); //タグに応じた取得方法 if (ctl) { switch (ctl[0].tagName.toUpperCase()) { case "DIV": case "SPAN": if (ctl.find("input").length > 0) { ctl.find("input").each(function () { switch ($(this).attr("type").toUpperCase()) { case "RADIO": ret = $(this).attr("name"); break; case "CHECKBOX": ret = $(this).attr("name"); break; default: break; } }); } else { ret = (($(this).attr("id")) ? $(this).attr("id") : $(this).attr("name")); } break; case "A": ret = (($(this).attr("id")) ? $(this).attr("id") : $(this).attr("name")); break; case "INPUT": switch (ctl.attr("type").toUpperCase()) { case "RADIO": $("input[name='" + ctl.attr("name") + "']").each(function () { ret = $(this).attr("name"); }); break; case "CHECKBOX": $("input[name='" + ctl.attr("name") + "']").each(function () { ret = $(this).attr("name"); }); break; default: ret = (($(this).attr("id")) ? $(this).attr("id") : $(this).attr("name")); break; } break; case "TEXTAREA": ret = (($(this).attr("id")) ? $(this).attr("id") : $(this).attr("name")); break; case "SELECT": ret = (($(this).attr("id")) ? $(this).attr("id") : $(this).attr("name")); break; } } } catch (e) { alert(e); } return ((ret) ? ret : ""); } /************************ ** common.js [Write file text] ************************/ // use infomation // // html or aspx write example source in header tag [script type="text/javascript"] // // var ajax_top = /ajax // var q; $(function () { q = QueryStrings(); }); function QueryStrings() { var vars = [], hash, qPos; qPos = window.location.href.indexOf('?') + 1; if (qPos > 0) { var hashes = location.href.slice(qPos).split('&'); for (var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); var val = hash[1]; val = decodeURI(val); vars[hash[0]] = val; } } return vars; } function GetFormdata() { var vars = new Object; $("input, select, textarea").each(function () { switch ($(this).attr("type").toUpperCase()) { case "SUBMIT": case "BUTTON": case "IMAGE": break; case "RADIO": if ($(this).prop("checked")) { vars[$(this).attr("name")] = $(this).val(); } break; case "CHECKBOX": if ($(this).prop("checked")) { if (!vars[$(this).attr("name")]) { vars[$(this).attr("name")] = $(this).val(); } else { vars[$(this).attr("name")] += "," + $(this).val(); } } break; default: if ($(this).attr("name")) vars[$(this).attr("name")] = $(this).val(); } }); return vars; } function set_radio(val, radio_name, defIdx) { var flg = false; for (i = 1; i < $("[name='" + radio_name + "']").length + 1; i++) { if ($("#" + radio_name + "_" + String(i)).val() == val) { $("#" + radio_name + "_" + String(i)).prop("checked", true); flg = true; } else { $("#" + radio_name + "_" + String(i)).prop("checked", false); } } if (!flg) { if (defIdx) { $("#" + radio_name + "_" + defIdx).prop("checked", true); } } } function get_radio(radio_name) { for (i = 1; i < $("[name='" + radio_name + "']").length + 1; i++) { if ($("#" + radio_name + "_" + String(i)).prop("checked")) { return $("#" + radio_name + "_" + String(i)).val(); } } return ""; } function ajax_error(XMLHttpRequest, textStatus, errorThrown) { // , error: ajax_error var msg = "【通信エラー】\n"; msg += "この画面をキャプチャーしてご連絡ください。\n"; msg += "XMLHttpRequest : " + XMLHttpRequest.status + "\n"; msg += "textStatus : " + textStatus + "\n"; msg += "errorThrown : " + errorThrown.message + "\n"; //alert(msg); } function ajax_complete(XMLHttpRequest, textStatus) { // , complete: ajax_complete var msg = "【Complete】\n"; msg += "XMLHttpRequest : " + XMLHttpRequest.status + "\n"; msg += "textStatus : " + textStatus + "\n"; alert(msg); } /** ajax call (base) **/ function ajax_proc(ashx, parms, async, success, error) { if (async) async = true; else async = false; if (ashx) { $.ajax({ url: ashx , type: 'POST' , cache: false , dataType: 'json' , processData: false , contentType: false , async: async , data: parms , success: function (res) { if (res["result"] == "success") { if (success) success(res); } else alert(res["msg"]); } , error: function (XMLHttpRequest, textStatus, errorThrown) { if (error) { error(XMLHttpRequest, textStatus, errorThrown); } else { ajax_error(XMLHttpRequest, textStatus, errorThrown); } } }); } else { alert("引数[ashx]を指定してください。"); } } /** ajax util **/ function get_youtube(youtubeId, success, error) { $.ajax({ url: ajax_top + '/youtube.ashx' , type: 'POST' , cache: false , async: false , dataType: 'json' , data: { uid: youtubeId } , success: function (res) { if (res["result"] == "success") { success(res); } else alert(res["msg"]); } , error: function (XMLHttpRequest, textStatus, errorThrown) { if (error) { error(XMLHttpRequest, textStatus, errorThrown); } else { ajax_error(XMLHttpRequest, textStatus, errorThrown); } } }); } function ajax_set_address(obj1, obj2, success, error) { if ((obj1) && (obj2)) { obj1.keyup(function () { ajax_get_address(obj1.val() + obj2.val(), success, error); }); obj2.keyup(function () { ajax_get_address(obj1.val() + obj2.val(), success, error); }); } else if (obj1) { obj1.keyup(function () { ajax_get_address(obj1.val(), success, error); }); } else if (obj2) { obj2.keyup(function () { ajax_get_address(obj2.val(), success, error); }); } } function ajax_get_address(val, success, error) { if (val.length == 7) { $.ajax({ url: "https://ajax.deprog.jp/post_get.ashx" , type: 'POST' , cache: false , dataType: 'json' , data: { postno: val } , success: function (res) { if (res["result"] == "success") { if (success) success(res); } else alert(res["msg"]); } , error: function (XMLHttpRequest, textStatus, errorThrown) { if (error) { error(XMLHttpRequest, textStatus, errorThrown); } else { ajax_error(XMLHttpRequest, textStatus, errorThrown); } } }); } } function ajax_requestinfo(async, success, error) { if (async) async = true; else async = false; $.ajax({ url: ajax_top + '/requestinfo.ashx' , type: 'POST' , cache: false , async: async , dataType: 'json' , success: function (res) { if (res["result"] == "success") { if (success) success(res); } else alert(res["msg"]); } , error: function (XMLHttpRequest, textStatus, errorThrown) { if (error) { error(XMLHttpRequest, textStatus, errorThrown); } else { ajax_error(XMLHttpRequest, textStatus, errorThrown); } } }); } function ajax_decrypt(val, success, error) { $.ajax({ url: ajax_top + '/sec_decrypt.ashx' , type: 'POST' , cache: false , async: false , dataType: 'json' , data: { val: val } , success: function (res) { if (res["result"] == "success") { success(res); } else alert(res["msg"]); } , error: function (XMLHttpRequest, textStatus, errorThrown) { if (error) { error(XMLHttpRequest, textStatus, errorThrown); } else { ajax_error(XMLHttpRequest, textStatus, errorThrown); } } }); } function ajax_encrypt(val, success, error) { $.ajax({ url: ajax_top + '/sec_encrypt.ashx' , type: 'POST' , cache: false , async: false , dataType: 'json' , data: { val: val } , success: function (res) { if (res["result"] == "success") { success(res); } else alert(res["msg"]); } , error: function (XMLHttpRequest, textStatus, errorThrown) { if (error) { error(XMLHttpRequest, textStatus, errorThrown); } else { ajax_error(XMLHttpRequest, textStatus, errorThrown); } } }); } function ajax_mail(mt, ms, mb, success, error) { $.ajax({ url: ajax_top + '/mail.ashx' , type: 'POST' , cache: false , async: false , dataType: 'json' , data: { to: mt , subject: ms , body: mb } , success: function (res) { if (res["result"] == "success") { success(res); } else alert(res["msg"]); } , error: function (XMLHttpRequest, textStatus, errorThrown) { if (error) { error(XMLHttpRequest, textStatus, errorThrown); } else { ajax_error(XMLHttpRequest, textStatus, errorThrown); } } }); } function ajax_ekidata(prefObj, lineObj, stationObj, stationObj2) { //initialize if (prefObj) { if (prefObj.children().length == 0) { $.ajax({ url: ajax_top + '/ekidata.ashx' , type: 'POST' , cache: false , dataType: 'json' , async: true , success: function (res) { if (res["result"] == "success") { prefObj.children().remove(); prefObj.append($("