Files
WebODF/programs/touchui/scripts.js
T
Jos van den Oever d79bab927e Add zoom in and out.
This was very hard to achieve because the webkit transform does not affect the percieved element width and height (at the moment). So a buffer <div/> was needed.
2012-02-21 20:44:19 +01:00

92 lines
2.5 KiB
JavaScript

/*global alert, app, window, runtime*/
var LocalFileSystem = {
PERSISTENT: 0,
TEMPORARY: 1
};
function FileEntry(name, fullPath) {
"use strict";
this.isFile = true;
this.isDirectory = false;
this.name = name;
this.fullPath = fullPath;
this.file = function (onsuccess, onerror) {
function File(fullPath) {
this.name = name;
this.fullPath = fullPath;
this.type = "";
this.size = -1;
this.lastModifiedDate = -1;
}
var file = new File(fullPath);
try {
onsuccess(file);
} catch (e) {
alert("Error on determining file properties: " + e);
onerror(e);
}
};
}
function FileReader() {
"use strict";
var fr = this;
this.readAsArrayBuffer = function (file) {
var path = file.fullPath.substr(7);
runtime.readFile(path, 'binary', function (error, data) {
fr.onloadend({target: {result: data}});
});
};
}
var DirectoryReader;
function DirectoryEntry(name, fullPath) {
"use strict";
this.isFile = false;
this.isDirectory = true;
this.name = name;
this.fullPath = fullPath;
this.createReader = function () {
var reader = new DirectoryReader(fullPath);
return reader;
};
}
function DirectoryReader(fullPath) {
"use strict";
this.readEntries = function (onsuccess, onerror) {
window.setTimeout(function () {
var entries = [];
entries[entries.length] = new FileEntry("welcome.odt",
"welcome.odt");
entries[entries.length] = new FileEntry("Traktatenblad.odt",
"Traktatenblad.odt");
try {
onsuccess(entries);
} catch (e) {
onerror(e);
}
}, 1);
};
}
window.resolveLocalFileSystemURI = function (path, onsuccess, onerror) {
"use strict";
var p = path.lastIndexOf("/"),
name = (p === -1) ? path : path.substr(p + 1);
onsuccess(new FileEntry(name, path));
};
window.requestFileSystem = function (filesystem, id, onsuccess, onerror) {
"use strict";
var dirs = [], shared, subfolder, path;
try {
if (filesystem === LocalFileSystem.PERSISTENT) {
path = "";
onsuccess({
name: "root",
root: new DirectoryEntry("root", path)
});
} else {
onerror("not defined");
}
} catch (e) {
onerror(e);
}
};
var device = {};