Skip to content
Snippets Groups Projects
Commit 773893a9 authored by Jack Reed's avatar Jack Reed Committed by Chris Beer
Browse files

Support multiple selectors for WebAnnotations

parent c7089b44
No related branches found
No related tags found
No related merge requests found
...@@ -105,6 +105,12 @@ describe('AnnotationItem', () => { ...@@ -105,6 +105,12 @@ describe('AnnotationItem', () => {
it('returns the on string (for simple fragment selector)', () => { it('returns the on string (for simple fragment selector)', () => {
expect(new AnnotationItem({ target: 'yolo' }).selector).toEqual('yolo'); expect(new AnnotationItem({ target: 'yolo' }).selector).toEqual('yolo');
}); });
it('returns objects wrapped in an array', () => {
expect(new AnnotationItem({ target: { selector: 'yolo' } }).selector).toEqual(['yolo']);
});
it('handles multiple selectors', () => {
expect(new AnnotationItem({ target: { selector: ['yolo', 'foo'] } }).selector).toEqual(['yolo', 'foo']);
});
}); });
describe('chars', () => { describe('chars', () => {
it('with no resource', () => { it('with no resource', () => {
...@@ -124,6 +130,10 @@ describe('AnnotationItem', () => { ...@@ -124,6 +130,10 @@ describe('AnnotationItem', () => {
expect(new AnnotationItem({ target: 'www.example.com/#xywh=10,10,100,200' }) expect(new AnnotationItem({ target: 'www.example.com/#xywh=10,10,100,200' })
.fragmentSelector).toEqual([10, 10, 100, 200]); .fragmentSelector).toEqual([10, 10, 100, 200]);
}); });
it('multiple selectors', () => {
expect(new AnnotationItem({ target: { selector: [{ type: 'FragmentSelector', value: '#xywh=10,10,100,200' }] } })
.fragmentSelector).toEqual([10, 10, 100, 200]);
});
it('url without a fragment', () => { it('url without a fragment', () => {
expect(new AnnotationItem({ target: 'www.example.com' }) expect(new AnnotationItem({ target: 'www.example.com' })
.fragmentSelector).toEqual(null); .fragmentSelector).toEqual(null);
...@@ -142,7 +152,7 @@ describe('AnnotationItem', () => { ...@@ -142,7 +152,7 @@ describe('AnnotationItem', () => {
it('without specified type', () => { it('without specified type', () => {
expect(new AnnotationItem({ target: { selector: { } } }) expect(new AnnotationItem({ target: { selector: { } } })
.svgSelector).toEqual(null); .svgSelector).toEqual(undefined);
}); });
}); });
}); });
...@@ -78,7 +78,7 @@ export default class AnnotationItem { ...@@ -78,7 +78,7 @@ export default class AnnotationItem {
case 'string': case 'string':
return target; return target;
case 'object': case 'object':
return target.selector; return flatten(compact(new Array(target.selector)));
default: default:
return null; return null;
} }
...@@ -91,10 +91,7 @@ export default class AnnotationItem { ...@@ -91,10 +91,7 @@ export default class AnnotationItem {
case 'string': case 'string':
return null; return null;
case 'object': case 'object':
if (selector.type && selector.type === 'SvgSelector') { return selector.find(s => s.type && s.type === 'SvgSelector');
return selector;
}
return null;
default: default:
return null; return null;
} }
...@@ -105,13 +102,15 @@ export default class AnnotationItem { ...@@ -105,13 +102,15 @@ export default class AnnotationItem {
const { selector } = this; const { selector } = this;
let match; let match;
let fragmentSelector;
switch (typeof selector) { switch (typeof selector) {
case 'string': case 'string':
match = selector.match(/xywh=(.*)$/); match = selector.match(/xywh=(.*)$/);
break; break;
case 'object': case 'object':
match = selector.value.match(/xywh=(.*)$/); fragmentSelector = selector.find(s => s.type && s.type === 'FragmentSelector');
match = fragmentSelector && fragmentSelector.value.match(/xywh=(.*)$/);
break; break;
default: default:
return null; return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment