Add File module
This commit is contained in:
parent
07812287be
commit
8e9acf172c
3 changed files with 63 additions and 0 deletions
5
CHANGELOG.md
Normal file
5
CHANGELOG.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Revision history for WTK
|
||||
|
||||
## 0.1.0 -- 2022-07-25
|
||||
|
||||
* Start WTK around a simple file handling module.
|
25
guix.scm
Normal file
25
guix.scm
Normal file
|
@ -0,0 +1,25 @@
|
|||
(use-modules (guix build-system copy)
|
||||
(guix gexp)
|
||||
(guix git-download)
|
||||
(guix licenses)
|
||||
(guix packages))
|
||||
|
||||
(let
|
||||
((%source-dir (dirname (current-filename))))
|
||||
(package
|
||||
(name "sjw-wtk")
|
||||
(version "devel")
|
||||
(source
|
||||
(local-file %source-dir
|
||||
#:recursive? #t
|
||||
#:select? (git-predicate %source-dir)))
|
||||
(build-system copy-build-system)
|
||||
(arguments
|
||||
'(#:install-plan
|
||||
'(("src" "lib/SJW/WTK"))))
|
||||
(home-page "https://git.marvid.fr/Tissevert/WTK")
|
||||
(synopsis "The Web Tool Kit")
|
||||
(description
|
||||
"The Web Tool Kit aims at providing high-level abstraction modules to
|
||||
build web applications easily.")
|
||||
(license gpl3+)))
|
33
src/WTK/File.js
Normal file
33
src/WTK/File.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
import * as Dom from UnitJS.Dom;
|
||||
|
||||
return {
|
||||
load: load,
|
||||
pick: pick,
|
||||
save: save
|
||||
};
|
||||
|
||||
function pick(attributes) {
|
||||
return function(f) {
|
||||
attributes.type = 'file';
|
||||
var input = Dom.make('input', attributes);
|
||||
input.addEventListener('change', function() {
|
||||
f(input);
|
||||
});
|
||||
input.click();
|
||||
}
|
||||
}
|
||||
|
||||
function load(file) {
|
||||
return function(f) {
|
||||
var fileReader = new FileReader();
|
||||
fileReader.addEventListener('load', function() {
|
||||
f(fileReader.result);
|
||||
})
|
||||
fileReader.readAsText(file);
|
||||
};
|
||||
}
|
||||
|
||||
function save(data, name) {
|
||||
var a = Dom.make('a', {download: name, href: data});
|
||||
a.click();
|
||||
}
|
Loading…
Reference in a new issue