-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimo-ve_code_storage.js
213 lines (189 loc) · 6.69 KB
/
primo-ve_code_storage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
(function () {
'use strict';
'use strict';
var app = angular.module('viewCustom', [
'angularLoad',
'hathiTrustAvailability',
]);
('use strict');
('use strict');
('use strict');
('use strict');
/*----------below is the code for libchat-----------*/
// Adds the chat button
(function () {
var lc = document.createElement('script');
lc.type = 'text/javascript';
lc.async = 'true';
lc.src =
('https:' == document.location.protocol ? 'https://' : 'http://') +
'v2.libanswers.com/load_chat.php?hash=8695fcdfdfdf1ec2b50aabde6d1afd61';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(lc, s);
})();
/*---------------libchat code ends here---------------*/
// LibAnswers System Status widget
(function (s, o, g, a, m) {
(a = s.createElement(o)), (m = s.head);
a.async = 1;
a.src = g;
m.appendChild(a);
a.onload = function () {
var x = document.getElementById('s-la-widget-st-1305');
x && x.firstElementChild.removeAttribute('href');
};
})(document, 'script', 'https://api2.libanswers.com/1.0/status/widgets/1305');
/*----------twitter starts here-----------*/
// Adds the chat button
window.twttr = (function (d, s, id) {
var js,
fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = 'https://platform.twitter.com/widgets.js';
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function (f) {
t._e.push(f);
};
return t;
})(document, 'script', 'twitter-wjs');
/*---------------twitter end---------------*/
//Auto generated code by primo app store DO NOT DELETE!!! -START-
/*
hookName is a place holder with should hold the hook name not including "prm" at the beginning and in upper camel case
e.g: for hook prmSearchBarAfter (in html prm-search-bar-after) it should be given "SearchBarAfter"
*/
app.controller('SearchResultAvailabilityLineAfterController', [
function () {
var vm = this;
},
]);
app.component('prmSearchResultAvailabilityLineAfter', {
bindings: { parentCtrl: '<' },
controller: 'SearchResultAvailabilityLineAfterController',
template:
'\n <hathi-trust-availability-studio ignore-copyright="true" entity-id="https://shibboleth.brandeis.edu/idp/shibboleth"></hathi-trust-availability-studio>\n',
});
//Auto generated code by primo app store DO NOT DELETE!!! -END-
//Auto generated code by primo app store DO NOT DELETE!!! -START-
angular
.module('hathiTrustAvailability', [])
.value('hathiTrustIconPath', 'custom/CENTRAL_PACKAGE/img/hathitrust.svg')
.constant(
'hathiTrustBaseUrl',
'https://catalog.hathitrust.org/api/volumes/brief/json/'
)
.config([
'$sceDelegateProvider',
'hathiTrustBaseUrl',
function ($sceDelegateProvider, hathiTrustBaseUrl) {
var urlWhitelist = $sceDelegateProvider.resourceUrlWhitelist();
urlWhitelist.push(hathiTrustBaseUrl + '**');
$sceDelegateProvider.resourceUrlWhitelist(urlWhitelist);
},
])
.factory('hathiTrust', [
'$http',
'$q',
function ($http, $q) {
var svc = {};
var hathiTrustBaseUrl =
'https://catalog.hathitrust.org/api/volumes/brief/json/';
svc.findFullViewRecord = function (ids) {
var deferred = $q.defer();
var handleResponse = function handleResponse(resp) {
var data = resp.data;
var fullTextUrl = null;
for (var i = 0; !fullTextUrl && i < ids.length; i++) {
var result = data[ids[i]];
for (var j = 0; j < result.items.length; j++) {
var item = result.items[j];
if (item.usRightsString.toLowerCase() === 'full view') {
fullTextUrl = result.records[item.fromRecord].recordURL;
break;
}
}
}
deferred.resolve(fullTextUrl);
};
if (ids.length) {
var hathiTrustLookupUrl = hathiTrustBaseUrl + ids.join('|');
$http
.jsonp(hathiTrustLookupUrl, {
cache: true,
jsonpCallbackParam: 'callback',
})
.then(handleResponse)
.catch(function (e) {
console.log(e);
});
} else {
deferred.resolve(null);
}
return deferred.promise;
};
return svc;
},
])
.controller('hathiTrustAvailabilityStudioController', [
'hathiTrust',
'hathiTrustIconPath',
function (hathiTrust, hathiTrustIconPath) {
var self = this;
self.hathiTrustIconPath = hathiTrustIconPath;
self.$onInit = function () {
setDefaults();
if (!(isOnline() && self.hideOnline)) {
updateHathiTrustAvailability();
}
};
var setDefaults = function setDefaults() {
if (!self.msg) self.msg = 'Full Text Available at HathiTrust';
};
var isOnline = function isOnline() {
return self.prmSearchResultAvailabilityLine.result.delivery.GetIt1.some(
function (g) {
return g.links.some(function (l) {
return l.isLinktoOnline;
});
}
);
};
var updateHathiTrustAvailability =
function updateHathiTrustAvailability() {
var hathiTrustIds = (
self.prmSearchResultAvailabilityLine.result.pnx.addata.oclcid ||
[]
).map(function (id) {
return 'oclc:' + id;
});
hathiTrust.findFullViewRecord(hathiTrustIds).then(function (res) {
self.fullTextLink = res;
});
};
},
])
.component('hathiTrustAvailabilityStudio', {
require: {
prmSearchResultAvailabilityLine: '^prmSearchResultAvailabilityLine',
},
bindings: {
hideOnline: '<',
msg: '@?',
},
controller: 'hathiTrustAvailabilityStudioController',
template:
'<span ng-if="$ctrl.fullTextLink" class="umnHathiTrustLink">\
<md-icon md-svg-src="{{$ctrl.hathiTrustIconPath}}" alt="HathiTrust Logo"></md-icon>\
<a target="_blank" ng-href="{{$ctrl.fullTextLink}}">\
{{ ::$ctrl.msg }}\
<prm-icon external-link="" icon-type="svg" svg-icon-set="primo-ui" icon-definition="open-in-new"></prm-icon>\
</a>\
</span>',
});
app.requires.push('hathiTrustAvailability');
//Auto generated code by primo app store DO NOT DELETE!!! -END-
})();