Skip to content

Commit

Permalink
Update tests for encapsulating anchor plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ang-zeyu committed Mar 23, 2020
1 parent ec29d9e commit a4f55ac
Show file tree
Hide file tree
Showing 67 changed files with 465 additions and 483 deletions.
1 change: 1 addition & 0 deletions test/functional/test_site/expected/bugs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<link rel="stylesheet" href="../markbind/css/github.min.css">
<link rel="stylesheet" href="../markbind/css/markbind.css">
<link rel="stylesheet" href="/test_site/plugins/testMarkbindPlugin/testMarkbindPluginStylesheet.css">
<link rel="stylesheet" href="/test_site/plugins/markbind-plugin-anchors/markbind-plugin-anchors.css">
<link rel="stylesheet" href="../markbind/layouts/default/styles.css">
<meta name="default-head-bottom">
<link rel="icon" href="/test_site/favicon.png">
Expand Down
73 changes: 37 additions & 36 deletions test/functional/test_site/expected/index.html

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions test/functional/test_site/expected/markbind/css/markbind.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,6 @@ kbd {
outline: none !important;
}

.fa.fa-anchor {
color: #ccc;
display: inline;
font-size: 14px;
margin-left: 10px;
padding: 3px;
text-decoration: none;
visibility: hidden;
}

.fa.fa-anchor:hover {
color: #555;
}

code.hljs.inline {
background: #f8f8f8;
color: #333;
Expand Down
63 changes: 23 additions & 40 deletions test/functional/test_site/expected/markbind/js/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,47 @@ function scrollToUrlAnchorHeading() {
}
}

function flattenModals() {
jQuery('.modal').each((index, modal) => {
jQuery(modal).detach().appendTo(jQuery('#app'));
});
}

function insertCss(cssCode) {
const newNode = document.createElement('style');
newNode.innerHTML = cssCode;
document.getElementsByTagName('head')[0].appendChild(newNode);
}

