- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.html
More file actions
Latest commit
77 lines (72 loc) · 2.71 KB
/
Copy pathexample.html
File metadata and controls
77 lines (72 loc) · 2.71 KB
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
<html>
<head>
<scripttype="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<scripttype="text/javascript" src="lcs.js"></script>
<styletype="text/css">
#result { border: solid 1px black; border-collapse: collapse; min-width:200px; margin-right:20px;}
#resulttd { border: solid 1px black; padding:5px; }
.left { float: left; }
</style>
</head>
<body>
<h1>Javascript LCS error detection example</h1>
<form>
<labelfor="reference">reference</label>
<inputname="reference" type="text" value="012012012"/>
<labelfor="input">input</label>
<inputname="input" type="text" value="0102012012"/>
<inputvalue="ok" type="button"/>
</form>
<div>
<divclass="left">
<h2>Result:</h2>
<tableid="result"></table>
</div>
<divclass="left">
<h2>Message:</h2>
<divid="message"></div>
</div>
</div>
<scripttype="text/javascript">
$(function(){
$('form input[type="button"]').click(function(){
// Build the matrix.
varreference=this.form.reference.value;
varinput=this.form.input.value;
varresult=lcs.compare(reference,input);
// Get the line and the column of the matrix
varline_count=result.length;
varcolumn_count=0;
result.forEach(function(line){column_count=Math.max(line.length,column_count);});
// Display the matrix: display the first line
vartable=$('#result').empty();
vartr=$('<tr><td/></tr>').appendTo(table);
for(varcinreference){
tr.append('<td>'+reference[c]+'</td>');
}
tr.append('<td/>');
// Display the matrix: display the result
for(vari=0;i<line_count;i++){
vartr=$('<tr/>').appendTo(table);
tr.append('<td>'+(input[i]||'')+'</td>');
for(varj=0;j<column_count;j++){
tr.append('<td>'+result[i][j].value+'</td>');
}
}
// Highlight the path and display the messages
$('#message').empty();
lcs.run(result,0,0,function(i,j){
// Display the message.
if(result[i][j].status==lcs.DELETION){
$('#message').append('<p>Missing a caracter at index '+j+'.</p>');
}elseif(result[i][j].status==lcs.INSERTION){
$('#message').append('<p>Extra caracter at index '+j+'.</p>');
}
// Highlight the path
$(table.find('tr').get(i+1)).find('td').get(j+1).style.setProperty('color','red');
});
});
});
</script>
</body>
</html>