annotate webapp/src/main/webapp/jquery/jquery.digilib.annotator.js @ 1120:8bd10cd04169

authentication for annotations with password works now. (permissions are still flaky.)
author robcast
date Wed, 07 Nov 2012 18:09:57 +0100
parents 036efe7361c8
children efe4b0f18cf8
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"
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
32 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
33 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
34
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
35 var defaults = {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
36 // are annotations active?
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
37 'isAnnotationsVisible' : true,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
38 // buttonset of this plugin
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
39 'annotationSet' : ['annotations', 'annotationuser', 'annotationmark', 'lessoptions'],
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
40 // URL of annotation server
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
41 'annotationServerUrl' : 'http://virtuoso.mpiwg-berlin.mpg.de:8080/AnnotationManager/annotator',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
42 // URL of authentication token server
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
43 'annotationTokenUrl' : 'http://localhost:8080/test/annotator/token',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
44 // annotation user name
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
45 'annotationUser' : 'anonymous',
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
46 // function to translate user name from annotation server format
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
47 'annotationServerUserString' : function() {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
48 if (this.user && this.user.name) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
49 return this.user.name;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
50 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
51 return this.user;
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
1118
f0474c1faaff trying new annotator authentication.
robcast
parents: 1116
diff changeset
54 // Annotator plugin settings (some values provided in handleSetup)
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
55 'annotatorPlugins' : {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
56 //'Tags' : {},
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
57 'Auth' : {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
58 //token : data.annotationToken
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
59 //tokenUrl: data.settings.annotationTokenUrl
1118
f0474c1faaff trying new annotator authentication.
robcast
parents: 1116
diff changeset
60 autoFetch: true,
f0474c1faaff trying new annotator authentication.
robcast
parents: 1116
diff changeset
61 requestMethod: 'POST',
f0474c1faaff trying new annotator authentication.
robcast
parents: 1116
diff changeset
62 requestData: {
f0474c1faaff trying new annotator authentication.
robcast
parents: 1116
diff changeset
63 //'user': data.settings.annotationUser,
f0474c1faaff trying new annotator authentication.
robcast
parents: 1116
diff changeset
64 //'password': data.annotationPassword
f0474c1faaff trying new annotator authentication.
robcast
parents: 1116
diff changeset
65 }
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
66 },
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
67 'Permissions' : {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
68 //user: data.settings.annotationUser,
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
69 userString : function(user) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
70 if (user && user.name) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
71 return user.name;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
72 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
73 return user;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
74 },
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
75 userId: function (user) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
76 if (user && user.id) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
77 return user.id;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
78 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
79 return user;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
80 }
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 'Store' : {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
83 //prefix : data.settings.annotationServerUrl,
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
84 annotationData: {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
85 //'uri': getAnnotationPageUrl()
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
86 },
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
87 loadFromSearch: {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
88 'limit': 20,
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
89 //'uri': getAnnotationPageUrl()
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 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
92 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
93
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
94 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
95
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
96 var actions = {
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 * show/hide annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
99 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
100 toggleAnnotations : function (data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
101 var show = !data.settings.isAnnotationsVisible;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
102 data.settings.isAnnotationsVisible = show;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
103 digilib.fn.highlightButtons(data, 'annotations', show);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
104 renderAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
105 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
106
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
107 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
108 * set user account for annotations
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 setAnnotationUser : function (data, user, password) {
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
111 var annotator = data.annotator;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
112 var auth = annotator.plugins.Auth;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
113 if (auth == null) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
114 console.error("setAnnotationUser: No Auth plugin!!");
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
115 return;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
116 }
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
117 setAnnotationUser(data, auth, user, password);
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
118 // get new token
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
119 auth.token = null;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
120 auth._unsafeToken = null;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
121 auth.requestToken();
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
122 // save new token in cookie
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
123 auth.withToken(function (tkn) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
124 data.dlOpts.annotationToken = auth.token;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
125 digilib.fn.storeOptions(data);
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
126 // reload annotations
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
127 data.annotations = [];
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
128 renderAnnotations(data);
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
129 annotator.plugins.Store.pluginInit();
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
130 });
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 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
134 * 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
135 *
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
136 * @param data
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
137 * @param mpos
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
138 * @param 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 setAnnotationMark : function (data, mpos, text) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
141 if (mpos == null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
142 // interactive
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
143 setAnnotationMark(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
144 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
145 // use position and text (and user-id)
1118
f0474c1faaff trying new annotator authentication.
robcast
parents: 1116
diff changeset
146 console.error("Currently only interactive annotations!");
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
147 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
148 },
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
149 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
150
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 * returns an annotatable url to this digilib image
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
153 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
154 var getAnnotationPageUrl = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
155 var url = data.settings.digilibBaseUrl + '/jquery/digilib.html?';
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
156 url += digilib.fn.getParamString(data.settings, ['fn', 'pn'], digilib.defaults);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
157 return url;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
158 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
159
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
160 /**
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
161 * 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
162 * auth is Auth plugin instance.
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
163 */
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
164 var setAnnotationUser = function (data, auth, user, password) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
165 if (user == null) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
166 // user name entered in JS-prompt
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
167 user = window.prompt("Please authenticate: User name", data.settings.annotationUser);
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
168 if (user != null && user != 'anonymous') {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
169 // password entered in JS-prompt
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
170 password = window.prompt("Please authenticate: Password", '');
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
171 // set params for Auth plugin
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
172 auth.options.requestData.password = password;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
173 } else {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
174 // use anonymous user
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
175 user = 'anonymous';
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
176 delete auth.options.requestData.password;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
177 }
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
178 }
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
179 // set user in digilib
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
180 data.settings.annotationUser = user;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
181 data.dlOpts.annotationUser = user;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
182 digilib.fn.storeOptions(data);
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
183 // set params for Auth plugin
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
184 auth.options.requestData.user = user;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
185 // set params for Permissions plugin
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
186 var perms = data.annotator.plugins.Permissions;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
187 if (perms != null) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
188 perms.options.user = user;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
189 }
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
190 };
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
191
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
192
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
193 /**
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
194 * add a mark-annotation where clicked.
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 var setAnnotationMark = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
197 var $scaler = data.$scaler;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
198 // unbind other handler TODO: do we need to do this?
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
199 $scaler.off(".dlZoomDrag");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
200 // start event capturing
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
201 $scaler.one('mousedown.dlSetAnnotationMark', function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
202 // event handler adding a new mark
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
203 console.log("setAnnotationMark at=", evt);
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
204 var annotator = data.annotator;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
205 var mpos = geom.position(evt);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
206 var pos = data.imgTrafo.invtransform(mpos);
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
207 // mark selected areas
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
208 annotator.selectedAreas = [geom.rectangle(pos)];
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
209 // create and edit new annotation
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
210 var annotation = annotator.createAnnotation();
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
211 annotator.showEditor(annotation, mpos.getAsCss());
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
212 return false;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
213 });
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
214 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
215
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
216 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
217 * place annotations on the image
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
218 */
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
219 var renderAnnotations = function (data) {
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
220 console.debug("renderAnnotations!");
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
221 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
222 return;
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
223 var annotations = data.annotations;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
224 var cssPrefix = data.settings.cssPrefix;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
225 var $elem = data.$elem;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
226 // try to show annotation user state
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
227 $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
228 // clear annotations
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
229 $elem.find('div.' + cssPrefix + 'annotationmark').remove();
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
230 if (!data.settings.isAnnotationsVisible) return;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
231 for (var i = 0; i < annotations.length; i++) {
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
232 renderAnnotation(data, annotations[i]);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
233 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
234 };
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 /**
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
237 * place single annotation on the image
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
238 */
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
239 var renderAnnotation = function (data, annot) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
240 console.debug("renderAnnotation: annotation=", annot);
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
241 if (annot == null || annot.annotation == null || annot.annotation.areas == null
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
242 || 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;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
249 var idx = annot.idx ? annot.idx : '?';
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
250 var pos = geom.position(annotation.areas[0]);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
251 if (data.zoomArea.containsPosition(pos)) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
252 var mpos = data.imgTrafo.transform(pos);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
253 console.debug("renderannotations: pos=", mpos);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
254 // create annotation
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
255 var html = '<div class="'+cssPrefix+'annotationmark '+cssPrefix+'overlay annotator-hl">'+idx+'</div>';
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
256 var $annotation = $(html);
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
257 // save annotation in data for Annotator
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
258 $annotation.data('annotation', annotation);
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
259 // save reference to div
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
260 annot.$div = $annotation;
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
261 $elem.append($annotation);
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
262 // hook up Annotator events
1114
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
263 $annotation.on("mouseover", annotator.onHighlightMouseover);
1525c820ee27 annotator annotations even show up now.
casties
parents: 1113
diff changeset
264 $annotation.on("mouseout", annotator.startViewerHideTimer);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
265 mpos.adjustDiv($annotation);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
266 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
267 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
268
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
269 /**
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
270 * returns setupAnnotation function using the given data.
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
271 */
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
272 var getSetupAnnotation = function(data) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
273 return function (annotation) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
274 // create annotation wrapper
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
275 var ann = {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
276 'annotation' : annotation,
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
277 'idx' : data.annotations.length+1
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
278 };
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
279 // add to list
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
280 data.annotations.push(ann);
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
281 // render this annotation
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
282 renderAnnotation(data, ann);
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
283 };
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
284 };
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
285
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
286 /**
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
287 * returns annotationDeleted function using the given data.
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
288 */
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
289 var getAnnotationDeleted = function(data) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
290 return function (annotation) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
291 // remove annotation mark
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
292 var annots = data.annotations;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
293 for (var i = 0; i < annots.length; ++i) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
294 var annot = annots[i];
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
295 if (annot.annotation === annotation) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
296 // this is the right wrapper
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
297 if (annot.$div != null) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
298 // remove from screen
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
299 annot.$div.remove();
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
300 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
301 // remove from list
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
302 delete annots[i];
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
303 break;
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
304 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
305 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
306 };
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
307 };
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
308
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
309 /**
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
310 * returns handleUnauthorized function for Annotator.Auth plugin.
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
311 */
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
312 var getHandleUnauthorized = function (data) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
313 return function (auth) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
314 // prompt for user name and set user
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
315 setAnnotationUser(data, auth);
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
316 // then try again
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
317 return true;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
318 };
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
319 };
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
320
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
321 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
322 * install additional buttons
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
323 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
324 var installButtons = function(data) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
325 var settings = data.settings;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
326 var mode = settings.interactionMode;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
327 var buttonSettings = settings.buttonSettings[mode];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
328 // configure buttons through digilib "annotationSet" option
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
329 var buttonSet = settings.annotationSet || annotationSet;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
330 // set annotationSet to [] or '' for no buttons (when showing annotations only)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
331 if (buttonSet.length && buttonSet.length > 0) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
332 buttonSettings.annotationSet = buttonSet;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
333 buttonSettings.buttonSets.push('annotationSet');
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
334 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
335 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
336
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
337 /**
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
338 * plugin installation. called by digilib on plugin object.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
339 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
340 var install = function(plugin) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
341 digilib = plugin;
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
342 console.debug('installing annotator plugin. digilib:', digilib);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
343 // import geometry classes
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
344 geom = digilib.fn.geometry;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
345 FULL_AREA = geom.rectangle(0, 0, 1, 1);
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
346 // add defaults, actions, buttons
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
347 $.extend(digilib.defaults, defaults);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
348 $.extend(digilib.actions, actions);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
349 $.extend(digilib.buttons, buttons);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
350 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
351
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
352 /** plugin initialization */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
353 var init = function(data) {
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
354 console.debug('initialising annotator plugin. data:', data);
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
355 var $data = $(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
356 // set up
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
357 data.annotations = [];
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
358 if (digilib.plugins.buttons != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
359 installButtons(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
360 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
361 if (data.dlOpts.annotationUser != null) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
362 // get annotation user from cookie
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
363 data.settings.annotationUser = data.dlOpts.annotationUser;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
364 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
365 // install event handler
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
366 $data.bind('setup', handleSetup);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
367 $data.bind('update', handleUpdate);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
368 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
369
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
370 /**
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
371 * setup creates Annotator object.
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
372 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
373 var handleSetup = function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
374 console.debug("annotations: handleSetup");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
375 var data = this;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
376 // set up annotator (after html has been set up)
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
377 var uri = getAnnotationPageUrl(data);
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
378 var annotator = new Annotator(data.$elem.get(0));
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
379 // set plugin parameters
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
380 var pluginParams = {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
381 'Auth' : {
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
382 'token' : data.dlOpts.annotationToken,
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
383 'tokenUrl' : data.settings.annotationTokenUrl,
1119
036efe7361c8 working on new auth for annotations.
robcast
parents: 1118
diff changeset
384 'autoFetch' : true,
036efe7361c8 working on new auth for annotations.
robcast
parents: 1118
diff changeset
385 'requestMethod' : 'POST',
036efe7361c8 working on new auth for annotations.
robcast
parents: 1118
diff changeset
386 'requestData' : {
036efe7361c8 working on new auth for annotations.
robcast
parents: 1118
diff changeset
387 'user': data.settings.annotationUser,
036efe7361c8 working on new auth for annotations.
robcast
parents: 1118
diff changeset
388 },
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
389 'unauthorizedCallback' : getHandleUnauthorized(data)
1116
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
390 },
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
391 'Permissions' : {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
392 'user' : data.settings.annotationUser
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
393 },
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
394 'Store' : {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
395 'prefix' : data.settings.annotationServerUrl,
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
396 'annotationData' : {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
397 'uri': uri
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
398 },
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
399 'loadFromSearch' : {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
400 'uri': uri
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
401 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
402 },
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
403 'DigilibIntegrator' : {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
404 'hooks' : {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
405 'setupAnnotation' : getSetupAnnotation(data),
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
406 'annotationDeleted' : getAnnotationDeleted(data)
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
407 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
408 }
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
409 };
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
410 // merge with settings
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
411 $.extend(true, pluginParams, data.settings.annotatorPlugins);
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
412 // add plugins
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
413 $.each(pluginParams, function (name, params) {
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
414 console.debug("plugin:", name, params);
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
415 annotator.addPlugin(name, params);
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
416 });
08206603c7dc annotations use new Annotator-digilibintegration plugin.
robcast
parents: 1115
diff changeset
417 // save annotator reference
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
418 data.annotator = annotator;
1120
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
419 // save annotation token in cookie
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
420 var auth = annotator.plugins.Auth;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
421 // save new token in cookie
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
422 auth.withToken(function (tkn) {
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
423 data.dlOpts.annotationToken = auth.token;
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
424 digilib.fn.storeOptions(data);
8bd10cd04169 authentication for annotations with password works now. (permissions are still flaky.)
robcast
parents: 1119
diff changeset
425 });
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
426 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
427
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 * update renders all annotations.
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
430 */
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
431 var handleUpdate = function(evt) {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
432 console.debug("annotations: handleUpdate");
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
433 var data = this;
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
434 renderAnnotations(data);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
435 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
436
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
437 // plugin object with name and init
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
438 // shared objects filled by digilib on registration
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
439 var plugin = {
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
440 name : 'annotator',
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
441 install : install,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
442 init : init,
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
443 buttons : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
444 actions : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
445 fn : {},
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
446 plugins : {}
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
447 };
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
448
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
449 if ($.fn.digilib == null) {
1115
526dafa4690d using annotator in digilib works now. code still ugly.
robcast
parents: 1114
diff changeset
450 $.error("jquery.digilib.annotator must be loaded after jquery.digilib!");
1113
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
451 } else {
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
452 $.fn.digilib('plugin', plugin);
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
453 }
7affda55c10e using annotator in digilib works somewhat now.
robcast
parents:
diff changeset
454 })(jQuery);