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 () {
const toc = $('.ui-toc-dropdown .toc')
const toggle = $('.expand-toggle')
const expand = $('.expand-toggle.expand-all')
const collapse = $('.expand-toggle.collapse-all')
if (!tocExpand) {
toc.removeClass('expand')
toggle.text('Expand all')
expand.show()
collapse.hide()
} else {
toc.addClass('expand')
toggle.text('Collapse all')
expand.hide()
collapse.show()
}
}
@ -903,11 +906,12 @@ export function generateToc (id) {
})
/* eslint-enable no-unused-vars */
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()
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 => {
e.preventDefault()
e.stopPropagation()
@ -926,8 +930,6 @@ export function generateToc (id) {
if (window.scrollToBottom) { window.scrollToBottom() }
removeHash()
})
tocMenu.append(toggle).append(backtotop).append(gotobottom)
target.append(tocMenu)
}
// smooth all hash trigger scrolling

View File

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

View File

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

View File

@ -12,23 +12,27 @@
<span class="ui-lastchange text-uppercase"></span>
</span>
<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>
<ul class="dropdown-menu" aria-labelledby="permissionLabel">
<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-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 &amp; edit</a></li>
<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 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>
<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>
<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>
<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>
<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>
<ul class="dropdown-menu" aria-labelledby="permissionLabelFreely permissionLabelEditable permissionLabelLimited permissionLabelLocked permissionLabelProtected permissionLabelPrivate">
<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-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="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>
</span>
<br>
<span class="ui-owner" style="display: none;">
&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>
</small>
</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>
</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 -->
<div class="modal fade" id="clipboardModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">

View File

@ -8,7 +8,10 @@
<div class="visible-lg">&nbsp;</div>
</div>
<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>
<ul class="dropdown-menu list" role="menu" aria-labelledby="menu">
</ul>
@ -109,7 +112,9 @@
<ul class="nav navbar-nav navbar-right">
<li id="online-user-list">
<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>
<ul class="dropdown-menu list" role="menu" aria-labelledby="menu" style="right: 15px;width: 200px;">
</ul>