diff --git a/assets/javascripts/app.js b/assets/javascripts/app.js index 4c2e3fb..eb767a6 100644 --- a/assets/javascripts/app.js +++ b/assets/javascripts/app.js @@ -11,10 +11,15 @@ this.replaceWith(new_html); } }); - function fix_first_element() { + function fix_first_element(force_fix) { + if(!force_fix && window.already_fix_first_element){ + return; + } + window.already_fix_first_element = false; if (!window.has_topest_banner) { $('.downIcon').css('display','none'); var first_element = $('.header-banner'); + var parent_element = $() if(first_element.length == 0){ first_element = $('.layout-content .layout-content-inner').eq(0); }else{ @@ -24,7 +29,7 @@ } if(first_element.length != 0){ first_element.css("margin-top", ""); - var ele_offset = first_element[0].getBoundingClientRect().top; + var ele_offset = first_element[0].getBoundingClientRect().top + document.documentElement.scrollTop; if(first_element.parents('.kenjohn.navFixed').length == 0) ele_offset -= window.top_barrier_height; if(ele_offset < 0){ @@ -37,6 +42,7 @@ $("#onesection").css("margin", "0"); $('.layout-content-inner .row, .layout-content-inner .row > [class*="col-"]').css("padding", "0"); } + window.already_fix_first_element = true; } function initdata1 () { window.temp_scrollY = window.pageYOffset; @@ -63,6 +69,7 @@ } var navFixed = $('.kenjohn.navFixed'); window.top_barrier_height = (navFixed.length ? navFixed.height() : 0) + $('#orbit-bar').height(); + fix_first_element(); } // 初始函數: 把所有的程式碼都包在init裡面,方便在之後的jQuery ready 函數裡一次呼叫 function init() { @@ -474,7 +481,6 @@ // 在所有的頁面(包含首頁)執行下面這幾個函數 window.has_topest_banner = ($('[data-pp="300"] .w-ad-banner').length != 0); initdata1(); - fix_first_element(); orbit.sitemenuDropdown(); orbit.goBackTop('top', 800); orbit.plugins.bullEye(); @@ -498,7 +504,7 @@ $(window).resize(function() { var navFixed = $('.kenjohn.navFixed'); window.top_barrier_height = (navFixed.length ? navFixed.height() : 0) + $('#orbit-bar').height(); - fix_first_element(); + fix_first_element(true); if ($(window).outerWidth() >200) { if (resizeTimer) clearTimeout(resizeTimer); $('.outdropdowns').before($('.header-nav')); @@ -526,88 +532,6 @@ // }else{ // $('.header-buttom').appendTo($('.dropdowns')); // } - function forFreeGo() { - // 幫有連結目的之所有a標籤加上title - for(var i=0;i<$('a').length;i++){ - if($('a').eq(i).attr("href") != "" || $('a').eq(i).attr("href") != undefined ){ - var titlestr=""; - if($('a').eq(i).attr('target')=='_self') - titlestr += '在本視窗開啟 '; - else if($('a').eq(i).attr('target') == '_blank') - titlestr += '在新視窗開啟 '; - if($('a').eq(i).attr('title') == "" || $('a').eq(i).attr('title')==undefined && $('a').eq(i).html().search('span').length==1) - titlestr += $('a').eq(i).find('>span').html().trim(); - else if($('a').eq(i).attr('title') == "" || $('a').eq(i).attr('title') == undefined){ - try{ - if($('a').eq(i).html().trim().split('>').length==2) - titlestr += $('a').eq(i).html().trim().split('>')[1].trim(); - else if($('a').eq(i).html().trim().split('>').length==3) - titlestr += $('a').eq(i).html().trim().split('>')[2].trim(); - }catch(e){}; - } - else - titlestr += $('a').eq(i).attr('title'); - if(titlestr.search('=0;i--) - if($('dd a.i-archive-files-item').eq(i).html().trim()=="") - $('dd a.i-archive-files-item').eq(i).parent('dd').remove(); - // 刪除具有空連結欄位的橫列 - for(var i = 0;i < $('*[data-list] tr td a').length ; i++) - if($('*[data-list] tr td a').eq(i).html().trim()=="") - $('*[data-list] tr td a').eq(i).parent('td').parent('tr').remove(); - // tab按鍵選到menu,會顯示下層的menu(為了符合無障礙) - /* - $('.nav-level-0>li>a').focus(function(e) { - e.stopPropagation(); - $(this).parent().focus(); - if ($(this).parent().find('.nav-level-1').hasClass('show')) { - } else { - $('.nav-level-1').removeClass('show'); - $(this).parent().find('.nav-level-1').addClass('show'); - } - }); - $('.nav-level-1>li>a').focus(function(e) { - e.stopPropagation(); - if ($(this).parent().find('.nav-level-2').hasClass('show')) { - }else{ - $('.nav-level-2').removeClass('show'); - $(this).parent().find('.nav-level-2').addClass('show'); - } - }); - $('show').parent('li').focus(); - */ - } - forFreeGo(); $(document).on('touchstart','a',function(e){ e.stopPropagation(); $(this).trigger('focus');