forked from x/ContextOS
opt js
This commit is contained in:
parent
d72d769efb
commit
b65bacaf72
@ -2298,29 +2298,25 @@ var CGI = template.FuncMap{
|
||||
}
|
||||
|
||||
cli := Pulse.Sess("cli")
|
||||
cli.Cmd("source", strings.Join(Trans(arg), " "))
|
||||
cmd := strings.Join(Trans(arg), " ")
|
||||
cli.Cmd("source", cmd)
|
||||
|
||||
result := []string{}
|
||||
if len(cli.Meta["append"]) > 0 {
|
||||
result = append(result, "<table>")
|
||||
result = append(result, "<caption>")
|
||||
result = append(result, Trans(arg)...)
|
||||
result = append(result, "</caption>")
|
||||
result = append(result, "<caption>", cmd, "</caption>")
|
||||
cli.Table(func(maps map[string]string, list []string, line int) bool {
|
||||
if line == -1 {
|
||||
result = append(result, "<tr>")
|
||||
for _, v := range list {
|
||||
result = append(result, "<th>")
|
||||
result = append(result, v)
|
||||
result = append(result, "</th>")
|
||||
result = append(result, "<th>", v, "</th>")
|
||||
}
|
||||
result = append(result, "</tr>")
|
||||
return true
|
||||
}
|
||||
result = append(result, "<tr>")
|
||||
for _, v := range list {
|
||||
result = append(result, "<td>")
|
||||
result = append(result, v)
|
||||
result = append(result, "</td>")
|
||||
result = append(result, "<td>", v, "</td>")
|
||||
}
|
||||
result = append(result, "</tr>")
|
||||
return true
|
||||
@ -2328,12 +2324,9 @@ var CGI = template.FuncMap{
|
||||
result = append(result, "</table>")
|
||||
} else {
|
||||
result = append(result, "<pre><code>")
|
||||
result = append(result, fmt.Sprintf("%s", cli.Find("shy", false).Conf("prompt")))
|
||||
result = append(result, Trans(arg)...)
|
||||
result = append(result, "\n")
|
||||
result = append(result, fmt.Sprintf("%s", cli.Find("shy", false).Conf("prompt")), cmd, "\n")
|
||||
result = append(result, cli.Meta["result"]...)
|
||||
result = append(result, "</code></pre>")
|
||||
|
||||
}
|
||||
|
||||
return template.HTML(strings.Join(result, ""))
|
||||
|
@ -36,11 +36,15 @@ function save_clipboard(item) {
|
||||
alert("保存成功")
|
||||
})
|
||||
}
|
||||
function copy_to_clipboard(text, skip_docker) {
|
||||
function copy_to_clipboard(text, skip_blur, skip_docker) {
|
||||
var clipboard = modify_node(".clipboard", {"value": text})
|
||||
clipboard.select()
|
||||
document.execCommand("copy")
|
||||
clipboard.blur()
|
||||
if (skip_blur) {
|
||||
document.execCommand("copy")
|
||||
} else {
|
||||
clipboard.select()
|
||||
document.execCommand("copy")
|
||||
clipboard.blur()
|
||||
}
|
||||
|
||||
var clipstack = document.querySelector("#clipstack")
|
||||
insert_child(clipstack, "option").value = text
|
||||
@ -62,12 +66,13 @@ function copy_to_clipboard(text, skip_docker) {
|
||||
target.parentElement.removeChild(target)
|
||||
return
|
||||
}
|
||||
|
||||
if (event.shiftKey) {
|
||||
var cmd = document.querySelector("form.option.command"+code.current_cmd+" input[name=cmd]")
|
||||
cmd && (cmd.value += " "+text)
|
||||
return
|
||||
}
|
||||
copy_to_clipboard(text, true)
|
||||
copy_to_clipboard(text, false, true)
|
||||
},
|
||||
})
|
||||
}
|
||||
@ -99,10 +104,16 @@ function add_sort(append, field, cb) {
|
||||
if (tr.childNodes[i].innerText.startsWith(field)) {
|
||||
typeof cb == "function" && cb(event)
|
||||
}
|
||||
var has = document.querySelector("td.clip")
|
||||
has && (has.className = "")
|
||||
target.className = "clip"
|
||||
copy_to_clipboard(target.innerText, !event.shiftKey)
|
||||
|
||||
var text = window.getSelection().toString()
|
||||
if (!text) {
|
||||
var has = document.querySelector("td.clip")
|
||||
has && (has.className = "")
|
||||
target.className = "clip"
|
||||
text = target.innerText
|
||||
}
|
||||
|
||||
copy_to_clipboard(text, true, !event.shiftKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -582,7 +593,10 @@ function init_append(event) {
|
||||
function init_result(event) {
|
||||
var result = document.querySelectorAll("code.result pre").forEach(function(item) {
|
||||
item.onclick = function(event) {
|
||||
// copy_to_clipboard(event.target.innerText)
|
||||
var text = window.getSelection().toString()
|
||||
if (text) {
|
||||
copy_to_clipboard(text, true, !event.shiftKey)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -131,6 +131,42 @@ context = {
|
||||
context.isMobile = navigator.userAgent.indexOf("Mobile") > -1
|
||||
context.scroll_by = window.innerHeight/2
|
||||
|
||||
function right(arg) {
|
||||
if (arg == "true") {
|
||||
return true
|
||||
}
|
||||
if (arg == "false") {
|
||||
return false
|
||||
}
|
||||
if (arg) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
function format_date(arg) {
|
||||
var date = arg.getDate()
|
||||
if (date < 10) {
|
||||
date = "0"+date
|
||||
}
|
||||
var month = arg.getMonth()+1
|
||||
if (month < 10) {
|
||||
month = "0"+month
|
||||
}
|
||||
var hour = arg.getHours()
|
||||
if (hour < 10) {
|
||||
hour = "0"+hour
|
||||
}
|
||||
var minute = arg.getMinutes()
|
||||
if (minute < 10) {
|
||||
minute = "0"+minute
|
||||
}
|
||||
var second = arg.getSeconds()
|
||||
if (second < 10) {
|
||||
second = "0"+second
|
||||
}
|
||||
return arg.getFullYear()+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
|
||||
}
|
||||
|
||||
function modify_node(which, html) {
|
||||
var node = which
|
||||
if (typeof which == "string") {
|
||||
@ -174,42 +210,6 @@ function insert_button(which, value, callback) {
|
||||
"type": "button", "value": value, "onclick": callback,
|
||||
})
|
||||
}
|
||||
function right(arg) {
|
||||
if (arg == "true") {
|
||||
return true
|
||||
}
|
||||
if (arg == "false") {
|
||||
return false
|
||||
}
|
||||
if (arg) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function format_date(arg) {
|
||||
var date = arg.getDate()
|
||||
if (date < 10) {
|
||||
date = "0"+date
|
||||
}
|
||||
var month = arg.getMonth()+1
|
||||
if (month < 10) {
|
||||
month = "0"+month
|
||||
}
|
||||
var hour = arg.getHours()
|
||||
if (hour < 10) {
|
||||
hour = "0"+hour
|
||||
}
|
||||
var minute = arg.getMinutes()
|
||||
if (minute < 10) {
|
||||
minute = "0"+minute
|
||||
}
|
||||
var second = arg.getSeconds()
|
||||
if (second < 10) {
|
||||
second = "0"+second
|
||||
}
|
||||
return arg.getFullYear()+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
|
||||
}
|
||||
|
||||
function sort_table(table, index, sort_asc) {
|
||||
var list = table.querySelectorAll("tr")
|
||||
@ -277,4 +277,24 @@ function sort_table(table, index, sort_asc) {
|
||||
}
|
||||
return sort_order
|
||||
}
|
||||
function add_sort(append, field, cb) {
|
||||
append.onclick = function(event) {
|
||||
var target = event.target
|
||||
var dataset = target.dataset
|
||||
var nodes = target.parentElement.childNodes
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (nodes[i] == target) {
|
||||
if (target.tagName == "TH") {
|
||||
dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1
|
||||
sort_table(append, i, dataset["sort_asc"] == "1")
|
||||
} else if (target.tagName == "TD") {
|
||||
var tr = target.parentElement.parentElement.querySelector("tr")
|
||||
if (tr.childNodes[i].innerText.startsWith(field)) {
|
||||
typeof cb == "function" && cb(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,34 @@
|
||||
var wiki = {
|
||||
layout: {
|
||||
header: {
|
||||
height: 40,
|
||||
},
|
||||
nav: {
|
||||
min_width: 240,
|
||||
},
|
||||
article: {
|
||||
padding: 20,
|
||||
},
|
||||
footer: {
|
||||
height: 40,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
function set_layout() {
|
||||
var nav = document.querySelector("nav")
|
||||
var article = document.querySelector("article")
|
||||
|
||||
if (window.innerWidth > 600) {
|
||||
nav.className = "fixed"
|
||||
wiki.layout.article.width = window.innerWidth - nav.offsetWidth- 2*wiki.layout.article.padding
|
||||
article.style.width = wiki.layout.article.width+"px"
|
||||
} else {
|
||||
nav.className = ""
|
||||
article.style.width = ""
|
||||
}
|
||||
}
|
||||
|
||||
function action(event, cmd) {
|
||||
switch (cmd) {
|
||||
case "toggle_nav":
|
||||
@ -6,20 +37,31 @@ function action(event, cmd) {
|
||||
set_layout(event)
|
||||
break
|
||||
case "toggle_list":
|
||||
var list = document.querySelector(".list")
|
||||
var list = event.target.nextElementSibling
|
||||
list.hidden = !list.hidden
|
||||
break
|
||||
case "toggle_menu":
|
||||
var menu = document.querySelector(".menu")
|
||||
menu.hidden = !menu.hidden
|
||||
break
|
||||
case "toggle_link":
|
||||
var link = document.querySelector(".link")
|
||||
link.hidden = !link.hidden
|
||||
break
|
||||
}
|
||||
}
|
||||
function init_layout() {
|
||||
var header = document.querySelector("header")
|
||||
var nav = document.querySelector("nav")
|
||||
var article = document.querySelector("article")
|
||||
var footer = document.querySelector("footer")
|
||||
|
||||
wiki.layout.nav.height = window.innerHeight - wiki.layout.header.height - wiki.layout.footer.height
|
||||
wiki.layout.article.min_height = window.innerHeight - wiki.layout.header.height - wiki.layout.footer.height - 2*wiki.layout.article.padding
|
||||
|
||||
header.style.height = wiki.layout.header.height+"px"
|
||||
footer.style.height = wiki.layout.footer.height+"px"
|
||||
nav.style.height = wiki.layout.nav.height+"px"
|
||||
nav.style.minWidth = wiki.layout.nav.min_width+"px"
|
||||
nav.style.marginTop = wiki.layout.header.height+"px"
|
||||
article.style.minHeight = wiki.layout.article.min_height+"px"
|
||||
article.style.marginTop = wiki.layout.header.height+"px"
|
||||
article.style.padding = wiki.layout.article.padding+"px"
|
||||
|
||||
set_layout()
|
||||
}
|
||||
function init_menu() {
|
||||
var max = 0;
|
||||
var min = 1000;
|
||||
@ -96,35 +138,22 @@ function init_menu() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init_link() {
|
||||
var link = [];
|
||||
var a = document.querySelectorAll(".text a");
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
link.push({href: a[i].href, title: a[i].innerText});
|
||||
}
|
||||
var m = document.getElementsByClassName("link");
|
||||
for (var i = 0; i < m.length; i++) {
|
||||
var one = append_child(m[i], "li")
|
||||
var a = one.appendChild(document.createTextNode("相关链接: "));
|
||||
|
||||
for (var j = 0; j < link.length; j++) {
|
||||
var one = append_child(m[i], "li")
|
||||
var a = one.appendChild(document.createTextNode(link[j].title+": "));
|
||||
var a = append_child(one, "a");
|
||||
a.href = link[j].href
|
||||
a.innerText = a.href
|
||||
}
|
||||
}
|
||||
var link = document.querySelector("nav .link");
|
||||
document.querySelectorAll("article a").forEach(function(item) {
|
||||
append_child(append_child(link, "li", {"innertText": item.innerText}), "a", {
|
||||
"href": item.href,
|
||||
"innerText": item.href,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function init_code() {
|
||||
var fuck = context.isMobile? 22: 16
|
||||
var m = document.getElementsByTagName("pre");
|
||||
for (var i = 0; i < m.length; i++) {
|
||||
var nu = insert_before(m[i], "div", {"className": "number1"})
|
||||
|
||||
var line = (m[i].clientHeight-10)/fuck
|
||||
document.querySelectorAll("article pre").forEach(function(item, i) {
|
||||
var nu = insert_before(item, "div", {"className": "number1"})
|
||||
|
||||
var line = (item.clientHeight-10)/fuck
|
||||
for (var j = 1; j <= line; j++) {
|
||||
append_child(nu, "div", {
|
||||
"style": {
|
||||
@ -137,54 +166,23 @@ function init_code() {
|
||||
},
|
||||
}).appendChild(document.createTextNode(""+j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function add_sort(append, field, cb) {
|
||||
append.onclick = function(event) {
|
||||
var target = event.target
|
||||
var dataset = target.dataset
|
||||
var nodes = target.parentElement.childNodes
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (nodes[i] == target) {
|
||||
if (target.tagName == "TH") {
|
||||
dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1
|
||||
sort_table(append, i, dataset["sort_asc"] == "1")
|
||||
} else if (target.tagName == "TD") {
|
||||
var tr = target.parentElement.parentElement.querySelector("tr")
|
||||
if (tr.childNodes[i].innerText.startsWith(field)) {
|
||||
typeof cb == "function" && cb(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
item.onclick = function(event) {
|
||||
window.getSelection().toString() && document.execCommand("copy")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function init_table(event) {
|
||||
var append = document.querySelectorAll("article table").forEach(add_sort)
|
||||
}
|
||||
|
||||
function set_layout() {
|
||||
article = document.querySelector("article")
|
||||
nav = document.querySelector("nav")
|
||||
if (window.innerWidth > 600) {
|
||||
article.style.maxWidth = (window.innerWidth - nav.offsetWidth-40)+"px"
|
||||
nav.className = "fixed"
|
||||
} else {
|
||||
article.style.maxWidth = ""
|
||||
nav.className = ""
|
||||
}
|
||||
}
|
||||
|
||||
window.onresize = function (event) {
|
||||
set_layout()
|
||||
init_layout()
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
window.onload = function(event) {
|
||||
init_layout()
|
||||
init_menu()
|
||||
init_link()
|
||||
init_code()
|
||||
init_table()
|
||||
set_layout()
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.7">
|
||||
<link rel="shortcut icon" type="image/ico" href="/favicon.ico">
|
||||
<title>code</title>
|
||||
<style>
|
||||
html, body {
|
||||
|
@ -3,13 +3,14 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.7">
|
||||
<link rel="shortcut icon" type="image/ico" href="/favicon.ico">
|
||||
<title>{{option .Meta "page_title"}}</title>
|
||||
<style>
|
||||
html, body {
|
||||
height:100%;
|
||||
width:100%;
|
||||
margin:0px;
|
||||
background-color:#d8d8d8;
|
||||
width:100%;
|
||||
height:100%;
|
||||
margin:0px;
|
||||
}
|
||||
header {
|
||||
color:white;
|
||||
@ -18,7 +19,6 @@ header {
|
||||
text-align:center;
|
||||
background-color:#0747a6;
|
||||
width:100%;
|
||||
height:40px;
|
||||
position:fixed;
|
||||
}
|
||||
header .title {
|
||||
@ -50,13 +50,10 @@ header .search input:focus {
|
||||
}
|
||||
|
||||
nav {
|
||||
min-width:240px;
|
||||
margin-top:40px;
|
||||
overflow:auto;
|
||||
float:left;
|
||||
}
|
||||
nav.fixed {
|
||||
overflow:auto;
|
||||
max-height:calc(100% - 40px);
|
||||
position:fixed;
|
||||
}
|
||||
nav>ul {
|
||||
@ -80,13 +77,11 @@ nav>ul>li>ul>li:hover {
|
||||
nav>ul>li>ul>li>a {
|
||||
text-decoration-line:none;
|
||||
}
|
||||
.mono {
|
||||
nav>ul>li>ul>li .mono {
|
||||
font-family:monospace;
|
||||
}
|
||||
|
||||
article {
|
||||
padding:20px;
|
||||
max-width:calc(100% - 40px);
|
||||
float:right;
|
||||
}
|
||||
article h2 {
|
||||
@ -135,6 +130,7 @@ article pre {
|
||||
padding:5px;
|
||||
border:solid 2px green;
|
||||
border-left:solid 4px green;
|
||||
max-width:800px;
|
||||
margin:0;
|
||||
font-size:14px;
|
||||
line-height:16px;
|
||||
@ -157,12 +153,18 @@ article div.number1 div:hover {
|
||||
}
|
||||
|
||||
footer {
|
||||
height:40px;
|
||||
color:white;
|
||||
font-size:20px;
|
||||
font-family:monospace;
|
||||
text-align:center;
|
||||
background-color:red;
|
||||
text-align:center;
|
||||
vertical-align:middle;
|
||||
clear:both;
|
||||
}
|
||||
footer .title {
|
||||
padding:6px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -172,14 +174,14 @@ footer {
|
||||
<header>
|
||||
<div class="toggle" onclick="action(event, 'toggle_nav')">三</div>
|
||||
<div class="search"><input type="text" placeholder="搜索"></div>
|
||||
<div class="title">shylinux</div>
|
||||
<div class="title">shylinux 天行健,君子以自强不息</div>
|
||||
</header>
|
||||
{{end}}
|
||||
|
||||
{{define "list"}}
|
||||
<nav>
|
||||
<ul>
|
||||
<li><div class="toggle_menu" onclick="action(event, 'toggle_list')">文章</div>
|
||||
<li><div onclick="action(event, 'toggle_list')">文档</div>
|
||||
<ul class="list" hidden>
|
||||
{{range $i, $l := table .}}
|
||||
<li>
|
||||
@ -189,10 +191,10 @@ footer {
|
||||
{{end}}
|
||||
</ul>
|
||||
</li>
|
||||
<li><div class="toggle_menu" onclick="action(event, 'toggle_menu')">目录</div>
|
||||
<li><div onclick="action(event, 'toggle_list')">目录</div>
|
||||
<ul class="menu"></ul>
|
||||
</li>
|
||||
<li><div class="toggle_link" onclick="action(event, 'toggle_link')">参考链接</div>
|
||||
<li><div onclick="action(event, 'toggle_list')">链接</div>
|
||||
<ul class="link" hidden></ul>
|
||||
</li>
|
||||
</ul>
|
||||
@ -204,7 +206,7 @@ footer {
|
||||
{{end}}
|
||||
|
||||
{{define "footer"}}
|
||||
<footer><div>shylinux</div></footer>
|
||||
<footer><div class="title">shycontext 地势坤,君子以厚德载物</div></footer>
|
||||
{{end}}
|
||||
|
||||
{{define "tail"}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user