|
|
@@ -89,47 +89,75 @@ const commentMDEditors = {}; |
|
|
|
// Silence fomantic's error logging when tabs are used without a target content element |
|
|
|
$.fn.tab.settings.silent = true; |
|
|
|
|
|
|
|
$(document).ready(function(){ |
|
|
|
if ($('.file-view.markdown').length && $('.file-view.markdown').length>0) { |
|
|
|
setTimeout(()=>{ |
|
|
|
const eleList =document.querySelectorAll('div.anchor-wrap .anchor') |
|
|
|
(function() { |
|
|
|
function isInviewPort(element){ |
|
|
|
const viewWidth = window.innerWidth || document.documentElement.clientWidth || '' |
|
|
|
const viewHeight = window.innerHeight || document.documentElement.clientHeight || '' |
|
|
|
const {top,right,bottom,left} = element.getBoundingClientRect() |
|
|
|
return (top>=0 && left>=0 && right<viewWidth && bottom<=viewHeight) |
|
|
|
} |
|
|
|
function clickHandler() { |
|
|
|
if(!this.parentElement.classList.contains('hidden')) { |
|
|
|
this.parentElement.classList.add('hidden') |
|
|
|
this.firstChild.classList.replace('ri-arrow-drop-left-line','ri-arrow-drop-right-line') |
|
|
|
} else { |
|
|
|
this.parentElement.classList.remove('hidden') |
|
|
|
this.firstChild.classList.replace('ri-arrow-drop-right-line','ri-arrow-drop-left-line') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let timeout = null; |
|
|
|
function scrollHandler() { |
|
|
|
timeout && clearTimeout(timeout); |
|
|
|
timeout = setTimeout(function(){ |
|
|
|
let flag = false |
|
|
|
const eleList = document.querySelectorAll('div.anchor-wrap .anchor') |
|
|
|
const navList = document.querySelectorAll('.markdown_toc .catalog-li') |
|
|
|
const toggleIcon = document.getElementsByClassName('toggle-container') |
|
|
|
toggleIcon[0].addEventListener('click',function(){ |
|
|
|
if(!this.parentElement.classList.contains('hidden')){ |
|
|
|
this.parentElement.classList.add('hidden') |
|
|
|
this.firstChild.classList.replace('ri-arrow-drop-left-line','ri-arrow-drop-right-line') |
|
|
|
}else{ |
|
|
|
this.parentElement.classList.remove('hidden') |
|
|
|
this.firstChild.classList.replace('ri-arrow-drop-right-line','ri-arrow-drop-left-line') |
|
|
|
eleList.forEach((k,index)=>{ |
|
|
|
if(isInviewPort(k) && !flag){ |
|
|
|
flag = true |
|
|
|
navList.forEach((ele)=>{ |
|
|
|
ele.classList.remove('active') |
|
|
|
}) |
|
|
|
navList[index].classList.add('active') |
|
|
|
} |
|
|
|
}) |
|
|
|
navList[0].classList.add('active') |
|
|
|
let timeout = null; |
|
|
|
$(window).on('scroll', () => { |
|
|
|
if(timeout !== null) clearTimeout(timeout); |
|
|
|
timeout = setTimeout(function(){ |
|
|
|
let flag = false |
|
|
|
eleList.forEach((k,index)=>{ |
|
|
|
if(isInviewPort(k) && !flag){ |
|
|
|
flag = true |
|
|
|
navList.forEach((ele)=>{ |
|
|
|
ele.classList.remove('active') |
|
|
|
}) |
|
|
|
navList[index].classList.add('active') |
|
|
|
} |
|
|
|
}) |
|
|
|
},50) |
|
|
|
}, 50) |
|
|
|
} |
|
|
|
window.initMarkdownCatalog = function() { |
|
|
|
if ($('.file-view.markdown').length && $('.file-view.markdown').length > 0) { |
|
|
|
const navList = document.querySelectorAll('.markdown_toc .catalog-li') |
|
|
|
const toggleIcon = document.getElementsByClassName('toggle-container') |
|
|
|
toggleIcon[0].removeEventListener('click', clickHandler) |
|
|
|
toggleIcon[0].addEventListener('click', clickHandler) |
|
|
|
navList.forEach((ele)=>{ |
|
|
|
ele.classList.remove('active') |
|
|
|
}) |
|
|
|
},0) |
|
|
|
navList[0].classList.add('active') |
|
|
|
$(window).off('scroll', scrollHandler) |
|
|
|
$(window).on('scroll', scrollHandler) |
|
|
|
// Set anchor. |
|
|
|
$(".markdown").each(function () { |
|
|
|
$(this).find("h1, h2, h3, h4, h5, h6").each(function () { |
|
|
|
let node = $(this); |
|
|
|
if (!node.closest('.anchor-wrap').length) { |
|
|
|
node = node.wrap('<div class="anchor-wrap"></div>'); |
|
|
|
node.append( |
|
|
|
`<a class="anchor" href="#${encodeURIComponent( |
|
|
|
node.attr("id") |
|
|
|
)}">${svg("octicon-link", 16)}</a>` |
|
|
|
); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
function isInviewPort(element){ |
|
|
|
const viewWidth = window.innerWidth || document.documentElement.clientWidth || '' |
|
|
|
const viewHeight = window.innerHeight || document.documentElement.clientHeight || '' |
|
|
|
const {top,right,bottom,left} = element.getBoundingClientRect() |
|
|
|
return (top>=0 && left>=0 && right<viewWidth && bottom<=viewHeight) |
|
|
|
} |
|
|
|
$(document).ready(function() { |
|
|
|
setTimeout(() => { |
|
|
|
window.initMarkdownCatalog && window.initMarkdownCatalog(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
})(); |
|
|
|
|
|
|
|
function initCommentPreviewTab($form) { |
|
|
|
const $tabMenu = $form.find(".tabular.menu"); |
|
|
@@ -2887,12 +2915,14 @@ $(document).ready(async () => { |
|
|
|
.find("h1, h2, h3, h4, h5, h6") |
|
|
|
.each(function () { |
|
|
|
let node = $(this); |
|
|
|
node = node.wrap('<div class="anchor-wrap"></div>'); |
|
|
|
node.append( |
|
|
|
`<a class="anchor" href="#${encodeURIComponent( |
|
|
|
node.attr("id") |
|
|
|
)}">${svg("octicon-link", 16)}</a>` |
|
|
|
); |
|
|
|
if (!node.closest('.anchor-wrap').length) { |
|
|
|
node = node.wrap('<div class="anchor-wrap"></div>'); |
|
|
|
node.append( |
|
|
|
`<a class="anchor" href="#${encodeURIComponent( |
|
|
|
node.attr("id") |
|
|
|
)}">${svg("octicon-link", 16)}</a>` |
|
|
|
); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|