(function($) { /** * @author nagai * @version 1.0 */ /** * 外部リンクは別窓表示 * @param object */ $.fn.linkBlank = function(_cfg) { var target = this; target.each(function() { var href = $(this).attr("href"); var regs = []; for(var i=0; i < _cfg.url.length; i++) { regs.push( new RegExp(_cfg.url[i], 'i') ); } //_blank var myDomain = false; for(var i=0; i < regs.length; i++) { if( href.match(regs[i]) ) { myDomain = true; break; } } if(myDomain) { $(this).attr("target", "_self"); } else { $(this).attr("target", "_blank"); } }); }; /** * ファイルリンクは別窓表示 */ //$.fn.fileBlank = function() { // var target = this; // // target.each(function() { // $(this).attr("target", "_blank"); // }); //}; $.fn.fileBlank = function(ext_) { var target = this; this.addClass(ext_); this.attr("target", "_blank"); }; /** * class名で別窓表示(外部リンク付) */ $.fn.jsBlankAddText = function() { var target = this; target.each(function() { $(this).prepend('(外部リンク)'); //$(this).append(' 外部サイトへ'); $(this).click(function(){ window.open(this.href,'_blank'); return false; }); }); }; /** * class名で別窓表示 */ $.fn.jsBlank = function() { var target = this; target.each(function() { $(this).click(function(){ window.open(this.href,'_blank'); return false; }); }); }; /** * スムーズスクロール * $('a[href*=#].jsSmooth').smoothScroll(); */ $.fn.smoothScroll = function() { var target = this; target.each(function(){ var href = $(this).attr("href"); if(href=='#') { $(this).click(function() { return false; }); return true; } var hrefAry = href.match(/^([^#]*)#([^#]+)$/,function(whole,$1){ return $1 }); if(hrefAry) { var j = $( "#" + hrefAry[2] ); if(j.size() > 0) { jQuery.data($(this).get(0), "pos", j); $(this).click(function() { $('html,body').animate({scrollTop: jQuery.data($(this).get(0), "pos").offset().top}, 400, "linear", function(){ location.hash = hrefAry[2]; }); return false; }); } } }); }; /** * 現在のカテゴリを_onにする(特別コンテンツ) * $("#headerNav li a").categoryOn('^(/[^/]+/[^/]+/).*$'); * * @param string 判定するパス範囲(正規表現) */ $.fn.categoryOn = function(path) { var target = this; var regPath = new RegExp(path, "i"); var req = location.pathname; req = req.replace(regPath, '$1'); target.each(function(idx){ var href = $(this).attr("href"); // ドメイン付きリンクでも反転できるようにする if(href.indexOf(req) > -1) { var imgJ = $(this).find('img'); imgJ.unbind('mouseenter').unbind('mouseleave'); imgJ.attr('src', imgJ.attr('src').replace(/_off(\.gif|\.jpg|\.png)/,"_on"+'$1') ); return false; } }); }; /** * ._offの画像をロールオーバー * @param object 設定 */ $.fn.rollOver = function(_cfg) { var target = this; target.each(function(){ $(this).hover(function () { $(this).attr("src", $(this).attr("src").replace(_cfg.off, _cfg.on)); },function () { $(this).attr("src", $(this).attr("src").replace(_cfg.on, _cfg.off)); }); }); }; /** * 透過ロールオーバー */ $.fn.rollOverAlpha = function() { var target = this; target.hover(function(){ $(this).fadeTo(100, 0.7); // マウスオーバーで透明度を60%にする },function(){ $(this).fadeTo(100, 1.0); // マウスアウトで透明度を100%に戻す }); }; /** * フラッシュロールオーバー */ $.fn.rollOverFlash = function() { var target = this; // 注意:rollOverFlashのように識別子をつけること(http://js.studio-kingdom.com/jquery/events/off) target.off('mouseenter.rollOverFlash'); target.on({ 'mouseenter.rollOverFlash':function(){ $(this).stop(true).css({ 'opacity': '0.7' }).animate({ 'opacity': '1' }, 500); } }); }; /** * 文字サイズ変更(標準 or 大きくする)背景色変更 * $.fn.styleCatcherUpNormal({btnCls: "scSize",cssID: "scSize",prAry: ['size_default.css', 'size_up.css', 'size_up2.css', 'size_up3.css'],cssPath: '/material/template/css/',def: 0}); * * @param object 設定 */ $.fn.styleCatcherUpNormal = function(config) { config = $.extend({ btnCls: "scSize", cssID: "scSize", prAry: ['0.css', '1.css', '2.css', '3.css'], cssPath: '/material/template/css/', def: 0 },config); var cssTag = $(''); cssTag.attr('id', config.cssID); $("body").append(cssTag); //parameter number var prNum; if($.cookie(config.cssID)) { prNum = Number($.cookie(config.cssID)); } else { prNum = Number(config.def); } //_idはon画像、後はoffのロールオーバー function offRollAndOn(cl_) { $('.' + config.btnCls).each(function(idx){ var j = $(this); var cl = j.attr("class"); var img = j.find("img"); img.unbind(); if(cl.indexOf(cl_) != -1) { img.attr("src", img.attr("src").replace("_off.", "_on.")); $(this).css("cursor", "auto"); } else { img.attr("src", img.attr("src").replace("_on.", "_off.")); $(this).css("cursor", "pointer").css("cursor", "hand"); /* img.hover(function () { $(this).attr("src", $(this).attr("src").replace("_off.", "_on.")); },function () { $(this).attr("src", $(this).attr("src").replace("_on.", "_off.")); }); */ } }); } $('.' + config.btnCls).css("cursor", "pointer").css("cursor", "hand"); $('.' + config.btnCls).click(function(){ var j = $(this); var img = j.find("img"); var cl = j.attr("class"); if(cl.indexOf("up") != -1) { prNum++; if(config.prAry.length-1 <= prNum) { prNum = config.prAry.length-1; offRollAndOn("up"); } else { offRollAndOn("dummy");//どちらも押せる状態の画像にする } } else if(cl.indexOf("normal") != -1) { prNum = 0; offRollAndOn("normal"); } $('#' + config.cssID).attr("href", config.cssPath + config.prAry[prNum]); //prNumを保存 $.cookie(config.cssID, prNum, {path:'/'}); return false; }); if(config.prAry.length-1 <= prNum) { prNum = config.prAry.length-1; offRollAndOn("up"); } else if(0 >= prNum) { prNum = 0; offRollAndOn("normal"); } else { offRollAndOn("dummy");//unbindを防ぐため } $('#' + config.cssID).attr("href", config.cssPath + config.prAry[prNum]); }; /** * 文字サイズ(小、中、大)背景色変更 * $.fn.styleCatcher({btnCls: "scColor",cssID: "scColor", cssPath:'/material/template/css/',def: 2}); * * @param object 設定 */ $.fn.styleCatcher = function(config) { config = $.extend({ btnCls: "scSize", cssID: "scSize", cssPath:'/material/template/css/', def: 0 },config); var cssTag = $(''); cssTag.attr('id', config.cssID); $("body").append(cssTag); function offRollAndOn(_id) { $('.' + config.btnCls).each(function(idx){ var j2 = $(this); var id2 = j2.attr("id"); var img2 = j2.find("img"); img2.unbind(); if(_id == id2) { img2.attr("src", img2.attr("src").replace("_off.", "_on.")); } else { img2.attr("src", img2.attr("src").replace("_on.", "_off.")); img2.hover(function () { $(this).attr("src", $(this).attr("src").replace("_off.", "_on.")); },function () { $(this).attr("src", $(this).attr("src").replace("_on.", "_off.")); }); } }); } $('.' + config.btnCls).attr("href", "#"); $('.' + config.btnCls).click(function(){ var j = $(this); var img = j.find("img"); var id = j.attr("id"); offRollAndOn(id); $('#' + config.cssID).attr("href", config.cssPath + id + '.css'); $.cookie(config.cssID, id, {path:'/'}); return false; }); var fileName; if($.cookie(config.cssID)) { fileName = $.cookie(config.cssID); } else { fileName = $($('.' + config.btnCls).get(config.def)).attr("id"); } offRollAndOn(fileName); $('#' + config.cssID).attr("href", config.cssPath + fileName + '.css'); }; /** * 段組の個々に高さを設定する * ※文字の高さなどが変わるためフォントを変更してから実行すること * $(".level1Row2Mod").eqGroupHeight(2); * * @param integer 段組数 */ $.fn.eqGroupHeight = function(turn_) { var target = this; target.each(function(){ //揃えたい分確保した後、高さ揃える…ループ var ary = new Array(); //一旦、高さをリセット $(this).find("> *").css('height', 'auto'); $(this).find("> *").each(function(idx2_){ ary.push($(this)); if(ary.length >= turn_) { var max = 0; for (var i=0; i < ary.length; i++){ max = Math.max(ary[i].height(), max); } for (var j=0; j < ary.length; j++){ ary[j].height(max); } ary[0].addClass("firstElement_ml0");//最初の要素にだけClassを振る ary = new Array(); } }); //未だ配列に残っている分を高さ揃える if(ary.length > 0) { var max = 0; for (var i=0; i < ary.length; i++){ max = Math.max(ary[i].height(), max); } for (var j=0; j < ary.length; j++){ ary[j].height(max); } ary[0].addClass("firstElement_ml0");//最初の要素にだけClassを振る } }); }; /** * 文字サイズ変更監視 * $.fn.fontSizeChange({func:function(){ * $(".level1Row2Mod").eqGroupHeight(2); * $(".level2Row1Mod .list").eqGroupHeight(2); * $("#wrapper").show(); * }}); * * @param object 設定 */ $.fn.fontSizeChange = function(cfg_) { function setFontSizeListener(func_) { var s = $("") .text(" ") .hide() .appendTo("body"); s.data("size", s.css("font-size")); s.data("timer", setInterval(function(){ if(s.css("font-size") != s.data("size")) { s.data("size", s.css("font-size")); func_(); } }, 1000)); }; cfg_.func(); setFontSizeListener(cfg_.func); }; /** * 横並び画像※ie6 zoom:0.97で画像が落ちる現象を解消、下のキャプションが折り返すため */ $.fn.colImgSetWidth = function() { var target = this; target.each(function(){ var L = $(this).find(".L"); var R = $(this).find(".R"); var LImg = L.find("img"); var RImg = R.find("img"); L.width(LImg.width()); R.width(RImg.width()); }); }; /** * 画像タブ * ※classHideは設定してください、tabsとpagesは一つだけ存在するmodを指定してください(id指定が最適) * $.fn.imgLinkTab({defaultSelect:0,cookie:'topTab',tabs:$("#topTab .list img"),pages:$("#topTab .box")}); * * @param object 設定 */ $.fn.imgTab = function(config) { var targetJ = this; config = $.extend({ tabs: null, pages: null, defaultSelect:0, cookie: 'tab', off:'_off.', on:'_on.', classHide:'hide' },config); if(config.tabs == null || config.pages == null) { return; } var ClassTab = function() { } ClassTab.prototype = { rollOver : function(select) { var replaceOn = function(j) { j.attr("src", j.attr("src").replace(config.off, config.on)); }; var replaceOff = function(j) { j.attr("src", j.attr("src").replace(config.on, config.off)); }; config.tabs.unbind("mouseenter").unbind("mouseleave");//img.unbind('hover');ではできない config.tabs.each(function(idx){ var tabJ = $(this); replaceOff(tabJ); if(select == idx) { replaceOn(tabJ); } else { tabJ.hover(function () { replaceOn(tabJ); },function () { replaceOff(tabJ); }); } }); }, showpage : function(select) { config.pages.each(function(idx){ if(idx == select) { $(this).removeClass(config.classHide); } else{ $(this).addClass(config.classHide); } }); }, init : function() { var cls = this; config.pages.each(function(idx){ if(idx == config.defaultSelect) { $(this).removeClass(config.classHide); } else{ $(this).addClass(config.classHide); } }); config.tabs.click(function(){ var idx = config.tabs.index(this); cls.showpage(idx); //選択されたタブの番号をクッキーに保存 $.cookie(config.cookie, idx, { path:'/',expires: 30 }); cls.rollOver(idx); return false; }); cls.rollOver(config.defaultSelect); } }; // 前回選択タブ復元 if($.cookie(config.cookie)) { config.defaultSelect = $.cookie(config.cookie); } // タブ作成 var tab = new ClassTab(); tab.init(); }; /** * テキストタブ * ※classHideは設定してください、tabsとpagesは一つだけ存在するmodを指定してください(id指定が最適) * $.fn.textTab({defaultSelect:0,cookie:'topTab',tabs:$("#topTab .titleList li"),pages:$("#topTab .box")}); * * @param object 設定 */ $.fn.textTab = function(config) { var targetJ = this; config = $.extend({ tabs: null, pages: null, defaultSelect:0, cookie: 'tab', classHover:'hover', classHide:'hide' },config); if(config.tabs == null || config.pages == null) { return; } var ClassTab = function() { } ClassTab.prototype = { rollOver : function(select) { config.tabs.unbind("mouseenter").unbind("mouseleave");//img.unbind('hover');ではできない config.tabs.removeClass(config.classHover); config.tabs.each(function(idx){ var tabJ = $(this); if(select == idx) { tabJ.addClass(config.classHover); } else { tabJ.hover(function () { tabJ.addClass(config.classHover); },function () { tabJ.removeClass(config.classHover); }); } }); }, showpage : function(select) { config.pages.each(function(idx){ if(idx == select) { $(this).removeClass(config.classHide); } else{ $(this).addClass(config.classHide); } }); }, init : function() { var cls = this; config.pages.each(function(idx){ if(idx == config.defaultSelect) { $(this).removeClass(config.classHide); } else{ $(this).addClass(config.classHide); } }); config.tabs.click(function(){ var idx = config.tabs.index(this); cls.showpage(idx); //選択されたタブの番号をクッキーに保存 $.cookie(config.cookie, idx, { path:'/' }); cls.rollOver(idx); return false; }); cls.rollOver(config.defaultSelect); } }; // 前回選択タブ復元 if($.cookie(config.cookie)) { config.defaultSelect = $.cookie(config.cookie); } // タブ作成 var tab = new ClassTab(); tab.init(); }; /** * シーズンの画像差し替え * // 1 2 3 4 5 6 7 8 9 10 11 12 * var seasons = [3, 3, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3]; * $('#headerGraphic').seasonClass({ * seasons:seasons * }); * ex.otsu * * @param object 設定 */ $.fn.seasonClass = function(config) { config = $.extend({ // 1 2 3 4 5 6 7 8 9 10 11 12 seasons: [3, 3, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3] ,imgs: ['jsSeason-Spring', 'jsSeason-Summer', 'jsSeason-Sutumn', 'jsSeason-Sinter'] },config); // 季節の画像取得 var month = (new Date()).getMonth(); var seasonNum = config.seasons[month]; var newImg = config.imgs[seasonNum]; var targetsJ = this; targetsJ.each(function() { var targetJ = $(this); targetJ.addClass(newImg); }); }; /** * アコーディオン * $('.accordionMod > li').accordion({ * classHead:'.title', * classBody:'.childs', * classToggle:'on' * }); * ex.fujii sp * * @param object 設定 */ $.fn.accordion = function(config) { var targetsJ = this; config = $.extend({ classHead: '.head', classBody: '.body', classToggle: 'minus' },config); var applyAccordion = function(targetJ) { var headJ = targetJ.find(config.classHead); var bodyJ = targetJ.find(config.classBody); // 元々開いているかチェック if(!headJ.hasClass(config.classToggle)) { bodyJ.hide(); } headJ.click(function() { if(bodyJ.is(':animated')) { return false; } bodyJ.slideToggle("normal",function(){ if(bodyJ.is(':visible')) { headJ.addClass(config.classToggle); } else { headJ.removeClass(config.classToggle); } }); return false; }); } targetsJ.each(function(){ applyAccordion($(this)); }); }; /** * スマホ向けライトボックス * * @param object 設定 */ $.fn.lightbox = function(config) { var targetJ = this; config = $.extend({ modalBg:null, modal:null, close:null, scrollID:'sWrapper', lightSpot:null },config); if(config.modalBg == null || config.modal == null) { return; } // 簡易スクロール var anchorScroll = function(id){ var j = $( "#" + id); if(j.size() == 0) { return; } $('html,body').animate({scrollTop: j.offset().top}, 200, "linear"); } var applyModal = function(targetJ) { var showModal = function() { var docH = $(document).height(); config.modalBg.height(docH); config.modalBg.fadeIn(200); config.modal.fadeIn(200); config.lightSpot.css({'z-index': '99'}); }; var hideModal = function() { config.modalBg.hide(); config.modal.hide(); anchorScroll(config.scrollID); config.lightSpot.css({'z-index': 'auto'}); }; targetJ.click(function() { showModal(); return false; }); config.close.click(function() { hideModal(); return false; }); config.modalBg.click(function() { hideModal(); return false; }); } applyModal(targetJ); }; /** * バナークリック数カウント * $('.banners_list a').bannerClick({ * title:'トップページ 広告クリック数' * }); * * @param object 設定 */ $.fn.bannerClick = function(config_) { var targetJ = this; config_ = $.extend({ title:'トップページ 広告クリック数' },config_); targetJ.click(function(){ //_gaq.push(['_trackEvent', config_.title, $(this).find("img").attr('alt'), $(this).attr('href')]);// old(旧) ga('send', 'event', config_.title, 'click', $(this).find("img").attr('alt') + ':' + $(this).attr('href'));// new(ユニバーサル) }); }; /** * Google Map表示 * $('.jsMap').replaceGoogleMap({ * zoom: 16, * markerClass: '.jsMap_marker' * }); * * ■html *
*
*
* * @param object 設定 */ $.fn.replaceGoogleMap = function(config_) { var targetsJ = this; config_ = $.extend({ zoom: 16, markerClass: null },config_); if(config_.markerClass == null) { return; } /* * マーカー追加 * * @param $marker (jQuery element) * @param map (Google Map object) */ var add_marker = function ( $marker, map ) { var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') ); var marker = new google.maps.Marker({ position : latlng, map : map }); map.markers.push( marker ); if( $marker.html() ) { var infowindow = new google.maps.InfoWindow({ content : $marker.html() }); // google.maps.event.addListener(marker, 'click', function() { infowindow.open( map, marker ); // }); } }; /* * ピンを中心にGoogle Mapを表示 * * @param map (Google Map object) */ var center_map = function ( map ) { var bounds = new google.maps.LatLngBounds(); $.each( map.markers, function( i, marker ){ var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() ); bounds.extend( latlng ); }); if( map.markers.length == 1 ) { map.setCenter( bounds.getCenter() ); map.setZoom( config_.zoom ); } else { map.fitBounds( bounds ); } }; /* * Google Map表示 * * @param $el (jQuery element) */ var new_map = function ( $el ) { var $markers = $el.find(config_.markerClass); var args = { zoom : 16, center : new google.maps.LatLng(0, 0), mapTypeId : google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map( $el[0], args); map.markers = []; $markers.each(function(){ add_marker( $(this), map ); }); center_map( map ); return map; } targetsJ.each(function() { new_map( $(this) ); }); }; // スマホ固定メニュー $.fn.fixedHeader = function(config_) { var targetJ = this; // リサイズのたびに実行させないため var timer = false; config_ = $.extend({ header:null ,contents:null },config_); if(config_.header == null || config_.contents == null) { return; } var addPadding = function() { config_.contents.css({ 'padding-top': (config_.header.outerHeight(false)) + 'px' }); }; addPadding(); $(window).resize(function() { if (timer !== false) { clearTimeout(timer); } timer = setTimeout(function() { addPadding(); }, 200); }); }; // スマホの左ドロワーメニュー $.fn.drawerMenu = function(config_) { var targetJ = this; // リサイズのたびに実行させないため var timer = false; var timer2 = false; config_ = $.extend({ sideMenu:null ,sideMenuScroll:null ,header:null ,openBtn:null ,contents:null },config_); if(config_.sideMenu == null || config_.sideMenuScroll == null || config_.header == null || config_.openBtn == null || config_.contents == null) { return; } var openFlg = false; var sideMenuOpen = function() { config_.sideMenu.show(); config_.sideMenu.animate({ 'width': '88%' }, 200, function() { // アニメーション完了後にレスポンシブのサイドメニューの高さが決定するためここで実行 fixPosSideMenu(); }); config_.contents.animate({ 'left': '88%' }, 200); config_.header.animate({ 'left': '88%' }, 200); config_.contents.on('click', function() { sideMenuClose(); return false; }); openFlg = true; }; var sideMenuClose = function() { config_.sideMenu.animate({ 'width': '0%' }, 200, function() { $(this).hide(); }); config_.contents.animate({ 'left': '0%' }, 200); config_.header.animate({ 'left': '0%' }, 200); config_.contents.off('click'); openFlg = false; }; config_.openBtn.click(function(){ if(openFlg) { sideMenuClose(); } else { sideMenuOpen(); } return false; }); var fixPosSideMenu = function() { config_.sideMenu.css({ 'height': 'auto' }); config_.sideMenuScroll.css({ 'top': $(window).scrollTop() + 'px' }); var sideMenuH = config_.sideMenuScroll.outerHeight(false) + config_.sideMenuScroll.position().top; var contentsH = config_.contents.outerHeight(false); var fixH = sideMenuH > contentsH ? sideMenuH : contentsH; config_.sideMenu.css({ 'height': fixH + 'px' }); }; var fixPosSideMenuByScroll = function() { var winScroll = $(window).scrollTop(); var menuScroll = config_.sideMenuScroll.position().top; var fixPos = winScroll; if(menuScroll > winScroll) { config_.sideMenuScroll.animate({ 'top': winScroll + 'px' },200); } }; $(window).scroll(function() { if (timer !== false) { clearTimeout(timer); } timer = setTimeout(function() { // メニューより上にスクロールが来たら上にメニューを移動 fixPosSideMenuByScroll(); }, 200); }); var isIphoneSafari = function() { var appVersion = window.navigator.appVersion.toLowerCase(); if (appVersion.indexOf('iphone') > -1 && appVersion.indexOf('safari') > -1) { return true; } return false; }; // メニューが開いた状態でPC版を開くと表示が崩れるため閉じる $(window).resize(function() { if(isIphoneSafari()) { return; } if (timer2 !== false) { clearTimeout(timer2); } timer2 = setTimeout(function() { if(openFlg) { sideMenuClose(); } }, 200); }); }; // はみ出した画像をセンター寄せにする $.fn.overSizeImgCenter = function() { var targetsJ = this; // リサイズのたびに実行させないため var timer = false; var imgCenter = function() { targetsJ.each(function() { var targetJ = $(this); var parentJ = targetJ.parent(); var parentW = parentJ.width(); var targetW = targetJ.width(); targetJ.css({ 'margin-left': '-' + ((targetW - parentW) / 2) + 'px' }); }); }; imgCenter(); var timerFunc = function() { if (timer !== false) { clearTimeout(timer); } timer = setTimeout(function() { imgCenter(); }, 200); }; // 注意:overSizeImgCenterのように識別子をつけること(http://js.studio-kingdom.com/jquery/events/off) $(window).off('resize.overSizeImgCenter'); $(window).on('resize.overSizeImgCenter', timerFunc); }; // ドロップメニュー $.fn.dropMenu = function(config_) { var targetsJ = this; config_ = $.extend({ dropMenu:'' },config_); if(config_.dropMenu == '') { return; } var dropMenu = function() { targetsJ.each(function() { var targetJ = $(this); targetJ.find('> a').on('click', function() { return false; }); var dropMenuJ = targetJ.find(config_.dropMenu); targetJ.hover(function(){ dropMenuJ.slideDown(200); },function(){ dropMenuJ.slideUp(200); }); }); }; dropMenu(); }; $.fn.ie8Check = function() { var targetJ = this; var appVersion = window.navigator.appVersion.toLowerCase(); if (appVersion.indexOf('msie 8.0') > -1) { targetJ.addClass('ie8JS') } }; // clear:bothで折り返される要素の高さを揃える // $('.list').arrangeHeight(); $.fn.arrangeHeight = function(config_) { var targetsJ = this; var arrangeHeight = function(j) { // グループを作る var parents = []; var children = j.children(); // 要素が非表示で、高さが0になってしまう際は処理を行わない var hideCheck = true; children.each(function(index_) { if(!$(this).is(':visible')) { hideCheck = false; return false; } }); if(!hideCheck) { return; } children.css('height', 'auto'); children.each(function(index_) { var childJ = $(this); if(childJ.css('clear') == 'both' || index_=== 0) { parents.push([]); } var index = parents.length-1; parents[index].push(childJ); }); // 高さを揃える $.each(parents, function() { var parent = this; var max = 0; $.each(parent, function() { max = Math.max(this.height(), max); }); $.each(parent, function() { this.height(max); }); }); }; // すべて実行 var applyAll = function() { targetsJ.each(function() { arrangeHeight($(this)); }); }; applyAll(); // サイズ変更時に実行 $(window).resize(applyAll); }; /** * レスポンシブタブレット対応 * $.fn.tabletApply({width: "1000"}); * * @param object 設定 */ $.fn.tabletApply = function(config) { config = $.extend({ width: "1000" },config); if ((navigator.userAgent.indexOf('iPhone') > -1 || navigator.userAgent.indexOf('iPod') > -1 || (navigator.userAgent.indexOf('Android') > -1 && navigator.userAgent.indexOf('Mobile') > -1)) === false) { document.write(''); } else { document.write(''); } }; /** * 隠れるページトップ * $.fn.hidePagetop({ * pagetopSelector: '#pagetop', * footerSelector: '#footer' * }); * * @param object 設定 */ $.fn.hidePagetop = function(config) { config = $.extend({ pagetopSelector: '#pagetop', footerSelector: '#footer' },config); var pagetopJ = $(config.pagetopSelector); if(pagetopJ.size() == 0) { return; } pagetopJ.hide(); $(window).on('load',function() { pagetopJ.show(); var footerJ = $(config.footerSelector); var pagetopH = pagetopJ.height(); pagetopJ.css({ 'position':'fixed' ,'bottom':'0px' ,'right':'10px' }); var isIphoneSafari = function() { var appVersion = window.navigator.appVersion.toLowerCase(); if (appVersion.indexOf('iphone') > -1 && appVersion.indexOf('safari') > -1) { return true; } return false; }; // 処理重複を防ぐ var mode = -1; var apllyPagetop = function() { var scrollY = $(window).scrollTop(); var winH = $(window).height(); // iphone safari対策(http://yami-beta.hateblo.jp/entry/2014/11/13/223859) if(isIphoneSafari()) { winH = window.innerHeight; } var viewY = winH+scrollY; var footerY = footerJ.offset().top; if(scrollY == 0) { if(mode == 0) { return; } pagetopJ.stop(true).animate({ 'bottom':'-' + pagetopH + 'px' }, 200); mode == 0; } else if(scrollY > 0 && viewY < footerY) { if(mode == 1) { return; } pagetopJ.stop(true).animate({ 'bottom':'0px' }, 200); mode == 1; } else if(viewY >= footerY) { var sa = viewY - footerY; pagetopJ.stop(true).css({ 'bottom':sa+'px' }); } }; apllyPagetop(); $(window).scroll(function() { apllyPagetop(); }); $(window).resize(function() { apllyPagetop(); }); pagetopJ.on('click', function() { $('html,body').animate({ scrollTop: 0 }); return false; }); }); }; /** * リンクタグをsubmitボタンにする * $('.jsSubmit').submitWithAnchor(); * */ $.fn.submitWithAnchor = function() { var $target = this; var $form = $target.closest('form'); if($form.size() == 0) { return; } $target.on('click', function() { $form.submit(); return false; }); }; })(jQuery);