@@ -6,6 +6,7 @@ Formulae.scriptAtStart = true;
66Formulae . timeZone = null ;
77Formulae . fontSize = null ;
88Formulae . ltr = true ;
9+ Formulae . readMode = true ;
910Formulae . parameters = new URL ( window . location . href ) . searchParams ;
1011//Formulae.pathName = new URL(window.location.href).pathname;
1112
@@ -315,7 +316,23 @@ Formulae.mouseMove = function(handler, mouseEvent) {
315316 if ( ! Formulae . ltr ) x = handler . context . canvas . width - x ;
316317 let test = handler . fromPoint ( x , mouseEvent . offsetY ) ;
317318
318- if ( test != Formulae . hExpression ) {
319+ if ( test !== Formulae . hExpression ) { // current expression (test) has changed
320+ if ( Formulae . readMode ) {
321+ if ( test !== null ) {
322+ if ( test . getTag ( ) === "Internet.UniformResourceLocator" ) {
323+ document . body . style . cursor = "pointer" ;
324+ }
325+ else {
326+ //if (Formulae.hExpression !== null && Formulae.hExpression.getTag() === "Internet.UniformResourceLocator") {
327+ document . body . style . cursor = "default" ;
328+ //}
329+ }
330+ }
331+
332+ Formulae . hExpression = test ;
333+ return ;
334+ }
335+
319336 let context = handler . context ;
320337
321338 let bkpOperation = context . globalCompositeOperation ;
@@ -349,6 +366,12 @@ Formulae.mouseMove = function(handler, mouseEvent) {
349366} ;
350367
351368Formulae . mouseOut = function ( handler ) {
369+ if ( Formulae . readMode ) {
370+ Formulae . hExpression = null ;
371+ document . body . style . cursor = "default" ;
372+ return ;
373+ }
374+
352375 if ( Formulae . hExpression != null ) {
353376 let context = handler . context ;
354377
@@ -371,10 +394,25 @@ Formulae.mouseOut = function(handler) {
371394}
372395
373396Formulae . mouseWheel = function ( ) {
397+ if ( Formulae . readMode ) {
398+ Formulae . hExpression = null ;
399+ document . body . style . cursor = "default" ;
400+ return ;
401+ }
402+
374403 Formulae . clearHighlightedExpression ( ) ;
375404}
376405
377406Formulae . mouseClick = function ( handler , mouseEvent ) {
407+ if ( Formulae . readMode ) {
408+ if ( Formulae . hExpression !== null && Formulae . hExpression . getTag ( ) === "Internet.UniformResourceLocator" ) {
409+ let win = window . open ( Formulae . hExpression . get ( "Value" ) , "_blank" ) ;
410+ win . focus ( ) ;
411+ }
412+
413+ return ;
414+ }
415+
378416 if ( Formulae . menu . style . visibility == "visible" ) {
379417 Formulae . menu . style . visibility = "hidden" ;
380418 return ;
@@ -385,6 +423,25 @@ Formulae.mouseClick = function(handler, mouseEvent) {
385423 }
386424}
387425
426+ Formulae . clearSelected = function ( ) {
427+ if ( Formulae . sExpression === null ) return ;
428+
429+ let context = Formulae . sHandler . context ;
430+
431+ let bkpOperation = context . globalCompositeOperation ;
432+ context . globalCompositeOperation = "difference" ;
433+
434+ let bkpFillStyle = context . fillStyle ;
435+ context . fillStyle = "white" ;
436+
437+ Formulae . sExpression . drawSelecionShape ( context ) ;
438+
439+ context . fillStyle = bkpFillStyle ;
440+ context . globalCompositeOperation = bkpOperation ;
441+
442+ Formulae . sExpression = null ;
443+ } ;
444+
388445Formulae . setSelected = function ( handler , expression , removePrevious ) {
389446 Formulae . clearHighlightedExpression ( ) ;
390447
@@ -490,6 +547,10 @@ Formulae.editionEscape = function() {
490547}
491548
492549Formulae . editionArrow = function ( direction ) {
550+ if ( Formulae . readMode ) {
551+ return ;
552+ }
553+
493554 let test = Formulae . sExpression . moveOut ( direction ) ;
494555
495556 if ( test != null && test != Formulae . sExpression ) {
@@ -1795,7 +1856,13 @@ Formulae.newFile = function() {
17951856 let handler = Formulae . addExpression ( expression , Formulae . ROW_INPUT ) ;
17961857 handler . prepareDisplay ( ) ;
17971858 handler . display ( ) ;
1798- Formulae . setSelected ( handler , expression , false ) ;
1859+
1860+ if ( Formulae . readMode ) {
1861+ Formulae . toggleMode ( ) ;
1862+ }
1863+ else {
1864+ Formulae . setSelected ( handler , expression , false ) ;
1865+ }
17991866}
18001867
18011868Formulae . openFile = function ( e ) {
@@ -1820,7 +1887,10 @@ Formulae.openFile = function(e) {
18201887 //}
18211888
18221889 let newPackagesLoaded = await Formulae . xmlToScript ( e . target . result ) ;
1823- Formulae . setSelected ( Formulae . handlers [ 0 ] , Formulae . handlers [ 0 ] . expression . moveTo ( Expression . DOWN ) , false ) ;
1890+
1891+ if ( ! Formulae . readMode ) {
1892+ Formulae . setSelected ( Formulae . handlers [ 0 ] , Formulae . handlers [ 0 ] . expression . moveTo ( Expression . DOWN ) , false ) ;
1893+ }
18241894
18251895 if ( newPackagesLoaded ) {
18261896 Formulae . loadReloadEditions ( ) ;
@@ -1901,6 +1971,8 @@ Formulae.fillFileInfo = function() {
19011971
19021972 Formulae . fileName = f + '.formulae?' + ( new Date ( ) ) . getTime ( ) ;
19031973 Formulae . fileTitle = f . substring ( f . indexOf ( "/" ) + 1 ) ;
1974+
1975+ document . title = Formulae . fileTitle ;
19041976}
19051977
19061978Formulae . loadFile = async ( ) => {
@@ -1913,7 +1985,9 @@ Formulae.loadFile = async () => {
19131985 let xml = await response . text ( ) ;
19141986 let newPackagesLoaded = await Formulae . xmlToScript ( xml ) ;
19151987
1916- Formulae . setSelected ( Formulae . handlers [ 0 ] , Formulae . handlers [ 0 ] . expression . moveTo ( Expression . DOWN ) , false ) ;
1988+ if ( ! Formulae . readMode ) {
1989+ Formulae . setSelected ( Formulae . handlers [ 0 ] , Formulae . handlers [ 0 ] . expression . moveTo ( Expression . DOWN ) , false ) ;
1990+ }
19171991
19181992 if ( newPackagesLoaded ) {
19191993 Formulae . loadReloadEditions ( ) ;
@@ -1922,7 +1996,7 @@ Formulae.loadFile = async () => {
19221996 if ( Formulae . fileName != "Main page.formulae" ) {
19231997 let description = "Fōrmulæ - " + Formulae . fileTitle ;
19241998 document . title = description ;
1925- document . head . children . namedItem ( 'description' ) . content = description ;
1999+ document . head . children . namedItem ( 'description' ) . content = description ;
19262000 }
19272001
19282002 /*
@@ -2042,6 +2116,40 @@ Formulae.outputForCrawling = function() {
20422116 } ) ;
20432117}
20442118
2119+ Formulae . toggleMode = function ( ) {
2120+ Formulae . readMode = ! Formulae . readMode ;
2121+ let display = Formulae . readMode ? "none" : "block" ;
2122+
2123+ [
2124+ "button-home" , "button-save" , "button-cut" , "button-copy" , "button-paste" , "button-ins-after" , "button-ins-before" , "button-delete" ,
2125+ "button-change-type" , "button-execute_sticky" , "button-tools" , "button-settings"
2126+ ] . forEach ( element => {
2127+ document . getElementById ( element ) . style . display = display ;
2128+ } ) ;
2129+
2130+ document . getElementById ( "sidebar" ) . style . width = Formulae . readMode ? "0px" : "300px" ;
2131+ document . getElementById ( "dragbar" ) . style . left = Formulae . readMode ? "0px" : "301px" ;
2132+ document . getElementById ( "main" ) . style . left = Formulae . readMode ? "0px" : "308px" ;
2133+
2134+ document . getElementById ( "main" ) . style . bottom = Formulae . readMode ? "0px" : "50px" ;
2135+ document . getElementById ( "footer" ) . style . height = Formulae . readMode ? "0px" : "50px" ;
2136+
2137+ document . getElementById ( "sidebar" ) . style . display = display ;
2138+ document . getElementById ( "dragbar" ) . style . display = display ;
2139+ document . getElementById ( "footer" ) . style . display = display ;
2140+
2141+ document . getElementById ( "button-mode" ) . innerHTML = Formulae . readMode ? "Edit / run" : "Exit edit / run" ;
2142+
2143+ if ( Formulae . readMode ) {
2144+ Formulae . clearSelected ( ) ;
2145+ }
2146+ else {
2147+ Formulae . setSelected ( Formulae . handlers [ 0 ] , Formulae . handlers [ 0 ] . expression . moveTo ( Expression . DOWN ) , false ) ;
2148+ }
2149+
2150+ document . getElementById ( "main" ) . focus ( ) ;
2151+ } ;
2152+
20452153Formulae . start = async function ( ) {
20462154 Formulae . fillFileInfo ( ) ;
20472155
@@ -2080,8 +2188,11 @@ Formulae.start = async function() {
20802188 // preventing scroll using arrow keys
20812189 // direction keys
20822190
2083- //window.addEventListener("keydown", function(e) {
20842191 document . addEventListener ( "keydown" , function ( e ) {
2192+ if ( Formulae . readMode ) {
2193+ return ;
2194+ }
2195+
20852196 if ( [ 37 , 38 , 39 , 40 ] . indexOf ( e . keyCode ) > - 1 ) {
20862197 e . preventDefault ( ) ;
20872198 }
@@ -2134,6 +2245,8 @@ Formulae.start = async function() {
21342245 document . getElementById ( "button-tools" ) . addEventListener ( "click" , ( ) => Formulae . Tools . showTools ( ) ) ;
21352246 document . getElementById ( "button-settings" ) . addEventListener ( "click" , ( ) => Formulae . Settings . showSettings ( ) ) ;
21362247
2248+ document . getElementById ( "button-mode" ) . addEventListener ( "click" , ( ) => Formulae . toggleMode ( ) ) ;
2249+
21372250 //////////////
21382251 // drag bar //
21392252 //////////////
@@ -2190,6 +2303,10 @@ Formulae.start = async function() {
21902303 Formulae . main . addEventListener (
21912304 'contextmenu' ,
21922305 function ( e ) {
2306+ if ( Formulae . readMode ) {
2307+ return ;
2308+ }
2309+
21932310 if ( Formulae . menu . style . visibility == "visible" ) {
21942311 Formulae . menu . style . visibility = "hidden" ;
21952312 }
@@ -2243,6 +2360,10 @@ Formulae.start = async function() {
22432360 document . addEventListener (
22442361 'dblclick' ,
22452362 function ( e ) {
2363+ if ( Formulae . readMode ) {
2364+ return ;
2365+ }
2366+
22462367 if ( Formulae . menu . style . visibility == "visible" ) {
22472368 Formulae . menu . style . visibility = "hidden" ;
22482369 }
@@ -2283,7 +2404,6 @@ Formulae.start = async function() {
22832404 //await Formulae.loadRefreshLocalization(true); // first time
22842405
22852406 Formulae . setOrientation ( ) ;
2286-
22872407
22882408 Formulae . messages = await Formulae . loadMessages ( null ) ;
22892409 Formulae . setLocalizationCodes ( ) ;
@@ -2301,6 +2421,8 @@ Formulae.start = async function() {
23012421 //if (!Formulae.supportsMouse()) {
23022422 // alert("x");
23032423 //}
2424+
2425+ document . getElementById ( "main" ) . focus ( ) ;
23042426}
23052427
23062428/*
@@ -2781,7 +2903,9 @@ Formulae.refreshTypesettingHandlers = function() {
27812903 Formulae . handlers [ i ] . display ( ) ;
27822904
27832905 if ( Formulae . sHandler == Formulae . handlers [ i ] ) { // restore selected expression
2784- Formulae . setSelected ( Formulae . sHandler , Formulae . sExpression , false ) ;
2906+ if ( ! Formulae . readMode ) {
2907+ Formulae . setSelected ( Formulae . sHandler , Formulae . sExpression , false ) ;
2908+ }
27852909 }
27862910 }
27872911 }
0 commit comments