Tech Blog

Display resource ID, permalink in info window

Description

Display MetaLib local resource ID and/or permalink to resource in info window.

  • Institution: Max Planck Digital Library
  • Year: 2010
  • License: BSD style
  • Short description: Use, modification and distribution of the code are permitted provided the copyright notice, list of conditions and disclaimer appear in all related material.
  • Skill required for using this code: Basic

State

Stable

Programming language

Javascript

Screen captures

Author(s) homepage

Download

local.js

Working example

Using the following Ex Libris open interfaces

MetaLib Deep Linking

Installation instructions

Add the below code to any Javascript file .js referenced in info window (templates quick-details-info, meta-1-info, find-db-info). Take a look at the ‘configure’ section. Do not forget to add the MetaLib institution prefix.
Next, add page elements required to the info window templates where you wish to display resource ID and/or permalink.
Eventually, add a call to the function to the onLoad event handler of the page (onLoad=”displayResID();”)

function displayResID () {

   /* ---- Elements required in info window template ----

   <body id="popup" onLoad="displayResID();">
   [...]
   <ELEM id="restitle">$0200</ELEM> - meta-1-info, find-db-info
   <ELEM id="restitle">$1700</ELEM> - quick-details-info
   [...]
   <ELEM id="resid"></ELEM>
   [...]
   <ELEM id="permalink"></ELEM>

   example:
   <h2 id="restitle">$0200</h2>
   <p id="resid"></p>
   <p id="permalink"></p>

   */

   // ---- configure ----

   var instPrefix = ''; // REQUIRED: set institution prefix
   var displayResID = 1; // yes, display resource ID in info window
   var displayPermalink = 1; // yes, display permalink in info window
   var permalinkTitle = "PermaLink"; // link title of permalink
   var permalinkTextBefore = ""; // text to appear before permalink
   var permalinkText = "PermaLink"; // link text of permalink
   var permalinkTextAfter = " to this resource in MetaLib"; // text to appear after permalink
   var urlParam = 'resource'; // MetaLib ULR parameter '&resource='
   var permalinkURL = "/V?func=meta-1&INIT_TYPE=LocateList&F-IDN="; // please note: based on UI URL index F-IDN

   // -------------------

   var resID = ''; // resource id
   var resTitle = ''; // resource title
   var resTitleElem = document.getElementById("restitle"); // element in info window
   var resIDElem = document.getElementById("resid"); // element in info window
   var permaLinkElem = document.getElementById("permalink"); // element in info window
   var str = ''; // html string containing resource id

   /* sample str

   <A HREF="http://vlib.mpg.de:80/V/BLU61PABTEK4EUKRFD7YTUR9L13UXJVNLIIPHVXYX5V38JVCJB-20799?func=native-link&resource=MPG03448
           " target="_blank" title="BVB Union Catalog">BVB Union Catalog</A>  

   */

   // check whether institution prefix was set
   if(!instPrefix) { return; }

   var resIDMatch = new RegExp(instPrefix + '[0-9]{5}'); // reg exp pattern to match resource id

      if(resTitleElem != null) {
          // get str
          if(resTitleElem.hasChildNodes()) {
              str = resTitleElem.firstChild.toString();
          }
          // process str
          if(str) {
              // apply pattern, get resID
              var matches = resIDMatch.exec(str);
                 if(matches) {
                    resID = matches[0];
                 }
                 if(resID) {
                      if(displayResID) { // add resID
                          if(resIDElem != null) {
                              resIDElem.appendChild(document.createTextNode(resID));
                          }
                      }
                      if(displayPermalink) { // add Permalink
                          if(permaLinkElem != null) {
                              var textBefore = document.createTextNode(permalinkTextBefore);
                              var linkText = document.createTextNode(permalinkText);
                              var textAfter = document.createTextNode(permalinkTextAfter);
                              var link = document.createElement('a');
                                  link.href = permalinkURL + resID;
                                  link.title = permalinkTitle;
                                  link.appendChild(linkText);
                              permaLinkElem.appendChild(textBefore);
                              permaLinkElem.appendChild(link);
                              permaLinkElem.appendChild(textAfter);
                          }
                      }
                }
          }
     }
}
Please note that the above solution is based on the MetaLib UI URL index F-IDN.

Page attachments

local.js

Leave a Reply