-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsJS.html
77 lines (70 loc) · 2.5 KB
/
SettingsJS.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
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
<script>
/**
* On document load, assign click handlers to each button.
* Load script preferences
*/
$(function() {
getPrefsOnServer(); // initialize UI with prefs values
$('#save-changes').click(setPrefsOnServer);
$('#test-server').click(validateServerURL);
$('#use-data-url').click(function(){
//enable save if a change
$('#save-changes').removeAttr('disabled');
});
$('#plantuml-server').keyup(function(){
//enable save if a change
$('#save-changes').removeAttr('disabled');
});
// /**
// * See http://jsfiddle.net/Pug3H/2/ and http://stackoverflow.com/a/24790754/1168342 for how this works
// */
// $('form')
// .each(function(){
// $(this).data('serialized', $(this).serialize())
// })
// .on('input', function(){
// window.alert("changed.");
// $(this)
// .find('input:submit, button:submit')
// .attr('disabled', $(this).serialize() == $(this).data('serialized'))
// ;
// })
// .find('input:submit, button:submit')
});
function validateServerURL() {
normalizePrefix();
var prefix = $('#plantuml-server').val();
var testImageURL = prefix + "img/oyXCILL8pIqegLJ8JSrDIYqgvYhEpimhI2nAp5KeBgdCIGMIHPd99QMvELmXgSKb2herTWh1fSd9gSN50000";
var div;
$('#test-preview').remove();
$('#test-result').remove();
if (!isValidServerUrl(prefix)) {
div = $('<div id="test-preview" class="error">Server prefix is not a valid URL.</div>');
$('#server-prefix-block').after(div);
} else {
div = $('<div id="test-preview"><img id="test-image" src="' + testImageURL + '"></div>');
$('#server-prefix-block').after(div);
$('#test-image').error(function() {
var div2 = $('<div id="test-result" class="error">Test image failed to load.</div>');
$('#server-prefix-block').after(div2);
});
}
}
function normalizePrefix() {
var prefix = $('#plantuml-server').val();
// remove leading or trailing spaces
prefix = prefix.trim();
// add a '/' to the end of the prefix if needed
if (prefix.slice(-1) != "/") {
prefix = prefix + "/";
}
// put it back
$('#plantuml-server').val(prefix);
}
function isValidServerUrl(s) {
var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return regexp.test(s);
}
</script>