Skip to content

Commit dec2f98

Browse files
author
Tamotsu Takahashi
committed
Make "Expand all" translatable
Move HTML from JS to EJS I don't know how to register i18n helper to handlebars, so "export to raw HTML" has not been touched. You can do the same for html.hbs if you want. Signed-off-by: Tamotsu Takahashi <ttakah@gmail.com>
1 parent 66fdf7b commit dec2f98

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

public/js/extra.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -840,13 +840,16 @@ let tocExpand = false
840840

841841
function checkExpandToggle () {
842842
const toc = $('.ui-toc-dropdown .toc')
843-
const toggle = $('.expand-toggle')
843+
const expand = $('.expand-toggle.expand-all')
844+
const collapse = $('.expand-toggle.collapse-all')
844845
if (!tocExpand) {
845846
toc.removeClass('expand')
846-
toggle.text('Expand all')
847+
expand.show()
848+
collapse.hide()
847849
} else {
848850
toc.addClass('expand')
849-
toggle.text('Collapse all')
851+
expand.hide()
852+
collapse.show()
850853
}
851854
}
852855

@@ -865,11 +868,12 @@ export function generateToc (id) {
865868
})
866869
/* eslint-enable no-unused-vars */
867870
if (target.text() === 'undefined') { target.html('') }
868-
const tocMenu = $('<div class="toc-menu"></div')
869-
const toggle = $('<a class="expand-toggle" href="#">Expand all</a>')
870-
const backtotop = $('<a class="back-to-top" href="#">Back to top</a>')
871-
const gotobottom = $('<a class="go-to-bottom" href="#">Go to bottom</a>')
872871
checkExpandToggle()
872+
const tocMenu = $('body').children('.toc-menu')
873+
target.append(tocMenu.clone().show())
874+
const toggle = $('.expand-toggle', target)
875+
const backtotop = $('.back-to-top', target)
876+
const gotobottom = $('.go-to-bottom', target)
873877
toggle.click(e => {
874878
e.preventDefault()
875879
e.stopPropagation()
@@ -888,8 +892,6 @@ export function generateToc (id) {
888892
if (window.scrollToBottom) { window.scrollToBottom() }
889893
removeHash()
890894
})
891-
tocMenu.append(toggle).append(backtotop).append(gotobottom)
892-
target.append(tocMenu)
893895
}
894896

895897
// smooth all hash trigger scrolling

public/views/codimd/body.ejs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
<div id="ui-toc-affix" class="ui-affix-toc ui-toc-dropdown unselectable hidden-print" data-spy="affix" style="top:51px;display:none;"></div>
5050
</div>
5151
</div>
52+
<!-- toc menu -->
53+
<div class="toc-menu" style="display: none;">
54+
<a class="expand-toggle expand-all" href="#"><%= __('Expand all') %></a>
55+
<a class="expand-toggle collapse-all" href="#" style="display: none;"><%= __('Collapse all') %></a>
56+
<a class="back-to-top" href="#"><%= __('Back to top') %></a>
57+
<a class="go-to-bottom" href="#"><%= __('Go to bottom') %></a>
58+
</div>
5259
<!-- clipboard modal -->
5360
<div class="modal fade" id="clipboardModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
5461
<div class="modal-dialog modal-lg">

0 commit comments

Comments
 (0)