-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBoom.js
114 lines (107 loc) · 2.17 KB
/
Boom.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
$app.strings = {
"en": {
"MAIN_TITLE": "Clips",
"PLACEHOLDER": "Please input text here",
"COPIED": "Copied"
},
"zh-Hans": {
"MAIN_TITLE": "文本收藏夹",
"PLACEHOLDER": "输入要收藏的内容",
"COPIED": "已复制"
}
}
var clips = $cache.get("clips") || []
if ($app.env == $env.today) {
$ui.menu({
items: clips,
handler: function(title, idx) {
$clipboard.copy({
text: title,
locally:true,
ttl: 300
})
$device.taptic()
$ui.toast($l10n("COPIED"))
}
})
return
}
$ui.render({
props: {
title: $l10n("MAIN_TITLE")
},
views: [
{
type: "input",
props: {
placeholder: $l10n("PLACEHOLDER")
},
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",
reorder: true,
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.copy({
text: title,
locally:true,
ttl: 300
})
$device.taptic()
$ui.toast($l10n("COPIED"))
},
reorderMoved: function(from, to) {
clips.move(from.row, to.row)
},
reorderFinished: function() {
saveItems()
}
}
}
]
})
var listView = $("list")
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)
}