function setupAnchors() {
function setupAnchorsForFixedNavbar() {
const headerSelector = jQuery('header');
const isFixed = headerSelector.filter('.header-fixed').length !== 0;
if (!isFixed) {
return;
}

const headerHeight = headerSelector.height();
const bufferHeight = 1;
if (isFixed) {
jQuery('.nav-inner').css('padding-top', `calc(${headerHeight}px)`);
jQuery('#content-wrapper').css('padding-top', `calc(${headerHeight}px)`);
insertCss(
`span.anchor {
display: block;
position: relative;
top: calc(-${headerHeight}px - ${bufferHeight}rem)
}`,
);
}
jQuery('.nav-inner').css('padding-top', `calc(${headerHeight}px)`);
jQuery('#content-wrapper').css('padding-top', `calc(${headerHeight}px)`);
insertCss(
`span.anchor {
display: block;
position: relative;
top: calc(-${headerHeight}px - ${bufferHeight}rem)
}`,
);
jQuery('h1, h2, h3, h4, h5, h6, .header-wrapper').each((index, heading) => {
if (heading.id) {
jQuery(heading).on('mouseenter',
() => jQuery(heading).find('.fa.fa-anchor').css('visibility', 'visible'));
jQuery(heading).on('mouseleave',
() => jQuery(heading).find('.fa.fa-anchor').css('visibility', 'hidden'));
if (isFixed) {
/**
* Fixing the top navbar would break anchor navigation,
* by creating empty spans above the <h> tag we can prevent
* the headings from being covered by the navbar.
*/
const spanId = heading.id;
heading.insertAdjacentHTML('beforebegin', `<span id="${spanId}" class="anchor"></span>`);
jQuery(heading).removeAttr('id'); // to avoid duplicated id problem
}
/**
* Fixing the top navbar would break anchor navigation,
* by creating empty spans above the <h> tag we can prevent
* the headings from being covered by the navbar.
*/
const spanId = heading.id;
heading.insertAdjacentHTML('beforebegin', `<span id="${spanId}" class="anchor"></span>`);
jQuery(heading).removeAttr('id'); // to avoid duplicated id problem
}
});
jQuery('.fa-anchor').each((index, anchor) => {
jQuery(anchor).on('click', function () {
window.location.href = jQuery(this).attr('href');
});
});
}

function updateSearchData(vm) {
jQuery.getJSON(`${baseUrl}/siteData.json`)
.then((siteData) => {
// eslint-disable-next-line no-param-reassign
vm.searchData = siteData.pages;
});
}
Expand Down Expand Up @@ -97,9 +81,8 @@ function executeAfterCreatedRoutines() {
}

function executeAfterMountedRoutines() {
flattenModals();
scrollToUrlAnchorHeading();
setupAnchors();
setupAnchorsForFixedNavbar();
MarkBind.executeAfterSetupScripts.resolve();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.fa.fa-anchor {
color: #ccc;
display: inline;
font-size: 14px;
margin-left: 10px;
padding: 3px;
text-decoration: none;
visibility: hidden;
}

.fa.fa-anchor:hover {
color: #555;
}

h1:hover > .fa.fa-anchor,
h2:hover > .fa.fa-anchor,
h3:hover > .fa.fa-anchor,
h4:hover > .fa.fa-anchor,
h5:hover > .fa.fa-anchor,
h6:hover > .fa.fa-anchor,
.header-wrapper:hover > .fa.fa-anchor {
visibility: visible;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p>This is a page from another Markbind site.</p>
<h2 id="feature-list">Feature list<a class="fa fa-anchor" href="#feature-list"></a></h2>
<h2 id="feature-list">Feature list<a class="fa fa-anchor" href="#feature-list" onclick="event.stopPropagation()"></a></h2>
<p>It is a list of features (or functionalities) grouped according to some criteria such as priority (e.g. must-have, nice-to-have, etc. ), order of delivery, object or process related (e.g. order-related, invoice-related, etc.). Here is a sample feature
list from Minesweeper (only a brief description has been provided to save space).</p>
<ol>
Expand Down
3 changes: 2 additions & 1 deletion test/functional/test_site/expected/sub_site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<link rel="stylesheet" href="../markbind/css/github.min.css">
<link rel="stylesheet" href="../markbind/css/markbind.css">
<link rel="stylesheet" href="/test_site/plugins/testMarkbindPlugin/testMarkbindPluginStylesheet.css">
<link rel="stylesheet" href="/test_site/plugins/markbind-plugin-anchors/markbind-plugin-anchors.css">
<link rel="stylesheet" href="../markbind/layouts/default/styles.css">
<meta name="default-head-bottom">
<link rel="icon" href="/test_site/favicon.png">
Expand All @@ -26,7 +27,7 @@
<div id="flex-body">
<div id="content-wrapper">
<p>This is a page from another Markbind site.</p>
<h2 id="feature-list">Feature list<a class="fa fa-anchor" href="#feature-list"></a></h2>
<h2 id="feature-list">Feature list<a class="fa fa-anchor" href="#feature-list" onclick="event.stopPropagation()"></a></h2>
<p>It is a list of features (or functionalities) grouped according to some criteria such as priority (e.g. must-have, nice-to-have, etc. ), order of delivery, object or process related (e.g. order-related, invoice-related, etc.). Here is a sample
feature list from Minesweeper (only a brief description has been provided to save space).</p>
<ol>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<link rel="stylesheet" href="../../markbind/css/github.min.css">
<link rel="stylesheet" href="../../markbind/css/markbind.css">
<link rel="stylesheet" href="/test_site/plugins/testMarkbindPlugin/testMarkbindPluginStylesheet.css">
<link rel="stylesheet" href="/test_site/plugins/markbind-plugin-anchors/markbind-plugin-anchors.css">
<link rel="stylesheet" href="../../markbind/layouts/default/styles.css">
<meta name="default-head-bottom">
<link rel="icon" href="/test_site/favicon.png">
Expand Down
1 change: 1 addition & 0 deletions test/functional/test_site/expected/testAfterSetup.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<link rel="stylesheet" href="markbind/css/github.min.css">
<link rel="stylesheet" href="markbind/css/markbind.css">
<link rel="stylesheet" href="/test_site/plugins/testMarkbindPlugin/testMarkbindPluginStylesheet.css">
<link rel="stylesheet" href="/test_site/plugins/markbind-plugin-anchors/markbind-plugin-anchors.css">
<link rel="stylesheet" href="markbind/layouts/testAfterSetup/styles.css">
<meta name="head-bottom">
<link rel="icon" href="/test_site/favicon.png">
Expand Down
Loading

0 comments on commit a4f55ac

Please sign in to comment.