-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
77 lines (57 loc) · 1.53 KB
/
script.js
File metadata and controls
77 lines (57 loc) · 1.53 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
$(document).ready(function(){
var store = [];
$(".btn").click(function(e){
e.preventDefault();
var id = $(this).attr('id');
if( id == 'AC' ){
clearScreen();
}else if( id == 'SAVE' ){
var data = { 'number': $('.answer').text(), 'ip': getIp(), 'browser': $.browser }
$.post( "save-csv.php", function( data ) {
if(data){
$('.answer').text('SAVED');
}
});
}else{
// Add to store array
if( id != null && $(this).attr('data-symbol') != null ){
store.push('<span>'+$(this).attr('data-symbol')+'</span>');
}else{
store.push( $(this).text() );
}
$('.calculus').html(store);
if( id == 'EQUALS' ){
$('.calculus').html(store).addClass('calculated');
$('.answer').show();
doCalculations()
}
}
});
function doCalculations(){
var newStore = [];
//Strip array of strings
$.each(store, function(index, value) {
newStore.push($('<span/>').html(value).text());
});
var answer = newStore.slice(0,-1).join("");
answer = eval(answer);
$('.answer').text( answer.toLocaleString() )
}
function clearScreen(){
$('.answer').hide();
$('.calculus').text('0').removeClass('calculated');
store.length = 0;
}
function formatNumber(number) {
var n = number.toString().split(".");
n[0] = n[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return n.join(".");
}
function getIp(){
var ip = '';
$.getJSON("http://jsonip.com?callback=?", function (data) {
ip = data;
});
return ip;
}
});