Merge pull request #1587 from tamo/more-i18n

Move HTML-related code from JS to EJS to enable more i18n
This commit is contained in:
Raccoon 2021-07-09 15:08:03 +08:00 committed by GitHub
commit e7a5ea813a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 80 deletions

View File

@ -874,13 +874,16 @@ let tocExpand = false
function checkExpandToggle () { function checkExpandToggle () {
const toc = $('.ui-toc-dropdown .toc') const toc = $('.ui-toc-dropdown .toc')
const toggle = $('.expand-toggle') const expand = $('.expand-toggle.expand-all')
const collapse = $('.expand-toggle.collapse-all')
if (!tocExpand) { if (!tocExpand) {
toc.removeClass('expand') toc.removeClass('expand')
toggle.text('Expand all') expand.show()
collapse.hide()
} else { } else {
toc.addClass('expand') toc.addClass('expand')
toggle.text('Collapse all') expand.hide()
collapse.show()
} }
} }
@ -903,11 +906,12 @@ export function generateToc (id) {
}) })
/* eslint-enable no-unused-vars */ /* eslint-enable no-unused-vars */
if (target.text() === 'undefined') { target.html('') } if (target.text() === 'undefined') { target.html('') }
const tocMenu = $('<div class="toc-menu"></div')
const toggle = $('<a class="expand-toggle" href="#">Expand all</a>')
const backtotop = $('<a class="back-to-top" href="#">Back to top</a>')
const gotobottom = $('<a class="go-to-bottom" href="#">Go to bottom</a>')
checkExpandToggle() checkExpandToggle()
const tocMenu = $('body').children('.toc-menu')
target.append(tocMenu.clone().show())
const toggle = $('.expand-toggle', target)
const backtotop = $('.back-to-top', target)
const gotobottom = $('.go-to-bottom', target)
toggle.click(e => { toggle.click(e => {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
@ -926,8 +930,6 @@ export function generateToc (id) {
if (window.scrollToBottom) { window.scrollToBottom() } if (window.scrollToBottom) { window.scrollToBottom() }
removeHash() removeHash()
}) })
tocMenu.append(toggle).append(backtotop).append(gotobottom)
target.append(tocMenu)
} }
// smooth all hash trigger scrolling // smooth all hash trigger scrolling

View File

