-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreferences.html
233 lines (194 loc) · 6.87 KB
/
preferences.html
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Preferences</title>
<link rel="stylesheet" href="css/vendor/photon.min.css">
<style type="text/css">
.preferences-form {
padding: 10px;
}
.toolbar-header {
-webkit-app-region: drag;
padding: 8px;
}
.window {
display: flex;
flex-direction: column;
justify-content: space-between;
background-color: #f5f5f4;
}
.form-control {
border-radius: 0px !important;
padding: 0px 5px !important;
}
.a-color-picker {
border-radius: 0px !important;
box-shadow: none !important;
border: 1px solid #ddd;
}
.a-color-picker-sl {
width: 278px !important;
}
.form-group label {
display: block !important;
}
</style>
</head>
<body>
<div class="window">
<form class="preferences-form">
<div class="form-group">
<label>Branch width</label>
<input data-pref-id="branchWidth" type="number" class="form-control fangorn-preference" placeholder="">
</div>
<div class="form-group">
<label>Default branch color</label>
<input data-pref-id="branchColor" type="hidden" class="form-control fangorn-preference" placeholder="">
<div id="default-branch-color-picker"
acp-color="#cddc39"
acp-show-rgb="no"
acp-show-hsl="no"
acp-show-hex="no">
</div>
</div>
<div class="checkbox">
<label>
<input data-pref-id="displayAlignmentCoverage" type="checkbox" class="fangorn-preference" placeholder="">Show alignment coverage
</label>
</div>
<div class="checkbox">
<label>
<input data-pref-id="displayBootstrap" type="checkbox" class="fangorn-preference" placeholder="">Show bootstrap
</label>
</div>
<div class="form-group">
<label>Taxa label font</label>
<select data-pref-id="taxaFontFamily" class="form-control fangorn-preference" style="width: 30%;">
<option>Serif</option>
<option>Sans-serif</option>
<option>Monospace</option>
</select>
<input data-pref-id="taxaFontSize" type="number" class="form-control fangorn-preference" placeholder="" style="width: 20%;">
<div class="btn-group">
<button data-pref-id="taxaFontBold" class="btn btn-default btn-radio fangorn-preference" type="button" style="font-weight: bold; width: 25px;">
B
</button>
<button data-pref-id="taxaFontItalic" class="btn btn-default btn-radio fangorn-preference" type="button" style="font-style: italic; width: 25px;">
I
</button>
<button data-pref-id="taxaFontUnderline" class="btn btn-default btn-radio fangorn-preference" type="button" style="text-decoration: underline; width: 25px;">
U
</button>
</div>
</div>
</form>
<footer class="toolbar toolbar-footer">
<div class="toolbar-actions">
<button id="cancel-button" type="button" class="btn btn-default">
Cancel
</button>
<button id="save-button" type="button" class="btn btn-primary pull-right">
Save
</button>
</div>
</footer>
</div>
<script src="node_modules/jquery/dist/jquery.js"></script>
<script src="node_modules/a-color-picker/dist/acolorpicker.js"></script>
<script src="js/color_picker.js"></script>
<script type="text/javascript">
function collectPreferences () {
var result = {}
$('.fangorn-preference').each( function () {
var key = $(this).attr('data-pref-id')
if ($(this).attr('type') === 'checkbox'){
result[key] = $(this).is(':checked') ? 'true' : 'false'
} else if ($(this).prop('tagName') === 'SELECT') {
result[key] = $(this).val()
} else if ($(this).attr('type') === 'button') {
result[key] = $(this).hasClass('active') ? 'true' : 'false'
} else {
result[key] = $(this).val()
}
})
return result
}
$(document).ready(function () {
$('.btn-radio').on('click', (e) => {
var el = $(e.target)
if ($(e.target).hasClass('active')) {
el.removeClass('active')
} else {
el.addClass('active')
}
})
var picker = AColorPicker.createPicker('#default-branch-color-picker', { hueBarSize: [150, 11], slBarSize: [280, 50] }).on('change', (picker, color) => {
var hex = AColorPicker.parseColor(color, 'hex')
$('.fangorn-preference[data-pref-id=branchColor]').val(hex)
})
function takeCheckboxValue(pref_id, message) {
var checkbox = $('.fangorn-preference[data-pref-id=' + pref_id + ']')
if (message.preferences[pref_id] === 'true') {
checkbox.prop('checked', true);
} else {
checkbox.prop('checked', false);
}
}
function takeCheckboxValue(pref_id, message) {
var checkbox = $('.fangorn-preference[data-pref-id=' + pref_id + ']')
if (message.preferences[pref_id] === 'true') {
checkbox.prop('checked', true);
} else {
checkbox.prop('checked', false);
}
}
function takeRadioButtonValue(pref_id, message) {
var button = $('.fangorn-preference[data-pref-id=' + pref_id + ']')
if (message.preferences[pref_id] === 'true') {
button.addClass('active');
} else {
button.removeClass('active');
}
}
window.api.handleTakeCurrentPrefs((event, message) => {
console.log('taking current preferences')
for (key in message.preferences) {
switch (key) {
case 'branchColor':
picker.setColor(message.preferences[key])
break
case 'displayAlignmentCoverage':
case 'displayBootstrap':
takeCheckboxValue(key, message)
break
case 'taxaFontBold':
case 'taxaFontItalic':
case 'taxaFontUnderline':
takeRadioButtonValue(key, message)
break
default:
$('.fangorn-preference[data-pref-id=' + key + ']').val(message.preferences[key])
}
}
})
function submit () {
var prefs = collectPreferences()
window.api.takeNewPrefs(prefs)
}
$('#cancel-button').on('click', () => {
window.api.closePrefWindow()
})
$('#save-button').on('click', () => {
submit()
})
$(window).on("keydown", (e) => {
if (e.keyCode === 13){
submit()
}
})
window.api.giveCurrentPrefs()
})
</script>
</body>
</html>