Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jsexplain
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Verified Software
jsexplain
Commits
30e34a5b
Commit
30e34a5b
authored
9 years ago
by
Thomas Wood
Browse files
Options
Downloads
Patches
Plain Diff
Add ability to select/load source files
parent
41d17969
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
driver.html
+4
-2
4 additions, 2 deletions
driver.html
navig-driver.js
+35
-13
35 additions, 13 deletions
navig-driver.js
with
39 additions
and
15 deletions
driver.html
+
4
−
2
View file @
30e34a5b
...
@@ -94,7 +94,9 @@
...
@@ -94,7 +94,9 @@
<div
class=
'source_div'
>
<div
class=
'source_div'
>
JavaScript code to run:
<br
/>
<select
id=
'select_source_code'
><option
disabled
selected
>
Examples
</option></select><br
/>
<input
type=
'file'
accept=
'.js'
id=
'select_file'
/>
<table
id=
'main_table'
><tr>
<table
id=
'main_table'
><tr>
<td>
<td>
<textarea
id=
'source_code'
class=
'source'
rows=
'6'
cols=
'60'
>
source code here
</textarea>
<textarea
id=
'source_code'
class=
'source'
rows=
'6'
cols=
'60'
>
source code here
</textarea>
...
@@ -208,4 +210,4 @@ var t = []; for (var i = 0; i < 3; i++) { t[i] = function() { return i; } };
...
@@ -208,4 +210,4 @@ var t = []; for (var i = 0; i < 3; i++) { t[i] = function() { return i; } };
t[0]();
t[0]();
3
3
-->
-->
\ No newline at end of file
This diff is collapsed.
Click to expand it.
navig-driver.js
+
35
−
13
View file @
30e34a5b
...
@@ -69,27 +69,49 @@ var tracer_length = 0;
...
@@ -69,27 +69,49 @@ var tracer_length = 0;
var
tracer_pos
=
0
;
var
tracer_pos
=
0
;
// Core Mirror objects
// Core Mirror objects
var
source
=
""
;
var
source
=
null
;
var
interpreter
=
null
;
var
interpreter
=
null
;
// Initial source code
// Initial source code
var
source_file
=
'
var x = 2;
\n
x
'
;
var
source_files
=
[
'
var x = 2;
\n
x
'
,
var
source_file
=
'
var t = {}; for (var i = 0; i < 3; i++) { t[i] = function() { return i; } }; t[0]();
'
;
'
var t = {}; for (var i = 0; i < 3; i++) { t[i] = function() { return i; } }; t[0]();
'
,
var
source_file
=
'
{}
'
;
'
{}
'
,
var
source_file
=
'
{} + {}
'
;
'
{} + {}
'
,
var
source_file
=
'
var x = { a : 1, b : 2 };
'
;
'
var x = { a : 1, b : 2 };
'
,
var
source_file
=
'
x = 1;
\n
x = 2;
\n
x = 3
'
;
'
x = 1;
\n
x = 2;
\n
x = 3
'
,
var
source_file
=
'
var x = { a : 1 };
\n
x.b = 2;
\n
x
'
;
'
var x = { a : 1 };
\n
x.b = 2;
\n
x
'
,
var
source_file
=
'
var x = { a : { c: 1 } };
\n
x.a.b = 2;
\n
x
'
;
'
var x = { a : { c: 1 } };
\n
x.a.b = 2;
\n
x
'
,
var
source_file
=
'
(function (x) {
\n
return 1;
\n
})()
'
;
'
(function (x) {return 1;})()
'
,
];
source_files
.
reduce
((
select
,
file_content
)
=>
{
let
option
=
document
.
createElement
(
'
option
'
);
option
.
textContent
=
file_content
;
select
.
append
(
option
);
return
select
;
},
$
(
'
#select_source_code
'
));
function
setSourceCode
(
text
)
{
$
(
"
#source_code
"
).
val
(
text
);
if
(
source
!==
null
)
{
source
.
setValue
(
text
);
}
}
$
(
'
#select_source_code
'
).
change
(
e
=>
{
setSourceCode
(
e
.
target
.
value
)});
$
(
'
#select_file
'
).
change
(
e
=>
{
let
fr
=
new
FileReader
();
fr
.
onload
=
function
(
e
)
{
setSourceCode
(
e
.
target
.
result
)
};
fr
.
readAsText
(
e
.
target
.
files
[
0
]);
});
// --------------- Initialization ----------------
// --------------- Initialization ----------------
// WARNING: do not move this initialization further down in the file
// WARNING: do not move this initialization further down in the file
// source code displayed initially
// source code displayed initially
$
(
"
#source_code
"
).
val
(
source_file
);
setSourceCode
(
source_files
[
source_files
.
length
-
1
]);
// --------------- Methods ----------------
// --------------- Methods ----------------
...
@@ -1091,4 +1113,4 @@ function findToken(token) {
...
@@ -1091,4 +1113,4 @@ function findToken(token) {
}
}
}
}
return
-
1
;
return
-
1
;
};
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment