-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path文本收藏夹.js
75 lines (71 loc) · 1.43 KB
/
文本收藏夹.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$ui.render({
props: {
title: "Clips"
},
views: [
{
type: "input",
props: {
placeholder: "Type text here..."
},
layout: function(make) {
make.top.left.right.inset(10);
make.height.equalTo(32);
},
events: {
returned: function(sender) {
insertItem(sender.text);
sender.blur();
sender.text = "";
}
}
},
{
type: "list",
props: {
id: "list",
actions: [
{
title: "delete",
handler: function(sender, indexPath) {
deleteItem(indexPath);
}
}
]
},
layout: function(make) {
make.left.bottom.right.equalTo(0);
make.top.equalTo($("input").bottom).offset(10);
},
events: {
didSelect: function(sender, indexPath, title) {
$clipboard.text = title;
$device.taptic();
$ui.toast("Copied");
}
}
}
]
});
var listView = $("list");
var clips = $cache.get("clips") || [];
listView.data = clips;
function insertItem(text) {
clips.unshift(text);
listView.insert({
index: 0,
value: text
});
saveItems();
}
function deleteItem(indexPath) {
var text = clips[indexPath.row];
var index = clips.indexOf(text);
if (index >= 0) {
clips.splice(index, 1);
saveItems();
}
}
function saveItems() {
$cache.set("clips", clips);
}