annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1138:2df84b3a9ad5

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