annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1150:d9d17eb3d731

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