{"size": 1854, "ext": "js", "max_stars_repo_path": "David and Pooja/topicexplorer/www/htrc.js", "max_stars_repo_name": "LinkedModernismProject/web_code", "max_stars_repo_stars_event_min_datetime": "2015-05-21T23:47:54.000Z", "max_stars_repo_stars_event_max_datetime": "2015-05-21T23:47:54.000Z", "max_issues_repo_path": "David and Pooja/topicexplorer/www/htrc.js", "max_issues_repo_name": "LinkedModernismProject/web_code", "max_issues_repo_issues_event_min_datetime": "2015-10-29T20:51:31.000Z", "max_issues_repo_issues_event_max_datetime": "2015-10-29T20:51:31.000Z", "max_forks_repo_path": "David and Pooja/topicexplorer/www/htrc.js", "max_forks_repo_name": "LinkedModernismProject/web_code", "max_forks_repo_forks_event_min_datetime": "2021-11-05T20:45:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-05T20:45:57.000Z"}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 27.2647058824, "max_line_length": 134, "alphanum_fraction": 0.5334412082}
/* htrc.js
 * Helpers for performing solr queries
 * 
 * Requires: 
 * - jQuery 1.11.0
 * - mustache.js
 * */

var htrc = htrc || {};
htrc.solr = htrc.solr || {};

htrc.solr.host = "http://chinkapin.pti.indiana.edu:9994";

/* htrc.solr.get(id)
 * Performs a query for the given id
 * */
htrc.solr.get = function(id, callback) {
  var url = htrc.solr.host + "/solr/meta/select/?q=id:" + id + "&wt=json";
  $.ajax({
    dataType: 'jsonp',
    url: url,
    success: callback,
    'jsonp' : 'json.wrf'
  });
  return true; 
};

/* htrc.popover
 * Create a popover for HTRC content
 * */
$.ajax({
  url : "/popover.content.mustache", 
  async: false,
  success: function(template) { 
    htrc.popover = function(elt) {
      if (!($(elt).data('popover'))) {
        var id = $(elt).data('htrc-id');
        var page = $(elt).data('htrc-page');

        htrc.solr.get(id, function (data) {
          data = data.response.docs[0];
          if (data.oclc)
            data.oclc = data.oclc[0].replace("(OCoLC)","").replace("ocm","");
          if (page)
            data.page = page;

          title = (data.title_ab && data.title_ab[0]) || data.title[0];
          var html = Mustache.to_html(template, data);
          $(elt).popover({
            html: true,
            content : html,
            title : title,
            container : 'body'
          });
         
         // append close button to title.
         var title = $(elt).data('popover').options.title;
         $(elt).data('popover').options.title = '<button type="button" class="close" data-dismiss="popover">&times;</button>' + title;
         $(elt).data('popover').tip().on('click', '[data-dismiss="popover"]', function(e) { $(elt).popover('hide'); });

         // manually show popover, instead of just initialize
         $(elt).popover('show');
        });
      }
    }
  } 
});
