Commit a57ff80a authored by Robert Hodan's avatar Robert Hodan Committed by Juan Corona

Add support for destroying connected frames

parent eb093f7e
......@@ -64,5 +64,4 @@ module.exports = class CrossFrame extends Plugin
FrameUtil.injectHypothesis(frame, options.embedScriptUrl)
_iframeUnloaded = (frame) ->
# TODO: Bridge call here not yet implemented, placeholder for now
bridge.call('destroyFrame', frame.src);
......@@ -124,6 +124,10 @@ function FrameSync($rootScope, $window, Discovery, annotationUI, bridge) {
$rootScope.$broadcast(events.BEFORE_ANNOTATION_CREATED, annot);
});
bridge.on('destroyFrame', function (uri) {
destroyFrame(uri);
});
// Anchoring an annotation in the frame completed
bridge.on('sync', function (events_) {
events_.forEach(function (event) {
......@@ -181,6 +185,19 @@ function FrameSync($rootScope, $window, Discovery, annotationUI, bridge) {
});
}
function destroyFrame(uri) {
var frames = annotationUI.frames();
var frameToDestroy;
for (var i = 0; i < frames.length; i++) {
var frame = frames[i];
if (frame.uri === uri) {
frameToDestroy = frame;
break;
}
}
if (frameToDestroy) annotationUI.destroyFrame(frameToDestroy);
}
/**
* Find and connect to Hypothesis clients in the current window.
*/
......
......@@ -17,6 +17,12 @@ var update = {
return {frames: state.frames.concat(action.frame)};
},
DESTROY_FRAME: function (state, action) {
var index = state.frames.indexOf(action.frame);
if (index >= 0) state.frames.splice(index, 1);
return {frames: state.frames};
},
UPDATE_FRAME_ANNOTATION_FETCH_STATUS: function (state, action) {
var frames = state.frames.map(function (frame) {
var match = (frame.uri && frame.uri === action.uri);
......@@ -43,6 +49,13 @@ function connectFrame(frame) {
return {type: actions.CONNECT_FRAME, frame: frame};
}
/**
* Remove a frame from the list of frames currently connected to the sidebar app.
*/
function destroyFrame(frame) {
return {type: actions.DESTROY_FRAME, frame: frame};
}
/**
* Update the `isAnnotationFetchComplete` flag of the frame.
*/
......@@ -100,6 +113,7 @@ module.exports = {
actions: {
connectFrame: connectFrame,
destroyFrame: destroyFrame,
updateFrameAnnotationFetchStatus: updateFrameAnnotationFetchStatus,
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment