annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1115:526dafa4690d

using annotator in digilib works now. code still ugly.
author robcast
date Fri, 02 Nov 2012 20:49:51 +0100
parents 1525c820ee27
children 08206603c7dc
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
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
13 var geom = null;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
14 // plugin object with digilib data
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
15 var digilib = null;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
16 // our Annotator instance
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
17 var annotator = null;
1113
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 buttons = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
20 annotations : {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
21 onclick : "toggleAnnotations",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
22 tooltip : "show or hide annotations",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
23 icon : "annotations.png"
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
24 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
25 annotationuser : {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
26 onclick : "setAnnotationUser",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
27 tooltip : "set user account for annotations",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
28 icon : "annotation-user.png"
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
29 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
30 annotationmark : {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
31 onclick : "setAnnotationMark",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
32 tooltip : "create an annotation for a point",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
33 icon : "annotation-mark.png"
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
34 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
35 };
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 var defaults = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
38 // are annotations active?
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
39 'isAnnotationsVisible' : true,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
40 // buttonset of this plugin
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
41 'annotationSet' : ['annotations', 'annotationuser', 'annotationmark', 'lessoptions'],
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
42 // URL of annotation server
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
43 'annotationServerUrl' : 'http://virtuoso.mpiwg-berlin.mpg.de:8080/AnnotationManager/annotator',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
44 // URL of authentication token server
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
45 'annotationTokenUrl' : 'http://localhost:8080/test/annotator/token',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
46 // annotation user name
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
47 'annotationUser' : 'anonymous',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
48 // function to translate user name from annotation server format
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
49 'annotationServerUserString' : function() {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
50 if (this.user && this.user.name) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
51 return this.user.name;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
52 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
53 return this.user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
54 },
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 };
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 var actions = {
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 * show/hide annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
61 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
62 toggleAnnotations : function (data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
63 var show = !data.settings.isAnnotationsVisible;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
64 data.settings.isAnnotationsVisible = show;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
65 digilib.fn.highlightButtons(data, 'annotations', show);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
66 renderAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
67 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
68
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
69 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
70 * set user account for annotations
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 setAnnotationUser : function (data, user, password) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
73 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
74 if (user == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
75 // user name entered in JS-prompt
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
76 user = window.prompt("User name:", settings.annotationUser);
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 // password entered in JS-prompt
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
79 password = window.prompt("Password:", '');
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
80 settings.annotationUser = user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
81 data.dlOpts.annotationUser = user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
82 digilib.fn.storeOptions(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
83 loadAnnotationToken(data, password);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
84 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
85 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
86 settings.annotationUser = user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
87 data.dlOpts.annotationUser = user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
88 digilib.fn.storeOptions(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
89 loadAnnotationToken(data, password);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
90 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
91 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
92
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 * 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
95 *
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
96 * @param data
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
97 * @param mpos
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
98 * @param text
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
99 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
100 setAnnotationMark : function (data, mpos, text) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
101 if (mpos == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
102 // interactive
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
103 setAnnotationMark(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
104 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
105 // use position and text (and user-id)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
106 var annotation = newAnnotation(data, mpos, text, null, null, data.settings.annotationUser);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
107 storeAnnotation(data, annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
108 // TODO: replace with annotation returned by server
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
109 data.annotations.push(annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
110 digilib.fn.redisplay(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
111 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
112 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
113 };
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 * returns an annotatable url to this digilib image
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 var getAnnotationPageUrl = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
119 var url = data.settings.digilibBaseUrl + '/jquery/digilib.html?';
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
120 url += digilib.fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
121 return url;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
122 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
123
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
124 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
125 * add a mark-annotation where clicked.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
126 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
127 var setAnnotationMark = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
128 var $scaler = data.$scaler;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
129 // unbind other handler TODO: do we need to do this?
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
130 $scaler.off(".dlZoomDrag");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
131 // start event capturing
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
132 $scaler.one('mousedown.dlSetAnnotationMark', function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
133 // event handler adding a new mark
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
134 console.log("setAnnotationMark at=", evt);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
135 var mpos = geom.position(evt);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
136 var pos = data.imgTrafo.invtransform(mpos);
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
137 // mark selected areas
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
138 annotator.selectedAreas = [geom.rectangle(pos)];
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
139 // create and edit new annotation
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
140 var annotation = annotator.createAnnotation();
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
141 annotator.showEditor(annotation, mpos.getAsCss());
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
142 return false;
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 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
147 * place annotations on the image
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
148 */
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
149 var renderAnnotations = function (data) {
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
150 console.debug("renderAnnotations: annotator=", annotator);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
151 if (annotator == null || data.$img == null || data.imgTrafo == null)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
152 return;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
153 var annotations = annotator.plugins['Store'].annotations;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
154 var cssPrefix = data.settings.cssPrefix;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
155 var $elem = data.$elem;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
156 // try to show annotation user state
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
157 $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
158 // clear annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
159 $elem.find('div.' + cssPrefix + 'annotationmark').remove();
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
160 if (!data.settings.isAnnotationsVisible) return;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
161 for (var i = 0; i < annotations.length; i++) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
162 var annotation = annotations[i];
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
163 annotation.idx = i+1;
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
164 renderAnnotation(data, annotation);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
165 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
166 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
167
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
168 /**
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
169 * place single annotation on the image
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
170 */
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
171 var renderAnnotation = function (data, annotation) {
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
172 console.debug("renderAnnotation: annotation=", annotation);
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
173 if (annotation == null || annotation.areas == null || data.$img == null || data.imgTrafo == null)
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
174 return;
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
175 if (!data.settings.isAnnotationsVisible) return;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
176 var cssPrefix = data.settings.cssPrefix;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
177 var $elem = data.$elem;
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
178 var idx = annotation.idx;
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
179 if (idx == null) idx = '?';
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
180 var pos = geom.position(annotation.areas[0]);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
181 if (data.zoomArea.containsPosition(pos)) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
182 var mpos = data.imgTrafo.transform(pos);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
183 console.debug("renderannotations: pos=", mpos);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
184 // create annotation
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
185 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
186 var $annotation = $(html);
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
187 // save annotation in data for Annotator
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
188 $annotation.data('annotation', annotation);
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
189 // save reference to div
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
190 annotation.$div = $annotation;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
191 $elem.append($annotation);
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
192 // hook up Annotator events
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
193 $annotation.on("mouseover", annotator.onHighlightMouseover);
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
194 $annotation.on("mouseout", annotator.startViewerHideTimer);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
195 mpos.adjustDiv($annotation);
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 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
200 * Get an authentication token from the token server.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
201 *
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
202 * Stores the token and loads annotations on success.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
203 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
204 var loadAnnotationToken = function(data, password) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
205 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
206 var url = settings.annotationTokenUrl;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
207 var params = {'user': settings.annotationUser};
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
208 if (password != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
209 params.password = password;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
210 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
211 // TODO: better error handling
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
212 $.post(url, params)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
213 .done(function (authToken, authStatus) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
214 console.debug("got auth token data=", authToken);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
215 data.annotationToken = authToken;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
216 data.dlOpts.annotationToken = authToken;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
217 digilib.fn.storeOptions(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
218 //loadAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
219 })
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
220 .fail(function (xhr, status) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
221 console.error("got auth token error:", xhr);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
222 data.annotationToken = null;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
223 data.settings.annotationUser = "anonymous";
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
224 //loadAnnotations(data);
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 * install additional buttons
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 var installButtons = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
232 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
233 var mode = settings.interactionMode;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
234 var buttonSettings = settings.buttonSettings[mode];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
235 // configure buttons through digilib "annotationSet" option
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
236 var buttonSet = settings.annotationSet || annotationSet;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
237 // set annotationSet to [] or '' for no buttons (when showing annotations only)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
238 if (buttonSet.length && buttonSet.length > 0) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
239 buttonSettings.annotationSet = buttonSet;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
240 buttonSettings.buttonSets.push('annotationSet');
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
241 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
242 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
243
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 * plugin installation. called by digilib on plugin object.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
246 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
247 var install = function(plugin) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
248 digilib = plugin;
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
249 console.debug('installing annotator plugin. digilib:', digilib);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
250 // import geometry classes
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
251 geom = digilib.fn.geometry;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
252 FULL_AREA = geom.rectangle(0, 0, 1, 1);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
253 // add defaults, actins, buttons
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
254 $.extend(digilib.defaults, defaults);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
255 $.extend(digilib.actions, actions);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
256 $.extend(digilib.buttons, buttons);
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
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
259 /** plugin initialization */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
260 var init = function(data) {
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
261 console.debug('initialising annotator plugin. data:', data);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
262 var $data = $(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
263 // set up
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
264 data.annotations = [];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
265 if (digilib.plugins.buttons != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
266 installButtons(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
267 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
268 if (data.dlOpts.annotationUser != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
269 // get annotation user from cookie
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
270 data.settings.annotationUser = data.dlOpts.annotationUser;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
271 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
272 if (data.dlOpts.annotationToken != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
273 // get annotation token from cookie
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
274 data.annotationToken = data.dlOpts.annotationToken;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
275 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
276 // install event handler
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
277 $data.bind('setup', handleSetup);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
278 $data.bind('update', handleUpdate);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
279 };
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 * setup loads all annotations.
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 var handleSetup = function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
285 console.debug("annotations: handleSetup");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
286 var data = this;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
287 if (data.annotationToken == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
288 loadAnnotationToken(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
289 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
290 // set up annotator (after html has been set up)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
291 var uri = getAnnotationPageUrl(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
292 annotator = new Annotator(data.$elem.get(0))
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
293 //.addPlugin('Tags')
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
294 .addPlugin('Auth', {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
295 token : data.annotationToken,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
296 //tokenUrl: 'http://annotateit.org/api/token'
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
297 //autoFetch: false
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 .addPlugin('Permissions', {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
300 user: data.settings.annotationUser,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
301 userString: function (user) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
302 if (user && user.name) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
303 return user.name;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
304 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
305 return user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
306 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
307 userId: function (user) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
308 if (user && user.id) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
309 return user.id;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
310 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
311 return user;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
312 }
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 .addPlugin('Store', {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
315 prefix : data.settings.annotationServerUrl,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
316 annotationData: {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
317 'uri': uri
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 loadFromSearch: {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
320 'limit': 20,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
321 'uri': uri
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
322 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
323 })
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
324 ;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
325
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
326 // monkey-patch Annotator.setupAnnotation
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
327 annotator.setupRangeAnnotation = annotator.setupAnnotation;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
328 annotator.setupAnnotation = function(annotation, fireEvents) {
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
329 if (annotator.selectedAreas == null && annotation.areas == null) {
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
330 // pass call to original method
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
331 return annotator.setupRangeAnnotation.apply(this, arguments);
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
332 } else {
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
333 // set up digilib-area annotation
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
334 if (fireEvents == null) {
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
335 fireEvents = true;
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
336 }
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
337 if (annotation.areas == null) {
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
338 annotation.areas = annotator.selectedAreas;
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
339 }
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
340 // compatibility crap
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
341 annotation.highlights = [];
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
342 // pre-render this annotation
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
343 renderAnnotation(data, annotation);
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
344 if (fireEvents) {
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
345 this.publish('annotationCreated', [annotation]);
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
346 }
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
347 return annotation;
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
348 }
1113
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
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
351 // hook Annotator events
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
352 annotator.subscribe('annotationDeleted', function (ann) {
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
353 console.debug("got annotationDeleted!");
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
354 if (ann.$div != null) {
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
355 ann.$div.remove();
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
356 delete ann.$div;
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
357 }
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
358 });
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
359
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
360 // TODO: should we really export annotator?
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
361 data.annotator = annotator;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
362 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
363
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
364 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
365 * update renders all annotations.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
366 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
367 var handleUpdate = function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
368 console.debug("annotations: handleUpdate");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
369 var data = this;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
370 renderAnnotations(data);
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 // plugin object with name and init
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
374 // shared objects filled by digilib on registration
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
375 var plugin = {
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
376 name : 'annotator',
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
377 install : install,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
378 init : init,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
379 buttons : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
380 actions : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
381 fn : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
382 plugins : {}
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 if ($.fn.digilib == null) {
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
386 $.error("jquery.digilib.annotator must be loaded after jquery.digilib!");
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
387 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
388 $.fn.digilib('plugin', plugin);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
389 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
390 })(jQuery);