Skip to content

Commit

Permalink
Merge pull request #818 from peitschie/runtime-hook-fix
Browse files Browse the repository at this point in the history
Change missed runtime.read hooks to override runtime.readFile instead
  • Loading branch information
peitschie committed Sep 17, 2014
2 parents 883a782 + b823607 commit 0f61742
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
18 changes: 9 additions & 9 deletions programs/docnosis/docnosis.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,17 +694,17 @@ function LoadingFile(file) {
reader.readAsBinaryString(file);
}
this.file = file;
this.read = function (offset, length, callback) {
function read() {
this.readFile = function (callback) {
function readFile() {
if (error) {
return callback(error);
}
if (data) {
return callback(error, data.subarray(offset, offset + length));
return callback(error, data);
}
readRequests.push(read);
readRequests.push(readFile);
}
read();
readFile();
};
this.load = load;
}
Expand Down Expand Up @@ -783,12 +783,12 @@ function Docnosis(element) {
}

function enhanceRuntime() {
var read = runtime.read;
runtime.read = function (path, offset, length, callback) {
var readFile = runtime.readFile;
runtime.readFile = function (path, encoding, callback) {
if (openedFiles.hasOwnProperty(path)) {
return openedFiles[path].read(offset, length, callback);
return openedFiles[path].readFile(callback);
} else {
return read(path, offset, length, callback);
return readFile(path, encoding, callback);
}
};
}
Expand Down
8 changes: 4 additions & 4 deletions programs/editor/localfileeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ function createEditor() {

function enhanceRuntime() {
var openedFiles = {},
read = runtime.read;
runtime.read = function (path, offset, length, callback) {
readFile = runtime.readFile;
runtime.readFile = function (path, encoding, callback) {
var array;
if (openedFiles.hasOwnProperty(path)) {
array = new Uint8Array(openedFiles[path], offset, length);
array = new Uint8Array(openedFiles[path]);
callback(undefined, array);
} else {
return read(path, offset, length, callback);
return readFile(path, encoding, callback);
}
};
runtime.registerFile = function (path, data) {
Expand Down
8 changes: 4 additions & 4 deletions programs/editor/revieweditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ function createReviewEditor() {

function enhanceRuntime() {
var openedFiles = {},
read = runtime.read;
runtime.read = function (path, offset, length, callback) {
readFile = runtime.readFile;
runtime.readFile = function (path, encoding, callback) {
var array;
if (openedFiles.hasOwnProperty(path)) {
array = new Uint8Array(openedFiles[path], offset, length);
array = new Uint8Array(openedFiles[path]);
callback(undefined, array);
} else {
return read(path, offset, length, callback);
return readFile(path, encoding, callback);
}
};
runtime.registerFile = function (path, data) {
Expand Down
17 changes: 4 additions & 13 deletions programs/touchui/app/views/OdfView.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,16 @@ Ext.define('WebODFApp.view.OdfView', (function () {
}
}
function initCanvas() {
var cmp;
if (globalreadfunction === undefined) {
// overload the global read function with one that only reads
// the data from this canvas
globalreadfunction = runtime.read;
globalfilesizefunction = runtime.getFileSize;
runtime.read = function (path, offset, length, callback) {
globalreadfunction = runtime.readFile;
runtime.readFile = function (path, encoding, callback) {
if (path !== overridePath) {
globalreadfunction.apply(runtime,
[path, offset, length, callback]);
[path, encoding, callback]);
} else {
callback(null, data.subarray(offset, offset + length));
}
};
runtime.getFileSize = function (path, callback) {
if (path !== overridePath) {
globalfilesizefunction.apply(runtime, [path, callback]);
} else {
callback(data.length);
callback(null, data);
}
};
dom = Ext.getCmp('webodf').element.dom;
Expand Down

0 comments on commit 0f61742

Please sign in to comment.