The missing model for PRIMO v4.9 and better.
This is a work in progress!
If you want a feature, have a comment, found a bug you can:
See the releases for downloads and release notes
jQuery.PRIMO.js is intended to be used with a vanilla(unchanged) view. You might not get the intended experience if you changed/removed/renamed class names, id's etc.
From February 2016 this will be a part of the general Primo release cycle. But if you have server access you can install it yourself.
<script type='text/javascript' src='/primo_library/libweb/javascript/jQuery.PRIMO.min.js'></script>
<mapping resource="com/exlibris/primo/domain/entities/OriginalSourceRecord.hbm.xml"/>
to the hibernate mapping file /exlibris/primo/p4_1/ng/primo/home/system/search/conf/hibernate.cfg.xml The hibernate mapping file will be overwritten after each update this means you need to reapply this patch after every Primo upgrade.
jQuery.PRIMO.version;
That is it.
I also created 3 screencasts(no audio) as a guide.
Or if you want to isolate jQuery.PRIMO.
You can inject the script into your results page, for testing. This works best using Firefox. Open the JavaScript console and paste the next line. You will not be able to use the more advanced functions but it should give you an idea of what it can be used for.
$.getScript('https://cdn.rawgit.com/mehmetc/jQuery.PRIMO/4a091fc5/dist/jQuery.PRIMO.min.js')
Browsers are getting stricter with every release. If you get strange errors just copy the complete source into your console.
If you would want to compile jquery.PRIMO.js then follow these steps
jQuery.PRIMO.version;
jQuery.PRIMO.reload();
Some functions and attributes will only be available when jQuery.PRIMO.jar is installed on the server. Otherwise it will load a minimum of session data from the default getUserInfoServlet service.
jQuery.PRIMO.session.sessionId;
jQuery.PRIMO.session.reload();
jQuery.PRIMO.session.user.id;
jQuery.PRIMO.session.user.name;
jQuery.PRIMO.session.user.email;
jQuery.PRIMO.session.user.isLoggedIn();
jQuery.PRIMO.session.user.isOnCampus();
jQuery.PRIMO.session.user.ranking.categories;
jQuery.PRIMO.session.user.ranking.prefer_new;
jQuery.PRIMO.session.view.code;
jQuery.PRIMO.session.view.institution.name;
jQuery.PRIMO.session.view.institution.code;
jQuery.PRIMO.session.view.interfaceLanguage;
jQuery.PRIMO.session.view.isFullDisplay();
This is the hashCode() of the machines hostname. It is usefull for debugging or if you want a feature to only work on for example your staging enviroment.
jQuery.PRIMO.session.view.frontEndID;
jQuery.PRIMO.session.ip.address;
jQuery.PRIMO.session.ip.institution.name;
jQuery.PRIMO.session.ip.institution.code;
When you are logged in you will get the bor-info from PDS. It serializes the xml into json.
jQuery.PRIMO.session.pds.url;
jQuery.PRIMO.session.pds.handle;
jQuery.PRIMO.session.pds.borInfo;
Only available if the browser supports it. Be careful the getPageLoad and getPageRender methods are non blocking. This means they will only return sain values after the page is completely loaded and rendered.
jQuery.PRIMO.session.performance.timing.getNetworkLatency();
jQuery.PRIMO.session.performance.timing.getPageLoad();
jQuery.PRIMO.session.performance.timing.getPageRender();
Extends the DOM.
jQuery.PRIMO.records.length;
jQuery.PRIMO.records[5].id;
jQuery.PRIMO.records[5].index;
jQuery.PRIMO.records[5].title;
jQuery.PRIMO.records[5].openUrl;
jQuery.PRIMO.records[5].materialType();
jQuery.PRIMO.records[5].getIt1();
jQuery.PRIMO.records[5].isRemoteRecord();
jQuery.PRIMO.records[5].isOnEShelf();
jQuery.PRIMO.records[5].getPNX('text');
jQuery.PRIMO.records[5].getPNX('json');
jQuery.PRIMO.records[5].getPNX();
jQuery.PRIMO.records[0].getData().display.type;
jQuery.PRIMO.records[5].isDedupedRecord();
jQuery.PRIMO.records[2].getDedupedRecordIds();
jQuery.PRIMO.records.each(
function(){
if (this.getData().display.type === 'journal') {
this.css('background-color', 'yellow')
}
}
);
jQuery.PRIMO.records.each(
function(index, record){
var view_online = record.tabs.getByName('ViewOnline');
try{
view_online.find('a').attr('target', '_blank').attr('href', record.getIt1);
} catch (e) {
console.log('Error setting url');
}
}
);
Extends the DOM.
jQuery.PRIMO.facets.getNames();
jQuery.PRIMO.facets.getByName('facet_lang')
_facetlang is the technical name. Title will return the screen name. The screen name depends on the view language.
jQuery.PRIMO.facets.getByName('facet_lang').title
jQuery.PRIMO.facets.getByName('facet_lang').values
jQuery.map(jQuery.PRIMO.facets[0].values, function(f,i){return f.value})
jQuery.PRIMO.facets.getByName('facet_lang').values[0].value
jQuery.PRIMO.facets.getByName('facet_lang').values[0].count
Extends the DOM.
jQuery.PRIMO.records.each(
function(index, record){
record.tabs.addTab('HelloTab',{
label: 'Hello World',
state:'enabled',
click:function(event, tab, record, options){
if (tab.isOpen()){
tab.close();
} else {
tab.open('Hello from tab', {reload:true});
}
}
});
}
);
jQuery.PRIMO.records.each(
function(index, record){
record.tabs.addTab('ShareTab', {label: 'Share',tooltip:'Share', state:'enabled', click:function (event, tab, record, options) {
if (tab.isOpen()) {
tab.close();
} else {
var tab_content = "";
var details_url = $(record.tabs).filter('.EXLDetailsTab').find('a').attr('href');
tab_content += "<div style='overflow:auto;height:100%;padding:20px;'>";
tab_content += ' <div class="share_options_import"></div>';
tab_content += '</div>';
$.get(details_url,
function(data){
var html = $($.parseHTML(data)).find('.EXLTabHeaderButtonSendToList li');
var permalink = html.filter('.EXLButtonSendToPermalink').length == 0 ? false : true;
var citation = html.filter('.EXLButtonSendToCitation').length == 0 ? false : true;
if (permalink) {
html.filter('.EXLButtonSendToPermalink').find('a').attr('onclick', html.filter('.EXLButtonSendToPermalink').find('a').attr('onclick').replace(/-1/g, record.index));
}
if (citation){
html.filter('.EXLButtonSendToCitation').find('a').attr('onclick', html.filter('.EXLButtonSendToCitation').find('a').attr('onclick').replace(/-1/g, record.index));
}
$('.share_options_import').empty().append(html);
eshelfUpdate(record.children(), record.isOnEShelf());
}, 'html'
);
details_url = 'http://' + location.hostname + location.pathname.substr(0, location.pathname.lastIndexOf('/')) + '/display.do?tabs=detailsTab&ct=display&fn=search&doc=' + record.id + "&recIds=" + record.id;
tab.open(tab_content, {reload:false, url:details_url});
}
}
});
}
);
jQuery.PRIMO.records[0].tabs.addTab('KULeuvenTab', {label: 'KULeuven',
state:'enabled',
url:'http://www.kuleuven.be',
click:function(event, tab, record, options) {
if (tab.isOpen()) {
tab.close();
} else {
tab.open('<iframe src="https://github.com/mehmetc/jQuery.PRIMO/raw/master/'+options.url+'"/>', {reload: true});
}
}
});
jQuery.PRIMO.records[1].tabs.addTab('UrlTab', {label: 'Url',
state:'enabled',
url:'http://www.kuleuven.be', url_target: '_blank',
click: null
});
jQuery.PRIMO.records[5].tabs.getNames();
jQuery.PRIMO.records[5].tabs.getEnabled();
jQuery.PRIMO.records[5].tabs.getByName('DetailsTab');
jQuery.PRIMO.records[0].tabs.getByName('DetailsTab').find('a').click();
jQuery.PRIMO.records[5].tabs.getByName('DetailsTab').find('a').attr('href');
jQuery.PRIMO.records[5].tabs[0].name;
jQuery.PRIMO.records[5].tabs[0].index;
jQuery.PRIMO.records[5].tabs[1].container;
jQuery.PRIMO.records[5].tabs[4].isOpen();
Wraps the default XServices API this means that 'WS and XS IP' restrictions apply Wraps the default REST API
The results returned by the different API's are not compatible(feel free to fork and change) you can not switch between them without rewriting your code that consumes the search result.
query: can be a string or an array options: can be one of
bulkSize: amount of records to return. default = 10
extra options for use with REST api
regionURL is one of:
* America https://api-na.hosted.exlibrisgroup.com
* EU https://api-eu.hosted.exlibrisgroup.com
* APAC https://api-ap.hosted.exlibrisgroup.com
var result = jQuery.PRIMO.search.byQuery('any,contains,water');
var result = jQuery.PRIMO.search.byQuery(['title,contains,water', 'subject,contains,pollution'], {"index":10, "bulkSize":100});
var result = jQuery.PRIMO.search.byQuery('any,contains,water', {"restAPI":true, "bulkSize":5});
var result = jQuery.PRIMO.search.byQuery("any,contains,water", {"restAPI":true,"apiKey":"1234567890", "regionURL": "https://api-na.hosted.exlibrisgroup.com"})
Parses the URL and scrapes the DOM for data.
jQuery.PRIMO.query.count;
jQuery.PRIMO.query.page;
jQuery.PRIMO.query.step;
should be equal to
jQuery.PRIMO.records.length;
jQuery.PRIMO.query.type;
jQuery.PRIMO.query.tab;
jQuery.PRIMO.query.sorted_by;
This will return an Array of Object parsed from the URL not the DOM The Object contains the index, precision and term.
jQuery.PRIMO.query.query;
contains
[
{
"index":"any",
"precision":"contains",
"term":"perceval"
}
]
jQuery.PRIMO.query.query.toText();
returns
(any contains perceval)
jQuery.PRIMO.query.scope;
jQuery.PRIMO.query.facets;
jQuery.PRIMO.query.isDeeplinkSearch();
jQuery('body').append(jQuery.PRIMO.template.render('<div> Hello, {{who}}</div>', {who: 'world'}));
You can create templates using the script tag
<script type='text/template' id='helloWorld-tpl'>
<div>Hello {{who}}</div>
</script>
and use them in your javascript
<script type='text/javascript'>
jQuery('body').append(jQuery.PRIMO.template.renderById('helloWorld-tpl', {who: 'world'}));
</script>
Loop over all records and print title
<script type='text/template' id='allTitles-tpl'>
<div id="allTitles">
<ol>
{{ for(var i=0;i<records.length;i++){ }}
<li>{{ records[i].title }}</li>
{{ } }}
</ol>
</div>
</script>
Render the allTitles template and append it to the body
<script type='text/javascript'>
jQuery('body').append(jQuery.PRIMO.template.renderById('allTitles-tpl', {records: $.PRIMO.records}));
</script>
Template to add extra Search Scope Tab
<script type='text/template' id='searchTab-tpl'>
<li class="EXLSearchTab" id="{{id}}">
<a href="https://github.com/mehmetc/jQuery.PRIMO/blob/master/{{href}}" title="{{description}}" target="{{target}}">
<span>{{label}}</span>
</a>
</li>
</script>
Render the template using some variables
<script type='text/javascript'>
var query = jQuery.PRIMO.query.query.map(function(d){return d.term}).join(" ");
var renderedTemplate = jQuery.PRIMO.template.renderById('searchTab-tpl',
{id: 'exlidTabGoogleScolar',
label: 'Google Scholar',
description: 'Perform search on Google Scholar',
href:'http://scholar.google.com/scholar?as_q=' + query,
target:'_blank'});
jQuery('#exlidSearchTabs').append(renderedTemplate);
</script>
!!This is experimental might change in the future.
When a tab is done loading a tabReady callback is fired. You can attach a callback function to a tab that gets executed when the tab content is loaded.
Add the record id to the details tab when opened.
$.each($.PRIMO.records, function(i, record){
record.tabs.getByName('DetailsTab')[0].onTabReady = function(record, container, tab){
$($(container.tabUtils.tabContent).find('.EXLDetailsContent ul')[0]).prepend("<li><strong>Record id:</strong><span class='EXLDetailsDisplayVal'>" + record.id + "</span></li>");
}
});
MIT (c) 2015 KULeuven/LIBIS written by Mehmet Celik