(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 *