annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1140:50d6eaa74b4b

reorganized annotator plugin settings handling... again.
author robcast
date Fri, 16 Nov 2012 20:30:18 +0100
parents 2df84b3a9ad5
children e05b101f7790
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
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
17 var buttons = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
18 annotations : {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
19 onclick : "toggleAnnotations",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
20 tooltip : "show or hide annotations",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
21 icon : "annotations.png"
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
22 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
23 annotationuser : {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
24 onclick : "setAnnotationUser",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
25 tooltip : "set user account for annotations",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
26 icon : "annotation-user.png"
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
27 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
28 annotationmark : {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
29 onclick : "setAnnotationMark",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
30 tooltip : "create an annotation for a point",
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
31 icon : "annotation-mark.png"
1121
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
32 },
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
33 annotationregion : {
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
34 onclick : "setAnnotationRegion",
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
35 tooltip : "create an annotation for a region",
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
36 icon : "annotation-region.png"
1113
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
1140
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
40 // for defaults see below (we need to define the functions used in annotatorPluginSettings first)
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
41
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
42 var actions = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
43 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
44 * show/hide annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
45 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
46 toggleAnnotations : function (data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
47 var show = !data.settings.isAnnotationsVisible;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
48 data.settings.isAnnotationsVisible = show;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
49 digilib.fn.highlightButtons(data, 'annotations', show);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
50 renderAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
51 },
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 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
54 * set user account for annotations
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 setAnnotationUser : function (data, user, password) {
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
57 var annotator = data.annotator;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
58 var auth = annotator.plugins.Auth;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
59 if (auth == null) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
60 console.error("setAnnotationUser: No Auth plugin!!");
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
61 return;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
62 }
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
63 setAnnotationUser(data, auth, user, password);
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
64 // get new token
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
65 auth.token = null;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
66 auth._unsafeToken = null;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
67 auth.requestToken();
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
68 // save new token in cookie
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
69 auth.withToken(function (tkn) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
70 data.dlOpts.annotationToken = auth.token;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
71 digilib.fn.storeOptions(data);
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
72 // clear annotations
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
73 data.annotations = [];
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
74 renderAnnotations(data);
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
75 // reload annotations
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
76 annotator.plugins.Store.pluginInit();
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
77 });
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
78 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
79
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
80 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
81 * 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
82 *
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
83 * @param data
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
84 * @param mpos
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
85 * @param text
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
86 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
87 setAnnotationMark : function (data, mpos, text) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
88 if (mpos == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
89 // interactive
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
90 setAnnotationMark(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
91 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
92 // use position and text (and user-id)
1118
f0474c1faaff trying new annotator authentication.
robcast
parents: 1116
diff changeset
93 console.error("Currently only interactive annotations!");
1113
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 },
1121
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
96
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
97 /**
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
98 * set a region-annotation by clicking (or giving a position and a text)
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
99 *
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
100 * @param data
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
101 * @param rect
1121
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
102 * @param text
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
103 */
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
104 setAnnotationRegion : function (data, rect, text) {
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
105 if (rect == null) {
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
106 // interactive
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
107 setAnnotationRegion(data);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
108 } else {
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
109 // use position and text (and user-id)
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
110 console.error("Currently only interactive annotations!");
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
111 }
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
112 }
1113
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 /**
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
125 * sets annotation user and password in digilib and Annotator.Auth plugin.
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
126 * auth is Auth plugin instance.
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
127 */
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
128 var setAnnotationUser = function (data, auth, user, password) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
129 if (user == null) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
130 // user name entered in JS-prompt
1133
beb7e0f48242 nicer message.
robcast
parents: 1132
diff changeset
131 user = window.prompt("Please authenticate (Cancel to log out): User name", data.settings.annotationUser);
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
132 if (user != null && user != 'anonymous') {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
133 // password entered in JS-prompt
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
134 password = window.prompt("Please authenticate: Password", '');
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
135 // set params for Auth plugin
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
136 auth.options.requestData.password = password;
1132
d47513632da5 additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents: 1129
diff changeset
137 // try to use the safe url for the password
d47513632da5 additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents: 1129
diff changeset
138 if (data.settings.annotationSafeTokenUrl != null) {
d47513632da5 additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents: 1129
diff changeset
139 auth.options.tokenUrl = data.settings.annotationSafeTokenUrl;
d47513632da5 additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents: 1129
diff changeset
140 } else {
d47513632da5 additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents: 1129
diff changeset
141 console.warn("Sending token password over standard-URL!");
d47513632da5 additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents: 1129
diff changeset
142 }
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
143 } else {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
144 // use anonymous user
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
145 user = 'anonymous';
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
146 delete auth.options.requestData.password;
1132
d47513632da5 additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents: 1129
diff changeset
147 if (data.settings.annotationSafeTokenUrl != null) {
d47513632da5 additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents: 1129
diff changeset
148 // reset url to unsafe
d47513632da5 additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents: 1129
diff changeset
149 auth.options.tokenUrl = data.settings.annotationTokenUrl;
d47513632da5 additional annotationSafeTokenUrl for https url, used with passwords.
robcast
parents: 1129
diff changeset
150 }
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
151 }
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
152 }
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
153 // set user in digilib
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
154 data.settings.annotationUser = user;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
155 data.dlOpts.annotationUser = user;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
156 digilib.fn.storeOptions(data);
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
157 // set params for Auth plugin
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
158 auth.options.requestData.user = user;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
159 // set params for Permissions plugin
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
160 var perms = data.annotator.plugins.Permissions;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
161 if (perms != null) {
1123
1fad569ccb4f provide annotator javascript for digilib.annotator plugin.
robcast
parents: 1121
diff changeset
162 perms.setUser(user);
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
163 }
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
164 };
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
165
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
166
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
167 /**
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
168 * add a mark-annotation where clicked.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
169 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
170 var setAnnotationMark = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
171 var $scaler = data.$scaler;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
172 // start event capturing
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
173 $scaler.one('mousedown.dlSetAnnotationMark', function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
174 // event handler adding a new mark
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
175 console.log("setAnnotationMark at=", evt);
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
176 var annotator = data.annotator;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
177 var mpos = geom.position(evt);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
178 var pos = data.imgTrafo.invtransform(mpos);
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
179 // mark selected areas
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
180 annotator.selectedAreas = [geom.rectangle(pos)];
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
181 // create and edit new annotation
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
182 var annotation = annotator.createAnnotation();
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
183 annotator.showEditor(annotation, mpos.getAsCss());
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
184 return false;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
185 });
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
186 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
187
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
188 /**
1121
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
189 * add a region-annotation where clicked.
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
190 */
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
191 var setAnnotationRegion = function(data) {
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
192 var annotator = data.annotator;
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
193 digilib.fn.defineArea(data, function (data, rect) {
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
194 if (rect == null) return;
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
195 // event handler adding a new mark
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
196 console.log("setAnnotationRegion at=", rect);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
197 // mark selected areas
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
198 annotator.selectedAreas = [rect];
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
199 // create and edit new annotation
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
200 var pos = rect.getPt1();
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
201 var mpos = data.imgTrafo.transform(pos);
1121
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
202 var annotation = annotator.createAnnotation();
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
203 annotator.showEditor(annotation, mpos.getAsCss());
1121
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
204 });
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
205 };
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
206
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
207 /**
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
208 * place annotations on the image
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
209 */
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
210 var renderAnnotations = function (data) {
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
211 if (data.annotations == null || data.annotator == null || data.$img == null || data.imgTrafo == null)
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
212 return;
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
213 var annotations = data.annotations;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
214 var cssPrefix = data.settings.cssPrefix;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
215 var $elem = data.$elem;
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
216 // show annotation user state
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
217 $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
218 // clear annotations
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
219 $elem.find('div.'+cssPrefix+'annotationmark,div.'+cssPrefix+'annotationregion').remove();
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
220 if (!data.settings.isAnnotationsVisible) return;
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
221 // re-render
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
222 for (var i = 0; i < annotations.length; i++) {
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
223 renderAnnotation(data, annotations[i]);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
224 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
225 };
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 /**
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
228 * place single annotation on the image
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
229 */
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
230 var renderAnnotation = function (data, annot) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
231 if (annot == null || annot.annotation == null || annot.annotation.areas == null
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
232 || data.$img == null || data.imgTrafo == null)
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
233 return;
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
234 if (!data.settings.isAnnotationsVisible) return;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
235 var cssPrefix = data.settings.cssPrefix;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
236 var $elem = data.$elem;
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
237 var annotator = data.annotator;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
238 var annotation = annot.annotation;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
239 var idx = annot.idx ? annot.idx : '?';
1121
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
240 var area = geom.rectangle(annotation.areas[0]);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
241 var screenRect = null;
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
242 var $annotation = null;
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
243 if (area.isRectangle()) {
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
244 var clippedArea = data.zoomArea.intersect(area);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
245 if (clippedArea == null) return;
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
246 screenRect = data.imgTrafo.transform(clippedArea);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
247 // console.debug("renderRegion: pos=",geom.position(screenRect));
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
248 $annotation = $('<div class="'+cssPrefix+'annotationregion '+cssPrefix+'overlay annotator-hl">'+idx+'</div>');
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
249 //addRegionAttributes(data, $regionDiv, attr);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
250 } else {
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
251 var pos = area.getPosition();
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
252 if (!data.zoomArea.containsPosition(pos)) return;
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
253 var screenRect = data.imgTrafo.transform(pos);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
254 // create annotation
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
255 var html = '<div class="'+cssPrefix+'annotationmark '+cssPrefix+'overlay annotator-hl">'+idx+'</div>';
1121
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
256 $annotation = $(html);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
257 }
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
258 // save annotation in data for Annotator
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
259 $annotation.data('annotation', annotation);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
260 // save reference to div
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
261 annot.$div = $annotation;
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
262 $elem.append($annotation);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
263 // hook up Annotator events
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
264 $annotation.on("mouseover", annotator.onHighlightMouseover);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
265 $annotation.on("mouseout", annotator.startViewerHideTimer);
efe4b0f18cf8 annotator plugin does regions now.
robcast
parents: 1120
diff changeset
266 screenRect.adjustDiv($annotation);
1113
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
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
269 /**
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
270 * returns setupAnnotation function using the given data.
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
271 */
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
272 var getSetupAnnotation = function(data) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
273 return function (annotation) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
274 // create annotation wrapper
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
275 var ann = {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
276 'annotation' : annotation,
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
277 'idx' : data.annotations.length+1
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
278 };
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
279 // add to list
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
280 data.annotations.push(ann);
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
281 // render this annotation
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
282 renderAnnotation(data, ann);
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
283 };
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
284 };
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
285
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
286 /**
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
287 * returns annotationDeleted function using the given data.
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
288 */
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
289 var getAnnotationDeleted = function(data) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
290 return function (annotation) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
291 // remove annotation mark
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
292 var annots = data.annotations;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
293 for (var i = 0; i < annots.length; ++i) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
294 var annot = annots[i];
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
295 if (annot.annotation === annotation) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
296 // this is the right wrapper
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
297 if (annot.$div != null) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
298 // remove from screen
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
299 annot.$div.remove();
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
300 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
301 // remove from list
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
302 delete annots[i];
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
303 break;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
304 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
305 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
306 };
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
307 };
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
308
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
309 /**
1125
f1be20adc98b annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents: 1123
diff changeset
310 * returns unauthorizedCallback function for Annotator authlogin plugin.
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
311 */
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
312 var getHandleUnauthorized = function (data) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
313 return function (auth) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
314 // prompt for user name and set user
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
315 setAnnotationUser(data, auth);
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
316 // then try again
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
317 return true;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
318 };
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
319 };
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
320
1140
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
321 /**
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
322 * returns the annotation server URL.
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
323 */
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
324 var getAnnotationServerUrl = function (data) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
325 return data.settings.annotationServerUrl;
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
326 };
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
327
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
328 /**
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
329 * returns the annotation token URL.
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
330 */
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
331 var getAnnotationTokenUrl = function (data) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
332 return data.settings.annotationTokenUrl;
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
333 };
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
334
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
335 /**
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
336 * returns the cached annotation token.
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
337 */
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
338 var getAnnotationToken = function (data) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
339 return data.dlOpts.annotationToken;
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
340 };
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
341
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
342 /**
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
343 * returns the annotation user.
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
344 */
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
345 var getAnnotationUser = function (data) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
346 return data.settings.annotationUser;
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
347 };
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
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 * install additional buttons
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
351 */
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
352 var installButtons = function(data, buttonSet) {
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
353 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
354 var mode = settings.interactionMode;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
355 var buttonSettings = settings.buttonSettings[mode];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
356 // set annotationSet to [] or '' for no buttons (when showing annotations only)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
357 if (buttonSet.length && buttonSet.length > 0) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
358 buttonSettings.annotationSet = buttonSet;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
359 buttonSettings.buttonSets.push('annotationSet');
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 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
362
1140
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
363 var defaults = {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
364 // are annotations active?
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
365 'isAnnotationsVisible' : true,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
366 // buttonset of this plugin
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
367 'annotationSet' : ['annotations', 'annotationuser', 'annotationmark', 'annotationregion', 'lessoptions'],
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
368 'annotationReadOnlySet' : ['annotations', 'lessoptions'],
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
369 // URL of annotation server .e.g. 'http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator'
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
370 'annotationServerUrl' : null,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
371 // are the annotations read-only
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
372 'annotationsReadOnly' : false,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
373 // URL of authentication token server e.g. 'http://libcoll.mpiwg-berlin.mpg.de/libviewa/template/token'
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
374 'annotationTokenUrl' : null,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
375 // URL of safe authentication token server e.g. 'https://libcoll.mpiwg-berlin.mpg.de/libviewa/template/token'
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
376 'annotationSafeTokenUrl' : null,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
377 // annotation user name
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
378 'annotationUser' : 'anonymous',
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
379 // list of Annotator plugins
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
380 'annotatorPlugins' : ['Auth', 'Permissions', 'Store', 'DigilibIntegrator'],
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
381 // Annotator plugin settings (values that are functions are replaced by fn(data))
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
382 'annotatorPluginSettings' : {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
383 'Auth' : {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
384 'token' : getAnnotationToken,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
385 'tokenUrl' : getAnnotationTokenUrl,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
386 'autoFetch' : true,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
387 'requestMethod' : 'POST',
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
388 'requestData' : {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
389 'user': getAnnotationUser
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
390 },
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
391 'unauthorizedCallback' : getHandleUnauthorized
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
392 },
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
393 'Permissions' : {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
394 'user' : getAnnotationUser,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
395 // userString and userId have to remain functions after evaluation
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
396 'userString' : function (data) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
397 return function(user) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
398 if (user && user.name) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
399 return user.name;
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
400 }
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
401 return user;
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
402 };
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
403 },
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
404 'userId' : function (data) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
405 return function(user) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
406 if (user && user.id) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
407 return user.id;
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
408 }
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
409 return user;
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
410 };
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
411 }
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
412 },
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
413 'Store' : {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
414 'prefix' : getAnnotationServerUrl,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
415 'annotationData': {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
416 'uri': getAnnotationPageUrl
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
417 },
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
418 'loadFromSearch': {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
419 'uri': getAnnotationPageUrl
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
420 }
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
421 },
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
422 'DigilibIntegrator' : {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
423 'hooks' : {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
424 'setupAnnotation' : getSetupAnnotation,
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
425 'annotationDeleted' : getAnnotationDeleted
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
426 }
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
427 }
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
428
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
429 }
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
430 };
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
431
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
432 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
433 * plugin installation. called by digilib on plugin object.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
434 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
435 var install = function(plugin) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
436 digilib = plugin;
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
437 console.debug('installing annotator plugin. digilib:', digilib);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
438 // import geometry classes
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
439 geom = digilib.fn.geometry;
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
440 // add defaults, actions, buttons
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
441 $.extend(digilib.defaults, defaults);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
442 $.extend(digilib.actions, actions);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
443 $.extend(digilib.buttons, buttons);
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
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
446 /** plugin initialization */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
447 var init = function(data) {
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
448 console.debug('initialising annotator plugin. data:', data);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
449 var $data = $(data);
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
450 var settings = data.settings;
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
451 // set up list of annotation wrappers
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
452 data.annotations = [];
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
453 // set up buttons
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
454 if (digilib.plugins.buttons != null) {
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
455 if (settings.annotationsReadOnly) {
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
456 installButtons(data, settings.annotationReadOnlySet);
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
457 } else {
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
458 installButtons(data, settings.annotationSet);
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
459 }
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
460 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
461 if (data.dlOpts.annotationUser != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
462 // get annotation user from cookie
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
463 settings.annotationUser = data.dlOpts.annotationUser;
1113
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 // install event handler
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
466 $data.bind('setup', handleSetup);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
467 $data.bind('update', handleUpdate);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
468 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
469
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
470 /**
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
471 * setup creates Annotator object (after HTML setup by digilib).
1113
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 var handleSetup = function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
474 console.debug("annotations: handleSetup");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
475 var data = this;
1125
f1be20adc98b annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents: 1123
diff changeset
476 var settings = data.settings;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
477 // set up annotator (after html has been set up)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
478 var uri = getAnnotationPageUrl(data);
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
479 var elem = data.$elem.get(0);
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
480 var opts = {'readOnly' : data.settings.annotationsReadOnly};
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
481 var annotator = new Annotator(elem, opts);
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
482 // set plugin parameters
1140
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
483 var def = defaults.annotatorPluginSettings;
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
484 var pluginParams = {};
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
485 // merge settings
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
486 // (deep copy of defaults from plugin and options from HTML)
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
487 $.extend(true, pluginParams, defaults.annotatorPluginSettings, data.options.annotatorPluginSettings);
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
488 // function to evaluate plugin settings
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
489 var evalParams = function (params) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
490 if (params == null) return;
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
491 // eval functions in params
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
492 $.each(params, function (idx, param) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
493 if (typeof param === 'function') {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
494 // replace function by value
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
495 params[idx] = param(data);
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
496 } else if (param == null) {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
497 // delete value null
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
498 delete params[idx];
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
499 } else if (typeof param === 'object') {
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
500 // evaluate sub-objects
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
501 evalParams(param);
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
502 }
1140
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
503 });
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
504 };
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
505 // add plugins
1125
f1be20adc98b annotatorPlugins is now a list of plugin names (preserving order).
robcast
parents: 1123
diff changeset
506 $.each(settings.annotatorPlugins, function (idx, name) {
1140
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
507 var params = pluginParams[name];
50d6eaa74b4b reorganized annotator plugin settings handling... again.
robcast
parents: 1138
diff changeset
508 evalParams(params);
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
509 console.debug("plugin:", name, params);
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
510 annotator.addPlugin(name, params);
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
511 });
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
512 // save annotator reference
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
513 data.annotator = annotator;
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
514 // save annotation token in cookie
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
515 var auth = annotator.plugins.Auth;
1126
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
516 if (auth != null) {
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
517 auth.withToken(function (tkn) {
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
518 data.dlOpts.annotationToken = auth.token;
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
519 digilib.fn.storeOptions(data);
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
520 });
f14220f939d5 add annotationsReadOnly mode.
robcast
parents: 1125
diff changeset
521 }
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
522 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
523
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
524 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
525 * update renders all annotations.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
526 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
527 var handleUpdate = function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
528 console.debug("annotations: handleUpdate");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
529 var data = this;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
530 renderAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
531 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
532
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
533 // plugin object with name and init
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
534 // shared objects filled by digilib on registration
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
535 var plugin = {
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
536 name : 'annotator',
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
537 install : install,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
538 init : init,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
539 buttons : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
540 actions : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
541 fn : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
542 plugins : {}
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
543 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
544
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
545 if ($.fn.digilib == null) {
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
546 $.error("jquery.digilib.annotator must be loaded after jquery.digilib!");
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
547 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
548 $.fn.digilib('plugin', plugin);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
549 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
550 })(jQuery);