From 1d248c4cefcb940f0033239e2fc32ab11fa159ed Mon Sep 17 00:00:00 2001 From: Jamos Tay Date: Mon, 15 Oct 2018 20:34:57 +0800 Subject: [PATCH 1/3] Fix anchors in panel headings --- asset/js/setup.js | 9 ++++++-- lib/Page.js | 8 +++++++ test/test_site/expected/index.html | 24 ++++++++++---------- test/test_site/expected/markbind/js/setup.js | 9 ++++++-- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/asset/js/setup.js b/asset/js/setup.js index 168c00424e..8eb48e6dc2 100644 --- a/asset/js/setup.js +++ b/asset/js/setup.js @@ -15,7 +15,7 @@ function flattenModals() { }); } -function setupAnchorVisibility() { +function setupAnchors() { jQuery('h1, h2, h3, h4, h5, h6').each((index, heading) => { jQuery(heading).on('mouseenter', function () { jQuery(this).children('.fa.fa-anchor').show(); @@ -24,12 +24,17 @@ function setupAnchorVisibility() { jQuery(this).children('.fa.fa-anchor').hide(); }); }); + jQuery('.fa-anchor').each((index, anchor) => { + jQuery(anchor).on('click', function () { + window.location.href = jQuery(this).attr('href'); + }); + }); } function executeAfterMountedRoutines() { flattenModals(); scrollToUrlAnchorHeading(); - setupAnchorVisibility(); + setupAnchors(); } function setupSiteNav() { diff --git a/lib/Page.js b/lib/Page.js index 997b238c3b..f867ae308a 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -330,6 +330,14 @@ Page.prototype.addAnchors = function (content) { $(headingsSelector).each((i, heading) => { $(heading).append(ANCHOR_HTML.replace('#', `#${$(heading).attr('id')}`)); }); + $('panel[header]').each((i, panel) => { + const panelHeading = cheerio.load(md.render(panel.attribs.header), { xmlMode: false }); + if (panelHeading(headingsSelector).length >= 1) { + const headingId = $(panelHeading(headingsSelector)[0]).attr('id'); + const anchorIcon = ANCHOR_HTML.replace(/"/g, "'").replace('#', `#${headingId}`); + $(panel).attr('header', `${$(panel).attr('header')}${anchorIcon}`); + } + }); } return $.html(); }; diff --git a/test/test_site/expected/index.html b/test/test_site/expected/index.html index 65a81a9fca..ad48c9a03b 100644 --- a/test/test_site/expected/index.html +++ b/test/test_site/expected/index.html @@ -235,43 +235,43 @@

Feature list<

Panel without src

- +

Panel without src content heading

Panel with normal src

- +

Panel with src from a page segment

- +

Panel with boilerplate

- - + +

Nested panel

- +

Nested panel without src

- +

Panel content of outer nested panel

- +

Panel content of inner nested panel

Panel with src from another Markbind site

- +

Modal with panel inside

trigger

- +

Panel content inside modal

Unexpanded panel

- +

Panel content of unexpanded panel should not appear in search data

- +

Panel content inside unexpanded panel should not appear in search data

diff --git a/test/test_site/expected/markbind/js/setup.js b/test/test_site/expected/markbind/js/setup.js index 168c00424e..8eb48e6dc2 100644 --- a/test/test_site/expected/markbind/js/setup.js +++ b/test/test_site/expected/markbind/js/setup.js @@ -15,7 +15,7 @@ function flattenModals() { }); } -function setupAnchorVisibility() { +function setupAnchors() { jQuery('h1, h2, h3, h4, h5, h6').each((index, heading) => { jQuery(heading).on('mouseenter', function () { jQuery(this).children('.fa.fa-anchor').show(); @@ -24,12 +24,17 @@ function setupAnchorVisibility() { jQuery(this).children('.fa.fa-anchor').hide(); }); }); + jQuery('.fa-anchor').each((index, anchor) => { + jQuery(anchor).on('click', function () { + window.location.href = jQuery(this).attr('href'); + }); + }); } function executeAfterMountedRoutines() { flattenModals(); scrollToUrlAnchorHeading(); - setupAnchorVisibility(); + setupAnchors(); } function setupSiteNav() { From fa3be99ffdbd45f9863e92290151c11ab1a3ecd5 Mon Sep 17 00:00:00 2001 From: Jamos Tay Date: Wed, 31 Oct 2018 01:00:44 +0800 Subject: [PATCH 2/3] Make hover apply to wrapper --- asset/js/setup.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/asset/js/setup.js b/asset/js/setup.js index 8eb48e6dc2..1e868398bf 100644 --- a/asset/js/setup.js +++ b/asset/js/setup.js @@ -16,13 +16,9 @@ function flattenModals() { } function setupAnchors() { - jQuery('h1, h2, h3, h4, h5, h6').each((index, heading) => { - jQuery(heading).on('mouseenter', function () { - jQuery(this).children('.fa.fa-anchor').show(); - }); - jQuery(heading).on('mouseleave', function () { - jQuery(this).children('.fa.fa-anchor').hide(); - }); + jQuery('h1, h2, h3, h4, h5, h6, .header-wrapper').each((index, heading) => { + jQuery(heading).on('mouseenter', () => jQuery(heading).find('.fa.fa-anchor').show()); + jQuery(heading).on('mouseleave', () => jQuery(heading).find('.fa.fa-anchor').hide()); }); jQuery('.fa-anchor').each((index, anchor) => { jQuery(anchor).on('click', function () { From bc74909f711bb5f2680d2ff88065381148167910 Mon Sep 17 00:00:00 2001 From: Jamos Tay Date: Mon, 5 Nov 2018 13:26:51 +0800 Subject: [PATCH 3/3] Replace setup file in expected --- test/test_site/expected/markbind/js/setup.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/test_site/expected/markbind/js/setup.js b/test/test_site/expected/markbind/js/setup.js index 8eb48e6dc2..1e868398bf 100644 --- a/test/test_site/expected/markbind/js/setup.js +++ b/test/test_site/expected/markbind/js/setup.js @@ -16,13 +16,9 @@ function flattenModals() { } function setupAnchors() { - jQuery('h1, h2, h3, h4, h5, h6').each((index, heading) => { - jQuery(heading).on('mouseenter', function () { - jQuery(this).children('.fa.fa-anchor').show(); - }); - jQuery(heading).on('mouseleave', function () { - jQuery(this).children('.fa.fa-anchor').hide(); - }); + jQuery('h1, h2, h3, h4, h5, h6, .header-wrapper').each((index, heading) => { + jQuery(heading).on('mouseenter', () => jQuery(heading).find('.fa.fa-anchor').show()); + jQuery(heading).on('mouseleave', () => jQuery(heading).find('.fa.fa-anchor').hide()); }); jQuery('.fa-anchor').each((index, anchor) => { jQuery(anchor).on('click', function () {