-
Notifications
You must be signed in to change notification settings - Fork 2
/
to-table.txt
53 lines (46 loc) · 1.87 KB
/
to-table.txt
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
(function () {
/*
* Function [loadScript](https://www.sitepoint.com/dynamically-load-jquery-library-javascript/)
* Author [Sam Deering](https://www.sitepoint.com/author/sdeering/)
*/
function loadScript(url, callback) {
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState) { //IE
script.onreadystatechange = function () {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function () {
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
function txt(obj){
switch(obj.prop("tagName")){
case 'INPUT': return obj.val(); break;
case 'OPTION': return obj.text(); break;
}
return '';
}
loadScript("https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js", function () {
lastEntry = jQuery('#dnsEntries > .form-panels > .form-panel').last().find('input[name="name[]"]');
if(lastEntry.length > 0 && lastEntry.val()==''){ jQuery('#dnsEntries > .form-panels > .form-panel').last().remove() }
var tbl = '<table style="width:100%;"><thead><th>name</th><th>ttl</th><th>type</th><th>value</th></thead>';
var rows = '';
jQuery('#dnsEntries .form-group').each(function(){
var row='';
jQuery(this).find('input, select option:selected').each(function(){
row+= '<td>'+ txt(jQuery(this)) + '</td>';
});
rows += '\n' + '<tr>' + row + '</tr>';
});
tbl += '<tbody>' + rows + '</tbody></table>';
jQuery('form.dns').html(tbl);
});
})();