-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutine-builder.html
115 lines (108 loc) · 6.21 KB
/
routine-builder.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
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="./pdf.js"></script>
<script type="text/javascript">
//disable f5 and tab
window.addEventListener("keydown",
function(e){
switch(e.keyCode){
case 116: e.preventDefault(); break; // Space
default: break; // do not block other keys
}
},
false);
$(document).delegate('textarea', 'keydown', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
e.preventDefault();
var start = $(this).get(0).selectionStart;
var end = $(this).get(0).selectionEnd;
// set textarea value to: text before caret + tab + text after caret
$(this).val($(this).val().substring(0, start)
+ "\t"
+ $(this).val().substring(end));
// put caret at right position again
$(this).get(0).selectionStart =
$(this).get(0).selectionEnd = start + 1;
}
});
$(document).ready(function(){
$('#submit').click(function(){
var doc = new pdf();
doc.setProperties({
title: 'Routine PDF',
subject: 'routine',
author: 'Ryan Wong'
});
// doc.addPage();
//doc.setFontSize(22);
/*doc.drawLine(100, 100, 100, 120, 1.0, 'dashed');
doc.drawLine(100, 100, 120, 100, 1.2, 'dotted');
doc.drawLine(120, 120, 100, 120, 1.4, 'dashed');
doc.drawLine(120, 120, 120, 100, 1.6, 'solid');
doc.drawRect(140, 140, 10, 10, 'solid');
*/
doc.setFont('Courier');
doc.setFontSize(9);
var start = 10;
var increment = 5;
start = titleline(doc,'Function Name: ' + $('#function-name').val(),start,increment);
start = titleline(doc,'Function Input: ' + $('#inputs').val(),start,increment);
start = titleline(doc,'Function Output: ' + $('#outputs').val(),start,increment);
start = titleline(doc,'Problem trying to solve:',start,increment);
start = multiline(doc,$('#solve').val(),start,increment);
start = titleline(doc,'Precondition:',start,increment);
start = multiline(doc,$('#precondition').val(),start,increment);
start = titleline(doc,'Postcondition:',start,increment);
start = multiline(doc,$('#postcondition').val(),start,increment);
start = titleline(doc,'Encapsulation:',start,increment);
start = multiline(doc,$('#hide').val(),start,increment);
start = titleline(doc,'Pseudocode:',start,increment);
start = multiline(doc,$('#pseudocode').val(),start,increment);
start = titleline(doc,'How you test Code',start,increment);
start = multiline(doc,$('#test').val(),start,increment);
start = titleline(doc,'How you Handle Errors:',start,increment);
start = multiline(doc,$('#error-handle').val(),start,increment);
start = titleline(doc,'How Efficient is your code:',start,increment);
start = multiline(doc,$('#efficient').val(),start,increment);
var fileName = "routine-"+$('#function-name').val()+".pdf";
var pdfAsDataURI = doc.output('datauri', {"fileName":fileName});
$('#pdfLink').html('<a href = "'+pdfAsDataURI+'">'+fileName+'</a>');
function titleline(doc,str,start,increment){
doc.text(5,start,str);
start= start + increment;
return start;
}
function multiline(doc,str,start,increment){
var problemstatement = str.split("\n");
for(x in problemstatement){
doc.text(10,start,problemstatement[x]);
start= start + increment;
}
return start;
}
});
});
</script>
</head>
<body>
<div>
<center>
<center><h1>Routine Builder</h1></center>
<p>Function Name:</p><input type="text" id="function-name" size="100"/>
<p>Input:</p><input type="text" id="inputs" size="100"/>
<p>Outputs:</p><input type="text" id="outputs" size="100"/>
<p>Problem to Solve:</p><textarea id="solve" rows="4" cols="100"></textarea>
<p>Precondition:</p><textarea id="precondition" rows="4" cols="100"></textarea>
<p>Postcondition:</p><textarea id="postcondition" rows="4" cols="100"></textarea>
<p>Information you want to hide:</p><textarea id="hide" rows="4" cols="100"></textarea>
<p>Pseudocode:</p><textarea id="pseudocode" rows="20" cols="100"></textarea>
<p>How you test Code:</p><textarea id="test" rows="5" cols="100"></textarea>
<p>Error handling:</p><textarea id="error-handle" rows="5" cols="100"></textarea>
<p>How efficient:</p><textarea id="efficient" rows="5" cols="100"></textarea>
<center><input type="button" id="submit" value="Create Document"/><span id="pdfLink"></span></center>
</center>
</div>
</body>
</html>