18 var lockedbackup = "";
21 function text_of_html(h)
30 function unescape_html(s)
32 u = document.getElementById("unescape");
34 return text_of_html(u)
37 function filterByClass (elements,cname){
38 var itemsfound = new Array;
39 for(var i=0;i<elements.length;i++){
40 if(elements[i].className == cname){
41 itemsfound.push(elements[i]);
49 if (readCookie("session") == null) {
50 window.location = "/login.html"
53 titlebar = document.getElementById("titlebar");
54 matitaTitle = document.getElementById("matitaTitle");
55 apparea = document.getElementById("matitaapparea");
56 locked = document.getElementById("locked");
57 unlocked = document.getElementById("unlocked");
58 toparea = document.getElementById("toparea");
59 workarea = document.getElementById("workarea");
60 scriptcell = document.getElementById("scriptcell");
61 sidearea = document.getElementById("sidearea");
62 disambcell = document.getElementById("disambcell");
63 goalcell = document.getElementById("goalcell");
64 goals = document.getElementById("goals");
65 goalview = document.getElementById("goalview");
66 filename = document.getElementById("filename");
67 logarea = document.getElementById("logarea");
68 advanceButton = document.getElementById("advance");
69 retractButton = document.getElementById("retract");
70 cursorButton = document.getElementById("cursor");
71 bottomButton = document.getElementById("bottom");
72 dialogBox = document.getElementById("dialogBox");
73 uploadBox = document.getElementById("uploadBox");
74 dialogTitle = document.getElementById("dialogTitle");
75 dialogContent = document.getElementById("dialogContent");
77 matita = new Object();
78 matita.disambMode = matita.proofMode = false;
80 // hide sequent view at start
84 changeFile("test.ma");
86 // initialize keyboard events in the unlocked script
87 init_keyboard(unlocked);
94 function init_autotraces() {
95 $("#unlocked .autotactic").tooltip({
98 bodyHandler: function() {
99 return (trace_of($(this)[0]));
102 $("#locked .autotactic").tooltip({
105 bodyHandler: function() {
106 return (trace_of($(this)[0]));
111 function trace_of(node) {
112 return text_of_html(filterByClass(node.childNodes,"autotrace")[0]);
115 function changeFile(name) {
116 current_fname = name;
117 matitaTitle.innerHTML = "Matita - cic:/matita/" + name;
120 function init_keyboard(target)
122 if (target.addEventListener)
124 // target.addEventListener("keydown",keydown,false);
125 target.addEventListener("keypress",keypress,false);
126 // target.addEventListener("keyup",keyup,false);
127 // target.addEventListener("textInput",textinput,false);
129 else if (target.attachEvent)
131 // target.attachEvent("onkeydown", keydown);
132 target.attachEvent("onkeypress", keypress);
133 // target.attachEvent("onkeyup", keyup);
134 // target.attachEvent("ontextInput", textinput);
138 // target.onkeydown= keydown;
139 target.onkeypress= keypress;
140 // target.onkeyup= keyup;
141 // target.ontextinput= textinput; // probably doesn't work
148 if (n == null) return 'undefined';
150 if (n >= 32 && n < 127) s+= ' (' + String.fromCharCode(n) + ')';
151 while (s.length < 9) s+= ' ';
155 function string_of_key(n)
157 if (n == null) return 'undefined';
158 return String.fromCharCode(n);
161 function pressmesg(w,e)
163 debug(w + ' keyCode=' + keyval(e.keyCode) +
164 ' which=' + keyval(e.which) +
165 ' charCode=' + keyval(e.charCode) +
166 '\n shiftKey='+e.shiftKey
167 + ' ctrlKey='+e.ctrlKey
168 + ' altKey='+e.altKey
169 + ' metaKey='+e.metaKey);
172 function suppressdefault(e,flag)
176 if (e.preventDefault) e.preventDefault();
177 if (e.stopPropagation) e.stopPropagation();
182 function restoreSelection(r) {
185 if (window.getSelection)//non IE and there is already a selection
187 var s = window.getSelection();
188 if (s.rangeCount > 0)
193 if (document.createRange)//non IE and no selection
195 window.getSelection().addRange(r);
198 if (document.selection)//IE
205 function lookup_tex(texmacro)
207 texmacro = texmacro.substring(1);
208 return unescape(macro2utf8[texmacro]);
211 function strip_tags(tagname,classname)
213 var tags = unlocked.getElementsByTagName(tagname);
214 if (is_defined(classname)) {
215 tags = filterByClass(tags,classname);
217 for (i = 0; i < tags.length; i++) {
218 var children = tags[i].childNodes;
219 for (j = 0; j < children.length; j++) {
220 tags[i].parentNode.insertBefore(children[j],tags[i]);
223 while (tags.length > 0) {
224 tags[0].parentNode.removeChild(tags[0]);
228 function strip_interpr() {
230 alert("strip_interpr ended");
236 pressmesg('keypress',e);
237 var s = string_of_key(e.charCode);
238 strip_tags("span","error");
241 i = unlocked.innerHTML.html_to_matita().lastIndexOf('\\',j);
243 match = unlocked.innerHTML.html_to_matita().substring(i,j);
244 sym = unescape_html(lookup_tex(match));
245 if (sym != "undefined") {
246 if (window.getSelection) { // non IE
247 savedRange.setStart(savedsc,savedso - (j-i));
248 savedRange.deleteContents();
249 savedRange.insertNode(document.createTextNode(sym));
250 savedsc.parentNode.normalize();
251 if (savedRange.collapsed) { // Mozilla
252 savedRange.setEnd(savedsc,savedRange.endOffset + sym.length);
254 savedRange.collapse(false);
256 savedRange.moveStart(i-j);
257 savedRange.text(sym);
258 savedRange.collapse(false);
260 restoreSelection(savedRange);
261 return suppressdefault(e,true);
264 // restoreSelection(0);
265 return suppressdefault(e,false);
268 else return suppressdefault(e,false);
270 return suppressdefault(e,false);
278 // internet explorer (v.9) doesn't work with innerHTML
279 // but google chrome's innerText is, in a sense, "write only"
280 // what should we do?
281 // logarea.innerText = txt + "\n" + logarea.innerText;
282 logtxt = /* logtxt + "\n" +*/ txt;
286 logWin = window.open( "", "Matita Log",
287 "width=600,height=450,status,scrollbars,resizable,screenX=20,screenY=40,left=20,top=40");
288 logWin.document.write('<html><head><title>Matita Log' + '</title></head>');
289 logWin.document.write('<body><textarea style="width:100%;height:100%;">' +
290 logtxt + '</textarea></body></html>');
291 logWin.document.close();
297 debug("hd of '" + l + "' = '" + ar[0] + "'");
305 debug("tl of '" + l + "' = '" + tl + "'");
309 function listcons(x,l)
311 debug("cons '" + x + "' on '" + l + "'");
312 return (x + "#" + l);
325 function fold_left (f,acc,l)
328 { debug("'" + l + "' is fold end");
331 { debug("'" + l + "' is fold cons");
332 return(fold_left (f,f(acc,(listhd(l))),listtl(l))); }
335 function listiter (f,l)
338 { debug("'" + l + "' is nil");
343 debug("'" + l + "' is not nil");
345 listiter(f,listtl(l));
349 function listmap (f,l)
351 debug("listmap on " + l);
353 { debug("returning listnil");
357 { debug("cons f(hd) map(f,tl)");
358 return(f(listhd(l)) + "#" + listmap(f,listtl(l)));
362 var statements = listnil();
365 var metalist = listnil();
367 function pairmap (f,p)
369 debug("pairmap of '" + p + "'");
371 return (f(ar[0],ar[1]));
374 function tripletmap (f,p)
376 debug("tripletmap of '" + p + "'");
378 return (f(ar[0],ar[1],ar[2]));
384 return (pairmap (function (a,b) { return (a); }, p));
390 return (tripletmap (function (a,b,c) { return (a); }, p));
396 return (tripletmap (function (a,b,c) { return (b); }, p));
402 return (tripletmap (function (a,b,c) { return (c); }, p));
405 function populate_goalarray(menv)
407 debug("metasenv.length = " + menv.length);
408 if (menv.length == 0) {
414 goalarray = new Array();
415 metalist = listnil();
416 var tmp_goallist = "";
417 for (i = 0; i < menv.length; i++) {
418 metano = menv[i].getAttribute("number");
419 metaname = menv[i].childNodes[0].childNodes[0].data;
420 goal = menv[i].childNodes[1].childNodes[0].data;
421 debug ("found meta n. " + metano);
422 debug ("found goal\nBEGIN" + goal + "\nEND");
423 goalarray[metano] = goal;
424 tmp_goallist = " <A href=\"javascript:switch_goal(" + metano + ")\">" + metaname + "</A>" + tmp_goallist;
425 metalist = listcons(metano,metalist);
426 debug ("goalarray[\"" + metano + "\"] = " + goalarray[metano]);
428 goals.innerHTML = tmp_goallist;
429 debug("new metalist is '" + metalist + "'");
430 if (is_nil(metalist)) {
434 switch_goal(listhd(metalist));
439 function switch_goal(meta)
441 if (typeof meta == "undefined") {
442 goalview.innerHTML = "";
445 debug("switch_goal " + meta + "\n" + goalarray[meta]);
446 goalview.innerHTML = "<B>Goal ?" + meta + ":</B>\n\n" + goalarray[meta];
450 // the following is used to avoid escaping unicode, which results in
451 // the server being unable to unescape the string
452 String.prototype.sescape = function() {
458 result = result.replace(patt1,"%25");
459 result = result.replace(patt2,"%3D");
460 result = result.replace(patt3,"%26");
461 result = result.replace(patt4,"%2B");
465 String.prototype.html_to_matita = function()
467 var patt1 = /<br(\/|)>/gi;
470 var patt4 = /</gi;
471 var patt5 = />/gi;
472 var patt6 = / /gi;
474 result = result.replace(patt1,"\n");
475 result = result.replace(patt2,"\005");
476 result = result.replace(patt3,"\006");
477 result = result.replace(patt4,"<");
478 result = result.replace(patt5,">");
479 result = result.replace(patt6," ");
480 return (unescape(result));
483 String.prototype.matita_to_html = function()
487 var patt3 = /\005/gi;
488 var patt4 = /\006/gi;
490 result = result.replace(patt1,"<");
491 result = result.replace(patt2,">");
492 result = result.replace(patt3,"<");
493 result = result.replace(patt4,">");
494 return (unescape(result));
499 advanceButton.disabled = true;
500 retractButton.disabled = true;
501 cursorButton.disabled = true;
502 bottomButton.disabled = true;
507 advanceButton.disabled = false;
508 retractButton.disabled = false;
509 cursorButton.disabled = false;
510 bottomButton.disabled = false;
513 function is_defined(x)
515 return (typeof x != "undefined");
518 /* servicename: name of the service being called
519 * reqbody: text of the request
520 * processResponse: processes the server response
521 * (takes the response text in input, undefined in case of error)
523 function callServer(servicename,processResponse,reqbody)
527 if (window.XMLHttpRequest)
529 req = new XMLHttpRequest();
531 else if (window.ActiveXObject)
534 req = new ActiveXObject("Msxml2.XMLHTTP");
538 req = new ActiveXObject("Microsoft.XMLHTTP");
542 req.onreadystatechange = function()
550 stxt = req.statusText;
553 debug(req.responseText);
554 if (window.DOMParser) {
555 parser=new DOMParser();
556 xmlDoc=parser.parseFromString(req.responseText,"text/xml");
558 else // Internet Explorer
560 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
561 xmlDoc.async="false";
562 xmlDoc.loadXML(req.responseText);
564 processResponse(xmlDoc);
570 req.open("POST", servicename); // + escape(unlocked.innerHTML), true);
571 req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
580 function advanceForm1()
582 processor = function(xml) {
583 if (is_defined(xml)) {
584 var parsed = xml.getElementsByTagName("parsed")[0];
585 var ambiguity = xml.getElementsByTagName("ambiguity")[0];
586 if (is_defined(parsed)) {
587 // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
588 var len = parseInt(parsed.getAttribute("length"));
589 // len0 = unlocked.innerHTML.length;
590 var unescaped = unlocked.innerHTML.html_to_matita();
591 var parsedtxt = parsed.childNodes[0].nodeValue;
592 //parsedtxt = unescaped.substr(0,len);
593 var unparsedtxt = unescaped.substr(len);
594 lockedbackup += parsedtxt;
595 locked.innerHTML = lockedbackup;
596 unlocked.innerHTML = unparsedtxt.matita_to_html();
597 // len1 = unlocked.innerHTML.length;
598 // len2 = len0 - len1;
599 var len2 = parsedtxt.length;
600 var metasenv = xml.getElementsByTagName("meta");
601 populate_goalarray(metasenv);
603 statements = listcons(len2,statements);
604 unlocked.scrollIntoView(true);
606 else if (is_defined(ambiguity)) {
607 var start = parseInt(ambiguity.getAttribute("start"));
608 var stop = parseInt(ambiguity.getAttribute("stop"));
609 var choices = xml.getElementsByTagName("choice");
611 matita.ambiguityStart = start;
612 matita.ambiguityStop = stop;
613 matita.unlockedbackup = unlocked.innerHTML.html_to_matita();
614 matita.interpretations = [];
616 var unlockedtxt = unlocked.innerHTML.html_to_matita();
617 var pre = unlockedtxt.substring(0,start).matita_to_html();
618 var mid = unlockedtxt.substring(start,stop).matita_to_html();
619 var post = unlockedtxt.substring(stop).matita_to_html();
620 unlocked.innerHTML = pre +
621 "<span class=\"error\" title=\"disambiguation error\">" +
622 mid + "</span>" + post;
624 var title = "<H3>Ambiguous input</H3>";
625 disambcell.innerHTML = title;
626 for (i = 0;i < choices.length;i++) {
627 matita.interpretations[i] = new Object();
629 var href = choices[i].getAttribute("href");
630 var title = choices[i].getAttribute("title");
631 var desc = choices[i].childNodes[0].nodeValue;
633 matita.interpretations[i].href = href;
634 matita.interpretations[i].title = title;
635 matita.interpretations[i].desc = desc;
637 var choice = document.createElement("input");
638 choice.setAttribute("type","radio");
639 choice.setAttribute("name","interpr");
640 choice.setAttribute("href",href);
641 choice.setAttribute("title",title);
642 if (i == 0) choice.setAttribute("checked","");
644 disambcell.appendChild(choice);
645 disambcell.appendChild(document.createTextNode(desc));
646 disambcell.appendChild(document.createElement("br"));
649 var okbutton = document.createElement("input");
650 okbutton.setAttribute("type","button");
651 okbutton.setAttribute("value","OK");
652 okbutton.setAttribute("onclick","do_disambiguate()");
653 var cancelbutton = document.createElement("input");
654 cancelbutton.setAttribute("type","button");
655 cancelbutton.setAttribute("value","Cancel");
656 cancelbutton.setAttribute("onclick","cancel_disambiguate()");
658 disambcell.appendChild(okbutton);
659 disambcell.appendChild(cancelbutton);
663 matita.disambMode = true;
667 var error = xml.getElementsByTagName("error")[0];
668 unlocked.innerHTML = error.childNodes[0].nodeValue;
669 // debug(xml.childNodes[0].nodeValue);
672 debug("advance failed");
677 callServer("advance",processor,"body=" + (unlocked.innerHTML.html_to_matita()).sescape());
681 function gotoBottom()
683 processor = function(xml) {
684 if (is_defined(xml)) {
685 // debug("goto bottom: received response\nBEGIN\n" + req.responseText + "\nEND");
686 parsed = xml.getElementsByTagName("parsed")[0];
687 len = parseInt(parsed.getAttribute("length"));
689 // len0 = unlocked.innerHTML.length;
690 unescaped = unlocked.innerHTML.html_to_matita();
691 // not working in mozilla
692 // parsedtxt = parsed.childNodes[0].nodeValue;
693 parsedtxt = parsed.childNodes[0].wholeText;
694 //parsedtxt = unescaped.substr(0,len);
695 unparsedtxt = unescaped.substr(len);
696 lockedbackup += parsedtxt;
697 locked.innerHTML = lockedbackup; //.matita_to_html();
698 unlocked.innerHTML = unparsedtxt.matita_to_html();
699 // len1 = unlocked.innerHTML.length;
700 len2 = parsedtxt.length;
701 metasenv = xml.getElementsByTagName("meta");
703 populate_goalarray(metasenv);
705 statements = listcons(len2,statements);
706 unlocked.scrollIntoView(true);
709 debug("goto bottom failed");
714 callServer("bottom",processor,"body=" + (unlocked.innerHTML.html_to_matita()).sescape());
721 processor = function(xml) {
722 if (is_defined(xml)) {
723 if (xml.childNodes[0].textContent != "ok") {
724 debug("goto top failed");
727 statements = listnil();
729 lockedlen = locked.innerHTML.length - statementlen;
730 statement = locked.innerHTML.substr(lockedlen, statementlen);
731 locked.innerHTML = locked.innerHTML.substr(0,lockedlen);
732 unlocked.innerHTML = statement + unlocked.innerHTML;
734 unlocked.innerHTML = lockedbackup + unlocked.innerHTML;
736 locked.innerHTML = lockedbackup;
739 unlocked.scrollIntoView(true);
741 debug("goto top failed");
746 callServer("top",processor,"body=" + (unlocked.innerHTML.html_to_matita()).sescape());
749 function gotoPos(offset)
751 if (!is_defined(offset)) {
752 offset = getCursorPos();
754 processor = function(xml) {
755 if (is_defined(xml)) {
756 parsed = xml.getElementsByTagName("parsed")[0];
757 len = parseInt(parsed.getAttribute("length"));
758 // len0 = unlocked.innerHTML.length;
759 unescaped = unlocked.innerHTML.html_to_matita();
760 parsedtxt = parsed.childNodes[0].nodeValue;
761 //parsedtxt = unescaped.substr(0,len);
762 unparsedtxt = unescaped.substr(len);
763 lockedbackup += parsedtxt;
764 locked.innerHTML = lockedbackup; //.matita_to_html();
765 unlocked.innerHTML = unparsedtxt.matita_to_html();
766 // len1 = unlocked.innerHTML.length;
767 len2 = parsedtxt.length;
768 metasenv = xml.getElementsByTagName("meta");
769 // populate_goalarray(metasenv);
770 statements = listcons(len2,statements);
771 unlocked.scrollIntoView(true);
772 // la populate non andrebbe fatta a ogni passo
775 populate_goalarray(metasenv);
778 gotoPos(offset - len);
782 unlocked.scrollIntoView(true);
783 populate_goalarray(metasenv);
788 callServer("advance",processor,"body=" + (unlocked.innerHTML.html_to_matita()).sescape());
793 processor = function(xml) {
794 if (typeof xml != "undefined") {
795 // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
796 statementlen = parseInt(listhd(statements));
797 statements = listtl(statements);
799 lockedlen = locked.innerHTML.length - statementlen;
800 statement = locked.innerHTML.substr(lockedlen, statementlen);
801 locked.innerHTML = locked.innerHTML.substr(0,lockedlen);
802 unlocked.innerHTML = statement + unlocked.innerHTML;
804 lockedlen = lockedbackup.length - statementlen;
805 statement = lockedbackup.substr(lockedlen, statementlen);
806 lockedbackup = lockedbackup.substr(0,lockedlen);
807 locked.innerHTML = lockedbackup;
808 unlocked.innerHTML = statement + unlocked.innerHTML;
809 metasenv = xml.getElementsByTagName("meta");
811 populate_goalarray(metasenv);
812 unlocked.scrollIntoView(true);
814 debug("retract failed");
820 callServer("retract",processor);
826 processor = function(xml)
828 if (is_defined(xml)) {
830 locked.innerHTML = lockedbackup;
831 unlocked.innerHTML = xml.documentElement.wholeText;
833 debug("file open failed");
836 callServer("open",processor,"file=" + escape(filename.value));
839 function retrieveFile(thefile)
841 processor = function(xml)
843 if (is_defined(xml)) {
846 locked.innerHTML = lockedbackup;
847 // code originally used in google chrome (problems with mozilla)
848 // debug(xml.getElementsByTagName("file")[0].childNodes[0].nodeValue);
849 // unlocked.innerHTML = xml.getElementsByTagName("file")[0].childNodes[0].nodeValue;
850 debug(xml.childNodes[0].textContent);
851 if (document.all) { // IE
852 unlocked.innerHTML = xml.childNodes[0].text;
854 unlocked.innerHTML = xml.childNodes[0].textContent;
859 debug("file open failed");
863 callServer("open",processor,"file=" + escape(thefile));
866 function showLibrary(title,callback,reloadDialog)
869 dialogBox.reload = reloadDialog;
871 if (window.XMLHttpRequest)
873 req = new XMLHttpRequest();
875 else if (window.ActiveXObject)
878 req = new ActiveXObject("Msxml2.XMLHTTP");
882 req = new ActiveXObject("Microsoft.XMLHTTP");
886 req.onreadystatechange = function()
894 stxt = req.statusText;
897 debug(req.responseText);
898 showDialog("<H2>" + title + "</H2>",req.responseText, callback);
902 req.open("POST", "viewlib"); // + escape(unlocked.innerHTML), true);
903 req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
908 function uploadDialog()
910 uploadBox.style.display = "block";
915 var file = document.getElementById("uploadFilename").files[0];
917 var filecontent = file.getAsText("UTF-8");
918 locked.innerHTML = lockedbackup;
919 unlocked.innerHTML = filecontent;
920 uploadBox.style.display = "none";
923 // var reader = new FileReader();
924 // reader.readAsText(file, "UTF-8");
925 // reader.onloadend = function (evt) {
926 // lockedbackup = "";
927 // locked.innerHTML = lockedbackup
928 // unlocked.innerHTML = evt.target.result;
929 // uploadBox.style.display = "none";
931 // reader.onerror = function (evt) {
932 // debug("file open failed");
933 // uploadBox.style.display = "none";
938 function openDialog()
940 callback = function (fname) { retrieveFile(fname); };
941 showLibrary("Open file", callback, openDialog);
944 function saveDialog()
946 callback = function (fname) {
949 (locked.innerHTML.html_to_matita()).sescape(),
950 (unlocked.innerHTML.html_to_matita()).sescape(),
953 showLibrary("Save file as", callback, saveDialog);
958 callback = function (fname) {
960 saveFile(fname,"","",false,newDialog,true);
962 showLibrary("Create new file", callback, newDialog);
966 function saveFile(fname,lockedtxt,unlockedtxt,force,reloadDialog,reloadFile)
968 if (!is_defined(reloadFile)) { reloadFile = true };
969 if (!is_defined(fname)) {
970 fname = current_fname;
971 lockedtxt = (locked.innerHTML.html_to_matita()).sescape();
972 unlockedtxt = (unlocked.innerHTML.html_to_matita()).sescape();
974 // when force is true, reloadDialog is not needed
976 processor = function(xml) {
977 if (is_defined(xml)) {
978 if (xml.childNodes[0].textContent != "ok") {
979 if (confirm("File already exists. All existing data will be lost.\nDo you want to proceed anyway?")) {
980 saveFile(fname,lockedtxt,unlockedtxt,true,reloadDialog,reloadFile);
986 debug("file saved!");
987 if (reloadFile) { retrieveFile(fname); }
990 debug("save file failed");
994 if (is_defined(fname)) {
996 callServer("save",processor,"file=" + escape(fname) +
997 "&locked=" + lockedtxt +
998 "&unlocked=" + unlockedtxt +
1001 else { debug("no file selected"); }
1004 function createDir() {
1006 dirname = prompt("New directory name:\ncic:/matita/","newdir");
1007 if (dirname != null) {
1008 processor = function(xml) {
1009 if (is_defined(xml)) {
1010 if (xml.childNodes[0].textContent != "ok") {
1011 alert("An error occurred :-(");
1014 alert("An error occurred :-(");
1019 callServer("save",processor,"file=" + escape(dirname) +
1020 "&locked=&unlocked=&force=false&dir=true");
1026 function commitAll()
1028 processor = function(xml) {
1029 if (is_defined(xml)) {
1030 debug(xml.getElementsByTagName("details")[0].textContent);
1031 alert("Commit executed: see details in the log.\n\n" +
1032 "NOTICE: this message does NOT imply (yet) that the commit was successful.");
1034 alert("Commit failed!");
1039 callServer("commit",processor);
1042 function updateAll()
1044 processor = function(xml) {
1045 if (is_defined(xml)) {
1046 alert("Update executed.\n\n" +
1048 xml.getElementsByTagName("details")[0].textContent);
1050 alert("Update failed!");
1055 callServer("update",processor);
1060 function hideSequent() {
1061 matita.proofMode = false;
1065 function showSequent() {
1066 matita.proofMode = true;
1070 function showDialog(title,content,callback) {
1071 dialogTitle.innerHTML = title;
1072 dialogContent.innerHTML = content;
1073 dialogBox.callback = callback;
1075 //Get the screen height and width
1076 var maskHeight = $(document).height();
1077 var maskWidth = $(window).width();
1079 //Set heigth and width to mask to fill up the whole screen
1080 $('#mask').css({'width':maskWidth,'height':maskHeight});
1083 $('#mask').fadeIn(100);
1084 $('#mask').fadeTo(200,0.8);
1086 //Get the window height and width
1087 var winH = $(window).height();
1088 var winW = $(window).width();
1090 //Set the popup window to center
1091 $('#dialogBox').css('top', winH/2-$('#dialogBox').height()/2);
1092 $('#dialogBox').css('left', winW/2-$('#dialogBox').width()/2);
1095 $('#dialogBox').fadeIn(200);
1097 dialogBox.style.display = "block";
1100 function abortDialog(dialog) {
1102 dialogBox.style.display = "none";
1105 function removeElement(id) {
1106 var element = document.getElementById(id);
1107 element.parentNode.removeChild(element);
1113 function getCursorPos() {
1115 if (window.getSelection) {
1116 var selObj = window.getSelection();
1117 savedRange = selObj.getRangeAt(0);
1118 savedsc = savedRange.startContainer;
1119 savedso = savedRange.startOffset;
1120 //cursorPos = findNode(selObj.anchorNode.parentNode.childNodes, selObj.anchorNode) + selObj.anchorOffset;
1121 cursorPos = findNode(unlocked.childNodes, selObj.anchorNode,0) + selObj.anchorOffset;
1122 /* FIXME the following works wrong in Opera when the document is longer than 32767 chars */
1125 else if (document.selection) {
1126 savedRange = document.selection.createRange();
1127 var bookmark = savedRange.getBookmark();
1128 /* FIXME the following works wrong when the document is longer than 65535 chars */
1129 cursorPos = bookmark.charCodeAt(2) - 11; /* Undocumented function [3] */
1134 function findNode(list, node, acc) {
1135 for (var i = 0; i < list.length; i++) {
1136 if (list[i] == node) {
1137 // debug("success " + i);
1140 if (list[i].hasChildNodes()) {
1142 // debug("recursion on node " + i);
1143 return (findNode(list[i].childNodes,node,acc))
1145 catch (e) { /* debug("recursion failed"); */ }
1147 sandbox = document.getElementById("sandbox");
1148 dup = list[i].cloneNode(true);
1149 sandbox.appendChild(dup);
1150 // debug("fail " + i + ": " + sandbox.innerHTML);
1151 acc += sandbox.innerHTML.html_to_matita().length;
1152 sandbox.removeChild(dup);
1158 debug("cursor test: " + unlocked.innerHTML.substr(0,getCursorPos()));
1161 function get_checked_index(name) {
1162 var radios = document.getElementsByName(name);
1163 for (i = 0; i < radios.length; i++) {
1164 if (radios[i].checked) {
1171 function cancel_disambiguate() {
1172 matita.disambMode = false;
1173 $('#whitemask').hide();
1177 function do_disambiguate() {
1178 var i = get_checked_index("interpr");
1180 var pre = matita.unlockedbackup
1181 .substring(0,matita.ambiguityStart).matita_to_html();
1182 var mid = matita.unlockedbackup
1183 .substring(matita.ambiguityStart,matita.ambiguityStop)
1185 var post = matita.unlockedbackup
1186 .substring(matita.ambiguityStop).matita_to_html();
1188 var href = matita.interpretations[i].href;
1189 var title = matita.interpretations[i].title;
1191 if (is_defined(title)) {
1192 mid = "<A href=\"" + href + "\" title=\"" + title + "\">" + mid + "</A>";
1194 mid = "<A href=\"" + href + "\">" + mid + "</A>";
1197 unlocked.innerHTML = pre + mid + post;
1199 matita.disambMode = false;
1200 $('#whitemask').hide();
1205 function readCookie(name) {
1206 var nameEQ = name + "=";
1207 var ca = document.cookie.split(';');
1208 for(var i=0;i < ca.length;i++) {
1210 while (c.charAt(0)==' ') c = c.substring(1,c.length);
1211 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
1216 function delete_cookie ( cookie_name )
1218 var cookie_date = new Date(); // current date & time
1219 cookie_date.setTime ( cookie_date.getTime() - 1 );
1220 document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
1223 function delete_session()
1225 delete_cookie("session");
1228 function disable_toparea() {
1229 var offset = $('#toparea').offset();
1230 $('#whitemask').css('top',offset.top);
1231 $('#whitemask').css('left',offset.left);
1232 $('#whitemask').css('width',$('#toparea').outerWidth() + "px");
1233 $('#whitemask').css('height',$('#toparea').outerHeight() + "px");
1234 $('#whitemask').fadeTo('fast',0.7);