This repository has been archived by the owner on Nov 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
69 lines (59 loc) · 1.81 KB
/
main.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
/* Copyright (c) 2013-present The TagSpaces Authors.
* Use of this source code is governed by the MIT license which can be found in the LICENSE.txt file. */
/* globals $, sendMessageToHost, getParameterByName, initI18N */
'use strict';
sendMessageToHost({ command: 'loadDefaultTextContent' });
$(document).ready(() => {
const locale = getParameterByName('locale');
initI18N(locale, 'ns.viewerURL.json');
});
function setContent(content) {
const $htmlContent = $('#htmlContent');
const urlBegin = 'URL=';
const commentTag = 'COMMENT=';
let url = content.substring(
content.indexOf(urlBegin) + urlBegin.length,
content.length
);
let comment = content.substring(
content.indexOf(commentTag) + commentTag.length,
content.length
);
// preventing the case the url is at the end of the file or line after the url lines
url = url + '\n';
url = url.substring(0, url.indexOf('\n'));
$htmlContent.append(
$('<input>', {
class: 'form-control',
readonly: 'readonly',
style: 'margin: 10px; height: 40px; width: 100%',
title: 'Opens the URL in the default browser',
value: url
}).prepend("<i class='fa fa-external-link'></i> ")
);
$htmlContent.append(
$('<a>', {
class: 'viewerURLButton btn btn-primary',
title: 'Opens the URL in the default browser',
'data-url': url,
text: 'Open URL'
})
.prepend("<i class='fa fa-external-link'></i> ")
.click(e => {
e.preventDefault();
sendMessageToHost({
command: 'openLinkExternally',
link: e.target.dataset.url
});
})
);
if (!comment.indexOf('data:image')) {
$htmlContent.append(
$('<img>', {
style: 'margin: 15px; height: 100%; width: 95%',
title: 'Image URL',
src: comment
})
);
}
}