diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go index a1f8ce70..939bc03b 100644 --- a/src/contexts/ctx/ctx.go +++ b/src/contexts/ctx/ctx.go @@ -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, "
") - result = append(result, v) - result = append(result, " | ") + result = append(result, "", v, " | ") } result = append(result, "
---|---|
") - result = append(result, v) - result = append(result, " | ") + result = append(result, "", v, " | ") } result = append(result, "
")
- 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, "
")
-
}
return template.HTML(strings.Join(result, ""))
diff --git a/usr/librarys/code.js b/usr/librarys/code.js
index 79985e48..a06c2b2d 100644
--- a/usr/librarys/code.js
+++ b/usr/librarys/code.js
@@ -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)
+ }
}
})
}
diff --git a/usr/librarys/context.js b/usr/librarys/context.js
index 78719646..1d3930e7 100644
--- a/usr/librarys/context.js
+++ b/usr/librarys/context.js
@@ -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)
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/usr/librarys/wiki.js b/usr/librarys/wiki.js
index b5734d6b..34bff23c 100644
--- a/usr/librarys/wiki.js
+++ b/usr/librarys/wiki.js
@@ -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()
}
diff --git a/usr/template/code/code.tmpl b/usr/template/code/code.tmpl
index 8d8a2348..ef526446 100644
--- a/usr/template/code/code.tmpl
+++ b/usr/template/code/code.tmpl
@@ -3,6 +3,7 @@
+