annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1113:7affda55c10e

using annotator in digilib works somewhat now.
author robcast
date Thu, 01 Nov 2012 18:38:11 +0100
parents
children 1525c820ee27
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
1 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
2 digilib plugin for annotations.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
3
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
4 currently only point-like annotations (like marks).
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
5
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
6 Annotations are stored on a Annotator http://annotateit.org compatible server.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
7
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
8 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
9
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
10 (function($) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
11
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
12 // affine geometry
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
13 var geom;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
14 // plugin object with digilib data
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
15 var digilib;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
16 // our Annotator instance
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
17 var annotator;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
18
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
19 var FULL_AREA;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
20
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
21 var buttons = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
22 annotations : {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
23 onclick : "toggleAnnotations",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
24 tooltip : "show or hide annotations",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
25 icon : "annotations.png"
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
26 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
27 annotationuser : {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
28 onclick : "setAnnotationUser",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
29 tooltip : "set user account for annotations",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
30 icon : "annotation-user.png"
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
31 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
32 annotationmark : {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
33 onclick : "setAnnotationMark",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
34 tooltip : "create an annotation for a point",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
35 icon : "annotation-mark.png"
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
36 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
37 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
38
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
39 var defaults = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
40 'annotatorInstance' : null,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
41 // are annotations active?
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
42 'isAnnotationsVisible' : true,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
43 // buttonset of this plugin
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
44 'annotationSet' : ['annotations', 'annotationuser', 'annotationmark', 'lessoptions'],
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
45 // URL of annotation server
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
46 'annotationServerUrl' : 'http://virtuoso.mpiwg-berlin.mpg.de:8080/AnnotationManager/annotator',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
47 // URL of authentication token server
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
48 'annotationTokenUrl' : 'http://localhost:8080/test/annotator/token',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
49 // annotation user name
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
50 'annotationUser' : 'anonymous',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
51 // function to translate user name from annotation server format
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
52 'annotationServerUserString' : function() {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
53 if (this.user && this.user.name) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
54 return this.user.name;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
55 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
56 return this.user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
57 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
58
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
59 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
60
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
61 var actions = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
62 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
63 * show/hide annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
64 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
65 toggleAnnotations : function (data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
66 var show = !data.settings.isAnnotationsVisible;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
67 data.settings.isAnnotationsVisible = show;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
68 digilib.fn.highlightButtons(data, 'annotations', show);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
69 renderAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
70 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
71
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
72 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
73 * set user account for annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
74 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
75 setAnnotationUser : function (data, user, password) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
76 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
77 if (user == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
78 // user name entered in JS-prompt
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
79 user = window.prompt("User name:", settings.annotationUser);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
80 if (user != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
81 // password entered in JS-prompt
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
82 password = window.prompt("Password:", '');
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
83 settings.annotationUser = user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
84 data.dlOpts.annotationUser = user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
85 digilib.fn.storeOptions(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
86 loadAnnotationToken(data, password);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
87 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
88 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
89 settings.annotationUser = user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
90 data.dlOpts.annotationUser = user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
91 digilib.fn.storeOptions(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
92 loadAnnotationToken(data, password);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
93 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
94 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
95
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
96 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
97 * set a mark-annotation by clicking (or giving a position and a text)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
98 *
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
99 * @param data
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
100 * @param mpos
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
101 * @param text
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
102 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
103 setAnnotationMark : function (data, mpos, text) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
104 if (mpos == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
105 // interactive
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
106 setAnnotationMark(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
107 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
108 // use position and text (and user-id)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
109 var annotation = newAnnotation(data, mpos, text, null, null, data.settings.annotationUser);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
110 storeAnnotation(data, annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
111 // TODO: replace with annotation returned by server
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
112 data.annotations.push(annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
113 digilib.fn.redisplay(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
114 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
115 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
116 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
117
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
118 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
119 * create a new annotation object
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
120 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
121 var newAnnotation = function (data, mpos, text, id, uri, user, permissions, tags) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
122 var annot = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
123 pos : mpos,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
124 text : text,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
125 id : id,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
126 uri : uri,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
127 user : user,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
128 permissions : permissions,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
129 tags : tags
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
130 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
131 // TODO: use prototype?
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
132 annot.getUserName = data.settings.annotationServerUserString;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
133 return annot;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
134 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
135
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
136 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
137 * returns an annotatable url to this digilib image
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
138 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
139 var getAnnotationPageUrl = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
140 var url = data.settings.digilibBaseUrl + '/jquery/digilib.html?';
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
141 url += digilib.fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
142 return url;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
143 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
144
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
145 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
146 * add a mark-annotation where clicked.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
147 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
148 var setAnnotationMark = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
149 var $scaler = data.$scaler;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
150 annotator = data.settings.annotatorInstance;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
151 // unbind other handler TODO: do we need to do this?
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
152 $scaler.off(".dlZoomDrag");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
153 // start event capturing
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
154 $scaler.one('mousedown.dlSetAnnotationMark', function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
155 // event handler adding a new mark
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
156 console.log("setAnnotationMark at=", evt);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
157 var mpos = geom.position(evt);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
158 var pos = data.imgTrafo.invtransform(mpos);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
159
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
160 console.debug("showing annotator editor!");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
161 var annotation = annotator.createAnnotation();
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
162 annotation.areas = [geom.rectangle(pos)];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
163 annotator.showEditor(annotation, mpos.getAsCss());
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
164
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
165 return false;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
166 // Annotation text entered in JS-prompt
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
167 var text = window.prompt("Annotation text:");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
168 if (text == null) return false;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
169 var annotation = newAnnotation(data, pos, text, null, null, data.settings.annotationUser);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
170 storeAnnotation(data, annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
171 data.annotations.push(annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
172 digilib.fn.redisplay(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
173 return false;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
174 });
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
175 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
176
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
177 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
178 * place annotations on the image
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
179 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
180 var renderAnnotations = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
181 console.debug("renderAnnotations: annotator=", annotator);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
182 if (annotator == null || data.$img == null || data.imgTrafo == null)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
183 return;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
184 var annotations = annotator.plugins['Store'].annotations;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
185 var cssPrefix = data.settings.cssPrefix;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
186 var $elem = data.$elem;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
187 // try to show annotation user state
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
188 $elem.find('div#'+cssPrefix+'button-annotationuser').attr('title', 'annotation user: '+data.settings.annotationUser);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
189 // clear annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
190 $elem.find('div.' + cssPrefix + 'annotationmark').remove();
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
191 if (!data.settings.isAnnotationsVisible) return;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
192 for (var i = 0; i < annotations.length; i++) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
193 var annotation = annotations[i];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
194 renderAnnotation(data, annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
195 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
196 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
197
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
198 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
199 * place annotation on the image
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
200 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
201 var renderAnnotation = function(data, annotation) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
202 console.debug("renderAnnotation: annotation=", annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
203 if (annotation == null || data.$img == null || data.imgTrafo == null)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
204 return;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
205 var cssPrefix = data.settings.cssPrefix;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
206 var $elem = data.$elem;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
207 // try to show annotation user state
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
208 $elem.find('div#'+cssPrefix+'button-annotationuser').attr('title', 'annotation user: '+data.settings.annotationUser);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
209 if (!data.settings.isAnnotationsVisible) return;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
210 var pos = geom.position(annotation.areas[0]);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
211 if (data.zoomArea.containsPosition(pos)) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
212 var mpos = data.imgTrafo.transform(pos);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
213 console.debug("renderannotations: pos=", mpos);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
214 // create annotation
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
215 var html = '<div class="' + cssPrefix + 'annotationmark ' + cssPrefix + 'overlay">?</div>';
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
216 // set text as tooltip
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
217 var $annotation = $(html);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
218 $annotation.attr('title', "Annotation: " + annotation.text);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
219 $elem.append($annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
220 mpos.adjustDiv($annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
221 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
222 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
223
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
224 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
225 * Get an authentication token from the token server.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
226 *
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
227 * Stores the token and loads annotations on success.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
228 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
229 var loadAnnotationToken = function(data, password) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
230 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
231 var url = settings.annotationTokenUrl;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
232 var params = {'user': settings.annotationUser};
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
233 if (password != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
234 params.password = password;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
235 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
236 // TODO: better error handling
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
237 $.post(url, params)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
238 .done(function (authToken, authStatus) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
239 console.debug("got auth token data=", authToken);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
240 data.annotationToken = authToken;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
241 data.dlOpts.annotationToken = authToken;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
242 digilib.fn.storeOptions(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
243 //loadAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
244 })
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
245 .fail(function (xhr, status) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
246 console.error("got auth token error:", xhr);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
247 data.annotationToken = null;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
248 data.settings.annotationUser = "anonymous";
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
249 //loadAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
250 });
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
251 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
252
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
253 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
254 * loads all annotations for this url from the annotation server.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
255 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
256 var loadAnnotations = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
257 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
258 // we use the search API
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
259 var url = settings.annotationServerUrl + '/search';
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
260 var pageUrl = getAnnotationPageUrl(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
261 // send authentication token in header
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
262 headers = {};
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
263 if (data.annotationToken != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
264 headers['x-annotator-auth-token'] = data.annotationToken;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
265 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
266 // get only 20 annotations with this url
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
267 var query = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
268 limit : 20,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
269 uri : pageUrl
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
270 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
271 $.ajax(url, {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
272 dataType : 'json',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
273 data : query,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
274 headers : headers,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
275 success : function(annotData, annotStatus) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
276 console.debug("got annotation data=", annotData);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
277 data.annotationData = annotData;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
278 parseAnnotations(data, annotData);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
279 renderAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
280 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
281 });
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
282 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
283
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
284 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
285 * parse all JSON-annotations in annotationData.rows and put in data.annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
286 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
287 var parseAnnotations = function(data, annotationData) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
288 var annotations = [];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
289 for (var i = 0; i < annotationData.rows.length; ++i) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
290 var ann = annotationData.rows[i];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
291 var annot = parseAnnotation(data, ann);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
292 if (annot != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
293 annotations.push(annot);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
294 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
295 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
296 data.annotations = annotations;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
297 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
298
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
299 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
300 * Parse a JSON-annotation.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
301 *
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
302 * Returns an annotation object.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
303 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
304 var parseAnnotation = function(data, ann) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
305 // TODO: check validity of annotation data
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
306 if (ann.areas != null && ann.areas.length > 0) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
307 var area = ann.areas[0];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
308 // currently only point annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
309 var pos = geom.position(area.x, area.y);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
310 return newAnnotation(data, pos, ann.text, ann.id, ann.uri, ann.user, ann.permissions, ann.tags);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
311 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
312 return null;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
313 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
314
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
315 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
316 * Store an annotation on the annotation server.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
317 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
318 var storeAnnotation = function(data, annotation) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
319 console.debug("storeAnnotation:", annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
320 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
321 var url = settings.annotationServerUrl + '/annotations';
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
322 var pageUrl = getAnnotationPageUrl(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
323 // send authentication token in header
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
324 headers = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
325 'x-annotator-auth-token' : data.annotationToken
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
326 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
327 // create annotation object to send
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
328 var annotData = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
329 areas : [{
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
330 x : annotation.pos.x,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
331 y : annotation.pos.y
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
332 }],
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
333 text : annotation.text,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
334 uri : pageUrl,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
335 user : settings.annotationUser
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
336 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
337 var dataString = JSON.stringify(annotData);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
338 $.ajax(url, {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
339 type : 'POST',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
340 dataType : 'json',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
341 contentType : 'application/json',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
342 data : dataString,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
343 headers : headers,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
344 success : function(annotData, annotStatus) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
345 console.debug("sent annotation data, got=", annotData, " status=" + annotStatus);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
346 var annot = parseAnnotation(data, annotData);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
347 // TODO: we have to add the returned data to the real annotation!
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
348 //renderAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
349 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
350 });
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
351
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
352 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
353
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
354 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
355 * install additional buttons
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
356 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
357 var installButtons = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
358 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
359 var mode = settings.interactionMode;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
360 var buttonSettings = settings.buttonSettings[mode];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
361 // configure buttons through digilib "annotationSet" option
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
362 var buttonSet = settings.annotationSet || annotationSet;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
363 // set annotationSet to [] or '' for no buttons (when showing annotations only)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
364 if (buttonSet.length && buttonSet.length > 0) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
365 buttonSettings.annotationSet = buttonSet;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
366 buttonSettings.buttonSets.push('annotationSet');
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
367 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
368 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
369
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
370 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
371 * plugin installation. called by digilib on plugin object.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
372 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
373 var install = function(plugin) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
374 digilib = plugin;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
375 console.debug('installing annotations plugin. digilib:', digilib);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
376 // import geometry classes
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
377 geom = digilib.fn.geometry;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
378 FULL_AREA = geom.rectangle(0, 0, 1, 1);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
379 // add defaults, actins, buttons
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
380 $.extend(digilib.defaults, defaults);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
381 $.extend(digilib.actions, actions);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
382 $.extend(digilib.buttons, buttons);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
383 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
384
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
385 /** plugin initialization */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
386 var init = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
387 console.debug('initialising annotations plugin. data:', data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
388 var $data = $(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
389 // set up
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
390 data.annotations = [];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
391 if (digilib.plugins.buttons != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
392 installButtons(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
393 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
394 if (data.dlOpts.annotationUser != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
395 // get annotation user from cookie
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
396 data.settings.annotationUser = data.dlOpts.annotationUser;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
397 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
398 if (data.dlOpts.annotationToken != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
399 // get annotation token from cookie
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
400 data.annotationToken = data.dlOpts.annotationToken;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
401 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
402 // install event handler
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
403 $data.bind('setup', handleSetup);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
404 $data.bind('update', handleUpdate);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
405 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
406
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
407 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
408 * setup loads all annotations.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
409 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
410 var handleSetup = function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
411 console.debug("annotations: handleSetup");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
412 var data = this;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
413 if (data.annotationToken == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
414 loadAnnotationToken(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
415 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
416 // set up annotator (after html has been set up)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
417 var uri = getAnnotationPageUrl(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
418 annotator = new Annotator(data.$elem.get(0))
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
419 //.addPlugin('Tags')
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
420 .addPlugin('Auth', {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
421 token : data.annotationToken,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
422 //tokenUrl: 'http://annotateit.org/api/token'
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
423 //tokenUrl: 'http://localhost:8080/test/annotator/token?user=anonymous'
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
424 //autoFetch: false
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
425 })
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
426 .addPlugin('Permissions', {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
427 user: data.settings.annotationUser,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
428 userString: function (user) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
429 if (user && user.name) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
430 return user.name;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
431 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
432 return user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
433 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
434 userId: function (user) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
435 if (user && user.id) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
436 return user.id;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
437 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
438 return user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
439 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
440 })
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
441 .addPlugin('Store', {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
442 prefix : data.settings.annotationServerUrl,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
443 //prefix: 'http://localhost:18080/AnnotationManager/annotator',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
444 //prefix: 'http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
445 //prefix: 'http://annotateit.org/api',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
446 annotationData: {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
447 'uri': uri
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
448 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
449 loadFromSearch: {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
450 'limit': 20,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
451 'uri': uri
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
452 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
453 })
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
454 ;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
455
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
456 // monkey-patch Annotator.setupAnnotation
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
457 annotator.setupAnnotation = function(annotation, fireEvents) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
458 if (fireEvents == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
459 fireEvents = true;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
460 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
461
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
462 renderAnnotation(data, annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
463
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
464 if (fireEvents) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
465 this.publish('annotationCreated', [annotation]);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
466 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
467 return annotation;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
468 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
469
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
470
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
471 data.settings.annotatorInstance = annotator;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
472 /* load annotations from server
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
473 if (data.annotationToken != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
474 loadAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
475 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
476 loadAnnotationToken(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
477 } */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
478 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
479
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
480 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
481 * update renders all annotations.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
482 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
483 var handleUpdate = function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
484 console.debug("annotations: handleUpdate");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
485 var data = this;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
486 renderAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
487 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
488
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
489 // plugin object with name and init
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
490 // shared objects filled by digilib on registration
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
491 var plugin = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
492 name : 'annotations',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
493 install : install,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
494 init : init,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
495 buttons : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
496 actions : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
497 fn : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
498 plugins : {}
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
499 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
500
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
501 if ($.fn.digilib == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
502 $.error("jquery.digilib.annotations must be loaded after jquery.digilib!");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
503 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
504 $.fn.digilib('plugin', plugin);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
505 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
506 })(jQuery);