forked from alpertron/calculators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gauss.js
240 lines (226 loc) · 7 KB
/
gauss.js
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
This file is part of Alpertron Calculators.
Copyright 2015 Dario Alejandro Alpern
Alpertron Calculators is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Alpertron Calculators is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Alpertron Calculators. If not, see <http://www.gnu.org/licenses/>.
*/
(function(global)
{ // This method separates the name space from the Google Analytics code.
var worker = 0;
var app;
function get(x)
{
return document.getElementById(x);
}
function setStorage(name, data)
{
localStorage.setItem(name, data);
}
function getStorage(name)
{
return localStorage.getItem(name);
}
function styleButtons(style1, style2)
{
get("eval").style.display = style1;
get("factor").style.display = style1;
get("config").style.display = style1;
get("stop").style.display = style2;
get("more").style.display = style2;
}
function callWorker(param)
{
if (!worker)
{
worker = new Worker("gaussianW0026.js");
worker.onmessage = function(e)
{ // First character of e.data is "1" for intermediate text
// and it is "2" for end of calculation.
// It is "9" for saving expression to factor into Web Storage.
var firstChar = e.data.substring(0, 1);
if (firstChar == "8")
{
// setStorage("ecmFactors", e.data.substring(1));
// setStorage("ecmCurve", "");
}
else if (firstChar == "7")
{
// setStorage("ecmCurve", e.data.substring(1));
}
else if (firstChar == "4")
{
get("status").innerHTML = e.data.substring(1);
}
else
{
get("result").innerHTML = e.data.substring(1);
if (e.data.substring(0, 1) == "2")
{ // First character passed from web worker is "2".
get("status").innerHTML = "";
styleButtons("inline", "none"); // Enable eval and factor
get("modal-more").style.display = "none";
}
}
};
}
worker.postMessage(param);
}
function dowork(n)
{
app = parseInt(get("app").value) + n;
var res = get("result");
var valueText = get("value").value;
var helphelp = get("helphelp");
get("help").style.display = "none";
helphelp.style.display = "block";
helphelp.innerHTML = (app & 1 ? "<p>Aprieta el botón <strong>Ayuda</strong> para obtener ayuda para esta aplicación. Apriétalo de nuevo para retornar a la factorización.</p>":
"<p>Press the <strong>Help</strong> button to get help about this application. Press it again to return to the factorization.</p>");
res.style.display = "block";
if (valueText == "")
{
res.innerHTML = (app & 1 ? "Por favor ingrese una expresión." :
"Please type an expression.");
return;
}
styleButtons("none", "inline"); // Enable "more" and "stop" buttons
res.innerHTML = (app & 1 ? "Factorizando la expresión..." :
"Factoring expression...");
param = digits + "," + app + "," + valueText + String.fromCharCode(0);
callWorker(param);
}
window.onload = function ()
{
var param;
get("eval").onclick = function ()
{
dowork(0);
};
get("factor").onclick = function ()
{
dowork(2);
};
get("stop").onclick = function ()
{
worker.terminate();
worker = 0;
styleButtons("inline", "none"); // Enable eval and factor
get("result").innerHTML =
(app & 1 ? "<p>Cálculo detenido por el usuario.</p>" :
"<p>Calculation stopped by user</p>");
get("status").innerHTML = "";
};
get("more").onclick = function ()
{
get("modal-more").style.display = "block";
};
get("config").onclick = function ()
{
get("digits").value = digits;
get("batch").checked = (config.substr(0,1)=="1");
get("verbose").checked = (config.substr(1,1)=="1");
get("pretty").checked = (config.substr(2,1)=="1");
get("cunnin").checked = (config.substr(3,1)=="1");
get("modal-config").style.display = "block";
};
get("close-config").onclick = function ()
{
get("modal-config").style.display = "none";
};
get("cancel-config").onclick = function ()
{
get("modal-config").style.display = "none";
};
get("save-config").onclick = function ()
{
oldconfig = config;
config = (get("batch").checked? "1" :"0") +
(get("verbose").checked? "1" :"0") +
(get("pretty").checked? "1" :"0") +
(get("cunnin").checked? "1" :"0");
digits = get("digits").value;
setStorage("ecmConfig", digits+","+config);
if (config.substr(0,1) != oldconfig.substr(0,1))
{
isBatch();
}
get("modal-config").style.display = "none";
};
get("close-more").onclick = function ()
{
get("modal-more").style.display = "none";
};
get("helpbtn").onclick = function ()
{
var help = get("help");
var helpStyle = help.style;
var helphelpStyle = get("helphelp").style;
var result = get("result");
var resultStyle = result.style;
if (helpStyle.display == "block" && result.innerHTML != "")
{
helpStyle.display = "none";
helphelpStyle.display = resultStyle.display = "block";
}
else
{
helpStyle.display = "block";
helphelpStyle.display = resultStyle.display = "none";
}
};
window.onclick = function(event)
{
var modal = get("modal");
if (event.target == modal)
{
modal.style.display = "none";
}
};
digits = getStorage("ecmConfig");
if (digits == null || digits == "")
{
digits = 6;
config = "0010";
setStorage("ecmConfig", digits+","+config);
}
else
{
index = digits.indexOf(",");
if (index<0)
{
digits = 6;
config = "0010";
setStorage("ecmConfig", digits+","+config);
}
else
{
config = digits.substr(index+1);
digits = digits.substr(0,index);
}
}
if ('serviceWorker' in navigator)
{ // Attempt to register service worker.
// There is no need to do anything on registration success or failure in this JavaScript module.
navigator.serviceWorker.register('calcSW.js').then(function() {}, function() {});
}
}
})(this);
if (typeof(window) !== "undefined")
{ // In main thread: register Google Analytics.
addEventListener("load", function ()
{
(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,"script","https://www.google-analytics.com/analytics.js","ga");
ga("create", "UA-4438475-1", "auto");
ga("send", "pageview");
});
}