annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1114:1525c820ee27

annotator annotations even show up now.
author casties
date Fri, 02 Nov 2012 10:51:57 +0100
parents 7affda55c10e
children 526dafa4690d
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 */
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
180 var renderAnnotations = function (data) {
1113
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];
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
194 renderAnnotation(data, annotation, i+1);
1113
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 */
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
201 var renderAnnotation = function (data, annotation, idx) {
1113
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;
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
207 if (idx == null) idx = '?';
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
208 // try to show annotation user state
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
209 $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
210 if (!data.settings.isAnnotationsVisible) return;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
211 var pos = geom.position(annotation.areas[0]);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
212 if (data.zoomArea.containsPosition(pos)) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
213 var mpos = data.imgTrafo.transform(pos);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
214 console.debug("renderannotations: pos=", mpos);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
215 // create annotation
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
216 var html = '<div class="'+cssPrefix+'annotationmark '+cssPrefix+'overlay annotator-hl">'+idx+'</div>';
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
217 var $annotation = $(html);
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
218 $annotation.data('annotation', annotation);
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
219 // set text as tooltip
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
220 //$annotation.attr('title', "Annotation: " + annotation.text);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
221 $elem.append($annotation);
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
222 $annotation.on("mouseover", annotator.onHighlightMouseover);
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
223 $annotation.on("mouseout", annotator.startViewerHideTimer);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
224 mpos.adjustDiv($annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
225 }
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
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 * Get an authentication token from the token server.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
230 *
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
231 * Stores the token and loads annotations on success.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
232 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
233 var loadAnnotationToken = function(data, password) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
234 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
235 var url = settings.annotationTokenUrl;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
236 var params = {'user': settings.annotationUser};
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
237 if (password != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
238 params.password = password;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
239 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
240 // TODO: better error handling
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
241 $.post(url, params)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
242 .done(function (authToken, authStatus) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
243 console.debug("got auth token data=", authToken);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
244 data.annotationToken = authToken;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
245 data.dlOpts.annotationToken = authToken;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
246 digilib.fn.storeOptions(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
247 //loadAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
248 })
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
249 .fail(function (xhr, status) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
250 console.error("got auth token error:", xhr);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
251 data.annotationToken = null;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
252 data.settings.annotationUser = "anonymous";
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
253 //loadAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
254 });
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
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
257 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
258 * loads all annotations for this url from the annotation server.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
259 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
260 var loadAnnotations = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
261 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
262 // we use the search API
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
263 var url = settings.annotationServerUrl + '/search';
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
264 var pageUrl = getAnnotationPageUrl(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
265 // send authentication token in header
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
266 headers = {};
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
267 if (data.annotationToken != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
268 headers['x-annotator-auth-token'] = data.annotationToken;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
269 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
270 // get only 20 annotations with this url
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
271 var query = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
272 limit : 20,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
273 uri : pageUrl
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
274 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
275 $.ajax(url, {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
276 dataType : 'json',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
277 data : query,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
278 headers : headers,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
279 success : function(annotData, annotStatus) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
280 console.debug("got annotation data=", annotData);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
281 data.annotationData = annotData;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
282 parseAnnotations(data, annotData);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
283 renderAnnotations(data);
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 });
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
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
288 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
289 * parse all JSON-annotations in annotationData.rows and put in data.annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
290 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
291 var parseAnnotations = function(data, annotationData) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
292 var annotations = [];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
293 for (var i = 0; i < annotationData.rows.length; ++i) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
294 var ann = annotationData.rows[i];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
295 var annot = parseAnnotation(data, ann);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
296 if (annot != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
297 annotations.push(annot);
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 data.annotations = annotations;
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
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 * Parse a JSON-annotation.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
305 *
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
306 * Returns an annotation object.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
307 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
308 var parseAnnotation = function(data, ann) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
309 // TODO: check validity of annotation data
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
310 if (ann.areas != null && ann.areas.length > 0) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
311 var area = ann.areas[0];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
312 // currently only point annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
313 var pos = geom.position(area.x, area.y);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
314 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
315 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
316 return null;
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
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
319 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
320 * Store an annotation on the annotation server.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
321 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
322 var storeAnnotation = function(data, annotation) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
323 console.debug("storeAnnotation:", annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
324 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
325 var url = settings.annotationServerUrl + '/annotations';
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
326 var pageUrl = getAnnotationPageUrl(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
327 // send authentication token in header
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
328 headers = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
329 'x-annotator-auth-token' : data.annotationToken
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
330 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
331 // create annotation object to send
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
332 var annotData = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
333 areas : [{
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
334 x : annotation.pos.x,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
335 y : annotation.pos.y
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 text : annotation.text,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
338 uri : pageUrl,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
339 user : settings.annotationUser
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
340 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
341 var dataString = JSON.stringify(annotData);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
342 $.ajax(url, {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
343 type : 'POST',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
344 dataType : 'json',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
345 contentType : 'application/json',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
346 data : dataString,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
347 headers : headers,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
348 success : function(annotData, annotStatus) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
349 console.debug("sent annotation data, got=", annotData, " status=" + annotStatus);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
350 var annot = parseAnnotation(data, annotData);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
351 // TODO: we have to add the returned data to the real annotation!
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
352 //renderAnnotations(data);
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
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
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
358 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
359 * install additional buttons
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
360 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
361 var installButtons = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
362 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
363 var mode = settings.interactionMode;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
364 var buttonSettings = settings.buttonSettings[mode];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
365 // configure buttons through digilib "annotationSet" option
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
366 var buttonSet = settings.annotationSet || annotationSet;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
367 // set annotationSet to [] or '' for no buttons (when showing annotations only)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
368 if (buttonSet.length && buttonSet.length > 0) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
369 buttonSettings.annotationSet = buttonSet;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
370 buttonSettings.buttonSets.push('annotationSet');
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
371 }
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
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
374 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
375 * plugin installation. called by digilib on plugin object.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
376 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
377 var install = function(plugin) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
378 digilib = plugin;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
379 console.debug('installing annotations plugin. digilib:', digilib);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
380 // import geometry classes
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
381 geom = digilib.fn.geometry;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
382 FULL_AREA = geom.rectangle(0, 0, 1, 1);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
383 // add defaults, actins, buttons
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
384 $.extend(digilib.defaults, defaults);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
385 $.extend(digilib.actions, actions);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
386 $.extend(digilib.buttons, buttons);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
387 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
388
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
389 /** plugin initialization */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
390 var init = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
391 console.debug('initialising annotations plugin. data:', data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
392 var $data = $(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
393 // set up
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
394 data.annotations = [];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
395 if (digilib.plugins.buttons != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
396 installButtons(data);
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.annotationUser != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
399 // get annotation user from cookie
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
400 data.settings.annotationUser = data.dlOpts.annotationUser;
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 if (data.dlOpts.annotationToken != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
403 // get annotation token from cookie
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
404 data.annotationToken = data.dlOpts.annotationToken;
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 // install event handler
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
407 $data.bind('setup', handleSetup);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
408 $data.bind('update', handleUpdate);
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
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
411 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
412 * setup loads all annotations.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
413 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
414 var handleSetup = function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
415 console.debug("annotations: handleSetup");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
416 var data = this;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
417 if (data.annotationToken == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
418 loadAnnotationToken(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
419 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
420 // set up annotator (after html has been set up)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
421 var uri = getAnnotationPageUrl(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
422 annotator = new Annotator(data.$elem.get(0))
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
423 //.addPlugin('Tags')
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
424 .addPlugin('Auth', {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
425 token : data.annotationToken,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
426 //tokenUrl: 'http://annotateit.org/api/token'
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
427 //tokenUrl: 'http://localhost:8080/test/annotator/token?user=anonymous'
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
428 //autoFetch: false
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
429 })
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
430 .addPlugin('Permissions', {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
431 user: data.settings.annotationUser,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
432 userString: function (user) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
433 if (user && user.name) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
434 return user.name;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
435 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
436 return user;
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 userId: function (user) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
439 if (user && user.id) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
440 return user.id;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
441 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
442 return user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
443 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
444 })
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
445 .addPlugin('Store', {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
446 prefix : data.settings.annotationServerUrl,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
447 //prefix: 'http://localhost:18080/AnnotationManager/annotator',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
448 //prefix: 'http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
449 //prefix: 'http://annotateit.org/api',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
450 annotationData: {
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 loadFromSearch: {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
454 'limit': 20,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
455 'uri': uri
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
456 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
457 })
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
458 ;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
459
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
460 // monkey-patch Annotator.setupAnnotation
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
461 annotator.setupAnnotation = function(annotation, fireEvents) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
462 if (fireEvents == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
463 fireEvents = true;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
464 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
465
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
466 renderAnnotation(data, annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
467
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
468 if (fireEvents) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
469 this.publish('annotationCreated', [annotation]);
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 return annotation;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
472 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
473
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
474
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
475 data.settings.annotatorInstance = annotator;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
476 /* load annotations from server
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
477 if (data.annotationToken != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
478 loadAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
479 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
480 loadAnnotationToken(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
481 } */
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
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
484 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
485 * update renders all annotations.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
486 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
487 var handleUpdate = function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
488 console.debug("annotations: handleUpdate");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
489 var data = this;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
490 renderAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
491 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
492
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
493 // plugin object with name and init
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
494 // shared objects filled by digilib on registration
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
495 var plugin = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
496 name : 'annotations',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
497 install : install,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
498 init : init,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
499 buttons : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
500 actions : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
501 fn : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
502 plugins : {}
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
503 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
504
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
505 if ($.fn.digilib == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
506 $.error("jquery.digilib.annotations must be loaded after jquery.digilib!");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
507 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
508 $.fn.digilib('plugin', plugin);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
509 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
510 })(jQuery);