$(function(){ var winScroll; var winHeight; $(window).scroll(function(){ winScroll = $(this).scrollTop(); winHeight = $(window).height(); showPageTop(); showSpCvArea(); if($('.js-follow_anchor').length){ sideAncLinksScrollActive(); } }); //SP Click Navigation var spNavigationBtn = function(){ var scrollposition; $(document).on('click', '.sp_navigation_btn', (function(){ if(!$('.wrapper').hasClass('navi_open')){ scrollposition = $(window).scrollTop(); $('.wrapper').addClass('navi_open'); $('.wrapper').css('top', (scrollposition * -1) + 'px'); }else{ $('.wrapper').removeClass('navi_open'); $('.wrapper').css('top', 'auto'); $('html, body').prop({ scrollTop: scrollposition }); } })); }; //Show Page Top var showPageTop = function(){ var $pageTop = $('.pagetop'); if(!$pageTop.length) return; var defaultPosition = $('.page_top_wrap').offset().top; if(winScroll > 50){ $pageTop.fadeIn(); }else{ $pageTop.fadeOut(); } if((winScroll + winHeight) > defaultPosition){ $pageTop.addClass('defoult'); }else{ $pageTop.removeClass('defoult'); } }; //Side Anc Links Scroll Active var sideAncLinksScrollActive = function(){ var $ancListSide = $('.anc_list_side'); if(!$ancListSide.length) return; var ancListSideHeight = $ancListSide.height(); var defaultPosition = $('.js-follow_anchor').offset().top; var fixedPosition = 30; var bottomMargin = 30; var deqwasPosition = $('.deqwas_contents').offset().top; var fixedEndPosition; var thisIndex = -1; if((winScroll + fixedPosition) > defaultPosition){ $ancListSide.addClass('fixed'); if((winScroll + ancListSideHeight + fixedPosition + bottomMargin) >= deqwasPosition){ fixedEndPosition = deqwasPosition - (winScroll + ancListSideHeight + fixedPosition); $ancListSide.css('top', fixedEndPosition + 'px'); }else{ $ancListSide.css('top', bottomMargin + 'px'); } }else if((winScroll + fixedPosition) <= defaultPosition){ $ancListSide.removeClass('fixed'); $ancListSide.css('top', '0px'); } $.each($('.js-anchor_title'), function(i){ if(($(this).offset().top - 10) <= winScroll){ thisIndex = i; } }); if(thisIndex >= 0 && $ancListSide.find('.anc_list dd.ac').index() != thisIndex){ $ancListSide.find('.anc_list dd').removeClass('ac'); $ancListSide.find('.anc_list dd').eq(thisIndex).addClass('ac'); } }; //Index Sort Tag var indexSortTag = function(){ if($('.topics_list').length){ var locationSearch = window.location.search.split('?')[1]; var prm = ''; if(locationSearch){ var prmArry = locationSearch.split('&'); for(var i = 0; i < prmArry.length; i++){ if(prmArry[i].indexOf('tag_tips') !== -1){ prm = decodeURIComponent(prmArry[i].split('=')[1]); } } } if(prm){ $('.js-search_title').html(escapeElements(prm)); $.each($('.js-tag'), function(){ var showFlag = false; var $this = $(this); $.each($this.find('li'), function(){ if($(this).find('a').text().toLowerCase() == prm.toLowerCase()){ $(this).find('a').addClass('match'); showFlag = true; } }); if(!showFlag){ $this.parents('.topics').remove(); } }); $.each($('.tag_cloud .tagwrap dd'), function(){ if($(this).find('a').html() == prm){ $(this).find('a').addClass('match'); } }); } $('.topics_list, .index_ttl').addClass('show'); } }; //Create Side Anc Links var createSideAncLinks = function(){ var $ancListMain = $('.anc_list_main'); if($ancListMain.length){ $('.anc_list_side').html($ancListMain.html()); }else{ $('.js-follow_anchor').remove(); } }; //Show SP CV Area var showSpCvArea = function(){ var $spCvArea = $('.cv_bottom_sp'); if(!$spCvArea.length) return; var defaultPosition = $('.cv_bottom_sp_wrap').offset().top; if((winScroll + winHeight) > defaultPosition){ $spCvArea.addClass('defoult'); }else{ $spCvArea.removeClass('defoult'); } }; var clickSideAnc = function(){ $(document).on('click', '.anc_list_side a', (function(){ var scroll_poseed = 500; var url = $(location).attr("href"); var href= $(this).attr("href"); var $target = $(href == "#" || href == "" ? "html" : href); var position = $target.offset().top; $("html, body").animate({scrollTop: position}, scroll_poseed, "swing"); return false; })); }; var HighlightWords = function(){ return this.init(); }; HighlightWords.prototype = { init: function(){ this.QUERY_NAME = "gl_keywords"; this.WRAPPER_CLASSNAME = "js_highlight_words"; this.NOWRAP_WORDS = ".page_header,.prt_header_01,.prt_header_02,.prt_header_03,.prt_header_04,.prt_header_05,.prt_caption_01,.prt_anchor_list,.industry_archives,.selection_point,."+this.WRAPPER_CLASSNAME; this.query = this.getQuery(); return this; }, executeOn: function(selector){ var $elem = typeof selector==="string" ? $(selector) : selector; $elem.length && this.query && this.forEachTextNode($elem); return this; }, forEachTextNode: function($elem){ var not = this.NOWRAP_WORDS; var forEachTextNode = this.forEachTextNode.bind(this); var iterator = this.iterator.bind(this); var callback = this.highlight.bind(this); var selector = not ? "> *:not("+not+")" : "> *"; var $contents = $elem.find(selector); $contents.each(function(i){ iterator(this, this.childNodes[0], callback); $(this).find(selector).length && forEachTextNode($(this), callback, not); }); return this; }, iterator: function(elem, node){ if(!node) return; var iterator = this.iterator.bind(this); var callback = this.highlight.bind(this); this.isTextNode(node) && typeof callback==="function" && callback(elem, node); node.nextSibling && iterator(elem, node.nextSibling, callback); }, highlight: function(elem, node){ var query = this.query; var classname = this.WRAPPER_CLASSNAME; query.forEach(function(q){ var s, len = q.length; if((s = node.data.toLowerCase().indexOf(q.toLowerCase()))!==-1){ var matches = node.splitText(s); var span = document.createElement("span"); if(classname) span.classList.add(classname); span.appendChild(document.createTextNode(matches.data.substr(0, len))); matches.splitText(len); elem.replaceChild(span, matches); } }); return this; }, isTextNode: function(node){ return node.nodeType===3; }, getQuery: function(){ var key = this.QUERY_NAME; var search = window.location.search; if(!search) return ""; var res = ""; search.replace(/^\?/, "").split("&").forEach(function(q){ q = q.split("="); if(q.length<2) return; if(q[0]===key){ res = q[1].split("+").map(function(v){ return decodeURIComponent(v); }); } }); return res; } }; $.fn.extend({ highlightWords: function(){ var hlwords = new HighlightWords(); hlwords.executeOn(this); return this; } }); //Escape function escapeElements(el) { return String(el).replace(/&/g, '&').replace(/"/g, '"').replace(//g, '>'); }; indexSortTag(); clickSideAnc(); createSideAncLinks(); spNavigationBtn(); $("#container").highlightWords(); $(".js_smp_accordion").on("click", ".js_accordion_switch", function(e){ if(window.matchMedia ? window.matchMedia("(min-width: 750px)").matches : $(window).width()>=750) return; e.preventDefault(); $(this).parents(".js_accordion_item").toggleClass("opened") .find(".js_accordion_cont").stop(true, true).slideToggle(300); }).on("click", ".js_accordion_switch a", function(e){ e.stopPropagation(); }); });