If your library uses another third-party link integration within your Primo discovery and you would also like to enable Lean Library's One Click to PDF feature, you may require an additional code snippet to ensure both services work together correctly.
Why is this necessary?
Some discovery link integrations and Lean Library’s One Click to PDF feature both rely on the same internal controller within Primo. Without a small adjustment, these snippets can interfere with each other, potentially causing links to disappear from your discovery results.
The solution
We have developed an additional code snippet that ensures both your existing discovery link integrations and Lean Library’s One Click to PDF feature initialise properly without conflict.
Important: This snippet is not included in the Lean Library dashboard. You can copy the code from the article and follow the steps below.
How to use the additional snippet
Once the main code snippet for One Click to PDF is available on your Lean Library dashboard after the initial setup (Click here to find out more about the setup process), you will need to also copy & paste the additional code snippet below the main snippet to make sure all your link integrations are working as expected. We've given you a full example so that you can compare with your own custom.js file.
Do not overwrite the whole of the Primo
custom.jsfile with any of our code snippets without proper analysis. Be aware that you may have other customisations included in yourcustom.jswhich we don't show in these examples.
Additional Code Snippet
Below is the additional code snippet that you will need to avoid any conflicts with other link integrations.
/**
* Both Lean Library and other Third Parties require the same controller to be used
* This controller initializes both services when the search results are loaded.
* Other controllers can be initialised here as needed.
*/
app.controller('ThirdPartyIntegrationController', function ($scope) {
this.$onInit = function () {
{
// Initialize Lean Library
if (window.llLinkingWidget && window.llLinkingWidget.primo) {
window.llLinkingWidget.primo($scope).catch(console.error);
}
// Initialize Third Party
// Exact code you use here will be dependant on your third party, and will need to be where their controller is passed the $scope
window.thirdpartyWidget.someInitialisationFunction($scope);
}
};
});
/**
* When you attach the controller to the component in Primo,
* instead of using the Lean Library specific Controller from the dashboard snippet,
* you use the controller defined above
*/
app.component('prmSearchResultAvailabilityLineAfter', {
bindings: { parentCtrl: '<' },
controller: 'ThirdPartyIntegrationController',
template: '',
}); Example:
Here is a worked example of what your final custom.js code might look like (simplified for clarity): Do not copy & paste this as it is not customised for your institution. Use this as a guide for how you'd need to customise your own primo custom.js file.
// These first 3 lines are the boilerplate in your custom.js file and should not be edited.
(function () {
'use strict';
var app = angular.module('viewCustom', ['angularLoad']);
// Lean Library integration
window.llLinkingWidget = {
institutionId: "$INSTITUTION_ID",
apiKey: "$LINKING_API_KEY",
};
window.llLinkingWidget.script = document.createElement('script');
window.llLinkingWidget.script.src = 'https://cdn-dev.leanlibrary.app/linking-widget/primo.js';
document.head.appendChild(window.llLinkingWidget.script);
// End Lean Library integration
// Begin Third Party Primo Integration
window.thirdparty = {
api: `https://example.com/path/to/api`,
apiKey: '$SOME_OTHER_API_KEY',
// rest of configuration...
};
thirdparty.script = document.createElement('script');
thirdparty.script.src = 'https://example.com/some/script/';
document.head.appendChild(thirdparty.script);
// End Third Party - Primo Integration
/**
* Both Lean Library and other Third Parties require the same controller to be used
* This controller initializes both services when the search results are loaded.
* Other controllers can be initialised here as needed.
*/
app.controller('ThirdPartyIntegrationController', function ($scope) {
this.$onInit = function () {
{
// Initialize Lean Library
if (window.llLinkingWidget && window.llLinkingWidget.primo) {
window.llLinkingWidget.primo($scope).catch(console.error);
}
// Initialize Third Party
// Exact code you use here will be dependant on your third party, and will need to be where their controller is passed the $scope
window.thirdpartyWidget.primo.searchResult($scope);
}
};
});
app.component('prmSearchResultAvailabilityLineAfter', {
bindings: { parentCtrl: '<' },
controller: 'ThirdPartyIntegrationController',
template: '',
});
// End custom code
})();