function $id(id) { return document.getElementById(id); }
var UI = {
Datestart:Date.now(),
mailto: '',
from: '',
ready: false,
focusaftereval: true,
frac_add:1.0, // set to 0 to avoid adding an approx value of a fraction
docprefix: "https://www-fourier.univ-grenoble-alpes.fr/%7eparisse/giac/doc/fr/cascmd_fr/",
base_url: "https://www-fourier.univ-grenoble-alpes.fr/%7eparisse/",
local_url:"file:///C:/xcaswin/doc/xcasfr.html",
//local_url: "file:///usr/share/giac/doc/xcasfr.html",
//forum_url: "http://xcas.e.univ-grenoble-alpes.fr/XCAS/viewforum.php?f=25",
forum_url: "http://xcas.univ-grenoble-alpes.fr/forum/viewforum.php?f=25",
// forum_url: "http://xcas.e.univ-grenoble-alpes.fr/XCAS/posting.php?mode=post&f=12&subject=session",
//forum_url: "http://xcas.univ-grenoble-alpes.fr/forum/posting.php?mode=post&f=12&subject=session",
forum_warn: true,
locallink_warn: true,
focused: entree,
savefocused: entree,
usecm: true,
fixeddel: false,
kbdshift: false,
usemathjax: false,
mathjax_version:2,
prettyprint: true,
qa: false,
histcount: 0,
selection: '',
langue: -1,
calc: 2, // 1 KhiCAS, 2 Numworks, 3 TI Nspire CX
calculator:0, // !=0 if hardware Numworks connected
calculator_connected:false,
nws_records:0,
xwaspy_shift: 33, // must be >32 for space encoding, and <=35 for a..z encoding
canvas_w: 350,
canvas_h: 200,
canvas_lastx: 0,
canvas_lasty: 0,
canvas_pushed: false,
gr2d_ncanvas: 0,
initconfigstring: '',
python_mode: 0,
python_indent: 4,
warnpy: true, // set to false if you do not want Python compat warning
xtn: 'x', // var name, depends on last app
clean_for_html: function(text){
text = text.replace(/&/g, "&");
text = text.replace(//g, ">");
text = text.replace(/\n/g, '
');
return text;
},
sleep: function (miliseconds) {
var currentTime = new Date().getTime();
while (currentTime + miliseconds >= new Date().getTime()) {
}
},
is_touch_device: function () {
return (('ontouchstart' in window)
|| (navigator.MaxTouchPoints > 0)
|| (navigator.msMaxTouchPoints > 0));
},
assistant_list: ['pour', 'tantque', 'solve', 'rsolve', 'fixe', 'test', 'prog', 'seq', 'plotpolar', 'series', 'limit', 'int', 'sum', 'diff', 'tabvarfunc', 'tabvarparam', 'plotfunc1var', 'plotfunc2var', 'plotparam', 'plotparam2var', 'plotimplicit', 'plotfield', 'desolve', 'matr', 'rand'
],
assistant_close: function () {
var t = UI.assistant_list;
var s = t.length;
for (var i = 0; i < s; i++) {
$id('assistant_' + t[i]).style.display = 'none';
}
},
assistant_ok: function () {
var t = UI.assistant_list;
var s = t.length;
for (var i = 0; i < s; i++) {
var tmp = $id('assistant_' + t[i]);
if (tmp.style.display == 'block') {
tmp = 'UI.assistant_' + t[i] + '_ok()';
//console.log(tmp);
eval(tmp);
return true;
}
}
return false;
},
assistant_pour_ok: function () {
UI.focused = UI.savefocused;
var st = $id('pourvarstep').value;
if (UI.python_mode) {
var sup=eval($id('pourvarmax').value)+1;
UI.insert(UI.focused, '\nfor ' + $id('pourvarname').value + ' in range(' + $id('pourvarmin').value + ',' + sup);
if (st.length) st = ',' + st;
UI.insert(UI.focused, st + '):');
UI.indentline(UI.focused);
UI.insert(UI.focused, '\n');
UI.indentline(UI.focused);
}
else {
var tmp = '\npour ' + $id('pourvarname').value + ' de ' + $id('pourvarmin').value + ' jusque ' + $id('pourvarmax').value;
//console.log(tmp);
UI.insert(UI.focused, tmp);
UI.indentline(UI.focused);
if (st.length) UI.insert(UI.focused, ' pas ' + st);
UI.insert(UI.focused, ' faire\n\nfpour;');
UI.indentline(UI.focused);
UI.moveCaretUpDown(UI.focused, -1);
UI.indentline(UI.focused);
}
UI.focused.focus();
$id('assistant_pour').style.display = 'none';
$id('assistant_boucle').style.display = 'none';
},
assistant_tantque_ok: function () {
UI.focused = UI.savefocused;
if (UI.python_mode) {
UI.insert(UI.focused, '\nwhile ' + $id('tantquecond').value + ':');
UI.indentline(UI.focused);
UI.insert(UI.focused, '\n');
}
else {
UI.insert(UI.focused, '\ntantque ' + $id('tantquecond').value + ' faire\n\nftantque;');
UI.indentline(UI.focused);
UI.moveCaretUpDown(UI.focused, -1);
UI.indentline(UI.focused);
UI.moveCaretUpDown(UI.focused, -1);
UI.indentline(UI.focused);
UI.moveCaretUpDown(UI.focused, 1);
}
UI.focused.focus();
$id('assistant_tantque').style.display = 'none';
$id('assistant_boucle').style.display = 'none';
},
assistant_solve_ok: function () {
UI.focused = UI.savefocused;
if ($id('solveC').style.display == 'inline') UI.insert(UI.focused, 'c');
if ($id('solvenum').style.display == 'inline') UI.insert(UI.focused, 'f');
UI.insert(UI.focused, 'solve(' + $id('solveeq').value);
UI.indentline(UI.focused);
var tmp = $id('solvevar').value;
if (tmp.length) UI.insert(UI.focused, ',' + tmp);
UI.insert(UI.focused, ')');
$id('assistant_solve').style.display = 'none';
},
assistant_rsolve_ok: function () {
UI.focused = UI.savefocused;
UI.insert(UI.focused, 'rsolve(' + $id('rsolveeq').value + ',' + $id('rsolvevar').value);
var tmp = $id('rsolveinit').value;
if (tmp.length) UI.insert(UI.focused, ',[' + tmp + ']');
UI.insert(UI.focused, ')');
$id('assistant_rsolve').style.display = 'none';
$id('assistant_suites').style.display = 'none';
},
assistant_desolve_ok: function () {
UI.focused = UI.savefocused;
var tmpeq = $id('desolveeq').value;
var tmpt = $id('desolvevar').value;
var tmpy = $id('desolvey').value;
var tmp = $id('desolveinit').value;
if (tmp.length) tmp = 'desolve([' + tmpeq + ',' + tmp + ']'; else tmp = 'desolve(' + tmpeq;
tmp += ',' + tmpt + ',' + tmpy + ')';
UI.insert(UI.focused, tmp);
$id('assistant_desolve').style.display = 'none';
},
assistant_fixe_ok: function () {
UI.focused = UI.savefocused;
var tmp = $id('rsolvef').value;
if (tmp.length) {
tmp += ':=' + $id('rsolvevarf').value + '->' + $id('rsolveexpr').value + ';\nplotseq(' + tmp + '(' + $id('rsolvevarf').value + ')';
} else tmp = 'plotseq(' + $id('rsolveexpr').value;
tmp += ',' + $id('rsolvevarf').value + '===';
var tmp1 = $id('rsolvemin').value;
if (tmp1.length) tmp += '[' + $id('rsolveu0').value + ',' + tmp1 + ',' + $id('rsolvemax').value + ']'; else tmp += $id('rsolveu0').value;
tmp += ',' + $id('rsolven').value + ')';
UI.insert(UI.focused, tmp);
$id('assistant_fixe').style.display = 'none';
$id('assistant_suites').style.display = 'none';
},
assistant_test_ok: function () {
UI.focused = UI.savefocused;
if (UI.python_mode) {
UI.insert(UI.focused, '\nif ' + $id('sicond').value + ':');
UI.indentline(UI.focused);
UI.insert(UI.focused, '\n' + $id('sialors').value);
} else UI.insert(UI.focused, '\nsi ' + $id('sicond').value + ' alors ' + $id('sialors').value);
UI.indentline(UI.focused);
var tmp = $id('sisinon').value;
if (tmp.length) {
if (UI.python_mode) {
UI.indentline(UI.focused);
UI.insert(UI.focused, '\nelse:')
UI.indentline(UI.focused); // should remove 2 spaces at start
UI.insert(UI.focused, '\n' + tmp);
} else {
UI.insert(UI.focused, ' sinon ' + tmp);
UI.insert(UI.focused, ' fsi;\n');
}
}
else {
if (!UI.python_mode)
UI.insert(UI.focused, ' fsi;\n');
}
UI.indentline(UI.focused);
UI.funcoff();
UI.focused.focus();
$id('assistant_test').style.display = 'none';
},
assistant_prog_ok: function () {
UI.focused = UI.savefocused;
var loc = $id('localvars').value;
var fc = $id('funcname').value;
var argu = $id('argsname').value;
var ret = $id('returnedvar').value;
if (UI.python_mode) {
UI.insert(UI.focused, 'def ' + fc + '(' + argu + '):');
UI.indentline(UI.focused);
if (0 && loc.length != 0) {
UI.insert(UI.focused, '\n# local ' + loc);
UI.indentline(UI.focused);
UI.insert(UI.focused, '\n\nreturn ' + ret);
UI.indentline(UI.focused);
UI.moveCaretUpDown(UI.focused, -1);
UI.indentline(UI.focused);
}
else {
UI.insert(UI.focused, '\nreturn ' + ret);
UI.indentline(UI.focused);
}
}
else {
if (loc.length == 0)
UI.insert(UI.focused, 'fonction ' + fc + '(' + argu + ')\n \nffonction:;\n'); // was fc + '(' + argu + '):=' + ret + ';');
else {
UI.insert(UI.focused, 'fonction ' + fc + '(' + argu + ')\n local ' + loc + ';\n \n retourne ' + ret + ';\nffonction:;\n');
UI.moveCaretUpDown(UI.focused, -3);
UI.moveCaret(UI.focused, 2);
}
}
$id('assistant_prog').style.display = 'none';
UI.focused.focus();
},
assistant_seq_ok: function () {
UI.focused = UI.savefocused;
var tmp = 'seq(' + $id('seqexpr').value + ',' + $id('seqvarname').value + ',' + $id('seqvarmin').value + ',' + $id('seqvarmax').value;
UI.insert(UI.focused, tmp);
tmp = $id('seqvarstep').value;
if (tmp.length) UI.insert(UI.focused, ',' + tmp);
UI.insert(UI.focused, ')');
$id('assistant_seq').style.display = 'none';
},
assistant_plot_polar: function () {
UI.focused = UI.savefocused;
var tmp = 'plotpolar(' + $id('plotpolarexpr').value + ',' + $id('plotpolarvarname').value + ',' + $id('plotpolarvarmin').value + ',' + $id('plotpolarvarmax').value;
UI.insert(UI.focused, tmp);
tmp = $id('plotpolarvarstep').value;
if (tmp.length) UI.insert(UI.focused, ',tstep===' + tmp);
UI.insert(UI.focused, ')');
$id('assistant_plotpolar').style.display = 'none';
},
assistant_series_ok: function () {
UI.focused = UI.savefocused;
var tmp = 'series(' + $id('seriesexpr').value + ',' + $id('seriesvarname').value + '===' + $id('seriesvarlim').value + ',' + $id('seriesvarorder').value;
UI.insert(UI.focused, tmp);
tmp = $id('seriesvarstep').value;
if (tmp.length) UI.insert(UI.focused, ',' + tmp);
UI.insert(UI.focused, ')');
$id('assistant_series').style.display = 'none';
},
assistant_limit_ok: function () {
UI.focused = UI.savefocused;
var tmp = 'limit(' + $id('limitexpr').value + ',' + $id('limitvarname').value + ',' + $id('limitvarlim').value;
UI.insert(UI.focused, tmp);
tmp = $id('limitvardir').value;
if (tmp.length) UI.insert(UI.focused, ',' + tmp);
UI.insert(UI.focused, ')');
$id('assistant_limit').style.display = 'none';
},
assistant_int_ok: function () {
UI.focused = UI.savefocused;
var tmp = $id('intexpr').value;
if (tmp.length) {
tmp = 'integrate(' + tmp + ',' + $id('intvarname').value;
UI.insert(UI.focused, tmp);
tmp = $id('intvarmin').value;
if (tmp.length) UI.insert(UI.focused, ',' + tmp + ',' + $id('intvarmax').value);
UI.insert(UI.focused, ')');
} else UI.insert(UI.focused, 'integrate(');
$id('assistant_int').style.display = 'none';
},
assistant_diff_ok: function () {
UI.focused = UI.savefocused;
var tmp = $id('diffexpr').value;
if (tmp.length) {
tmp = 'diff(' + tmp + ',' + $id('diffvarname').value;
UI.insert(UI.focused, tmp);
tmp = $id('diffnumber').value;
if (tmp.length) UI.insert(UI.focused, ',' + tmp);
UI.insert(UI.focused, ')');
} else UI.insert(UI.focused, 'diff(');
$id('assistant_diff').style.display = 'none';
},
assistant_sum_ok: function () {
UI.focused = UI.savefocused;
var tmp = $id('sumexpr').value;
if (tmp.length) {
tmp = 'sum(' + tmp + ',' + $id('sumvarname').value;
UI.insert(UI.focused, tmp);
tmp = $id('sumvarmin').value;
if (tmp.length) UI.insert(UI.focused, ',' + tmp + ',' + $id('sumvarmax').value);
UI.insert(UI.focused, ')');
} else UI.insert(UI.focused, 'sum(');
$id('assistant_sum').style.display = 'none';
},
assistant_tabvarfunc_ok: function () {
UI.focused = UI.savefocused;
$id('assistant_tabvar').style.display = 'none';
$id('assistant_tabvarfunc').style.display = 'none';
var tmp = $id('tabvarfuncname').value;
if (tmp.length) {
tmp += ':=' + $id('tabvarfuncvarname').value + '->' + $id('tabvarfuncexpr').value + ';\n';
tmp = tmp + 'tabvar(' + $id('tabvarfuncname').value + '(' + $id('tabvarfuncvarname').value + '),';
} else {
tmp = tmp + 'tabvar(' + $id('tabvarfuncexpr').value + ','
}
tmp += $id('tabvarfuncvarname').value + ',' + $id('tabvarfuncvarmin').value + ',' + $id('tabvarfuncvarmax').value;
var tmp1 = $id('tabvarfuncopt').value;
if (tmp1.length) tmp += ',' + tmp1;
tmp1 = $id('tabvarfuncvarstep').value;
if (tmp1.length) tmp = tmp + ',xstep===' + tmp1;
tmp += ',plot)';
UI.insert(UI.focused, tmp);
},
assistant_tabvarparam_ok: function () {
UI.focused = UI.savefocused;
$id('assistant_tabvar').style.display = 'none';
$id('assistant_tabvarparam').style.display = 'none';
var varname = $id('tabvarparamvarname').value;
var exprx = $id('tabvarparamexprx').value;
var expry = $id('tabvarparamexpry').value;
var tmp = $id('tabvarparamnamex').value;
if (tmp.length) tmp = tmp + ':=' + varname + '->' + exprx + ';\n' + $id('tabvarparamnamey').value + ':=' + varname + '->' + expry + ';\n';
tmp = tmp + 'tabvar([' + exprx + ',' + expry + '],' + varname + '===' + $id('tabvarparamvarmin').value + '..' + $id('tabvarparamvarmax').value;
var tmp1 = $id('tabvarparamvarstep').value;
if (tmp1.length) tmp = tmp + ',tstep===' + tmp1;
tmp += ',plot)';
UI.insert(UI.focused, tmp);
},
assistant_plotfunc1var_ok: function () {
UI.focused = UI.savefocused;
$id('assistant_plotfunc').style.display = 'none';
$id('assistant_plotfunc1var').style.display = 'none';
var tmp = 'plotfunc(' + $id('plotfuncexpr').value + ',' + $id('plotfuncvarname').value + ',' + $id('plotfuncvarmin').value + ',' + $id('plotfuncvarmax').value;
var tmp1 = $id('plotfuncvarstep').value;
if (tmp1.length) tmp = tmp + ',xstep===' + tmp1;
tmp += ')';
UI.insert(UI.focused, tmp);
},
assistant_plotfunc2var_ok: function () {
UI.focused = UI.savefocused;
$id('assistant_plotfunc').style.display = 'none';
$id('assistant_plotfunc2var').style.display = 'none';
var tmp = 'plotfunc(' + $id('plotfunc2expr').value + ',[' + $id('plotfunc2varx').value + ',' + $id('plotfunc2vary').value + ']';
var tmp1 = $id('plotfunc2varxstep').value;
if (tmp1.length) tmp = tmp + ',xstep===' + tmp1;
tmp1 = $id('plotfunc2varystep').value;
if (tmp1.length) tmp = tmp + ',ystep===' + tmp1;
tmp += ')';
UI.insert(UI.focused, tmp);
},
assistant_plotparam_ok: function () {
UI.focused = UI.savefocused;
$id('assistant_plotparam').style.display = 'none';
$id('assistant_plotparam1var').style.display = 'none';
var tmp = 'plotparam([' + $id('plotparamexprx').value + ',' + $id('plotparamexpry').value + '],' + $id('plotparamvarname').value + ',' + $id('plotparamvarmin').value + ',' + $id('plotparamvarmax').value;
var tmp1 = $id('plotparamvarstep').value;
if (tmp1.length) tmp = tmp + ',tstep===' + tmp1;
tmp += ',display===cap_flat_line)';
UI.insert(UI.focused, tmp);
},
assistant_plotparam2var_ok: function () {
UI.focused = UI.savefocused;
$id('assistant_plotparam').style.display = 'none';
$id('assistant_plotparam2var').style.display = 'none';
var tmp = 'plotparam([' + $id('plotparam2exprx').value + ',' + $id('plotparam2expry').value + ',' + $id('plotparam2exprz').value + '],[' + $id('plotparam2varx').value + ',' + $id('plotparam2vary').value + ']';
var tmp1 = $id('plotparam2varxstep').value;
if (tmp1.length) tmp = tmp + ',ustep===' + tmp1;
tmp1 = $id('plotparam2varystep').value;
if (tmp1.length) tmp = tmp + ',vstep===' + tmp1;
tmp += ')';
UI.insert(UI.focused, tmp);
},
assistant_plotimplicit_ok: function () {
UI.focused = UI.savefocused;
$id('assistant_plotimplicit').style.display = 'none';
var ctr = $id('plotimplicitlevel').value;
var tmp = $id('plotimplicitexprf').value + ',[' + $id('plotimplicitvarx').value + ',' + $id('plotimplicitvary').value + ']';
if (ctr.length) tmp = 'plotcontour(' + tmp + ',' + ctr; else tmp = 'plotimplicit(' + tmp;
var tmp1 = $id('plotimplicitvarxstep').value;
if (tmp1.length) tmp = tmp + ',xstep===' + tmp1;
tmp1 = $id('plotimplicitvarystep').value;
if (tmp1.length) tmp = tmp + ',ystep===' + tmp1;
tmp += ')';
UI.insert(UI.focused, tmp);
},
assistant_plotfield_ok: function () {
UI.focused = UI.savefocused;
$id('assistant_plotfield').style.display = 'none';
var ctr = $id('plotfieldinit').value;
var tmp = $id('plotfieldexprf').value + ',[' + $id('plotfieldvarx').value + ',' + $id('plotfieldvary').value + ']';
if (ctr.length) tmp = 'plotfield(' + tmp + ',plotode===' + ctr; else tmp = 'plotfield(' + tmp;
var tmp1 = $id('plotfieldvarxstep').value;
if (tmp1.length) tmp = tmp + ',xstep===' + tmp1;
tmp1 = $id('plotfieldvarystep').value;
if (tmp1.length) tmp = tmp + ',ystep===' + tmp1;
tmp += ')';
UI.insert(UI.focused, tmp);
},
assistant_plotpolar_ok: function () {
UI.focused = UI.savefocused;
var tmp = 'plotpolar(' + $id('plotpolarexpr').value + ',' + $id('plotpolarvarname').value + ',' + $id('plotpolarvarmin').value + ',' + $id('plotpolarvarmax').value;
UI.insert(UI.focused, tmp);
tmp = $id('plotpolarvarstep').value;
if (tmp.length) UI.insert(UI.focused, ',tstep===' + tmp);
UI.insert(UI.focused, ')');
$id('assistant_plotpolar').style.display = 'none';
},
assistant_rand_setdisplay: function () {
var form = $id('assistant_rand');
if (form.rand_int.checked) {
$id('chooselawdiv').style.display = 'none';
$id('rand_intdiv').style.display = 'block';
} else {
$id('chooselawdiv').style.display = 'block';
$id('law_arg').style.display = 'none';
$id('rand_intdiv').style.display = 'none';
}
},
assistant_matr_maxrows: 40,
assistant_matr_maxcols: 6,
assistant_matr_textarea: -1,
assistant_matr_source: [], // JS array for spreadsheet, if length==0 matrix
is_sheet: true,
sheet_i: 0,
sheet_j: 0,
save_sheet:false,
open_sheet: function (tableur) {
UI.savesheet=true;
UI.funcoff();
UI.savefocused = UI.focused;
$id('assistant_matr').style.display = 'block';
$id('matr_type_chooser').style.display = 'inline';
$id('matr_stats').style.display = 'none';
UI.assistant_matr_setdisplay();
UI.is_sheet = tableur;
$id('matr_or_sheet').checked = tableur;
$id('matr_type_chooser').style.display = tableur ? 'none' : 'inline';
if (tableur) {
$id('assistant_matr').matr_formuleshadow.checked = true;
$id('assistant_matr').matr_formule.checked = false;
}
UI.assistant_matr_setdisplay();
if (tableur) UI.matrix2spreadsheet(); else UI.spreadsheet2matrix(false);
var field = $id('matr_span0_0');
UI.sheet_onfocus(field);
//UI.set_focus('matr_span0_0');
},
sheet_rowadd: function (n) {
var field = $id('matr_nrows');
field.value = eval(field.value) + n;
var f = $id('stat_lmax');
f.value++;
UI.assistant_matr_setdisplay();
},
sheet_coladd: function (n) {
var field = $id('matr_ncols');
field.value = eval(field.value) + n;
UI.assistant_matr_setdisplay();
},
sheet_edit_cmd: function (cmd) {
var s = UI.focused.id;
var sh = UI.is_sheet;
if (!sh) {
UI.is_sheet = true;
UI.matrix2spreadsheet();
}
if (s === undefined) return;
if (s.length < 12 || s.substr(0, 9) != 'matr_case') return;
var l = s.length, i, j, err;
for (i = 8; i < l; ++i) {
if (s[i] == '_') break;
}
j = eval(s.substr(i + 1, l - i - 1));
i = eval(s.substr(9, i - 9));
s = cmd + ',' + i + ',' + j;
//console.log(s);
UI.sheet_recompute(s);
if (!sh) {
UI.is_sheet = false;
UI.spreadsheet2matrix(false);
}
if (cmd == 2) UI.sheet_rowadd(1);
if (cmd == 3) UI.sheet_rowadd(-1);
if (cmd == 4) UI.sheet_coladd(1);
if (cmd == 5) UI.sheet_coladd(-1);
},
sheet_set_ij:function(s,i,j){
//console.log('sheet_set',s,i,j);
// set cell i,j from spreadsheet
// must set UI.sheet=true and call UI.sheet_recompute(''); at some point after
if (i>=UI.assistant_matr_maxrows || j>=UI.assistant_matr_maxcols)
return 0;
var field=$id('matr_nrows');
if (i>=field.value)
field.value=i+1;
field=$id('matr_ncols');
if (j>=field.value)
field.value=j+1;
field = $id('matr_case' + i + '_' + j);
field.value=s;
return 1;
},
current_sheet: function(t){ // t=0 create 3 values per cell, t=1 1 value
var R = $id('matr_nrows').value;//UI.assistant_matr_maxrows;
var C = $id('matr_ncols').value; // UI.assistant_matr_maxcols;
var s = 'spreadsheet[';
for (var i = 0; i < R; i++) {
s += '[';
for (var j = 0; j < C; j++) {
var field = $id('matr_case' + i + '_' + j);
if (t==0){
var tmp = '[' + field.value;
if (tmp.length == 1) tmp += '""';
s += tmp + ',0,0],';
}
else
s += field.value+',';
}
s += '],';
}
s += ']';
return s;
},
sheet_recompute: function (cmd) {
// if cmd=='' convert to CAS sheet, eval and convert back
// else calls convert(matrix,cmd), where cmd='command,row,col',
// command=0 copy down, =1 copy right
// console.log('sheet_recompute',cmd);
var R = UI.assistant_matr_maxrows;
if (!UI.is_sheet || R == 0) return;
var s=UI.current_sheet(0);
if (cmd.length != 0)
s = 'convert(' + s + ',cell,' + cmd + ')';
//console.log(s);
s = UI.caseval_noautosimp(s);
if (s == ' Clic_on_Exec ') return;
//console.log(s);
s = eval(s);
UI.assistant_matr_source = s;
//console.log(s);
if (R > s.length) R = s.length;
// dispatch to UI
for (var i = 0; i < R; i++) {
var r = s[i];
var C = r.length;
if (C > UI.assistant_matr_maxcols) C = UI.assistant_matr_maxcols;
for (var j = 0; j < C; j++) {
var field = $id('matr_span' + i + '_' + j);
var field2 = $id('matr_case' + i + '_' + j);
//console.log(i,j,field,r);
var tmp = r[j], tmp2;
if (tmp === undefined) continue;
if (r[j].length > 1) {
tmp2 = tmp[0];
tmp = tmp[1];
} else tmp2 = tmp = tmp[0];
if (r[j].length == 3) tmp = r[j][2];
// console.log(i,j,tmp);
if (tmp == '""') tmp = ' ';
field.innerHTML = tmp;
if (tmp2 == '""') tmp2 = '';
field2.value = tmp2;
//console.log(i,j,tmp,field.innerHTML);
// field.style.display='inline';
}
}
UI.link(0);
return 1;
},
matrix2spreadsheet: function () {
// convert matrix headers to spreadsheet and store source formulae
var l = UI.assistant_matr_maxrows;
var c = UI.assistant_matr_maxcols;
//console.log(l,c);
if (c > 26) {
UI.assistant_matr_maxcols = c = 26;
}
for (var j = 0; j < c; j++) {
$id('matr_head_' + j).innerHTML = String.fromCharCode(65 + j);
}
UI.is_sheet = true;
UI.sheet_recompute('');
for (var i = 0; i < l; i++) {
for (var j = 0; j < c; j++) {
//console.log(i,j);
var field = $id('matr_span' + i + '_' + j);
field.style.display = 'inline';
field.previousSibling.style.display = 'none';
}
}
},
spreadsheet2matrix: function (evaled) {
var l = UI.assistant_matr_maxrows;
var c = UI.assistant_matr_maxcols;
if (c > 26) {
UI.assistant_matr_maxcols = c = 26;
}
for (var j = 0; j < c; j++) {
$id('matr_head_' + j).innerHTML = '' + j;
}
for (var i = 0; i < l; i++) {
ligne = UI.assistant_matr_source[i];
for (var j = 0; j < c; j++) {
var tmp = ligne[j][1];
if (tmp == '""') tmp = '';
var field = $id('matr_case' + i + '_' + j);
if (evaled) field.value = tmp;
field.style.display = 'inline';
field.nextSibling.style.display = 'none';
}
}
UI.is_sheet = false;
},
sheet_onfocus: function (field) {
//console.log(field.id,field.previousSibling.id);
s = field.id;
var l = s.length, i, j, err;
for (i = 8; i < l; ++i) {
if (s[i] == '_') break;
}
j = eval(s.substr(i + 1, l - i - 1));
i = eval(s.substr(9, i - 9));
$id('matr_line_' + UI.sheet_i).style.color = "black";
$id('matr_head_' + UI.sheet_j).style.color = "black";
UI.sheet_i = i;
UI.sheet_j = j;
$id('matr_line_' + UI.sheet_i).style.color = "red";
$id('matr_head_' + UI.sheet_j).style.color = "red";
field = field.previousSibling;
field.style.display = 'inline';
field.focus();
UI.focused = field;
},
sheet_set: function (field, value) {
field.value = value;
var s = field.id;
if (s.length > 9 && s.substr(0, 9) == 'matr_case')
$id('matr_span' + s.substr(9, s.length - 9)).innerHTML = value;
},
assistant_matr_setmatrix: function (l, c) {
// Code de creation de la matrice
if (l * c > 10000) {
l = 100;
c = 100;
}
var mydiv = $id('matr_casediv');
mydiv.style.maxHeight = window.innerHeight / 2 + 'px';
mydiv.style.maxWidth = (window.innerWidth - 50) + 'px';
mydiv.style.overflow = "auto";
UI.assistant_matr_maxrows = l;
UI.assistant_matr_maxcols = c;
var s = '
';
//console.log(s);
mydiv.innerHTML = s;
if ($id('matr_or_sheet').checked) {
UI.matrix2spreadsheet();
}
//console.log(mydiv.innerHTML);
//mydiv.style.display='none';
},
sheet_blur: function (field) {
UI.cb_matr_enter(field, false);
//console.log(field.innerHTML);
//console.log(field.nextSibling.innerHTML);
field.style.display = 'none';
field.nextSibling.style.display = 'inline';
},
cell_handle: function(field,event){
console.log('cell',event);
if (event.keyCode!=13) return true;
UI.cb_matr_enter(field,true);
return false;
},
sheet_handle: function(field,event){
console.log('sheet',event);
return true;
},
cb_matr_enter: function (field, focusnext) {
var s = 'csv2gen("' + field.value + '",string)';
//console.log(s);
var se = UI.caseval_noautosimp(s);
if (se.length > 8 && se.substr(0, 8) == 'matrix[[')
se = se.substr(6, se.length - 6);
//console.log(se);
s = field.id;
var l = s.length, i, j, err;
for (i = 8; i < l; ++i) {
if (s[i] == '_') break;
}
j = eval(s.substr(i + 1, l - i - 1));
i = eval(s.substr(9, i - 9));
var form = $id('assistant_matr'), nr = form.matr_nrows.value, nc = form.matr_ncols.value;
try {
se = eval(se);
} catch (err) {
se = UI.caseval_noautosimp(field.value);
}
// console.log(i,j); // position dans la matrice
if (!Array.isArray(se)) {
//console.log(i,j,field.id); // position dans la matrice
UI.sheet_set(field, se);
i++;
if (i >= nr) {
i = 0;
j++;
if (j >= nc) j = 0;
}
UI.sheet_recompute('');
var tmp = 'matr_span' + i + '_' + j; // console.log(tmp);
if (focusnext) $id(tmp).click();
return;
}
else {
l = se.length;
if (l == 0) return;
var cell = se[0];
if (Array.isArray(cell)) {
// remplissage style matrice
var iend = i + l, j0 = j, ishift = i, extend = false;
if (iend >= UI.assistant_matr_maxnrows) iend = UI.assistant_matr_maxnrows;
if (iend > form.matr_nrows.value) {
extend = true;
form.matr_nrows.value = iend;
}
for (; i < iend; ++i) {
var ligne = se[i - ishift];
if (Array.isArray(ligne)) {
var j_ = j, jend = j + ligne.length;
if (jend >= UI.assistant_matr_maxncols) jend = UI.assistant_matr_maxncols;
if (jend > form.matr_ncols.value) {
extend = true;
form.matr_ncols.value = jend;
}
for (; j_ < jend; ++j_) UI.sheet_set($id('matr_case' + i + '_' + j_), ligne[j_ - j]);
}
else
UI.sheet_set($id('matr_case' + i + '_' + j), ligne);
}
if (extend) {
UI.assistant_matr_setdisplay();
UI.sheet_recompute('');
}
else {
//console.log(iend,j0);
if (iend >= nr) iend = 0;
if (j0 >= nc) j0 = 0;
UI.sheet_recompute('');
tmp = 'matr_span' + iend + '_' + j0;
if (focusnext) $id(tmp).click();
}
return;
}
// remplissage ligne i, colonnes j -> j+l-1
var jend = j + l, shift = j;
if (jend >= UI.assistant_matr_maxncols) jend = UI.assistant_matr_maxncols;
for (; j < jend; ++j)
UI.sheet_set($id('matr_case' + i + '_' + j), se[j - shift]);
UI.sheet_recompute('');
}
},
adequation: function (form) {
var test;
for (test = 0; test < 7; ++test) {
if (form.adequation[test].checked) break;
}
//console.log(test);
if (test == 0 || test == 1) {
$id('matr').style.display = 'none';
$id('matr_matr').style.display = 'none';
}
else {
$id('matr').style.display = 'block';
$id('matr_matr').style.display = 'block';
}
},
assistant_rand_ok: function () {
$id('assistant_rand').style.display = 'none';
$id('chooselawdiv').style.display = 'none';
UI.focused = UI.savefocused;
var nr = $id('rand_nrows').value;
var nc = $id('rand_ncols').value, tmp;
if (nc <= 0)
tmp = 'rand(';
else {
if (nr <= 0)
tmp = 'ranv(' + nc + ',';
else
tmp = 'ranm(' + nr + ',' + nc + ',';
}
var form = $id('assistant_rand');
var entier = form.rand_int.checked;
if (entier) {
var nm = $id('rand_maxint').value;
tmp += nm + ')';
}
else {
form = $id('chooselawform');
tmp += form.rand_law.value;
if (form.rand_law1.style.display != 'none')
tmp += ',' + form.rand_law1.value;
if (form.rand_law2.style.display != 'none')
tmp += ',' + form.rand_law2.value;
tmp += ')';
}
//console.log(tmp);
UI.insert(UI.focused, tmp);
},
assistant_matr_ok: function () {
var stats = $id('matr_stats').style.display != 'none';
var stat12 = $id('matr_stat12').style.display != 'none';
var stathyp = $id('matr_testhyp').style.display != 'none';
var fluctu = $id('risque_alpha').style.display != 'none';
$id('assistant_matr').style.display = 'none';
$id('chooselawdiv').style.display = 'none';
$id('risque_alpha').style.display = 'none';
UI.focused = UI.savefocused;
var tmp;
if (stats && !stat12 && !stathyp) {
var form = $id('chooselawform');
tmp = form.rand_law.value;
if (fluctu) tmp += '_icdf';
tmp += '(';
if (form.rand_law1.style.display != 'none')
tmp += form.rand_law1.value + ',';
if (form.rand_law2.style.display != 'none')
tmp += form.rand_law2.value + ',';
if (fluctu) {
var alpha = 0.05;
var alphaf = $id('adequation_alpha');
//console.log(alphaf.value); return;
if (alphaf.value.length) alpha = eval(alphaf.value);
tmp = tmp + alpha / 2 + '),\n' + tmp + (1 - alpha / 2) + ');';
}
else {
var argu = $id('law_arg');
tmp += argu.value + ')';
}
UI.insert(UI.focused, tmp);
return;
}
var form = $id('assistant_matr');
var mat = form.matr_name.value;
if (stats && mat.length == 0) mat = 'm_s';
var nrows = $id('matr_nrows');
var ncols = $id('matr_ncols');
var maxrows = 40, maxcols = 6;
if (ncols.value > maxcols) ncols.value = maxcols;
if (nrows.value > maxrows) nrows.value = maxrows;
if (mat.length) tmp = mat + ':=';
if (form.matr_formule.checked) {
tmp += 'matrix(' + nrows.value + ',' + ncols.value + ',';
tmp += '(j,k)->';
var expr = $id('matr_expr').value;
//console.log(expr);
if (!form.matr_start0.checked) expr = UI.caseval_noautosimp('subst(' + expr + ',[j,k],[j+1,k+1])');
tmp += expr;
tmp += ')';
}
else {
tmp += '[';
for (var i = 0; i < nrows.value; i++) {
tmp += '[';
for (var j = 0; j < ncols.value; j++) {
//console.log(j,tmp);
var val = $id('matr_case' + i + '_' + j).value;
if (UI.is_sheet && i < UI.assistant_matr_source.length) {
var ligne = UI.assistant_matr_source[i];
if (j < ligne.length) {
ligne = ligne[j];
if (ligne.length > 1) {
ligne = ligne[1];
if (ligne != '""') val = ligne;
}
}
}
if (val.length > 0) tmp += val; else tmp += '0';
if (j < ncols.value - 1) tmp += ',';
}
tmp += ']';
if (i < nrows.value - 1) tmp += ',\n';
}
tmp += ']';
}
if (stats) {
tmp += ':;\n';
var submat = mat + '[' + form.stat_lmin.value + '..' + form.stat_lmax.value + ',' + form.stat_cmin.value + '..' + form.stat_cmax.value + ']';
if (stat12) {
if (form.stat_mean.checked) tmp += 'mean(' + submat + ');\n';
if (form.stat_stddev.checked) tmp += 'stddev(' + submat + ');\n';
if (form.stat_quartiles.checked) tmp += 'quartiles(' + submat + ');\n';
if (form.stat_histo.checked) tmp += 'histogram(' + submat + ',0,1);\n';
if (form.stat_moustache.checked) tmp += 'moustache(' + submat + ');\n';
if (form.stat_scatter.checked) tmp += 'scatterplot(' + submat + ');\n';
if (form.stat_polygonscatter.checked) tmp += 'polygonscatterplot(' + submat + ');\n';
if (form.stat_linreg.checked) tmp += 'linear_regression_plot(' + submat + ');\n';
}
else {
var alpha = 0.05, test, hyp, mu = form.adequation_mu.value, sigma = 0, dof = 1;
if (form.adequation_alpha.value.length)
alpha = form.adequation_alpha.value;
if (form.adequation_sigma.value.length)
sigma = form.adequation_sigma.value;
for (test = 0; test < 7; ++test) {
if (form.adequation[test].checked) break;
}
for (hyp = 0; hyp < 3; ++hyp) {
if (form.adequation_alt[hyp].checked) break;
}
if (test == 3) tmp += 'chisquaret(';
if (test == 4) tmp += 'kolmogorovt(';
if (test == 5) tmp += 'wilcoxont(';
var l1 = form.stat_lmin.value, l2 = form.stat_lmax.value,
c1 = form.stat_cmin.value, c2 = form.stat_cmax.value;
if (test >= 3 && test <= 5) {
if (l2 - l1 > c2 - c1) { // lines
tmp += mat + '[' + l1 + '..' + l2 + ',' + c1 + '],';
tmp += mat + '[' + l1 + '..' + l2 + ',' + c2 + ']';
dof = l2 - l1;
}
else {
tmp += mat + '[' + l1 + ',' + c1 + '..' + c2 + '],';
tmp += mat + '[' + l2 + ',' + c1 + '..' + c2 + ']';
dof = c2 - c1;
}
if (test == 5) {
if (hyp == 0) tmp += ',\'<\'';
if (hyp == 1) tmp += ',\'!=\'';
if (hyp == 2) tmp += ',\'>\'';
tmp += ',' + alpha;
}
tmp += ');';
}
if (test == 3) tmp += 'chisquare_icdf(' + dof + ',' + (1 - alpha) + ');';
if (test == 6) tmp += 'normalt(';
if (test == 7) tmp += 'studentt(';
if (test == 0) {
var n = form.confiance_n.value, p = form.confiance_p.value;
var coeff = '1/2';
if (n > 100) coeff = 'sqrt(' + (n / (n - 1) * p * (1 - p)) + ')';
tmp = 'p:=' + p + ';n:=' + n + ';alpha:=' + alpha + ';\ndelta_p:=' + coeff + '*normald_icdf(0,1,(1-alpha/2))/sqrt(n);';
tmp += '\n[p-delta_p,p+delta_p];\n';
if (n * p < 5 || n * (1 - p) < 5) tmp = "Erreur : n*p et n*(1-p) doivent etre plus grand que 5";
UI.insert(UI.focused, tmp);
return;
}
if (test == 1) {
var n = form.confiance_n_.value, mu = form.confiance_mu.value, sigma = form.confiance_sigma.value;
tmp = 'mu:=' + mu + '; sigma:=' + sigma + ';\n';
tmp += 'delta:=sigma/sqrt(' + n + ')*student_icdf(' + n + ',' + (1 - alpha / 2) + ');\n';
tmp += '[mu-delta,mu+delta]';
}
if (test == 2) {
tmp += 'mu:=mean(flatten(' + submat + '));\n'
dof = (c2 - c1 + 1) * (l2 - l1 + 1) - 1;
tmp += 'delta:=stddevp(flatten(' + submat + '))/sqrt(' + dof + ')*student_icdf(' + dof + ',' + (1 - alpha / 2) + ');\n';
tmp += '[mu-delta,mu+delta]';
}
if (test == 6 || test == 7) {
tmp += 'flatten(' + submat + '),' + mu + ',';
if (sigma > 0)
tmp += sigma + ',';
if (hyp == 0) tmp += '\'<\'';
if (hyp == 1) tmp += '\'!=\'';
if (hyp == 2) tmp += '\'>\'';
tmp += ',' + alpha + ')';
}
}
}
//console.log(tmp);
UI.insert(UI.focused, tmp);
},
assistant_matr_setdisplay: function () {
$id('matr_matr').style.display = 'block';
$id('chooselawdiv').style.display = 'none';
var form = $id('assistant_matr');
if (form.matr_nrows.value < 0) form.matr_nrows.value = 0;
if (form.matr_ncols.value < 0) form.matr_ncols.value = 0;
if ($id('matr_stats').style.display != 'none') {
if (form.matr_nrows.value < 1) form.matr_nrows.value = 1;
if (form.matr_ncols.value < 1) form.matr_ncols.value = 1;
if (form.stat_lmax.value >= form.matr_nrows.value)
form.stat_lmax.value = form.matr_nrows.value - 1;
if (form.stat_lmin.value >= form.matr_nrows.value)
form.stat_lmin.value = form.matr_nrows.value - 1;
form.stat_lmax.max = form.matr_nrows.value - 1;
form.stat_lmin.max = form.matr_nrows.value - 1;
if (form.stat_cmax.value >= form.matr_ncols.value)
form.stat_cmax.value = form.matr_ncols.value - 1;
if (form.stat_cmin.value >= form.matr_ncols.value)
form.stat_cmin.value = form.matr_ncols.value - 1;
form.stat_cmax.max = form.matr_ncols.value - 1;
form.stat_cmin.max = form.matr_ncols.value - 1;
}
form.matr_ncols.max = UI.assistant_matr_maxncols;
form.matr_nrows.max = UI.assistant_matr_maxnrows;
if (form.matr_formule.checked) {
$id('matr_formulediv').style.display = 'inline';
UI.set_focus('matr_expr');
$id('matr').style.display = 'none';
} else {
$id('matr_formulediv').style.display = 'none';
$id('matr').style.display = 'block';
var nrows = $id('matr_nrows');
var ncols = $id('matr_ncols');
var maxrows = UI.assistant_matr_maxrows, maxcols = UI.assistant_matr_maxcols;
//console.log(nrows.value,maxrows,ncols.value,maxcols);
if (ncols.value < 1) ncols.value = 1;
if (ncols.value > maxcols) ncols.value = maxcols;
if (nrows.value < 1) nrows.value = 1;
if (nrows.value > maxrows) nrows.value = maxrows;
//console.log("matr",nrows.value,ncols.value);
var matr = [];
matr.length = maxrows;
for (var j = 0; j < maxcols; j++) {
var tmp = $id('matr_head_' + j);
if (j < ncols.value) tmp.style.visibility = 'visible'; else tmp.style.visibility = 'hidden';
}
for (var i = 0; i < maxrows; i++) {
//$id('matr_ligne'+i).style.visibility='hidden';
$id('matr_ligne' + i).style.display = 'none';
var ligne = [];
ligne.length = maxcols;
for (var j = 0; j < maxcols; j++) {
ligne[j] = $id('matr_case' + i + '_' + j);
ligne[j].style.display = 'none';
//console.log(j,ligne[j].parentNode.style.display);
ligne[j].parentNode.style.display = 'none';
ligne[j].nextSibling.style.display = 'none';
}
matr[i] = ligne;
}
for (var i = 0; i < nrows.value; i++) {
//$id('matr_ligne'+i).style.visibility='visible';
$id('matr_ligne' + i).style.display = 'table-row';
if (UI.is_sheet) {
for (var j = 0; j < ncols.value; j++) {
var f = matr[i][j];
// console.log(i,j,f.innerHTML);
f.nextSibling.style.display = 'inline';
f.parentNode.style.display = '';
}
}
else {
for (var j = 0; j < ncols.value; j++) {
matr[i][j].style.display = 'inline';
matr[i][j].parentNode.style.display = '';
}
}
}
//UI.set_focus(matr[0][0]);
}
},
toggleshift: function () {
UI.kbdshift = !UI.kbdshift;
if (UI.kbdshift) {
$id('shift_key').style.backgroundColor = "white";
$id('add_left_par').value = "[";
$id('add_right_par').value = "]";
$id('add_ln').value = "ln";
$id('add_sin').value = "asin";
$id('add_cos').value = "acos";
$id('add_tan').value = "atan";
$id('add_newline').value = "\\n";
$id('add_,').value = "'";
$id('add_:').value = "!";
$id('add_semi').value = "\"";
$id('add-=').value = "_";
// $id('add_infer').value=">";
$id('add_sqrt').value = "^2";
$id('add_/').value = "%";
$id('add_pi').value = "∞";
}
else {
$id('shift_key').style.backgroundColor = "cyan";
$id('add_left_par').value = "(";
$id('add_right_par').value = ")";
$id('add_ln').value = "exp";
$id('add_sin').value = "sin";
$id('add_cos').value = "cos";
$id('add_tan').value = "tan";
$id('add_newline').value = " ";
$id('add_,').value = ",";
$id('add_:').value = UI.python_mode ? ':' : ':=';
$id('add_semi').value = ";";
$id('add-=').value = "=";
// $id('add_infer').value="<";
$id('add_sqrt').value = "√";
$id('add_/').value = "/";
$id('add_pi').value = "π";
}
},
codemirror_setoptions: function (cmentree) {
UI.setoption_mode(cmentree);
cmentree.on("focus", function (cm) {
UI.set_focused(cm);
UI.set_editline(cm, true); // insure OK is visible on mobile
UI.set_config_width();
});
cmentree.setOption("extraKeys", {
Enter: function (cm) { // guess if newline evaluates or adds a newline
var start = cm.getCursor('from');
var end = cm.getCursor('to');
var tst = cm.lineCount() > 1;
if (!tst) { // if the line begins by function/fonction or def/for/if/while/si/tantque/pour
var txt = cm.getLine(end.line);
//console.log(txt);
var l = txt.length, i, j;
for (i = 0; i < l; i++) {
if (txt[i] != ' ') break;
}
for (j = i; j < l; j++) {
if (txt[j] == ' ') break;
}
txt = txt.substr(i, j - i);
//console.log(txt);
if (txt == "for" || txt == "while" || txt == "if" || txt == "pour" || txt == "tantque" || txt == "si" || txt == "def" || txt == "fonction" || txt == "function")
tst = true;
}
if (tst && (end.line != start.line || end.ch != start.ch || ((start.line > 0 || start.ch > 0) && UI.not_empty(cm.getLine(end.line)))))
UI.insert(cm, '\n');
else
//UI.set_editline(cmentree,false);
UI.eval_cmdline();
},
"Ctrl-Enter": function (cm) {
//UI.set_editline(cmentree,false);
UI.eval_cmdline();
},
Backspace: function (cm) {
UI.backspace(cm);
},
F1: function (cm) {
UI.completion(cm);
},
"Ctrl-Space": function (cm) {
UI.completion(cm);
},
Tab: function (cm) {
UI.indent_or_complete(cm);
},
});
},
switchcm: function () {
if (UI.usecm) {
if (cmentree == entree) {
// cmentree may be released with cmentree.toTextArea();
cmentree = CodeMirror.fromTextArea(entree, {
matchBrackets: true,
lineNumbers: true,
viewportMargin: Infinity
});
UI.setoption_mode(cmentree);
//console.log(entree.type);
//cmentree.setSize(window.innerWidth-20,40);
cmentree.options.indentUnit = UI.python_mode ? UI.python_indent : 2;
cmentree.on("focus", function (cm) {
UI.set_focused(cm);
UI.set_config_width();
});
cmentree.on("blur", function (cm) {
if (cm.getSelection().length > 0) {
UI.selection = cm.getSelection();
}
});
cmentree.setValue(entree.value);
UI.changefontsize(cmentree, 18);
UI.codemirror_setoptions(cmentree);
} // if (UI.usecm)
} else {
if (cmentree != entree) cmentree.toTextArea();
cmentree = entree;
}
cmentree.focus();
},
setoption_mode: function (cmentree) {
if (!UI.usecm) return;
if (UI.python_mode) {
//console.log('Python mode');
if (UI.micropy>0)
cmentree.setOption("mode", "micropy");
else
cmentree.setOption("mode", "python");
}
else {
//console.log('Xcas mode');
cmentree.setOption("mode", "simplemode");
}
},
kbdonfuncoff: function () {
UI.savefocused = UI.focused;
$id('keyboard').style.display = 'inline';
$id('keyboardfunc').style.display = 'none';
},
funcoff: function () {
UI.savefocused = UI.focused;
$id('keyboardfunc').style.display = 'none';
},
restorefrom: function (c) {
var s = UI.readCookie(c);
UI.restoresession(s, $id('mathoutput'), true, false);
//console.log(c.substring(6,c.length));
$id('outputfilename').value = c.substring(6, c.length);
$id('loadfile_cookie').innerHTML = '';
},
listCookies: function () { // list cookies with name begin == ' xcas__'
var aString = '';
if (window.localStorage) {
for (var i = 0, len = localStorage.length; i < len; i++) {
var tmp = localStorage.key(i);
//console.log(tmp);
if (tmp.substr(0, 6) == 'xcas__') {
var tmpname = tmp.substr(6, tmp.length - 6);
aString += "\n";
}
}
}
var theCookies = document.cookie.split(';');
for (var i = 0; i < theCookies.length; i++) {
// console.log(i,theCookies[i].substr(0,7));
var tmp = theCookies[i];
var pos = tmp.search('=');
if (pos > 7 && tmp.substr(0, 7) == ' xcas__') {
var tmpname = tmp.substr(7, pos - 7);
aString += "\n";
}
}
aString += "\n"
//console.log(aString);
return aString;
},
createCookie: function (name, value, days) {
if (window.localStorage) return localStorage.setItem(name, value);
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
},
readCookie: function (name) {
if (window.localStorage) {
var tmp = localStorage.getItem(name);
if (tmp != null) return tmp;
}
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
},
eraseCookie: function (name) {
if (window.localStorage) return localStorage.removeItem(name);
createCookie(name, "", -1);
},
detectmob: function () {
if (navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
) return true;
else
return false;
},
browser_type: function () {
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
var isFirefox = typeof InstallTrigger !== 'undefined'; // Firefox 1.0+
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
var isChrome = !!window.chrome && !isOpera; // Chrome 1+
var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6
if (isFirefox) return 1;
if (isSafari) return 2;
if (isChrome) return 3;
if (isIE) return 4;
if (isOpera) return 5;
return 0;
},
lowercase1: function (text) {
var value = text;
if (value.length && value.charCodeAt(0) > 64 && value.charCodeAt(0) < 90)
value = value.substr(0, 1).toLowerCase() + value.substr(1, value.length - 1);
return value;
},
add_autosimplify: function (value) {
var n = value.search(';');
if (value.length == 0 || value[0] == '@')
return value;
if (n < 0 || n >= value.length) {
var n = value.search('//');
if (n < 0 || n >= value.length) {
n = value.search('\'');
if (n < 0 || n >= value.length) {
//console.log('add_autosimp', value);
if (UI.python_mode)
return 'add_autosimplify(@@' + value + ')';
return 'add_autosimplify(' + value + ')';
}
}
}
return value;
},
mp_init:function(taille){
var init = Module.cwrap('mp_js_init', 'null', ['number']);
UI.micropy_initialized=1;
return init(taille);
},
mp_str:function(s){
var ev = Module.cwrap('mp_js_do_str', 'number', ['string']);
return ev(s);
},
set_xcas:function(){
UI.micropy=0; UI.python_mode=0;
var form = $id('config');
form.python_xor.checked = false;
form.python_mode.checked = false;
form.js_mode.checked=false;
UI.set_settings();
return UI.caseval('python_compat(0)');
},
set_xcas_python:function(){
UI.micropy=0; UI.python_mode=1;
var form = $id('config');
form.python_xor.checked = false;
form.python_mode.checked = true;
form.js_mode.checked=false;
UI.set_settings();
return UI.caseval('python_compat(1)');
},
set_micropython:function(){
UI.micropy=1; UI.python_mode=4;
var form = $id('config');
form.python_xor.checked = false;
form.python_mode.checked = true;
form.js_mode.checked=false;
UI.set_settings();
return UI.caseval('python_compat(4)');
},
quickjs:function(text){
while (text.length>0){
var ch=text.substr(text.length-1,1);
if (ch!=' ')
break;
text=text.substr(0,text.length-1);
}
if (text=='xcas' || text=='xcas '){
UI.set_xcas();
}
if (text=='.'){ // show turtle
let s=UI.caseval('avance(0)');
//console.log(s);
return s;
}
if (text==','){ // show (matplotl)
Module.print('>>> show()');
let s=UI.caseval('show()');
return s;
}
if (text==';'){
let s=UI.caseval('show_pixels()');
return s;
}
if (text.length>=2 && text[0]=='@'){
if (text[1]=='@')
return eval(text.substr(2,text.length-2));
text=text.substr(1,text.length-1);
}
else text='"use math";'+text;
let ev=Module.cwrap('quickjs_ck_eval', 'string', ['string']);
return ev(text);
},
classlist2evaluator:function(l){
if (l===undefined) return '';
let evals=['cas','xcas','micropy','js'];
for (let i=0;i0){
var ch=text.substr(text.length-1,1);
if (ch!=' ')
break;
text=text.substr(0,text.length-1);
}
if (text=='xcas' || text=='xcas '){
UI.micropy=0; UI.python_mode=0;
var form = $id('config');
form.python_xor.checked = false;
form.python_mode.checked = true;
form.js_mode.checked=false;
UI.set_settings();
return UI.caseval('python_compat(1)');
}
if (text=='.'){ // show turtle
var s=UI.caseval('avance(0)');
//console.log(s);
return s;
}
if (text==','){ // show (matplotl)
Module.print('>>> show()');
var s=UI.caseval('show()');
return s;
}
if (text==';'){
var s=UI.caseval('show_pixels()');
return s;
}
if (!UI.micropy_initialized){
UI.mp_init(UI.micropy_heap);
console.log('mp init done');
}
UI.python_output='';
/*
var pos=text.search('=');
if (pos<0){
pos=text.search('print');
if (pos<0)
text='print('+text+')';
}
*/
//console.log('mpeval',text);
Module.print('>>> '+text);
UI.mp_str(text);
// console.log('mpevaled',UI.python_output);
if (UI.python_output==''){
return '"Done"';
}
if (UI.python_output.substr(UI.python_output.length-1,1)=='\n')
UI.python_output=UI.python_output.substr(0,UI.python_output.length-1);
if (UI.python_output.length>4 && UI.python_output.substr(0,5)=='"