-
Notifications
You must be signed in to change notification settings - Fork 74
/
cover_view.js
137 lines (111 loc) · 3.51 KB
/
cover_view.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
"use strict";
var _ = require("underscore");
var NodeView = require("../node").View;
var $$ = require("../../../substance/application").$$;
var articleUtil = require("../../article_util");
// Lens.Cover.View
// ==========================================================================
var CoverView = function(node, viewFactory) {
NodeView.call(this, node, viewFactory);
};
CoverView.Prototype = function() {
// Render it
// --------
//
// .content
// video
// source
// .title
// .caption
// .doi
this.render = function() {
NodeView.prototype.render.call(this);
var node = this.node;
var pubInfo = this.node.document.get('publication_info');
if (node.breadcrumbs && node.breadcrumbs.length > 0) {
var breadcrumbs = $$('.breadcrumbs', {
children: _.map(node.breadcrumbs, function(bc) {
var html;
if (bc.image) {
html = '<img src="'+bc.image+'" title="'+bc.name+'"/>';
} else {
html = bc.name;
}
return $$('a', {href: bc.url, html: html});
})
});
this.content.appendChild(breadcrumbs);
}
if (pubInfo) {
var pubDate = pubInfo.published_on;
if (pubDate) {
var items = [articleUtil.formatDate(pubDate)];
if (pubInfo.journal && !node.breadcrumbs) {
items.push(' in <i>'+pubInfo.journal+'</i>');
}
this.content.appendChild($$('.published-on', {
html: items.join('')
}));
}
}
// Title View
// --------------
//
var titleView = this.createTextPropertyView(['document', 'title'], { classes: 'title', elementType: 'div' });
this.content.appendChild(titleView.render().el);
// Render Authors
// --------------
//
var authors = $$('.authors', {
children: _.map(node.getAuthors(), function(authorPara) {
var paraView = this.viewFactory.createView(authorPara);
var paraEl = paraView.render().el;
this.content.appendChild(paraEl);
return paraEl;
}, this)
});
authors.appendChild($$('.content-node.text.plain', {
children: [
$$('.content', {text: this.node.document.on_behalf_of})
]
}));
this.content.appendChild(authors);
// Render Links
// --------------
//
if (pubInfo && pubInfo.links.length > 0) {
var linksEl = $$('.links');
_.each(pubInfo.links, function(link) {
if (link.type === "json" && link.url === "") {
// Make downloadable JSON
var json = JSON.stringify(this.node.document.toJSON(), null, ' ');
var bb = new Blob([json], {type: "application/json"});
linksEl.appendChild($$('a.json', {
href: window.URL ? window.URL.createObjectURL(bb) : "#",
html: '<i class="fa fa-external-link-square"></i> '+link.name,
target: '_blank'
}));
} else {
linksEl.appendChild($$('a.'+link.type, {
href: link.url,
html: '<i class="fa fa-external-link-square"></i> '+ link.name,
target: '_blank'
}));
}
}, this);
this.content.appendChild(linksEl);
}
if (pubInfo) {
var doi = pubInfo.doi;
if (doi) {
this.content.appendChild($$('.doi', {
html: 'DOI: <a href="http://dx.doi.org/'+doi+'">'+doi+'</a>'
}));
}
}
return this;
};
};
CoverView.Prototype.prototype = NodeView.prototype;
CoverView.prototype = new CoverView.Prototype();
module.exports = CoverView;