You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
6.2 KiB

  1. // Project: Web Reference Database (refbase) <http://www.refbase.net>
  2. // Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
  3. // original author(s).
  4. //
  5. // This code is distributed in the hope that it will be useful,
  6. // but WITHOUT ANY WARRANTY. Please see the GNU General Public
  7. // License for more details.
  8. //
  9. // File: ./javascript/common.js
  10. // Repository: $HeadURL$
  11. // Author(s): Matthias Steffens <mailto:refbase@extracts.de> and
  12. // Richard Karnesky <mailto:karnesky@gmail.com>
  13. //
  14. // Created: 26-Aug-08, 21:10
  15. // Modified: $Date: 2008-10-27 23:58:27 +0000 (Mon, 27 Oct 2008) $
  16. // $Author$
  17. // $Revision: 1277 $
  18. // This file contains common JavaScript functions that are used
  19. // within the refbase interface.
  20. // ------------------------------------------------------------------
  21. // Select (or deselect) all checkboxes (of 'name=formpart') on a page:
  22. function checkall(val, formpart) {
  23. var x = 0;
  24. while(document.queryResults.elements[x]) {
  25. if(document.queryResults.elements[x].name == formpart) {
  26. document.queryResults.elements[x].checked = val;
  27. }
  28. x++;
  29. }
  30. toggleRadio('allRecs', 'selRecs', val);
  31. }
  32. // ------------------------------------------------------------------
  33. // Show or hide the element with the given 'id':
  34. function toggleVisibility(id, imgid, txtid, txt, upd) {
  35. var e = document.getElementById(id);
  36. var i = document.getElementById(imgid);
  37. var t = document.getElementById(txtid);
  38. var upd;
  39. if (upd === undefined) upd = true;
  40. if (e.style.display == 'block' || e.style.display == '') {
  41. if (upd) e.style.display = 'none';
  42. i.src = 'img/closed.gif';
  43. t.innerHTML = txt;
  44. }
  45. else {
  46. if (upd) e.style.display = 'block';
  47. i.src = 'img/open.gif';
  48. t.innerHTML = '';
  49. }
  50. }
  51. // ------------------------------------------------------------------
  52. // Show or hide the element with the given 'id' using a slide effect:
  53. // TODO: figure out how to invoke the changes to the toggle image & text
  54. // (done via function 'toggleVisibility()') only *after* the slide
  55. // effect has been finished
  56. //
  57. // Requires the Prototype & script.aculo.us JavaScript frameworks:
  58. // <http://www.prototypejs.org/> and <http://script.aculo.us/>
  59. //
  60. // More info about 'Effect.toggle':
  61. // <http://github.com/madrobby/scriptaculous/wikis/effect-toggle>
  62. function toggleVisibilitySlide(id, imgid, txtid, txt) {
  63. Effect.toggle(id, 'blind', {duration:0.4});
  64. toggleVisibility(id, imgid, txtid, txt, false);
  65. }
  66. // ------------------------------------------------------------------
  67. // Select one of two radio buttons (and deselect the other):
  68. // ('val=true' selects radio button 'id2' and deselects 'id1')
  69. function toggleRadio(id1, id2, val) {
  70. document.getElementById(id1).checked = !(val);
  71. document.getElementById(id2).checked = val;
  72. }
  73. // ------------------------------------------------------------------
  74. // Update the state of the "All Found Records" & "Selected Records"
  75. // radio buttons based on whether any records where marked on a page:
  76. function updateAllRecs() {
  77. var val=!eval("document.getElementById('allRecs').checked");
  78. var x=0;
  79. var checked=0;
  80. while(document.queryResults.elements[x]) {
  81. if(document.queryResults.elements[x].name == "marked[]") {
  82. if (eval("document.queryResults.elements[x].checked")) {
  83. checked++;
  84. }
  85. }
  86. x++;
  87. }
  88. if (checked>0) {
  89. val=true;
  90. } else {
  91. val=false;
  92. }
  93. toggleRadio('allRecs', 'selRecs', val);
  94. }
  95. // ------------------------------------------------------------------
  96. // This is the callback function that gets called by the script.aculo.us
  97. // 'Ajax.Autocompleter'. If it makes sense, this function modifies the suggest
  98. // query such that the given search term ('entry') is prefixed with a CQL index
  99. // ('selectedField') and a default relation ('all').
  100. //
  101. // Requires the Prototype & script.aculo.us JavaScript frameworks:
  102. // <http://www.prototypejs.org/> and <http://script.aculo.us/>
  103. //
  104. // More info about 'Ajax.Autocompleter':
  105. // <http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter>
  106. function addCQLIndex(element, entry) {
  107. // NOTE: this 'if' block is a hack, see note above function 'buildSuggestElements()'
  108. // in 'include.inc.php'
  109. if (entry.match(/^(id|col)-\w+-\w+=/) != null) {
  110. if (entry.match(/^id-\w+-\w+=/) != null) {
  111. // extract the ID of the HTML form element that contains the selected field:
  112. var selectedFieldID = entry.replace(/^id-(\w+)-\w+=.*/, "$1");
  113. // get the the name of the field that's currently selected in the
  114. // specified HTML form element:
  115. var selectedField = document.getElementById(selectedFieldID).value;
  116. }
  117. else if (entry.match(/^col-\w+-\w+=/) != null) {
  118. // extract the column/field name (that was passed literally):
  119. var selectedField = entry.replace(/^col-(\w+)-\w+=.*/, "$1");
  120. }
  121. // re-establish the correct query parameter name & value:
  122. entry = entry.replace(/^(id|col)-\w+-/, "");
  123. }
  124. else
  125. var selectedField = "keywords"; // fallback
  126. // NOTES: - we may need to exclude the 'abstract' index here until there's a smarter
  127. // solution to present search suggestions from the abstract (currently, for
  128. // each match, full or partial sentences from the abstract will be returned)
  129. // - ATM, the special index 'main_fields' only works for search suggestions
  130. var CQLIndexes = " author title type year publication abbrev_journal volume issue"
  131. + " pages keywords abstract address corporate_author thesis publisher"
  132. + " place editor language summary_language orig_title series_editor"
  133. + " series_title abbrev_series_title series_volume series_issue"
  134. + " edition issn isbn medium area expedition conference notes"
  135. + " approved location call_number serial marked copy selected"
  136. + " user_keys user_notes user_file user_groups cite_key related"
  137. + " file url doi contribution_id online_publication online_citation"
  138. + " orig_record created_by modified_by main_fields ";
  139. if (CQLIndexes.search("\\b" + selectedField + "\\b") > 0)
  140. entry = entry.replace("=", "=" + selectedField + "%20all%20");
  141. return entry;
  142. }
  143. // ------------------------------------------------------------------