/
index.html
174 lines (161 loc) · 7.91 KB
/
index.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
<link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="vendor/bootstrap/css/navbar-fixed-top.css">
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap-typeahead.min.js"></script>
</head>
<body>
<title>fin-lib</title>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">fin-lib</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="http://www.github.com/nathanfrancy/fin-lib">Github</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>fin-lib <small>finance and time, value, money library</small></h1>
<p><button id="toggleInstructionsButton" class="btn btn-default btn-sm">See Instructions</button></p>
<div id="instructions">
<p>Enter a command below to try it out or use your browser's console. Refer to the <a id="documentationLink">documentation</a> below for the existing functions.</p>
<p>Be sure to include comma-separated parameters in the parentheses for your problem.</p>
</div>
<div id="guideContainer">
<p>Parameters: <span><code id="guide"></code></span></p>
</div>
<form class="form-inline">
<div class="form-group">
<label class="sr-only" for="command">Command</label>
<div class="input-group">
<div class="input-group-addon input-lg">fin.</div>
<input type="text" class="form-control input-lg" id="command" placeholder="Enter function here">
</div>
</div>
<button type="button" onclick="evaluateCommand();" class="btn btn-primary btn-lg">Evaluate command</button>
<button type="button" onclick="clearCommand();" class="btn btn-default btn-lg"><span class="glyphicon glyphicon-trash"></span></button>
</form>
<br>
<div id="outputContainer">
<p>Output:</p>
<div id="output"></div>
</div>
</div>
<div class="container-fluid">
<h1 class="page-header" id="documentationHeader">Documentation</h1>
<p>All functions are in the <code>fin</code> object, and can be run like this: <code>fin.methodName()</code> (you don't have to put fin. above in the demo).</p>
<div class="row">
<div class="col-sm-12">
<div id="documentationContainer"></div>
</div>
</div>
</div>
<br><br>
<h2 class="text-center">Like this project?</h2>
<p class="text-center">Grab the source on <a href="http://www.github.com/nathanfrancy/fin-lib">Github</a> (look in the <code>dist</code> folder).</p>
<br><br>
<hr>
<p class="text-center">Made by Nathan Francy. <a href="http://www.twitter.com/nathanfrancy">twitter</a> <a href="http://www.github.com/nathanfrancy">github</a></p>
</div>
<script src="dist/finlib.min.js"></script>
<script>
$(document).ready(function() {
$.getJSON('documentation.json', function(data) {
var documentationHTML = "";
for (var index = 0; index < data.length; ++index) {
var paramText = data[index].parameters.join(", ");
var thisDocumentationText = "<h3>"+ data[index].description +"</h3>";
thisDocumentationText += "<p><code>fin." + data[index].name +"("+ paramText + ")</code></p>";
thisDocumentationText += "<p><button class='btn btn-default btn-sm runCode' tvmCode='" + data[index].name + "()' params='"+paramText+"'>Run this function</button></p>";
thisDocumentationText += "<hr>";
documentationHTML += thisDocumentationText;
}
var functions = fin.allMethods();
var methods = [];
for (var j=0; j<functions.length; j++) {
methods.push(functions[j] + "()");
}
$("#command").typeahead({ source: methods });
$("#documentationContainer").html(documentationHTML);
});
});
function evaluateCommand() {
var origCommand = document.getElementById("command").value;
var command = "fin." + origCommand.trim();
var methodName = split(command);
// Check if the command box is empty
if (origCommand !== "" && origCommand !== null) {
// It's not null and is in the library.. so go for it
if ( $.inArray(methodName, fin.allMethods()) >= 0) {
var output = eval(command);
var outputDiv = document.getElementById("output");
outputDiv.innerHTML = output;
$("#outputContainer").slideDown();
}
else {
$("#output").html("Cool command, but it isn't one from this library.");
$("#outputContainer").slideDown();
}
}
else {
$("#output").html("Command field is blank. Try again?");
$("#outputContainer").slideDown();
}
return false;
}
function clearCommand() {
$("#command").val('');
$("#output").html('');
$("#outputContainer").slideUp();
$("#guideContainer").slideUp();
}
$(document).on("click", ".runCode", function(e){
e.preventDefault();
var code = $(this).attr("tvmCode");
$("#command").val(code);
$("#guide").html($(this).attr("params"));
$("#guideContainer").slideDown();
$('html, body').animate({
scrollTop: $(".jumbotron").offset().top
}, 500);
});
$(document).on("click", "#toggleInstructionsButton", function(e){
e.preventDefault();
$("#instructions").slideToggle();
$("#toggleInstructionsButton").toggleClass("active");
});
$(document).on("click", "#documentationLink", function(e){
e.preventDefault();
$('html, body').animate({
scrollTop: $("#documentationHeader").offset().top
}, 500);
});
/* Function stripping off TVM. and anything after the first occurrence of parentheses
to get the actual function name */
function split(str) {
var i = str.indexOf("(");
if(i > 0)
str = str.slice(0, i);
else
str = "";
var parts = str.split('.', 2);
return parts[1];
}
</script>
</body>
</html>