@ -237,21 +237,9 @@ const supportExtraTags = [
} }
] ]
const statusType = { const statusType = {
connected: { connected: 1,
msg: 'CONNECTED', online: 2,
label: 'label-warning', offline: 3
fa: 'fa-wifi'
},
online: {
msg: 'ONLINE',
label: 'label-primary',
fa: 'fa-users'
},
offline: {
msg: 'OFFLINE',
label: 'label-danger',
fa: 'fa-plug'
}
} }
// global vars // global vars
@ -723,43 +711,23 @@ function checkTocStyle () {
function showStatus (type, num) { function showStatus (type, num) {
currentStatus = type currentStatus = type
var shortStatus = ui.toolbar.shortStatus
var status = ui.toolbar.status
var label = $('<span class="label"></span>')
var fa = $('<i class="fa"></i>')
var msg = ''
var shortMsg = ''
shortStatus.html('') ui.toolbar.statusConnected.hide()
status.html('') ui.toolbar.statusOnline.hide()
ui.toolbar.statusOffline.hide()
switch (currentStatus) { switch (currentStatus) {
case statusType.connected: case statusType.connected:
label.addClass(statusType.connected.label) ui.toolbar.statusConnected.show()
fa.addClass(statusType.connected.fa)
msg = statusType.connected.msg
break break
case statusType.online: case statusType.online:
label.addClass(statusType.online.label) ui.toolbar.statusShortMsg.text(num)
fa.addClass(statusType.online.fa) ui.toolbar.statusOnline.show()
shortMsg = num
msg = num + ' ' + statusType.online.msg
break break
case statusType.offline: case statusType.offline:
label.addClass(statusType.offline.label) ui.toolbar.statusOffline.show()
fa.addClass(statusType.offline.fa)
msg = statusType.offline.msg
break break
} }
label.append(fa)
var shortLabel = label.clone()
shortLabel.append(' ' + shortMsg)
shortStatus.append(shortLabel)
label.append(' ' + msg)
status.append(label)
} }
function toggleMode () { function toggleMode () {
@ -1647,41 +1615,34 @@ function updatePermission (newPermission) {
permission = newPermission permission = newPermission
if (window.loaded) refreshView() if (window.loaded) refreshView()
} }
var label = null ui.infobar.permission.label.hide()
var title = null
switch (permission) { switch (permission) {
case 'freely': case 'freely':
label = '<i class="fa fa-leaf"></i> Freely' $('#permissionLabelFreely').show()
title = 'Anyone can edit'
break break
case 'editable': case 'editable':
label = '<i class="fa fa-shield"></i> Editable' $('#permissionLabelEditable').show()
title = 'Signed people can edit'
break break
case 'limited': case 'limited':
label = '<i class="fa fa-id-card"></i> Limited' $('#permissionLabelLimited').show()
title = 'Signed people can edit (forbid guest)'
break break
case 'locked': case 'locked':
label = '<i class="fa fa-lock"></i> Locked' $('#permissionLabelLocked').show()
title = 'Only owner can edit'
break break
case 'protected': case 'protected':
label = '<i class="fa fa-umbrella"></i> Protected' $('#permissionLabelProtected').show()
title = 'Only owner can edit (forbid guest)'
break break
case 'private': case 'private':
label = '<i class="fa fa-hand-stop-o"></i> Private' $('#permissionLabelPrivate').show()
title = 'Only owner can view & edit'
break break
} }
if (personalInfo.userid && window.owner && personalInfo.userid === window.owner) { if (personalInfo.userid && window.owner && personalInfo.userid === window.owner) {
label += ' <i class="fa fa-caret-down"></i>' ui.infobar.permission.labelCaretDown.show()
ui.infobar.permission.label.removeClass('disabled') ui.infobar.permission.label.removeClass('disabled')
} else { } else {
ui.infobar.permission.labelCaretDown.hide()
ui.infobar.permission.label.addClass('disabled') ui.infobar.permission.label.addClass('disabled')
} }
ui.infobar.permission.label.html(label).attr('title', title)
} }
function havePermission () { function havePermission () {

View File

@ -9,6 +9,10 @@ export const getUIElements = () => ({
toolbar: { toolbar: {
shortStatus: $('.ui-short-status'), shortStatus: $('.ui-short-status'),
status: $('.ui-status'), status: $('.ui-status'),
statusShortMsg: $('.ui-status-short-msg'),
statusConnected: $('.ui-status-connected'),
statusOnline: $('.ui-status-online'),
statusOffline: $('.ui-status-offline'),
new: $('.ui-new'), new: $('.ui-new'),
publish: $('.ui-publish'), publish: $('.ui-publish'),
extra: { extra: {
@ -46,6 +50,7 @@ export const getUIElements = () => ({
permission: { permission: {
permission: $('.ui-permission'), permission: $('.ui-permission'),
label: $('.ui-permission-label'), label: $('.ui-permission-label'),
labelCaretDown: $('.ui-permission-caret-down'),
freely: $('.ui-permission-freely'), freely: $('.ui-permission-freely'),
editable: $('.ui-permission-editable'), editable: $('.ui-permission-editable'),
locked: $('.ui-permission-locked'), locked: $('.ui-permission-locked'),

View File

@ -12,23 +12,27 @@
<span class="ui-lastchange text-uppercase"></span> <span class="ui-lastchange text-uppercase"></span>
</span> </span>
<span class="ui-permission dropdown pull-right"> <span class="ui-permission dropdown pull-right">
<a id="permissionLabel" class="ui-permission-label text-uppercase" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> <a id="permissionLabelFreely" class="ui-permission-label text-uppercase" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="display: none;" title="<%= __('Anyone can edit') %>"><i class="fa fa-leaf"></i> <%= __('Freely') %> <i class="ui-permission-caret-down fa fa-caret-down" style="display: none;"></i></a>
</a> <a id="permissionLabelEditable" class="ui-permission-label text-uppercase" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="display: none;" title="<%= __('Signed-in people can edit') %>"><i class="fa fa-shield fa-fw"></i> <%= __('Editable') %> <i class="ui-permission-caret-down fa fa-caret-down" style="display: none;"></i></a>
<ul class="dropdown-menu" aria-labelledby="permissionLabel"> <a id="permissionLabelLimited" class="ui-permission-label text-uppercase" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="display: none;" title="<%= __('Signed-in people can edit (forbid guests)') %>"><i class="fa fa-id-card fa-fw"></i> <%= __('Limited') %> <i class="ui-permission-caret-down fa fa-caret-down" style="display: none;"></i></a>
<li class="ui-permission-freely"<% if(!('freely' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-leaf fa-fw"></i> Freely - Anyone can edit</a></li> <a id="permissionLabelLocked" class="ui-permission-label text-uppercase" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="display: none;" title="<%= __('Only owner can edit') %>"><i class="fa fa-lock fa-fw"></i> <%= __('Locked') %> <i class="ui-permission-caret-down fa fa-caret-down" style="display: none;"></i></a>
<li class="ui-permission-editable"<% if(!('editable' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-shield fa-fw"></i> Editable - Signed-in people can edit</a></li> <a id="permissionLabelProtected" class="ui-permission-label text-uppercase" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="display: none;" title="<%= __('Only owner can edit (forbid guests)') %>"><i class="fa fa-umbrella fa-fw"></i> <%= __('Protected') %> <i class="ui-permission-caret-down fa fa-caret-down" style="display: none;"></i></a>
<li class="ui-permission-limited"<% if(!('limited' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-id-card fa-fw"></i> Limited - Signed-in people can edit (forbid guests)</a></li> <a id="permissionLabelPrivate" class="ui-permission-label text-uppercase" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" style="display: none;" title="<%= __('Only owner can view & edit') %>"><i class="fa fa-hand-stop-o fa-fw"></i> <%= __('Private') %> <i class="ui-permission-caret-down fa fa-caret-down" style="display: none;"></i></a>
<li class="ui-permission-locked"<% if(!('locked' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-lock fa-fw"></i> Locked - Only owner can edit</a></li> <ul class="dropdown-menu" aria-labelledby="permissionLabelFreely permissionLabelEditable permissionLabelLimited permissionLabelLocked permissionLabelProtected permissionLabelPrivate">
<li class="ui-permission-protected"<% if(!('protected' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-umbrella fa-fw"></i> Protected - Only owner can edit (forbid guests)</a></li> <li class="ui-permission-freely"<% if(!('freely' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-leaf fa-fw"></i> <%= __('Freely') %> - <%= __('Anyone can edit') %></a></li>
<li class="ui-permission-private"<% if(!('private' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-hand-stop-o fa-fw"></i> Private - Only owner can view &amp; edit</a></li> <li class="ui-permission-editable"<% if(!('editable' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-shield fa-fw"></i> <%= __('Editable') %> - <%= __('Signed-in people can edit') %></a></li>
<li class="ui-permission-limited"<% if(!('limited' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-id-card fa-fw"></i> <%= __('Limited') %> - <%= __('Signed-in people can edit (forbid guests)') %></a></li>
<li class="ui-permission-locked"<% if(!('locked' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-lock fa-fw"></i> <%= __('Locked') %> - <%= __('Only owner can edit') %></a></li>
<li class="ui-permission-protected"<% if(!('protected' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-umbrella fa-fw"></i> <%= __('Protected') %> - <%= __('Only owner can edit (forbid guests)') %></a></li>
<li class="ui-permission-private"<% if(!('private' in permission)) { %> style="display: none;"<% } %>><a><i class="fa fa-hand-stop-o fa-fw"></i> <%= __('Private') %> - <%= __('Only owner can view & edit') %></a></li>
<li class="divider"></li> <li class="divider"></li>
<li class="ui-delete-note"><a><i class="fa fa-trash-o fa-fw"></i> Delete this note</a></li> <li class="ui-delete-note"><a><i class="fa fa-trash-o fa-fw"></i> <%= __('Delete this note') %></a></li>
</ul> </ul>
</span> </span>
<br> <br>
<span class="ui-owner" style="display: none;"> <span class="ui-owner" style="display: none;">
&thinsp;<i class="ui-user-icon small" data-toggle="tooltip" data-placement="right"></i> &thinsp;<i class="ui-user-icon small" data-toggle="tooltip" data-placement="right"></i>
&nbsp;<span class="text-uppercase">owned this note</span> &nbsp;<span class="text-uppercase"><%= __('owned this note') %></span>
</span> </span>
</small> </small>
</div> </div>
@ -45,6 +49,13 @@
<div id="ui-toc-affix" class="ui-affix-toc ui-toc-dropdown unselectable hidden-print" data-spy="affix" style="top:51px;display:none;"></div> <div id="ui-toc-affix" class="ui-affix-toc ui-toc-dropdown unselectable hidden-print" data-spy="affix" style="top:51px;display:none;"></div>
</div> </div>
</div> </div>
<!-- toc menu -->
<div class="toc-menu" style="display: none;">
<a class="expand-toggle expand-all" href="#"><%= __('Expand all') %></a>
<a class="expand-toggle collapse-all" href="#" style="display: none;"><%= __('Collapse all') %></a>
<a class="back-to-top" href="#"><%= __('Back to top') %></a>
<a class="go-to-bottom" href="#"><%= __('Go to bottom') %></a>
</div>
<!-- clipboard modal --> <!-- clipboard modal -->
<div class="modal fade" id="clipboardModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal fade" id="clipboardModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-lg">

View File

@ -8,7 +8,10 @@
<div class="visible-lg">&nbsp;</div> <div class="visible-lg">&nbsp;</div>
</div> </div>
<div class="nav-mobile nav-status visible-xs" id="short-online-user-list"> <div class="nav-mobile nav-status visible-xs" id="short-online-user-list">
<a class="ui-short-status" data-toggle="dropdown"><span class="label label-danger"><i class="fa fa-plug"></i> </span> <a class="ui-short-status" data-toggle="dropdown">
<span class="label label-warning ui-status-connected" style="display: none;"><i class="fa fa-wifi"></i></span>
<span class="label label-primary ui-status-online" style="display: none;"><i class="fa fa-users"></i> <span class="ui-status-short-msg"></span></span>
<span class="label label-danger ui-status-offline"><i class="fa fa-plug"></i></span>
</a> </a>
<ul class="dropdown-menu list" role="menu" aria-labelledby="menu"> <ul class="dropdown-menu list" role="menu" aria-labelledby="menu">
</ul> </ul>
@ -109,7 +112,9 @@
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li id="online-user-list"> <li id="online-user-list">
<a class="ui-status" data-toggle="dropdown"> <a class="ui-status" data-toggle="dropdown">
<span class="label label-danger"><i class="fa fa-plug"></i> OFFLINE</span> <span class="label label-warning ui-status-connected" style="display: none;"><i class="fa fa-wifi"></i> <%= __('CONNECTED') %></span>
<span class="label label-primary ui-status-online" style="display: none;"><i class="fa fa-users"></i> <span class="ui-status-short-msg"></span> <%= __('ONLINE') %></span>
<span class="label label-danger ui-status-offline"><i class="fa fa-plug"></i> <%= __('OFFLINE') %></span>
</a> </a>
<ul class="dropdown-menu list" role="menu" aria-labelledby="menu" style="right: 15px;width: 200px;"> <ul class="dropdown-menu list" role="menu" aria-labelledby="menu" style="right: 15px;width: 200px;">
</ul> </ul>