mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-28 09:52:01 +08:00
opt js
This commit is contained in:
parent
f7c15360c5
commit
87dd24f4b8
@ -55,5 +55,7 @@ fun hello world "" "" \
|
|||||||
public \
|
public \
|
||||||
text "" \
|
text "" \
|
||||||
button "执行"
|
button "执行"
|
||||||
|
|
||||||
copy pwd
|
copy pwd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
function Page(page) {
|
function Meta(target, obj) {
|
||||||
|
var a = obj
|
||||||
|
for (var i = 2; i < arguments.length; i++) {
|
||||||
|
a.__proto__ = arguments[i], a = arguments[i]
|
||||||
|
}
|
||||||
|
|
||||||
var id = 1
|
var id = 1
|
||||||
var conf = {}, conf_cb = {}
|
var conf = {}, conf_cb = {}
|
||||||
var sync = {}
|
var sync = {}
|
||||||
page.__proto__ = {
|
return {
|
||||||
__proto__: kit,
|
__proto__: obj,
|
||||||
|
Target: target,
|
||||||
ID: function() {
|
ID: function() {
|
||||||
return id++
|
return id++
|
||||||
},
|
},
|
||||||
@ -19,7 +25,7 @@ function Page(page) {
|
|||||||
conf[key] = value
|
conf[key] = value
|
||||||
conf_cb[key] && conf_cb[key](value, old)
|
conf_cb[key] && conf_cb[key](value, old)
|
||||||
}
|
}
|
||||||
return conf[key]
|
return conf[key] == undefined && obj && obj.Conf? obj.Conf(key): conf[key]
|
||||||
},
|
},
|
||||||
Sync: function(m) {
|
Sync: function(m) {
|
||||||
var meta = m, data = "", list = []
|
var meta = m, data = "", list = []
|
||||||
@ -53,7 +59,7 @@ function Page(page) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
View: function(parent, type, line, key, cb) {
|
View: function(output, type, line, key, cb) {
|
||||||
var text = line, list = [], ui = {}
|
var text = line, list = [], ui = {}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "icon":
|
case "icon":
|
||||||
@ -98,20 +104,27 @@ function Page(page) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var item = []
|
var item = []
|
||||||
parent.DisplayUser && item.push({view: ["user", "div", line.create_nick||line.create_user]})
|
output.DisplayUser && item.push({view: ["user", "div", line.create_nick||line.create_user]})
|
||||||
parent.DisplayTime && (item.push({text: [line.create_time, "div", "time"]}))
|
output.DisplayTime && (item.push({text: [line.create_time, "div", "time"]}))
|
||||||
item.push({view: ["text"], list:list})
|
item.push({view: ["text"], list:list})
|
||||||
|
|
||||||
!parent.DisplayRaw && (list = [{view: ["item"], list:item}])
|
!output.DisplayRaw && (list = [{view: ["item"], list:item}])
|
||||||
ui = kit.AppendChild(parent, list)
|
ui = kit.AppendChild(output, list)
|
||||||
ui.field && (ui.field.Meta = text)
|
ui.field && (ui.field.Meta = text)
|
||||||
return ui
|
return ui
|
||||||
},
|
},
|
||||||
Include: function(src, cb) {
|
Include: function(src, cb) {
|
||||||
kit.AppendChild(document.body, [{include: [src[0], function(event) {
|
typeof src == "string" && (src = [src])
|
||||||
|
kit.AppendChild(target, [{include: [src[0], function(event) {
|
||||||
src.length == 1? cb(event): page.Include(src.slice(1), cb)
|
src.length == 1? cb(event): page.Include(src.slice(1), cb)
|
||||||
}]}])
|
}]}])
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Page(page) {
|
||||||
|
page = Meta(document.body, page, {
|
||||||
|
__proto__: kit,
|
||||||
ontoast: function(text, title, duration) {
|
ontoast: function(text, title, duration) {
|
||||||
var args = typeof text == "object"? text: {text: text, title: title, duration: duration}
|
var args = typeof text == "object"? text: {text: text, title: title, duration: duration}
|
||||||
var toast = kit.ModifyView("fieldset.toast", {
|
var toast = kit.ModifyView("fieldset.toast", {
|
||||||
@ -165,17 +178,6 @@ function Page(page) {
|
|||||||
page.toast = toast
|
page.toast = toast
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
ondebug: function() {
|
|
||||||
if (!this.debug) {
|
|
||||||
var pane = Pane(page)
|
|
||||||
pane.Field.style.position = "absolute"
|
|
||||||
pane.Field.style["background-color"] = "#ffffff00"
|
|
||||||
pane.Field.style["color"] = "red"
|
|
||||||
pane.ShowDialog(400, 400)
|
|
||||||
this.debug = pane
|
|
||||||
}
|
|
||||||
kit.AppendChild(this.debug.Field, [{text: [JSON.stringify(arguments.length==1? arguments[0]: arguments)]}])
|
|
||||||
},
|
|
||||||
oninput: function(event, local) {
|
oninput: function(event, local) {
|
||||||
var target = event.target
|
var target = event.target
|
||||||
kit.History.add("key", (event.ctrlKey? "Control+": "")+(event.shiftKey? "Shift+": "")+event.key)
|
kit.History.add("key", (event.ctrlKey? "Control+": "")+(event.shiftKey? "Shift+": "")+event.key)
|
||||||
@ -391,7 +393,7 @@ function Page(page) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Pane: Pane,
|
Pane: Pane,
|
||||||
}
|
})
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
document.querySelectorAll("body>fieldset").forEach(function(field) {
|
document.querySelectorAll("body>fieldset").forEach(function(field) {
|
||||||
page.Pane(page, field)
|
page.Pane(page, field)
|
||||||
@ -414,6 +416,7 @@ function Page(page) {
|
|||||||
}
|
}
|
||||||
function Pane(page, field) {
|
function Pane(page, field) {
|
||||||
field = field || kit.AppendChild(document.body, [{type: "fieldset", list: [{view: ["option", "form"]}, {view: ["output"]}]}]).last
|
field = field || kit.AppendChild(document.body, [{type: "fieldset", list: [{view: ["option", "form"]}, {view: ["output"]}]}]).last
|
||||||
|
|
||||||
var option = field.querySelector("form.option")
|
var option = field.querySelector("form.option")
|
||||||
var action = field.querySelector("div.action")
|
var action = field.querySelector("div.action")
|
||||||
var output = field.querySelector("div.output")
|
var output = field.querySelector("div.output")
|
||||||
@ -421,25 +424,10 @@ function Pane(page, field) {
|
|||||||
var cache = []
|
var cache = []
|
||||||
var timer = ""
|
var timer = ""
|
||||||
var list = [], last = -1
|
var list = [], last = -1
|
||||||
var conf = {}, conf_cb = {}
|
|
||||||
var name = option.dataset.name
|
var name = option.dataset.name
|
||||||
var pane = (page[field.dataset.init] || function() {
|
var pane = Meta(field, (page[field.dataset.init] || function() {
|
||||||
})(page, field, option, output) || {}; pane.__proto__ = {
|
})(page, field, option, output) || {}, {
|
||||||
__proto__: page,
|
__proto__: page,
|
||||||
Conf: function(key, value, cb) {
|
|
||||||
if (key == undefined) {
|
|
||||||
return conf
|
|
||||||
}
|
|
||||||
if (cb != undefined) {
|
|
||||||
conf_cb[key] = cb
|
|
||||||
}
|
|
||||||
if (value != undefined) {
|
|
||||||
var old = conf[key]
|
|
||||||
conf[key] = value
|
|
||||||
conf_cb[key] && conf_cb[key](value, old)
|
|
||||||
}
|
|
||||||
return conf[key]
|
|
||||||
},
|
|
||||||
ShowDialog: function(width, height) {
|
ShowDialog: function(width, height) {
|
||||||
if (field.style.display != "block") {
|
if (field.style.display != "block") {
|
||||||
page.dialog && page.dialog != field && page.dialog.style.display == "block" && page.dialog.Show()
|
page.dialog && page.dialog != field && page.dialog.style.display == "block" && page.dialog.Show()
|
||||||
@ -455,8 +443,8 @@ function Pane(page, field) {
|
|||||||
field.style.width = width+"px"
|
field.style.width = width+"px"
|
||||||
field.style.height = height+"px"
|
field.style.height = height+"px"
|
||||||
},
|
},
|
||||||
View: function(parent, type, line, key, cb) {
|
Views: function(output, type, line, key, cb) {
|
||||||
var ui = page.View(parent, type, line, key, cb)
|
var ui = page.View(output, type, line, key, cb)
|
||||||
if (type == "plugin" || type == "field") {
|
if (type == "plugin" || type == "field") {
|
||||||
pane.Plugin(page, pane, ui.field)
|
pane.Plugin(page, pane, ui.field)
|
||||||
}
|
}
|
||||||
@ -500,7 +488,7 @@ function Pane(page, field) {
|
|||||||
last = index, list[index] && (list[index].className = "item select")
|
last = index, list[index] && (list[index].className = "item select")
|
||||||
},
|
},
|
||||||
Append: function(type, line, key, which, cb) {
|
Append: function(type, line, key, which, cb) {
|
||||||
var index = list.length, ui = pane.View(output, line.type || type, line, key, function(event, cmds, cbs) {
|
var index = list.length, ui = pane.Views(output, line.type || type, line, key, function(event, cmds, cbs) {
|
||||||
pane.Select(index), pane.which.set(line[which])
|
pane.Select(index), pane.which.set(line[which])
|
||||||
typeof cb == "function" && cb(line, index, event, cmds, cbs)
|
typeof cb == "function" && cb(line, index, event, cmds, cbs)
|
||||||
})
|
})
|
||||||
@ -550,7 +538,7 @@ function Pane(page, field) {
|
|||||||
},
|
},
|
||||||
which: page.Sync(name), Listen: {},
|
which: page.Sync(name), Listen: {},
|
||||||
Action: {}, Button: [], Plugin: Plugin,
|
Action: {}, Button: [], Plugin: Plugin,
|
||||||
}
|
})
|
||||||
|
|
||||||
for (var k in pane.Listen) {
|
for (var k in pane.Listen) {
|
||||||
page.Sync(k).change(pane.Listen[k])
|
page.Sync(k).change(pane.Listen[k])
|
||||||
@ -563,6 +551,7 @@ function Pane(page, field) {
|
|||||||
typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
|
typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
|
||||||
}]}
|
}]}
|
||||||
})).className="action "+name)
|
})).className="action "+name)
|
||||||
|
|
||||||
option.onsubmit = function(event) {
|
option.onsubmit = function(event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
};
|
};
|
||||||
@ -573,7 +562,7 @@ function Plugin(page, pane, field) {
|
|||||||
var output = field.querySelector("div.output")
|
var output = field.querySelector("div.output")
|
||||||
|
|
||||||
var count = 0
|
var count = 0
|
||||||
var plugin = field.Script || {}; plugin.__proto__ = {
|
var plugin = Meta(field, field.Script || {}, {
|
||||||
__proto__: pane,
|
__proto__: pane,
|
||||||
Append: function(item, name) {
|
Append: function(item, name) {
|
||||||
name = item.name || "input"
|
name = item.name || "input"
|
||||||
@ -721,7 +710,7 @@ function Plugin(page, pane, field) {
|
|||||||
field.Meta.args = kit.Selector(option, "input.args", function(item, index) {
|
field.Meta.args = kit.Selector(option, "input.args", function(item, index) {
|
||||||
return item.value
|
return item.value
|
||||||
})
|
})
|
||||||
return pane.View(field.parentNode, "plugin", field.Meta, [], field.Run).field.Plugin
|
return pane.Views(field.parentNode, "plugin", field.Meta, [], field.Run).field.Plugin
|
||||||
},
|
},
|
||||||
Share: function() {
|
Share: function() {
|
||||||
location.href
|
location.href
|
||||||
@ -845,7 +834,7 @@ function Plugin(page, pane, field) {
|
|||||||
plugin.ondaemon[display.deal||"table"](plugin.msg)
|
plugin.ondaemon[display.deal||"table"](plugin.msg)
|
||||||
},
|
},
|
||||||
init: function() {},
|
init: function() {},
|
||||||
}
|
})
|
||||||
|
|
||||||
var meta = field.Meta
|
var meta = field.Meta
|
||||||
var args = meta.args || []
|
var args = meta.args || []
|
||||||
@ -856,6 +845,9 @@ function Plugin(page, pane, field) {
|
|||||||
plugin.init(page, pane, plugin, field, option, output)
|
plugin.init(page, pane, plugin, field, option, output)
|
||||||
return page[field.id] = pane[field.id] = plugin.Field = field, field.Plugin = plugin
|
return page[field.id] = pane[field.id] = plugin.Field = field, field.Plugin = plugin
|
||||||
}
|
}
|
||||||
|
function Action(pane, pane, plugin, item) {
|
||||||
|
}
|
||||||
|
|
||||||
function Editor(plugin, option, output, width, height, space, msg) {
|
function Editor(plugin, option, output, width, height, space, msg) {
|
||||||
exports = ["dir", "path", "dir"]
|
exports = ["dir", "path", "dir"]
|
||||||
msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
|
msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user