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);
91 function changeFile(name) {
93 matitaTitle.innerHTML = "Matita - cic:/matita/" + name;
96 function init_keyboard(target)
98 if (target.addEventListener)
100 // target.addEventListener("keydown",keydown,false);
101 target.addEventListener("keypress",keypress,false);
102 // target.addEventListener("keyup",keyup,false);
103 // target.addEventListener("textInput",textinput,false);
105 else if (target.attachEvent)
107 // target.attachEvent("onkeydown", keydown);
108 target.attachEvent("onkeypress", keypress);
109 // target.attachEvent("onkeyup", keyup);
110 // target.attachEvent("ontextInput", textinput);
114 // target.onkeydown= keydown;
115 target.onkeypress= keypress;
116 // target.onkeyup= keyup;
117 // target.ontextinput= textinput; // probably doesn't work
124 if (n == null) return 'undefined';
126 if (n >= 32 && n < 127) s+= ' (' + String.fromCharCode(n) + ')';
127 while (s.length < 9) s+= ' ';
131 function string_of_key(n)
133 if (n == null) return 'undefined';
134 return String.fromCharCode(n);
137 function pressmesg(w,e)
139 debug(w + ' keyCode=' + keyval(e.keyCode) +
140 ' which=' + keyval(e.which) +
141 ' charCode=' + keyval(e.charCode) +
142 '\n shiftKey='+e.shiftKey
143 + ' ctrlKey='+e.ctrlKey
144 + ' altKey='+e.altKey
145 + ' metaKey='+e.metaKey);
148 function suppressdefault(e,flag)
152 if (e.preventDefault) e.preventDefault();
153 if (e.stopPropagation) e.stopPropagation();
158 function restoreSelection(r) {
161 if (window.getSelection)//non IE and there is already a selection
163 var s = window.getSelection();
164 if (s.rangeCount > 0)
169 if (document.createRange)//non IE and no selection
171 window.getSelection().addRange(r);
174 if (document.selection)//IE
181 function lookup_tex(texmacro)
183 texmacro = texmacro.substring(1);
184 return unescape(macro2utf8[texmacro]);
187 function strip_tags(tagname,classname)
189 var tags = unlocked.getElementsByTagName(tagname);
190 if (is_defined(classname)) {
191 tags = filterByClass(tags,classname);
193 for (i = 0; i < tags.length; i++) {
194 var children = tags[i].childNodes;
195 for (j = 0; j < children.length; j++) {
196 tags[i].parentNode.insertBefore(children[j],tags[i]);
199 for (;tags.length > 0;) {
200 tags[0].parentNode.removeChild(tags[0]);
204 function strip_interpr() {
206 alert("strip_interpr ended");
212 pressmesg('keypress',e);
213 var s = string_of_key(e.charCode);
214 strip_tags("span","error");
217 i = unlocked.innerHTML.lastIndexOf('\\',j);
219 match = unlocked.innerHTML.substring(i,j);
220 sym = unescape_html(lookup_tex(match));
221 if (sym != "undefined") {
222 if (window.getSelection) { // non IE
223 savedRange.setStart(savedsc,savedso - (j-i));
224 savedRange.deleteContents();
225 savedRange.insertNode(document.createTextNode(sym));
226 savedsc.parentNode.normalize();
227 if (savedRange.collapsed) { // Mozilla
228 savedRange.setEnd(savedsc,savedRange.endOffset + sym.length);
230 savedRange.collapse(false);
232 savedRange.moveStart(i-j);
233 savedRange.text(sym);
234 savedRange.collapse(false);
236 restoreSelection(savedRange);
237 return suppressdefault(e,true);
240 // restoreSelection(0);
241 return suppressdefault(e,false);
244 else return suppressdefault(e,false);
246 return suppressdefault(e,false);
254 // internet explorer (v.9) doesn't work with innerHTML
255 // but google chrome's innerText is, in a sense, "write only"
256 // what should we do?
257 // logarea.innerText = txt + "\n" + logarea.innerText;
258 logtxt = /* logtxt + "\n" +*/ txt;
262 logWin = window.open( "", "Matita Log",
263 "width=600,height=450,status,scrollbars,resizable,screenX=20,screenY=40,left=20,top=40");
264 logWin.document.write('<html><head><title>Matita Log' + '</title></head>');
265 logWin.document.write('<body><textarea style="width:100%;height:100%;">' +
266 logtxt + '</textarea></body></html>');
267 logWin.document.close();
273 debug("hd of '" + l + "' = '" + ar[0] + "'");
281 debug("tl of '" + l + "' = '" + tl + "'");
285 function listcons(x,l)
287 debug("cons '" + x + "' on '" + l + "'");
288 return (x + "#" + l);
301 function fold_left (f,acc,l)
304 { debug("'" + l + "' is fold end");
307 { debug("'" + l + "' is fold cons");
308 return(fold_left (f,f(acc,(listhd(l))),listtl(l))); }
311 function listiter (f,l)
314 { debug("'" + l + "' is nil");
319 debug("'" + l + "' is not nil");
321 listiter(f,listtl(l));
325 function listmap (f,l)
327 debug("listmap on " + l);
329 { debug("returning listnil");
333 { debug("cons f(hd) map(f,tl)");
334 return(f(listhd(l)) + "#" + listmap(f,listtl(l)));
338 var statements = listnil();
341 var metalist = listnil();
343 function pairmap (f,p)
345 debug("pairmap of '" + p + "'");
347 return (f(ar[0],ar[1]));
350 function tripletmap (f,p)
352 debug("tripletmap of '" + p + "'");
354 return (f(ar[0],ar[1],ar[2]));
360 return (pairmap (function (a,b) { return (a); }, p));
366 return (tripletmap (function (a,b,c) { return (a); }, p));
372 return (tripletmap (function (a,b,c) { return (b); }, p));
378 return (tripletmap (function (a,b,c) { return (c); }, p));
381 function populate_goalarray(menv)
383 debug("metasenv.length = " + menv.length);
384 if (menv.length == 0) {
390 goalarray = new Array();
391 metalist = listnil();
392 var tmp_goallist = "";
393 for (i = 0; i < menv.length; i++) {
394 metano = menv[i].getAttribute("number");
395 metaname = menv[i].childNodes[0].childNodes[0].data;
396 goal = menv[i].childNodes[1].childNodes[0].data;
397 debug ("found meta n. " + metano);
398 debug ("found goal\nBEGIN" + goal + "\nEND");
399 goalarray[metano] = goal;
400 tmp_goallist = " <A href=\"javascript:switch_goal(" + metano + ")\">" + metaname + "</A>" + tmp_goallist;
401 metalist = listcons(metano,metalist);
402 debug ("goalarray[\"" + metano + "\"] = " + goalarray[metano]);
404 goals.innerHTML = tmp_goallist;
405 debug("new metalist is '" + metalist + "'");
406 if (is_nil(metalist)) {
410 switch_goal(listhd(metalist));
415 function switch_goal(meta)
417 if (typeof meta == "undefined") {
418 goalview.innerHTML = "";
421 debug("switch_goal " + meta + "\n" + goalarray[meta]);
422 goalview.innerHTML = "<B>Goal ?" + meta + ":</B>\n\n" + goalarray[meta];
426 // the following is used to avoid escaping unicode, which results in
427 // the server being unable to unescape the string
428 String.prototype.sescape = function() {
434 result = result.replace(patt1,"%25");
435 result = result.replace(patt2,"%3D");
436 result = result.replace(patt3,"%26");
437 result = result.replace(patt4,"%2B");
441 String.prototype.html_to_matita = function()
443 var patt1 = /<br(\/|)>/gi;
446 var patt4 = /</gi;
447 var patt5 = />/gi;
448 var patt6 = / /gi;
450 result = result.replace(patt1,"\n");
451 result = result.replace(patt2,"\005");
452 result = result.replace(patt3,"\006");
453 result = result.replace(patt4,"<");
454 result = result.replace(patt5,">");
455 result = result.replace(patt6," ");
456 return (unescape(result));
459 String.prototype.matita_to_html = function()
463 var patt3 = /\005/gi;
464 var patt4 = /\006/gi;
466 result = result.replace(patt1,"<");
467 result = result.replace(patt2,">");
468 result = result.replace(patt3,"<");
469 result = result.replace(patt4,">");
470 return (unescape(result));
475 advanceButton.disabled = true;
476 retractButton.disabled = true;
477 cursorButton.disabled = true;
478 bottomButton.disabled = true;
483 advanceButton.disabled = false;
484 retractButton.disabled = false;
485 cursorButton.disabled = false;
486 bottomButton.disabled = false;
489 function is_defined(x)
491 return (typeof x != "undefined");
494 /* servicename: name of the service being called
495 * reqbody: text of the request
496 * processResponse: processes the server response
497 * (takes the response text in input, undefined in case of error)
499 function callServer(servicename,processResponse,reqbody)
503 if (window.XMLHttpRequest)
505 req = new XMLHttpRequest();
507 else if (window.ActiveXObject)
510 req = new ActiveXObject("Msxml2.XMLHTTP");
514 req = new ActiveXObject("Microsoft.XMLHTTP");
518 req.onreadystatechange = function()
526 stxt = req.statusText;
529 debug(req.responseText);
530 if (window.DOMParser) {
531 parser=new DOMParser();
532 xmlDoc=parser.parseFromString(req.responseText,"text/xml");
534 else // Internet Explorer
536 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
537 xmlDoc.async="false";
538 xmlDoc.loadXML(req.responseText);
540 processResponse(xmlDoc);
546 req.open("POST", servicename); // + escape(unlocked.innerHTML), true);
547 req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
556 function advanceForm1()
558 processor = function(xml) {
559 if (is_defined(xml)) {
560 var parsed = xml.getElementsByTagName("parsed")[0];
561 var ambiguity = xml.getElementsByTagName("ambiguity")[0];
562 if (is_defined(parsed)) {
563 // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
564 var len = parseInt(parsed.getAttribute("length"));
565 // len0 = unlocked.innerHTML.length;
566 var unescaped = unlocked.innerHTML.html_to_matita();
567 var parsedtxt = parsed.childNodes[0].nodeValue;
568 //parsedtxt = unescaped.substr(0,len);
569 var unparsedtxt = unescaped.substr(len);
570 lockedbackup += parsedtxt;
571 locked.innerHTML = lockedbackup;
572 unlocked.innerHTML = unparsedtxt.matita_to_html();
573 // len1 = unlocked.innerHTML.length;
574 // len2 = len0 - len1;
575 var len2 = parsedtxt.length;
576 var metasenv = xml.getElementsByTagName("meta");
577 populate_goalarray(metasenv);
578 statements = listcons(len2,statements);
579 unlocked.scrollIntoView(true);
581 else if (is_defined(ambiguity)) {
582 var start = parseInt(ambiguity.getAttribute("start"));
583 var stop = parseInt(ambiguity.getAttribute("stop"));
584 var choices = xml.getElementsByTagName("choice");
586 matita.ambiguityStart = start;
587 matita.ambiguityStop = stop;
588 matita.unlockedbackup = unlocked.innerHTML.html_to_matita();
589 matita.interpretations = [];
591 var unlockedtxt = unlocked.innerHTML.html_to_matita();
592 var pre = unlockedtxt.substring(0,start).matita_to_html();
593 var mid = unlockedtxt.substring(start,stop).matita_to_html();
594 var post = unlockedtxt.substring(stop).matita_to_html();
595 unlocked.innerHTML = pre +
596 "<span class=\"error\" title=\"disambiguation error\">" +
597 mid + "</span>" + post;
599 var title = "<H3>Ambiguous input</H3>";
600 disambcell.innerHTML = title;
601 for (i = 0;i < choices.length;i++) {
602 matita.interpretations[i] = new Object();
604 var href = choices[i].getAttribute("href");
605 var title = choices[i].getAttribute("title");
606 var desc = choices[i].childNodes[0].nodeValue;
608 matita.interpretations[i].href = href;
609 matita.interpretations[i].title = title;
610 matita.interpretations[i].desc = desc;
612 var choice = document.createElement("input");
613 choice.setAttribute("type","radio");
614 choice.setAttribute("name","interpr");
615 choice.setAttribute("href",href);
616 choice.setAttribute("title",title);
617 if (i == 0) choice.setAttribute("checked","");
619 disambcell.appendChild(choice);
620 disambcell.appendChild(document.createTextNode(desc));
621 disambcell.appendChild(document.createElement("br"));
624 var okbutton = document.createElement("input");
625 okbutton.setAttribute("type","button");
626 okbutton.setAttribute("value","OK");
627 okbutton.setAttribute("onclick","do_disambiguate()");
628 var cancelbutton = document.createElement("input");
629 cancelbutton.setAttribute("type","button");
630 cancelbutton.setAttribute("value","Cancel");
631 cancelbutton.setAttribute("onclick","cancel_disambiguate()");
633 disambcell.appendChild(okbutton);
634 disambcell.appendChild(cancelbutton);
638 matita.disambMode = true;
642 var error = xml.getElementsByTagName("error")[0];
643 unlocked.innerHTML = error.childNodes[0].nodeValue;
644 // debug(xml.childNodes[0].nodeValue);
647 debug("advance failed");
652 callServer("advance",processor,"body=" + (unlocked.innerHTML.html_to_matita()).sescape());
656 function gotoBottom()
658 processor = function(xml) {
659 if (is_defined(xml)) {
660 // debug("goto bottom: received response\nBEGIN\n" + req.responseText + "\nEND");
661 parsed = xml.getElementsByTagName("parsed")[0];
662 len = parseInt(parsed.getAttribute("length"));
664 // len0 = unlocked.innerHTML.length;
665 unescaped = unlocked.innerHTML.html_to_matita();
666 // not working in mozilla
667 // parsedtxt = parsed.childNodes[0].nodeValue;
668 parsedtxt = parsed.childNodes[0].wholeText;
669 //parsedtxt = unescaped.substr(0,len);
670 unparsedtxt = unescaped.substr(len);
671 lockedbackup += parsedtxt;
672 locked.innerHTML = lockedbackup; //.matita_to_html();
673 unlocked.innerHTML = unparsedtxt.matita_to_html();
674 // len1 = unlocked.innerHTML.length;
675 len2 = parsedtxt.length;
676 metasenv = xml.getElementsByTagName("meta");
677 populate_goalarray(metasenv);
679 statements = listcons(len2,statements);
680 unlocked.scrollIntoView(true);
683 debug("goto bottom failed");
688 callServer("bottom",processor,"body=" + (unlocked.innerHTML.html_to_matita()).sescape());
695 processor = function(xml) {
696 if (is_defined(xml)) {
697 if (xml.childNodes[0].textContent != "ok") {
698 debug("goto top failed");
701 statements = listnil();
703 lockedlen = locked.innerHTML.length - statementlen;
704 statement = locked.innerHTML.substr(lockedlen, statementlen);
705 locked.innerHTML = locked.innerHTML.substr(0,lockedlen);
706 unlocked.innerHTML = statement + unlocked.innerHTML;
708 unlocked.innerHTML = lockedbackup + unlocked.innerHTML;
710 locked.innerHTML = lockedbackup;
712 unlocked.scrollIntoView(true);
714 debug("goto top failed");
719 callServer("top",processor,"body=" + (unlocked.innerHTML.html_to_matita()).sescape());
722 function gotoPos(offset)
724 if (!is_defined(offset)) {
725 offset = getCursorPos();
727 processor = function(xml) {
728 if (is_defined(xml)) {
729 parsed = xml.getElementsByTagName("parsed")[0];
730 len = parseInt(parsed.getAttribute("length"));
731 // len0 = unlocked.innerHTML.length;
732 unescaped = unlocked.innerHTML.html_to_matita();
733 parsedtxt = parsed.childNodes[0].nodeValue;
734 //parsedtxt = unescaped.substr(0,len);
735 unparsedtxt = unescaped.substr(len);
736 lockedbackup += parsedtxt;
737 locked.innerHTML = lockedbackup; //.matita_to_html();
738 unlocked.innerHTML = unparsedtxt.matita_to_html();
739 // len1 = unlocked.innerHTML.length;
740 len2 = parsedtxt.length;
741 metasenv = xml.getElementsByTagName("meta");
742 // populate_goalarray(metasenv);
743 statements = listcons(len2,statements);
744 unlocked.scrollIntoView(true);
745 // la populate non andrebbe fatta a ogni passo
747 populate_goalarray(metasenv);
750 gotoPos(offset - len);
753 unlocked.scrollIntoView(true);
754 populate_goalarray(metasenv);
759 callServer("advance",processor,"body=" + (unlocked.innerHTML.html_to_matita()).sescape());
764 processor = function(xml) {
765 if (typeof xml != "undefined") {
766 // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
767 statementlen = parseInt(listhd(statements));
768 statements = listtl(statements);
770 lockedlen = locked.innerHTML.length - statementlen;
771 statement = locked.innerHTML.substr(lockedlen, statementlen);
772 locked.innerHTML = locked.innerHTML.substr(0,lockedlen);
773 unlocked.innerHTML = statement + unlocked.innerHTML;
775 lockedlen = lockedbackup.length - statementlen;
776 statement = lockedbackup.substr(lockedlen, statementlen);
777 lockedbackup = lockedbackup.substr(0,lockedlen);
778 locked.innerHTML = lockedbackup;
779 unlocked.innerHTML = statement + unlocked.innerHTML;
780 metasenv = xml.getElementsByTagName("meta");
781 populate_goalarray(metasenv);
782 unlocked.scrollIntoView(true);
784 debug("retract failed");
790 callServer("retract",processor);
796 processor = function(xml)
798 if (is_defined(xml)) {
800 locked.innerHTML = lockedbackup;
801 unlocked.innerHTML = xml.documentElement.wholeText;
803 debug("file open failed");
806 callServer("open",processor,"file=" + escape(filename.value));
809 function retrieveFile(thefile)
811 processor = function(xml)
813 if (is_defined(xml)) {
816 locked.innerHTML = lockedbackup;
817 // code originally used in google chrome (problems with mozilla)
818 // debug(xml.getElementsByTagName("file")[0].childNodes[0].nodeValue);
819 // unlocked.innerHTML = xml.getElementsByTagName("file")[0].childNodes[0].nodeValue;
820 debug(xml.childNodes[0].textContent);
821 if (document.all) { // IE
822 unlocked.innerHTML = xml.childNodes[0].text;
824 unlocked.innerHTML = xml.childNodes[0].textContent;
828 debug("file open failed");
832 callServer("open",processor,"file=" + escape(thefile));
835 function showLibrary(title,callback,reloadDialog)
838 dialogBox.reload = reloadDialog;
840 if (window.XMLHttpRequest)
842 req = new XMLHttpRequest();
844 else if (window.ActiveXObject)
847 req = new ActiveXObject("Msxml2.XMLHTTP");
851 req = new ActiveXObject("Microsoft.XMLHTTP");
855 req.onreadystatechange = function()
863 stxt = req.statusText;
866 debug(req.responseText);
867 showDialog("<H2>" + title + "</H2>",req.responseText, callback);
871 req.open("POST", "viewlib"); // + escape(unlocked.innerHTML), true);
872 req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
877 function uploadDialog()
879 uploadBox.style.display = "block";
884 var file = document.getElementById("uploadFilename").files[0];
886 var filecontent = file.getAsText("UTF-8");
887 locked.innerHTML = lockedbackup;
888 unlocked.innerHTML = filecontent;
889 uploadBox.style.display = "none";
892 // var reader = new FileReader();
893 // reader.readAsText(file, "UTF-8");
894 // reader.onloadend = function (evt) {
895 // lockedbackup = "";
896 // locked.innerHTML = lockedbackup
897 // unlocked.innerHTML = evt.target.result;
898 // uploadBox.style.display = "none";
900 // reader.onerror = function (evt) {
901 // debug("file open failed");
902 // uploadBox.style.display = "none";
907 function openDialog()
909 callback = function (fname) { retrieveFile(fname); };
910 showLibrary("Open file", callback, openDialog);
913 function saveDialog()
915 callback = function (fname) {
918 (locked.innerHTML.html_to_matita()).sescape(),
919 (unlocked.innerHTML.html_to_matita()).sescape(),
922 showLibrary("Save file as", callback, saveDialog);
927 callback = function (fname) {
929 saveFile(fname,"","",false,newDialog,true);
931 showLibrary("Create new file", callback, newDialog);
935 function saveFile(fname,lockedtxt,unlockedtxt,force,reloadDialog,reloadFile)
937 if (!is_defined(reloadFile)) { reloadFile = true };
938 if (!is_defined(fname)) {
939 fname = current_fname;
940 lockedtxt = (locked.innerHTML.html_to_matita()).sescape();
941 unlockedtxt = (unlocked.innerHTML.html_to_matita()).sescape();
943 // when force is true, reloadDialog is not needed
945 processor = function(xml) {
946 if (is_defined(xml)) {
947 if (xml.childNodes[0].textContent != "ok") {
948 if (confirm("File already exists. All existing data will be lost.\nDo you want to proceed anyway?")) {
949 saveFile(fname,lockedtxt,unlockedtxt,true,reloadDialog,reloadFile);
955 debug("file saved!");
956 if (reloadFile) { retrieveFile(fname); }
959 debug("save file failed");
963 if (is_defined(fname)) {
965 callServer("save",processor,"file=" + escape(fname) +
966 "&locked=" + lockedtxt +
967 "&unlocked=" + unlockedtxt +
970 else { debug("no file selected"); }
973 function createDir() {
975 dirname = prompt("New directory name:\ncic:/matita/","newdir");
976 if (dirname != null) {
977 processor = function(xml) {
978 if (is_defined(xml)) {
979 if (xml.childNodes[0].textContent != "ok") {
980 alert("An error occurred :-(");
983 alert("An error occurred :-(");
988 callServer("save",processor,"file=" + escape(dirname) +
989 "&locked=&unlocked=&force=false&dir=true");
997 processor = function(xml) {
998 if (is_defined(xml)) {
999 debug(xml.getElementsByTagName("details")[0].textContent);
1000 alert("Commit executed: see details in the log.\n\n" +
1001 "NOTICE: this message does NOT imply (yet) that the commit was successful.");
1003 alert("Commit failed!");
1008 callServer("commit",processor);
1011 function updateAll()
1013 processor = function(xml) {
1014 if (is_defined(xml)) {
1015 alert("Update executed.\n\n" +
1017 xml.getElementsByTagName("details")[0].textContent);
1019 alert("Update failed!");
1024 callServer("update",processor);
1029 function hideSequent() {
1030 matita.proofMode = false;
1034 function showSequent() {
1035 matita.proofMode = true;
1039 function showDialog(title,content,callback) {
1040 dialogTitle.innerHTML = title;
1041 dialogContent.innerHTML = content;
1042 dialogBox.callback = callback;
1044 //Get the screen height and width
1045 var maskHeight = $(document).height();
1046 var maskWidth = $(window).width();
1048 //Set heigth and width to mask to fill up the whole screen
1049 $('#mask').css({'width':maskWidth,'height':maskHeight});
1052 $('#mask').fadeIn(1000);
1053 $('#mask').fadeTo("slow",0.8);
1055 //Get the window height and width
1056 var winH = $(window).height();
1057 var winW = $(window).width();
1059 //Set the popup window to center
1060 $('#dialogBox').css('top', winH/2-$('#dialogBox').height()/2);
1061 $('#dialogBox').css('left', winW/2-$('#dialogBox').width()/2);
1064 $('#dialogBox').fadeIn(2000);
1066 dialogBox.style.display = "block";
1069 function abortDialog(dialog) {
1071 dialogBox.style.display = "none";
1074 function removeElement(id) {
1075 var element = document.getElementById(id);
1076 element.parentNode.removeChild(element);
1082 function getCursorPos() {
1084 if (window.getSelection) {
1085 var selObj = window.getSelection();
1086 savedRange = selObj.getRangeAt(0);
1087 savedsc = savedRange.startContainer;
1088 savedso = savedRange.startOffset;
1089 //cursorPos = findNode(selObj.anchorNode.parentNode.childNodes, selObj.anchorNode) + selObj.anchorOffset;
1090 cursorPos = findNode(unlocked.childNodes, selObj.anchorNode,0) + selObj.anchorOffset;
1091 /* FIXME the following works wrong in Opera when the document is longer than 32767 chars */
1094 else if (document.selection) {
1095 savedRange = document.selection.createRange();
1096 var bookmark = savedRange.getBookmark();
1097 /* FIXME the following works wrong when the document is longer than 65535 chars */
1098 cursorPos = bookmark.charCodeAt(2) - 11; /* Undocumented function [3] */
1103 function findNode(list, node, acc) {
1104 for (var i = 0; i < list.length; i++) {
1105 if (list[i] == node) {
1106 // debug("success " + i);
1109 if (list[i].hasChildNodes()) {
1111 // debug("recursion on node " + i);
1112 return (findNode(list[i].childNodes,node,acc))
1114 catch (e) { /* debug("recursion failed"); */ }
1116 sandbox = document.getElementById("sandbox");
1117 dup = list[i].cloneNode(true);
1118 sandbox.appendChild(dup);
1119 // debug("fail " + i + ": " + sandbox.innerHTML);
1120 acc += sandbox.innerHTML.length;
1121 sandbox.removeChild(dup);
1127 debug("cursor test: " + unlocked.innerHTML.substr(0,getCursorPos()));
1130 function get_checked_index(name) {
1131 var radios = document.getElementsByName(name);
1132 for (i = 0; i < radios.length; i++) {
1133 if (radios[i].checked) {
1140 function cancel_disambiguate() {
1141 matita.disambMode = false;
1142 $('#whitemask').hide();
1146 function do_disambiguate() {
1147 var i = get_checked_index("interpr");
1149 var pre = matita.unlockedbackup
1150 .substring(0,matita.ambiguityStart).matita_to_html();
1151 var mid = matita.unlockedbackup
1152 .substring(matita.ambiguityStart,matita.ambiguityStop)
1154 var post = matita.unlockedbackup
1155 .substring(matita.ambiguityStop).matita_to_html();
1157 var href = matita.interpretations[i].href;
1158 var title = matita.interpretations[i].title;
1160 if (is_defined(title)) {
1161 mid = "<A href=\"" + href + "\" title=\"" + title + "\">" + mid + "</A>";
1163 mid = "<A href=\"" + href + "\">" + mid + "</A>";
1166 unlocked.innerHTML = pre + mid + post;
1168 matita.disambMode = false;
1169 $('#whitemask').hide();
1174 function readCookie(name) {
1175 var nameEQ = name + "=";
1176 var ca = document.cookie.split(';');
1177 for(var i=0;i < ca.length;i++) {
1179 while (c.charAt(0)==' ') c = c.substring(1,c.length);
1180 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
1185 function delete_cookie ( cookie_name )
1187 var cookie_date = new Date(); // current date & time
1188 cookie_date.setTime ( cookie_date.getTime() - 1 );
1189 document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
1192 function delete_session()
1194 delete_cookie("session");
1197 function disable_toparea() {
1198 var offset = $('#toparea').offset();
1199 $('#whitemask').css('top',offset.top);
1200 $('#whitemask').css('left',offset.left);
1201 $('#whitemask').css('width',$('#toparea').outerWidth() + "px");
1202 $('#whitemask').css('height',$('#toparea').outerHeight() + "px");
1203 $('#whitemask').fadeTo('fast',0.7);