-
Notifications
You must be signed in to change notification settings - Fork 33
/
bookmarks.go
128 lines (104 loc) · 4.73 KB
/
bookmarks.go
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package chrome
import "github.com/gopherjs/gopherjs/js"
type Bookmarks struct {
o *js.Object
}
/*
* Types
*/
type BookmarkTreeNode struct {
*js.Object
Id string `js:"id"`
ParentId string `js:"parentId"`
Index int `js:"index"`
Url string `js:"url"`
Title string `js:"title"`
DateAdded int64 `js:"dateAdded"`
DateGroupModified int64 `js:"dateGroupModified"`
Unmodifiable string `js:"unmodifiable"`
Children []BookmarkTreeNode `js:"children"`
}
/*
* Methods:
*/
// Get retrieves the specified BookmarkTreeNode(s).
func (b *Bookmarks) Get(idList []string, callback func(results []BookmarkTreeNode)) {
b.o.Call("get", idList, callback)
}
// GetChildren retrieves the children of the specified BookmarkTreeNode id.
func (b *Bookmarks) GetChildren(id string, callback func(results []BookmarkTreeNode)) {
b.o.Call("getChildren", id, callback)
}
// GetRecent retrieves the recently added bookmarks.
func (b *Bookmarks) GetRecent(numberOfItems int, callback func(results []BookmarkTreeNode)) {
b.o.Call("getRecent", numberOfItems, callback)
}
// GetTree retrieves the entire Bookmarks hierarchy.
func (b *Bookmarks) GetTree(callback func(results []BookmarkTreeNode)) {
b.o.Call("getTree", callback)
}
// GetSubTree retrieves part of the Bookmarks hierarchy, starting at the specified node.
func (b *Bookmarks) GetSubTree(id string, callback func(results []BookmarkTreeNode)) {
b.o.Call("getSubTree", id, callback)
}
// Search searches for BookmarkTreeNodes matching the given query. Queries specified
// with an object produce BookmarkTreeNodes matching all specified properties.
func (b *Bookmarks) Search(query interface{}, callback func(results []BookmarkTreeNode)) {
b.o.Call("search", query, callback)
}
// Create creates a bookmark or folder under the specified parentId.
// If url is nil or missing, it will be a folder.
func (b *Bookmarks) Create(bookmark Object, callback func(result BookmarkTreeNode)) {
b.o.Call("create", bookmark, callback)
}
// Move moves the specified BookmarkTreeNode to the provided location.
func (b *Bookmarks) Move(id string, destination Object, callback func(result BookmarkTreeNode)) {
b.o.Call("move", id, destination, callback)
}
// Update updates the properties of a bookmark or folder. Specify only the properties that you want
// to change; unspecified properties will be left unchanged. Note: Currently, only 'title' and 'url' are supported.
func (b *Bookmarks) Update(id string, changes Object, callback func(result BookmarkTreeNode)) {
b.o.Call("update", id, changes, callback)
}
// Remove removes a bookmark or an empty bookmark folder.
func (b *Bookmarks) Remove(id string, callback func()) {
b.o.Call("remove", id, callback)
}
// RemoveTree recursively removes a bookmark folder.
func (b *Bookmarks) RemoveTree(id string, callback func()) {
b.o.Call("removeTree", id, callback)
}
/*
* Events
*/
// OnCreated fired when a bookmark or folder is created.
func (b *Bookmarks) OnCreated(callback func(id string, bookmark BookmarkTreeNode)) {
b.o.Get("onCreated").Call("addListener", callback)
}
// OnRemoved fired when a bookmark or folder is removed. When a folder is removed recursively,
// a single notification is fired for the folder, and none for its contents.
func (b *Bookmarks) OnRemoved(callback func(id string, removeInfo Object)) {
b.o.Get("onRemoved").Call("addListener", callback)
}
// onChanged fired when a bookmark or folder changes. Note: Currently, only title and url changes trigger this.
func (b *Bookmarks) onChanged(callback func(id string, changeInfo Object)) {
b.o.Get("onChanged").Call("addListener", callback)
}
// OnMoved fired when a bookmark or folder is moved to a different parent folder.
func (b *Bookmarks) OnMoved(callback func(id string, moveInfo Object)) {
b.o.Get("onMoved").Call("addListener", callback)
}
// OnChildrenReordered fired when the children of a folder have changed their order due to
// the order being sorted in the UI. This is not called as a result of a move().
func (b *Bookmarks) OnChildrenReordered(callback func(id string, reorderInfo Object)) {
b.o.Get("onChildrenReordered").Call("addListener", callback)
}
// OnImportBegan fired when a bookmark import session is begun. Expensive observers should ignore
// onCreated updates until onImportEnded is fired. Observers should still handle other notifications immediately.
func (b *Bookmarks) OnImportBegan(callback func()) {
b.o.Get("onImportBegan").Call("addListener", callback)
}
// OnImportEnded fired when a bookmark import session is ended.
func (b *Bookmarks) OnImportEnded(callback func()) {
b.o.Get("onImportEnded").Call("addListener", callback)
}