-
Notifications
You must be signed in to change notification settings - Fork 0
/
ucdlib-sils-permalink.js
179 lines (145 loc) · 5 KB
/
ucdlib-sils-permalink.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
import { LitElement } from 'lit';
import {render, styles} from "./ucdlib-sils-permalink.tpl.js";
/**
* @class UcdlibSilsPermalink
* @description This component allows you to easily add individual objects from
* the UC SILS catalog into your webpage.
* @property {String} href - Pointer to the permalink
* @property {String} cite - Specify the citation style
*
* <ucdlib-sils-permalink href="https://search.library.ucdavis.edu/permalink/01UCD_INST/1uov27j/alma9981249369903126"/>
*/
export default class UcdlibSilsPermalink extends LitElement {
static get properties() {
return {
results : {type: Object, attribute:false},
permalink : {type: String},
image : {type: String, attribute:false},
title : {type: String, attribute:false},
authorFull : {type: String, attribute:false},
authorLast : {type: String, attribute:false},
authorFirst: {type: String, attribute:false},
authorID: {type: Array, attribute:false},
year : { type: String, attribute:false},
summary : {type: String, attribute:false},
tags : {type: Array, attribute:false},
teaserType : {type: String, attribute:false},
publisher : {type: String, attribute:false},
placePublication : {type: String, attribute:false},
notes : {type: Array, attribute:false},
language: {type: String, attribute:false},
randomClass: {type: String, attribute:false},
elemClass: {type: Array, attribute:false},
};
}
static get styles() {
return styles();
}
constructor() {
super();
this.results = {};
this.resultsPerPage = 9999;
this.page = 1;
this.permalink = '';
this.authorLast = '';
this.authorFirst = '';
this.authorFull = '';
this.title = '';
this.year = '';
this.summary= '';
this.tags = [];
this.authorID = [];
this.teaserType = '';
this.publisher = '';
this.placePublication = '';
this.notes = [];
this.language = '';
this.randomClass = '';
this.elemClass = [];
this.image = '';
this.render=render.bind(this);
}
updated(props) {
if( props.has('permalink') ) {
this._request();
}
}
loadJSON(path, success, error) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
success(JSON.parse(xhr.responseText));
}
else {
error(xhr);
}
}
};
xhr.open('GET', path, true);
xhr.responseType = 'text';
return new Promise(function (resolve, reject) {
xhr.onload = function () {
if (xhr.readyState === xhr.DONE) {
if (xhr.status === 200) {
resolve(xhr.response);
//
// json = output;
}
else {
reject(status);
}
}
};
xhr.send();
});
}
myData(Data)
{
// Output only the details on the first post
console.log("Title:", Data.title);
}
async _request(){
let url = this.permalink;
let output = await this.loadJSON(url, this.myData,'jsonp');
this.results = JSON.parse(output);
this.teaserType = this.results["@type"];
/* Note:
ISBN has multiple options so later address which items to pick and whether
to use default thumbnail
*/
let img = [];
for(let i = 0; i < this.results.identifier.length; i++){
if(this.results.identifier[i]['@type']){
if(this.results.identifier[i]['@type'].includes('bibo:isbn'))
img = img.concat(this.results.identifier[i].label);
if(this.results.identifier[i]['@type'].includes('bibo:ean'))
img = img.concat(this.results.identifier[i].label);
}
}
let identifer = img[0];
if(this.teaserType == 'Video' || this.teaserType == 'Music'){
this.image = 'https://syndetics.com/index.php?client=primo&isbn='+ identifer + '/sc.gif';
}
else{
this.image = 'https://syndetics.com/index.php?client=primo&isbn='+ identifer + '/sc.jpg';
}
this.year = this.results.date;
this.title = this.results.title.substring(0, this.results.title.lastIndexOf("/"));
this.authorFull = this.results.creator["label"].split(',');
this.authorID = this.authorID.concat({"id": this.results.creator["@id"], "sameAs": this.results.creator["sameAs"]}[0]);
this.authorLast = this.authorFull[0];
this.authorFirst = this.authorFull[1];
this.summary = this.results.description;
this.publisher = this.results.publisher;
this.placePublication = this.results.place_of_publication.split(' ')[0];
this.language = this.results.language;
for (let i = 0; i < Object.keys(this.results.subject).length; i++){
this.tags = this.tags.concat({"id": this.results.subject[i]["@id"], "subject": this.results.subject[i]["label"]});
}
this.notes = this.results.note;
this.elemClass = ['tahoe', 'california', 'quad'];
console.log(this.results);
}
}
customElements.define('ucdlib-sils-permalink',UcdlibSilsPermalink);