@@ -1437,130 +1437,57 @@ $(function () {
1437
1437
}
1438
1438
}
1439
1439
} else {
1440
- var editor = monaco . editor . create ( document . getElementById ( 'editorContainer' ) , {
1441
- value : [ progData . source ] . join ( '\n' ) ,
1442
- language : 'python'
1440
+ var editor = monaco . editor . create ( document . getElementById ( 'editorContainer' ) , {
1441
+ language : 'python' ,
1442
+ value : loader ( )
1443
1443
} ) ;
1444
- window . editor = editor
1445
-
1446
- // var editor = ace.edit(page.find(".program-editor").get(0));
1447
- // window.editor = editor
1448
- // customACEMode(lang, progData.source)
1449
- //var mode = ace_require("ace/mode/visualjs").Mode
1450
- //editor.getSession().setMode(new mode())
1451
- // editor.setTheme({ cssClass: "ace-custom" })
1452
- //editor.set(progData.source)
1453
- editor . setReadOnly ( ! isWritable )
1454
- editor . selection . moveCursorDown ( ) // position cursor at start of line 2, below GlowScript header
1455
- editor . focus ( )
1456
- if ( isWritable ) {
1457
- var save = saver ( { user :username , folder :folder , program :program } ,
1458
- function ( ) { return editor . getSession ( ) . getValue ( ) } ,
1459
- function ( status ) { page . find ( ".program-status" ) . text ( " (" + status + ")" ) }
1460
- )
1461
- // Save immediately when navigating away from this page
1462
- onNavigate . on ( function ( cb ) { save ( 0 , cb ) } )
1463
- editor . getSession ( ) . on ( 'change' , function ( ) {
1464
- save ( 1000 ) // Save after 1 second of not typing
1465
- } )
1466
- }
1467
- }
1468
-
1469
- } )
1470
- }
1471
-
1472
- // // NOTE: We use the "ace_require" function found in ace.js
1473
-
1474
- // /*********** Customization of the ACE editor *************/
1475
- // // See https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode
1476
- // // mode-javascript.js is loaded by ide/index.html.
1477
- // // These modules in turn load worker-javascript.js in lib/ace.
1478
- // // See lib/ace/FileSource.txt for where to find updated ACE files, and how they
1479
- // // were modified in minor ways for GlowScript use.
1480
- var customACEMode = function ( lang , source ) { // lang is "javascript" or some fragment
1481
-
1482
- var lib = "identifier.builtin"
1483
- var attr = "attribute.builtin"
1484
- var libraryWords = {
1485
- pos : attr , axis : attr , up : attr , /*color: attr, */ x : attr , y : attr , z : attr , size : attr ,
1486
- visible : attr , forward : attr , length : attr , width : attr , radius : attr ,
1487
- wait : "keyword.wait"
1488
- }
1489
-
1490
- // Adding "var" and "function" to libraryWords for JavaScript should be unnecessary,
1491
- // but without them they aren't colorized red as they were in earlier ACE:
1492
- if ( lang == 'javascript' ) {
1493
- libraryWords . var = "keyword"
1494
- libraryWords . function = "keyword"
1495
- }
1496
-
1497
- var globals = [ ]
1498
- if ( window . GlowscriptLibraryNames )
1499
- for ( var i = 0 ; i < window . GlowscriptLibraryNames . length ; i ++ ) {
1500
- var id = window . GlowscriptLibraryNames [ i ]
1501
- if ( libraryWords [ id ] === undefined )
1502
- libraryWords [ id ] = lib
1503
- }
1504
- for ( var id in libraryWords ) { // e.g. {sphere : identifier.builtin}
1505
- if ( ! libraryWords [ id ] ) delete libraryWords [ id ] ;
1506
- if ( libraryWords [ id ] == lib ) globals . push ( id )
1507
- }
1508
-
1509
- // The "//" at the end of lintPrefix comments out the line "GlowScript X.Y", hence ignored by the worker looking at JavaScript syntax
1510
- var lintPrefix = "/*jslint asi:true, undef:true*/ /*global wait " + globals . join ( " " ) + "*/\n//"
1511
-
1512
- define ( 'ace/mode/visualjs_highlight_rules' , function ( ace_require , exports , module ) {
1513
- var oop = ace_require ( "ace/lib/oop" )
1514
- var Rules
1515
- if ( lang == 'vpython' ) Rules = ace_require ( "ace/mode/python_highlight_rules" ) . PythonHighlightRules
1516
- else Rules = ace_require ( "ace/mode/javascript_highlight_rules" ) . JavaScriptHighlightRules
1517
-
1518
- var VisualHighlightRules = function ( ) {
1519
- this . $rules = ( new Rules ( ) ) . getRules ( )
1520
- if ( lang == 'vpython' ) this . $rules . start = [ { regex : / G l o w S c r i p t \s + [ \d \. ] * [ d e v ] * \s + [ A - Z a - z ] * / , token : "keyword.version_header" } ] . concat ( this . $rules . start )
1521
- else this . $rules . start = [ { regex : / G l o w S c r i p t \s + [ \d \. ] * [ d e v ] * / , token : "keyword.version_header" } ] . concat ( this . $rules . start )
1522
- for ( var id in libraryWords ) {
1523
- this . $rules . start = [ { regex : id , token : libraryWords [ id ] } ] . concat ( this . $rules . start )
1444
+
1445
+
1446
+ editor . onDidChangeModelContent ( ( ) => {
1447
+ localStorage . setItem ( 'editorContainer' , JSON . stringify ( editor . getValue ( ) ) ) ;
1448
+ } ) ;
1449
+
1450
+ function loader ( ) {
1451
+ var returnVal ;
1452
+ if ( apiGet != [ 'Python 3.2' ] . join ( '\n' ) ) {
1453
+ returnVal = apiGet ( { user :username , folder :folder , program :program } , function ( progData ) { } ) ;
1454
+ //returnVal = apiGet({'/api/user/<username>/folder/<foldername>/program/<programname>'}, function (progData) {});
1455
+
1456
+ // returnVal = JSON.parse(localStorage.getItem('editorContainer')
1457
+ }
1458
+ else {
1459
+ returnVal = [ 'Python 3.2' ] . join ( '\n' )
1460
+ }
1461
+ return returnVal
1524
1462
}
1463
+ if ( isWritable ) {
1464
+ var save = saver ( { user :username , folder :folder , program :program } ,
1465
+ function ( ) { return editor . getValue ( ) } ,
1466
+ function ( status ) { page . find ( ".program-status" ) . text ( " (" + status + ")" ) }
1467
+ )
1468
+ // Save immediately when navigating away from this page
1469
+ onNavigate . on ( function ( cb ) { save ( 0 , cb ) } )
1470
+ editor . onDidChangeModelContent ( 'change' , function ( ) {
1471
+ save ( 1000 ) // Save after 1 second of not typing
1472
+ } )
1473
+ }
1474
+ //localStorage.clear()
1475
+ // editor.onDidChangeModelContent(() => {
1476
+ // localStorage.setItem('editorContainer', JSON.stringify(editor.getValue()));
1477
+ // editor.save(editor.getValue())
1478
+ // });
1525
1479
}
1526
- oop . inherits ( VisualHighlightRules , Rules )
1527
- exports . VisualHighlightRules = VisualHighlightRules
1528
- } )
1529
-
1530
-
1531
- //------------------------------------------------------------------------------------------------------
1532
- define ( 'ace/mode/visualjs' , function ( ace_require , exports , module ) {
1533
- var oop = ace_require ( "ace/lib/oop" )
1534
- if ( lang == 'vpython' ) var BaseMode = ace_require ( "ace/mode/python" ) . Mode
1535
- else var BaseMode = ace_require ( "ace/mode/javascript" ) . Mode
1536
- var Tokenizer = ace_require ( "ace/tokenizer" ) . Tokenizer
1537
- var VisualHighlightRules = ace_require ( "ace/mode/visualjs_highlight_rules" ) . VisualHighlightRules
1538
- var WorkerClient = ace_require ( "ace/worker/worker_client" ) . WorkerClient // *****************************************************
1539
-
1540
- var Mode = function ( ) {
1541
- BaseMode . call ( this )
1542
- this . $tokenizer = new Tokenizer ( ( new VisualHighlightRules ( ) ) . getRules ( ) ) ;
1543
- }
1544
- oop . inherits ( Mode , BaseMode ) ; // nead a semicolon here due to following left parens
1545
-
1546
- // There was formerly "worker" machinery here which showed a warning icon at the left of an line with an error, but
1547
- // (1) This tends to confuse students.
1548
- // (2) GlowScript catches lots of errors already with respect to parens, brackets, braces, and quotes.
1549
- // (3) Highlighting is handled separately, so is not affected by eliminating workers.
1550
- // (4) Caused some awkwardness in changing the language on the first line.
1551
- // (5) And the killer issue: workers chew up LOTS of CPU time for little gain.
1552
-
1553
- exports . Mode = Mode
1554
- } )
1555
- }
1556
-
1480
+
1481
+ }
1482
+ ) }
1483
+
1557
1484
function iframefix ( ) {
1558
1485
// When a mouse operation is started outside an iframe, cover all iframes on the page so
1559
1486
// that mousemove events don't get eaten by them. Supposedly jquery UI 1.9 will have this
1560
1487
// feature, so maybe this can be removed in the future.
1561
-
1488
+
1562
1489
$ ( document ) . mousedown ( function ( ev ) {
1563
- $ ( "iframe" ) . not ( ".iframefix" ) . not ( ".template iframe" ) . each ( function ( ) {
1490
+ $ ( "iframe" ) . not ( ".iframefix" ) . not ( ".template iframe" ) . each ( function ( ) {
1564
1491
( "iframefix" , this , this . offsetWidth , this . offsetHeight , this . width )
1565
1492
$ ( '<div class="iframefix" style="background: #fff;"></div>' )
1566
1493
. css ( {
0 commit comments