Skip to content

Commit e640c92

Browse files
committed
Add permalink detection and display to Viewer.
1 parent d55d1d8 commit e640c92

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

css/annotator.css

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
.annotator-widget::after,
3434
.annotator-editor a::after,
3535
.annotator-viewer .annotator-controls button,
36+
.annotator-viewer .annotator-controls a,
3637
.annotator-filter .annotator-filter-navigation button::after,
3738
.annotator-filter .annotator-filter-property .annotator-filter-clear {
3839
background-image: url(../img/annotator-glyph-sprite.png);
@@ -237,7 +238,8 @@
237238
opacity: 1;
238239
}
239240

240-
.annotator-viewer .annotator-controls button {
241+
.annotator-viewer .annotator-controls button,
242+
.annotator-viewer .annotator-controls a {
241243
cursor: pointer;
242244
display: inline-block;
243245
width: 13px;
@@ -251,11 +253,14 @@
251253
}
252254

253255
.annotator-viewer .annotator-controls button:hover,
254-
.annotator-viewer .annotator-controls button:focus {
256+
.annotator-viewer .annotator-controls button:focus,
257+
.annotator-viewer .annotator-controls a:hover,
258+
.annotator-viewer .annotator-controls a:focus {
255259
opacity: 0.9;
256260
}
257261

258-
.annotator-viewer .annotator-controls button:active {
262+
.annotator-viewer .annotator-controls button:active,
263+
.annotator-viewer .annotator-controls a:active {
259264
opacity: 1;
260265
}
261266

@@ -271,6 +276,10 @@
271276
background-position: 0 -75px;
272277
}
273278

279+
.annotator-viewer .annotator-controls .annotator-link {
280+
background-position: 0 -270px;
281+
}
282+
274283
/* Annotator Editor
275284
-------------------------------------------------------------------- */
276285

dev.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ <h3>Header Level 3</h3>
9898
var elem = document.getElementById('airlock');
9999

100100
devAnnotator = new Annotator(elem)
101-
//.addPlugin('Auth')
101+
.addPlugin('Auth', {
102+
tokenUrl: 'http://localhost:5000/api/token'
103+
})
102104
.addPlugin('Unsupported')
103105
.addPlugin('Filter', {
104106
addAnnotationFilter: false
@@ -109,10 +111,15 @@ <h3>Header Level 3</h3>
109111
permissions: {
110112
update: ['alice']
111113
}
114+
})
115+
.addPlugin('Store', {
116+
prefix: 'http://localhost:5000/api',
117+
annotationData: {
118+
links: {
119+
alternate: { href: "http://google.com" }
120+
}
121+
}
112122
});
113-
// .addPlugin('Store', {
114-
// prefix: 'http://localhost:5000'
115-
// });
116123

117124
}(jQuery));
118125
</script>

img/annotator-glyph-sprite.png

282 Bytes
Loading

markup.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ <h3>Header Level 3</h3>
8080
<ul class="annotator-widget annotator-listing">
8181
<li class="annotator-annotation annotator-item">
8282
<span class="annotator-controls">
83+
<a href="#" class="annotator-link">View as webpage</a>
8384
<button class="annotator-edit">Edit</button>
8485
<button class="annotator-delete">Delete</button>
8586
</span>

src/viewer.coffee

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ class Annotator.Viewer extends Annotator.Widget
2121
item: """
2222
<li class="annotator-annotation annotator-item">
2323
<span class="annotator-controls">
24-
<button class="annotator-edit">Edit</button>
25-
<button class="annotator-delete">Delete</button>
24+
<a href="#" title="View as webpage" class="annotator-link">View as webpage</a>
25+
<button title="Edit" class="annotator-edit">Edit</button>
26+
<button title="Delete" class="annotator-delete">Delete</button>
2627
</span>
2728
</li>
2829
"""
@@ -121,7 +122,7 @@ class Annotator.Viewer extends Annotator.Widget
121122
#
122123
# Examples
123124
#
124-
# viewer.load([annotration1, annotation2, annotation3])
125+
# viewer.load([annotation1, annotation2, annotation3])
125126
#
126127
# Returns itslef.
127128
load: (annotations) =>
@@ -132,11 +133,19 @@ class Annotator.Viewer extends Annotator.Widget
132133
item = $(@item).clone().appendTo(list).data('annotation', annotation)
133134
controls = item.find('.annotator-controls')
134135

136+
link = controls.find('.annotator-link')
137+
edit = controls.find('.annotator-edit')
138+
del = controls.find('.annotator-delete')
139+
140+
unless annotation?.links?.alternate?.href
141+
link.remove()
142+
else
143+
link.attr('href', annotation.links.alternate.href)
144+
135145
if @options.readOnly
136-
controls.empty()
146+
edit.remove()
147+
del.remove()
137148
else
138-
edit = controls.find('.annotator-edit')
139-
del = controls.find('.annotator-delete')
140149
controller = {
141150
showEdit: -> edit.removeAttr('disabled')
142151
hideEdit: -> edit.attr('disabled', 'disabled')

0 commit comments

Comments
 (0)