Initial commit
[mkdrusampletheme.git] / customtheme.js
1 Drupal.theme.mkdruCounts = function(first, last, available, total) {
2   if (last > 0)
3     return '<strong>' + first  + '</strong>' + Drupal.t(' to ') + '<strong>' + last + '</strong>' + Drupal.t(' of ') + '<strong>'
4       + available + '</strong>' + Drupal.t(' available');
5   else
6     return Drupal.t('No results');
7 };
8
9 Drupal.theme.mkdruResult = function(hit, num, detailLink) {
10   var resultclass = "mkdru-result ";
11   if (num%2)
12     resultclass += "odd";
13   else
14     resultclass += "even";
15   var html = "";
16   html += '<li class="' + resultclass + '" id="rec_' + hit.recid + '" >'
17           + '<div class="mkdru-result-title"><a href="' + detailLink + '">'
18           + hit["md-title"] + '</a>';
19   if (hit["md-title-remainder"] !== undefined) {
20     html += ' <span class="mkdru-result-title-remainder">'
21             + hit["md-title-remainder"] + ' </span>';
22   }
23   html += '</div>';
24   if (hit["md-title-responsibility"] !== undefined) {
25     html += '<div class="mkdru-result-author"><em>'
26             + hit["md-title-responsibility"]
27             + '</em> ';
28     if (hit["md-date"] !== undefined) {
29       html += hit["md-date"];
30     }
31     html += '</div>';
32   }
33   if (hit["md-description"] !== undefined) {
34     // limit description to 400 characters
35     html += '<div class="mkdru-result-description">'
36             + String(hit["md-description"]).substr(0, 400)
37             + ' </div>';
38   }
39
40   html += '</li>';
41   return html;
42 };
43
44 Drupal.theme.mkdruDetail = function(data, linkBack) {
45   var html = '<table id="det_' + data.recid +'">';
46   if (data["md-title"] != undefined) {
47     html += '<tr><th>' + Drupal.t("Title") + '</th><td>'
48             + data["md-title"];
49     if (data["md-title-remainder"] !== undefined) {
50       html += ' : <span>' + data["md-title-remainder"] + ' </span>';
51     }
52     if (data["md-title-responsibility"] !== undefined) {
53       html += ' <span><i>'+ data["md-title-responsibility"] +'</i></span>';
54     }
55     html += '</td></tr>';
56   }
57   if (data["md-date"] != undefined)
58     html += '<tr><th>' + Drupal.t("Date") + '</th><td>' + data["md-date"] + '</td></tr>';
59   if (data["md-author"] != undefined)
60     html += '<tr><th>' + Drupal.t("Author") + '</th><td>' + data["md-author"] + '</td></tr>';
61   if (data["md-electronic-url"] != undefined)
62     html += '<tr><th>URL</th><td><a href="'
63             + data["md-electronic-url"] + '" target="_blank">'
64             + data["md-electronic-url"] + '</a>' + '</td></tr>';
65   // test if there is an array of per-location data; process it
66   if (Object.prototype.toString.call(data['location']) === '[object Array]') { 
67     var subject = false;
68     var locations = ""; 
69     for (var i = 0; i < data['location'].length; i++) {
70       var locRec = data['location'][i];
71       // grab the first value we find for subject
72       if (!subject && locRec['md-subject']) subject = locRec['md-subject'];
73       // list named locations and link to the record there if url is available
74       var link = locRec["md-electronic-url"];
75       if (!link) link = pz2urlrecipe.getUrlFromRecipe(locRec);
76       var name = locRec["@name"]
77       if (link && name) locations += '<a href="' + link + '">' + name + '</a><br>';
78       else if (name) locations += name + '<br>';
79     }
80     if (subject)
81       html += '<tr><th>' + Drupal.t("Subject") + '</th><td>' + subject + '</td></tr>';
82     if (locations)
83       html += '<tr><th>' + Drupal.t("Location") + '</th><td>' + locations + '</td></tr>';
84   }
85   html += '</table>';
86   html += '<a href="' + linkBack + '">' + Drupal.t('Return to result list...') + '</a>';
87   return html;
88 };