source: main/trunk/greenstone2/macros/style.dm@ 27297

Last change on this file since 27297 was 27297, checked in by ak19, 11 years ago

Username field should not be cleared as it's no longer hidden and stores the logged in user. Also added a logout for the add comments feature, but there's probably a better way to do this, though the admin pages don't provide a logout and require you to log in repeatedly.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
Line 
1# this file must be UTF-8 encoded
2#######################################################################
3# PAGE STYLES
4#######################################################################
5
6package Style
7
8# to use this style system output
9# _header_
10# all your page content, then
11# _footer_
12
13# use the page parameter 'style' to choose the appropriate style
14
15# Current values: "html" and "xhtml"
16_compliance_ {html}
17
18# the style system uses
19# _pagetitle_ - what gets displayed at the top of the browser window
20# _pagescriptextra_ - any extra javascript you want included in the header
21# _pagebannerextra_ - anything extra you want displayed in the page banner
22# _pagefooterextra_ - anything extra you want displayed in the footer
23
24# defaults for the above macros
25_pagetitle_ {_collectionname_}
26_pagescriptfileextra_ {}
27_pagescriptextra_ {}
28_pagebannerextra_ {}
29_pagefooterextra_ {}
30
31# collection specific style and script may be set in collection's extra.dm
32# using the following macros
33_collectionspecificstyle_ {}
34_collectionspecificscript_ {}
35
36# it also relies on lots of Globals, the most important of these are:
37# _cookie_ - put in the cgi header
38# _globalscripts_ - javascript stuff
39# _imagecollection_
40# _imagehome_
41# _imagehelp_
42# _imagepref_
43# _imagethispage_ (this is now not an image, but text. should be renamed?)
44# _linkotherversion_
45
46# _httpiconchalk_ - the image down the left of the page - is now done
47# by the style sheet.
48
49_header_ {_cgihead_
50_htmlhead_(class="bgimage")_startspacer__pagebanner_
51}
52
53_header_[v=1] {_cgihead_
54_htmlhead__pagebanner_
55}
56
57# _cgihead_ {Content-type: text/html
58# _cookie_
59#
60# }
61_cgihead_{}
62
63
64# any declarations relating to CSS that should go in the html head part.
65# declarations containing images are done here so the path is correct
66# at runtime.
67
68_csslink_{
69 <link rel="stylesheet" href="_cssfilelink_" type="text/css"
70 title="Greenstone Style" charset="UTF-8" _linktagend_
71 <link rel="alternate stylesheet" href="_httpstyle_/style-print.css"
72 type="text/css" title="Printer" charset="UTF-8" media="print, screen" _linktagend_
73 <link rel="stylesheet" href="_httpstyle_/style-print.css" type="text/css"
74 title="Printer" charset="UTF-8" media="print" _linktagend_
75 _cssfilelinkextra_
76}
77
78_cssheader_ {
79_csslink_
80<style type="text/css">
81body.bgimage \{ background: url("_httpimages_/chalk.gif") scroll repeat-y left top; \}
82div.navbar \{ background-image: url("_httpimages_/bg_green.png"); \}
83div.divbar \{ background-image: url("_httpimages_/bg_green.png"); \}
84a.navlink \{ background-image: url("_httpimages_/bg_off.png"); \}
85a.navlink_sel \{ background-image: url("_httpimages_/bg_green.png"); \}
86a.navlink:hover \{ background-image: url("_httpimages_/bg_on.png"); \}
87p.bannertitle \{background-image: url("_httpimages_/banner_bg.png"); \}
88p.collectiontitle \{background-image: url("_httpimages_/banner_bg.png"); \}
89</style>
90_collectionspecificstyle_
91
92}
93
94# separate macro so it can be easily overridden for customised collections
95_cssfilelink_ {_httpstyle_/style.css}
96
97# separate macro so additional stylesheets (to those included by default) can be specified
98_cssfilelinkextra_ {}
99
100# Languages that should be displayed right-to-left
101_htmlextra_ [l=ar] { dir=rtl }
102_htmlextra_ [l=fa] { dir=rtl }
103_htmlextra_ [l=he] { dir=rtl }
104_htmlextra_ [l=ur] { dir=rtl }
105_htmlextra_ [l=ps] { dir=rtl }
106_htmlextra_ [l=prs] { dir=rtl }
107
108# htmlhead uses:
109# _1_ - extra parameters for the body tag
110# _pagetitle_
111# _globalscripts_
112_htmlhead_ {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
113"http://www.w3.org/TR/html4/loose.dtd">
114
115<html_htmlextra_>
116<head>
117<title>_pagetitle_</title>
118<meta name="_status:textversion_" content="_versionnum_" _metatagend_
119_globalscripts_
120_cssheader_
121_document:documentheader_
122</head>
123
124<body _1_>
125}
126
127# Link and meta tags must be closed differently for HTML/XHTML validation
128_linktagend_ {_If_("_compliance_" eq "xhtml",/>,>)}
129_metatagend_ {_If_("_compliance_" eq "xhtml",/>,>)}
130
131_spacerwidth_ {65}
132
133# _startspacer_ is a spacer that gives pages a left-hand margin.
134# It must eventually be closed by _endspacer_.
135_startspacer_ {
136<div id="page">
137}
138
139# If you want to move the home/help/pref buttons, override this to be empty
140# and then explicitly include _globallinks_ somewhere else
141# on the page
142_optgloballinks_ {_globallinks_}
143
144# _bannertitle_ is defined in nav_css/ns4.dm, and is either text or
145# a banner image
146_pagebanner_ {
147<!-- page banner (\_style:pagebanner\_) -->
148<div id="banner">
149<div class="pageinfo">
150<p class="bannerlinks">_optgloballinks_</p>
151_bannertitle_
152</div>
153<div class="collectimage">_imagecollection_</div>
154</div>
155<div class="bannerextra">_pagebannerextra_</div>
156<!-- end of page banner -->
157_If_("_activateweb20_" eq "2",
158 _If_("_activatetalkback_" eq "1",_talkback:uploadForm_)
159)
160}
161
162_pagebanner_[v=1] {
163<!-- page banner - text version [v=1] (\_style:pagebanner\_) -->
164<center><h2><b><u>_imagecollection_</u></b></h2></center><p>
165_optgloballinks_
166_pagebannerextra_
167<p>
168<!-- end of page banner -->
169_If_("_activateweb20_" eq "2",
170 _If_("_activatetalkback_" eq "1",_talkback:uploadForm_)
171)
172}
173
174# note we no longer close off one of the startspacer tables here!!
175_footer_ {
176_If_("_cgiargtalkback_" eq "1",_talkback:monitorUpload_)
177<!-- page footer (\_style:footer\_) -->
178_pagefooterextra__endspacer__htmlfooter_
179}
180
181# v=1 footer: not using startspacer in the header, so dont put it in the footer
182_footer_ [v=1]{
183_If_("_cgiargtalkback_" eq "1",_talkback:monitorUpload_)
184<!-- page footer [v=1] (\_style:footer\_) -->
185_pagefooterextra_
186_htmlfooter_
187}
188
189# close off anything opened by startspacer
190_endspacer_ {
191</div> <!-- id=page -->
192}
193
194
195_htmlfooter_ {
196</body>
197</html>
198}
199
200_loginscript_ {
201 function appendUsernameArgs(id,addOn)
202 \{
203 var a=document.getElementById(id);
204 var url = a.getAttribute("href");
205 if (url == "") \{
206 url = document.location.toString();
207 \}
208
209 //alert("url before = " + url);
210
211 // clear out any earlier user name/authentication values
212 url = url.replace(/(&|\\\\?)uan=\\d\{0,1\}/g,"");
213 url = url.replace(/(&|\\\\?)un=[a-z0-9:\\-]*/g,"");
214 url = url.replace(/(&|\\\\?)pw=[a-z0-9:\\-]*/g,"");
215
216 //alert("url after = " + url);
217
218 var gwcgi = "_gwcgi_";
219
220 var tailUrl = url.substr(url.length-gwcgi.length);
221
222 url += (tailUrl == "_gwcgi_") ? "?" : "&";
223 url += addOn;
224
225 //alert("url with add on = " + url);
226
227 a.setAttribute("href",url);
228 \}
229}
230
231
232# imagescript only used in nav_ns4.dm
233_globalscripts_{
234 <script type="text/javascript" src="_httpscript_/gsajaxapi.js"></script>
235
236 <script language="javascript" type="text/javascript">
237 function gsdefined(val)
238 \{
239 return (typeof(val) != "undefined");
240 \}
241
242 var gsapi = new GSAjaxAPI("_gwcgi_","_cgiargc_");
243
244 // http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss
245 // Call as: alert(timestamp.printTime());
246 function formatTime(timestamp) \{
247 var int_timestamp = parseInt(timestamp, 10); // don't forget the second param
248 var date = new Date(int_timestamp);
249 return date.toLocaleDateString() + " " + date.toLocaleTimeString();
250 \}
251
252 // Logout is the following operation
253 // _gwcgi_?e=_compressedoptions_&amp;a=_cgiarga_&amp;c=_cgiargc_&amp;cl=_cgiargcl_&amp;d=_cgiargd_&un=
254 // Maybe this is better done as a post?
255 // http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-to-post-data-between-pages/
256 function logout() \{
257 var logoutForm = document.createElement("form");
258 logoutForm.method="post" ;
259 logoutForm.action = "_gwcgi_";
260
261 var params = \{
262 e: "_compressedoptions_",
263 a: "_cgiarga_",
264 c: "_cgiargc_",
265 cl: "_cgiargcl_",
266 d: "_cgiargd_",
267 un: null
268 \};
269
270 for (var param in params) \{
271 var myInput = document.createElement("input") ;
272 myInput.setAttribute("name", param) ;
273 myInput.setAttribute("value", params[param]);
274 logoutForm.appendChild(myInput) ;
275 \}
276 document.body.appendChild(logoutForm) ;
277 logoutForm.submit() ;
278 document.body.removeChild(logoutForm) ;
279 \}
280
281 function loadUserComments() \{
282
283 // don't bother loading comments if we're not on a document page (in which case there's no usercommentdiv)
284 var usercommentdiv = document.getElementById("usercomments");
285 if(usercommentdiv == undefined || usercommentdiv == null) \{
286 return;
287 \}
288
289 // else, if we have a usercommentdiv, we would have a docid. Get toplevel section of the docid
290 var doc_id = "_cgiargd_"; //escape("_cgiargd_");
291 var period = doc_id.indexOf(".");
292 if(period != -1) \{
293 doc_id = doc_id.substring(0, period);
294 \}
295
296 var metapos=0; // counter variable
297 var username = null;
298 var timestamp = null;
299 var comment = null;
300
301 var comments_arraymap = []; // array of comment records with timestamp, username and comment fields
302
303 // First retrieve all the usercomments (usernames, associated usertimestamps and usercomments)
304 // from the archives folder, where it is arranged easier than in index because it's in sequence already.
305
306 username = gsapi.getDocumentMetadata(doc_id, "username", metapos);
307
308 // Keep looping, retrieving username, comment and timestamp
309 // Store each triplet in the comments array. Stop when there's no further usernames in archives
310
311 while(username) \{ //&& !username.indexOf("ERROR") == -1) \{
312
313 var errorIndex = username.indexOf("ERROR");
314 if(errorIndex != -1) \{
315 var endIndex = username.indexOf("(");
316 var error = username.substring(errorIndex,endIndex);
317 var errormessage=document.createTextNode("Error retrieving comments. " + error);
318 usercommentdiv.appendChild(errormessage);
319 //alert(username);
320 break;
321 \}
322
323 timestamp = gsapi.getDocumentMetadata(doc_id, "usertimestamp", metapos);
324 comment = gsapi.getDocumentMetadata(doc_id, "usercomment", metapos);
325
326 //alert("username: " + username + "\\ntime: " + timestamp + "\\ncomment: " + comment);
327
328 // array of records (arraymap)
329 // http://stackoverflow.com/questions/8190658/sorting-objects-in-a-javascript-array-by-a-key-value
330 // http://stackoverflow.com/questions/4969121/in-javascript-is-there-an-easy-way-to-sort-key-value-pairs-by-the-value-and-re
331 // http://stackoverflow.com/questions/6298169/how-to-create-a-map-object-in-a-javascript
332
333 // object with member vars t, u and c.
334 var comment_record = \{
335 t: timestamp,
336 u: username,
337 c: comment
338 \};
339
340 comments_arraymap.push(comment_record);
341
342 metapos++;
343 username = gsapi.getDocumentMetadata(doc_id, "username", metapos);
344 \}
345
346 // No need to sort by time,
347 // as the array is already stored sorted and hence retrieved in the right order by using metapos counter
348 // If sorting the array of comment records, which would be by timestamp, see
349 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort
350
351 //comments_arraymap.sort(function(rec1, rec2) \{
352 // return rec1.t-rec2.t; // sort by timestamp
353 //\});
354
355 //alert("Found " + metapos + " number of comments in the archives folder for doc " + doc_id);
356
357 // create the output HTML for all comments in one go now
358 // (we do this here for all values together to hopefully avoid reloading the page for each comment)
359
360 if(metapos > 0) \{
361 var heading=document.createElement("div");
362 var attr=document.createAttribute("class");
363 attr.nodeValue="usercommentheading";
364 heading.setAttributeNode(attr);
365 var txt=document.createTextNode("_text-usercomments-section_");
366 heading.appendChild(txt);
367 usercommentdiv.appendChild(heading);
368 \}
369
370 for(var i = 0; i < metapos; i++) \{
371 var comment_record = comments_arraymap[i];
372
373 username = comment_record.u;
374 timestamp = comment_record.t;
375 comment = comment_record.c;
376
377 // for each usercomment, create a child div with the username, timestamp and comment
378 displayInUserCommentList(usercommentdiv, username, timestamp, comment);
379 \}
380
381
382 \}
383
384 function displayInUserCommentList(usercommentdiv, username, timestamp, comment) \{
385
386 var divgroup=document.createElement("div");
387 var attr=document.createAttribute("class");
388 attr.nodeValue="usercomment";
389 divgroup.setAttributeNode(attr);
390
391 var divuser=document.createElement("div");
392 var divtime=document.createElement("div");
393 var divcomment=document.createElement("div");
394
395
396 divgroup.appendChild(divuser);
397 var txt=document.createTextNode(username);
398 divuser.appendChild(txt);
399
400 divgroup.appendChild(divtime);
401 txt=document.createTextNode(formatTime(timestamp)); // format timestamp for date/time display
402 divtime.appendChild(txt);
403
404 divgroup.appendChild(divcomment);
405 txt=document.createTextNode(comment);
406 divcomment.appendChild(txt);
407
408 usercommentdiv.appendChild(divgroup);
409
410 \}
411
412 // http://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load
413 // ensure we don't replace any other onLoad() functions, but append the loadUserComments()
414 // function to the existing onLoad handlers
415
416 if(window.onload) {\
417 var curronload = window.onload;
418 var newonload = function() {\
419 curronload();
420 loadUserComments();
421 \};
422 window.onload = newonload;
423 \} else {\
424 window.onload = loadUserComments;
425 \}
426 </script>
427
428_If_("_activatejquery_" eq "1",_jqueryScriptAndStyle_)
429
430_If_("_activateweb20_" eq "2",
431 _If_("_activateseaweed_" eq "1",_seaweedscript_)
432 _If_("_activatetalkback_" eq "1",_talkbackscript_)
433)
434_If_(_pagescriptfileextra_,_pagescriptfileextra_)
435<script language="javascript" type="text/javascript">
436_loginscript_
437_If_(_pagescriptextra_,_pagescriptextra_)
438_collectionspecificscript_
439_imagescript_
440</script>
441}
442
443_globalscripts_ [v=1] {
444
445_If_("_activatejquery_" eq "1",_jqueryScriptAndStyle_)
446
447_If_("_activateweb20_" eq "2",
448 <script type="text/javascript" src="_httpscript_/gsajaxapi.js"></script>
449 _If_("_activateseaweed_" eq "1",_seaweedscript_)
450 _If_("_activatetalkback_" eq "1",_talkbackscript_)
451)
452_If_(_pagescriptfileextra_,_pagescriptfileextra_)
453<script language="javascript" type="text/javascript">
454<!--
455_loginscript_
456_If_(_cgiargx_,_scriptdetach_)
457_If_(_pagescriptextra_,_pagescriptextra_)
458_collectionspecificscript_
459// -->
460</script>
461}
462
463_scriptdetach_ {
464 function close\_detach() \{
465 close();
466 \}
467}
468
469
470_jqueryScriptAndStyle_ {
471<link type="text/css" href="_httpstyle_/max-video/jquery-ui-1.8.4.custom.css" rel="stylesheet" />
472<script type="text/javascript" src="_httpscript_/jquery-1.4.2.min.js"></script>
473<script type="text/javascript" src="_httpscript_/jquery-ui-1.8.4.custom.min.js"></script>
474}
475
Note: See TracBrowser for help on using the repository browser.