Skip to content

Commit

Permalink
Add a public abortLoad method.
Browse files Browse the repository at this point in the history
Relates to #412 and #433.
  • Loading branch information
ivmartel committed Dec 12, 2017
1 parent e59d308 commit 9aa21be
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ dwv.App = function ()

// Loadbox
var loadbox = null;
// Current loader
var currentLoader = null;

// UndoStack
var undoStack = null;

Expand Down Expand Up @@ -494,6 +497,17 @@ dwv.App = function ()
}
};

/**
* Abort the current load.
*/
this.abortLoad = function ()
{
if ( currentLoader ) {
currentLoader.abort();
currentLoader = null;
}
};

/**
* Load a list of ArrayBuffers.
* @param {Array} data The list of ArrayBuffers to load
Expand Down Expand Up @@ -550,13 +564,16 @@ dwv.App = function ()
*/
function loadImageData(data, loader, options)
{
// store loader
currentLoader = loader;

// allow to cancel
var previousOnKeyDown = window.onkeydown;
window.onkeydown = function (event) {
if (event.ctrlKey && event.keyCode === 88 ) // crtl-x
{
console.log("crtl-x pressed!");
loader.abort();
self.abortLoad();
}
};

Expand Down Expand Up @@ -594,6 +611,8 @@ dwv.App = function ()
fireEvent({type: "load-progress", lengthComputable: true,
loaded: 100, total: 100});
fireEvent({ 'type': 'load-end' });
// reset member
currentLoader = null;
};
loader.onprogress = onLoadProgress;
// main load (asynchronous)
Expand Down

0 comments on commit 9aa21be

Please sign in to comment.