Skip to content

Commit

Permalink
Update:
Browse files Browse the repository at this point in the history
When opening a file.  If the file is mapped to a regular html element then use textContent to get the content.  If the file is mapped to a textarea use value so that changed / pasted values are retrieved rather than the initial default values.
  • Loading branch information
bnmnetp committed Feb 26, 2013
1 parent a1bbb20 commit 91f2721
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dist/skulpt.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ Sk.builtin.file = function(name, mode, buffering)
var elem = document.getElementById(name.v);
if ( elem == null) {
throw new Sk.builtin.IOError("[Errno 2] No such file or directory: '"+name.v+"'");
} else if (document.all) {
this.data$ = elem.innerText;
} else { // stupid Firefox
this.data$ = elem.textContent;
} else {
if( elem.nodeName.toLowerCase() == "textarea") {
this.data$ = elem.value;
}
else {
this.data$ = elem.textContent;
}
}
} else {
this.data$ = Sk.read(name.v);
Expand All @@ -30,7 +33,7 @@ Sk.builtin.file = function(name, mode, buffering)
this.pos$ = 0;

this.__class__ = Sk.builtin.file;

return this;
};

Expand Down

0 comments on commit 91f2721

Please sign in to comment.