/** * javascript拡張 */ String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,""); }; /** * HTMLエンコード */ String.prototype.htmlEncode = function() { return $('

').text(this).html(); }; /** * HTMLデコード */ String.prototype.htmlDecode = function() { return $('

').html(this).text(); }; /** * エラー用画像切替 */ function setErrorImg(target, type) { var img_file_url; if(type == '') { img_file_url = 'no_img.gif'; } else { img_file_url = 'no_' + type + '.gif'; } $(target).attr('src', URL_HOME + 'img/' + img_file_url); $(target).removeAttr('onerror'); } /** * オブジェクト存在判定 */ function isVoid(obj) { return (obj == null || typeof obj == 'undefined' || obj == ''); } /** * 広告非表示 */ function closeAd() { $('#ad4').slideUp('fast', function() { $(this).remove(); }); } $(function() { /** * 初期化 */ function init() { // class が replaceLocalDatetime の全てをブラウザーのローカル時間に変更する $('.replaceLocalDatetime').each(function(idx, elm) { var value = $(elm).attr('data-date'); var format = $(elm).attr('data-date-format'); $(elm).text(replaceLocalDatetime(value, format ? format : undefined)); }); } init(); }); /** * 日付のローカライズ */ function replaceLocalDatetime(dateString, format) { if(format === undefined) format = '%Y-%m-%d %H:%i:%s'; //var value = new Date(dateString + ' GMT+0900'); let value = new Date(dateString); if (isNaN(value)) { value = new Date(dateString.replace(/-/g, '/') + 'GMT+0900'); } value.setHours(value.getHours() - 9 - value.getTimezoneOffset() / 60); format = format.replace(/%Y/g, value.getFullYear()); format = format.replace(/%m/g, ('0' + (value.getMonth() + 1)).slice(-2)); format = format.replace(/%d/g, ('0' + value.getDate()).slice(-2)); format = format.replace(/%H/g, ('0' + value.getHours()).slice(-2)); format = format.replace(/%i/g, ('0' + value.getMinutes()).slice(-2)); format = format.replace(/%s/g, ('0' + value.getSeconds()).slice(-2)); return format; } /** * iframe広告の高さ調整 */ (function(window, $){ $(window).on("load",function(){ $('iframe.autoHeight').each(function(){ try { var D = $(this).get(0).contentWindow.document; var innerHeight = Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); $(this).removeAttr("height").css('height', innerHeight + 'px'); } catch(e) { } }); }); })(window, jQuery);