forked from ayamomiji/bookmark-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_page.coffee
151 lines (123 loc) · 4.89 KB
/
options_page.coffee
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
jQuery ($) ->
tmpl = $('#option-tmpl')
$('#width')
.val(options.width)
.bind 'change keypress mousewheel', ->
delay => localStorage.width = parseInt(this.value)
$('#height')
.val(options.height)
.bind 'change keypress mousewheel', ->
delay => localStorage.height = parseInt(this.value)
updateFont = ->
font = JSON.parse(localStorage.font || '{}')
font.fontFace = $('#font-face').val()
font.fontSize = $('#font-size').val()
localStorage.font = JSON.stringify(font)
$('#font-face')
.val(options.font.fontFace)
.bind 'change keypress', ->
delay -> updateFont()
$('#font-size')
.val(options.font.fontSize)
.bind 'change keypress', ->
delay -> updateFont()
chrome.bookmarks.getTree (nodes) ->
rootDirectory = $('#root-directory')
while node = nodes.pop()
if node.children
nodes.push(child) for child in node.children if node.children
node.title = '(root)' if node.id == '0'
rootDirectory.append tmpl.tmpl(value: node.id, title: node.title)
$('#root-directory')
.val(options.rootDirectory)
.change ->
delay => localStorage.rootDirectory = this.value
$('#remember-opened-directory')
.attr('checked', options.rememberOpenedDirectory)
.change ->
delay => localStorage.rememberOpenedDirectory = this.checked
updateBookmarkBehaviors = ->
behaviors = JSON.parse(localStorage.behaviors || '{}')
behaviors.bookmark =
left: $('#behaviors-bookmark-left').val()
middle: $('#behaviors-bookmark-middle').val()
right: $('#behaviors-bookmark-right').val()
localStorage.behaviors = JSON.stringify(behaviors)
$('#behaviors-bookmark-left')
.val(options.behaviors.bookmark.left)
.change(updateBookmarkBehaviors)
$('#behaviors-bookmark-middle')
.val(options.behaviors.bookmark.middle)
.change(updateBookmarkBehaviors)
$('#behaviors-bookmark-right')
.val(options.behaviors.bookmark.right)
.change(updateBookmarkBehaviors)
updateDirectoryBehaviors = ->
behaviors = JSON.parse(localStorage.behaviors || '{}')
behaviors.directory =
left: $('#behaviors-directory-left').val()
middle: $('#behaviors-directory-middle').val()
right: $('#behaviors-directory-right').val()
localStorage.behaviors = JSON.stringify(behaviors)
$('#behaviors-directory-left')
.val(options.behaviors.directory.left)
.change(updateDirectoryBehaviors)
$('#behaviors-directory-middle')
.val(options.behaviors.directory.middle)
.change(updateDirectoryBehaviors)
$('#behaviors-directory-right')
.val(options.behaviors.directory.right)
.change(updateDirectoryBehaviors)
$('#custom-style')
.val(options.customStyle)
.bind 'change keypress mousewheel', ->
delay => localStorage.customStyle = this.value
keys = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
[0...keys.length].forEach (i) ->
$('#open-bookmark-tree-in-new-tab-key').append tmpl.tmpl
value: keys.charAt(i).toLowerCase()
title: keys.charAt(i)
$('#open-bookmark-tree-in-new-window-key').append tmpl.tmpl
value: keys.charAt(i).toLowerCase()
title: keys.charAt(i)
updateShortcuts = ->
shortcuts = JSON.parse(localStorage.shortcuts || '{}')
shortcuts.disable = $('#disable-shortcuts').attr('checked')
shortcuts.openBookmarkTreeInNewTab =
modifier: $('#open-bookmark-tree-in-new-tab-modifier').val()
key: $('#open-bookmark-tree-in-new-tab-key').val()
shortcuts.openBookmarkTreeInNewWindow =
modifier: $('#open-bookmark-tree-in-new-window-modifier').val()
key: $('#open-bookmark-tree-in-new-window-key').val()
localStorage.shortcuts = JSON.stringify(shortcuts)
$('#disable-shortcuts')
.attr('checked', !!options.shortcuts.disable)
.change(updateShortcuts)
$('#open-bookmark-tree-in-new-tab-modifier')
.val(options.shortcuts.openBookmarkTreeInNewTab.modifier)
.change(updateShortcuts)
$('#open-bookmark-tree-in-new-tab-key')
.val(options.shortcuts.openBookmarkTreeInNewTab.key)
.change(updateShortcuts)
$('#open-bookmark-tree-in-new-window-modifier')
.val(options.shortcuts.openBookmarkTreeInNewWindow.modifier)
.change(updateShortcuts)
$('#open-bookmark-tree-in-new-window-key')
.val(options.shortcuts.openBookmarkTreeInNewWindow.key)
.change(updateShortcuts)
$('#hide-scrollbar')
.attr('checked', options.hideScrollbar)
.change ->
delay => localStorage.hideScrollbar = this.checked
$('#close-popup-after-open-bookmark')
.attr('checked', options.closePopupAfterOpenBookmark)
.change ->
delay => localStorage.closePopupAfterOpenBookmark = this.checked
$('#move-directories-to-list-top')
.attr('checked', options.moveDirectoriesToListTop)
.change ->
delay => localStorage.moveDirectoriesToListTop = this.checked
$('#sort-by')
.val(options.sortBy)
.change ->
delay => localStorage.sortBy = this.value