-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathdocumentcloud.org.js
More file actions
122 lines (104 loc) · 4.54 KB
/
documentcloud.org.js
File metadata and controls
122 lines (104 loc) · 4.54 KB
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
export default {
re: /^https?:\/\/(?:www|embed)?\.?documentcloud\.org\/documents?\/\d+/i,
mixins: [
"domain-icon",
"oembed-site",
"canonical",
"author",
"og-title",
"og-image",
"og-description",
"oembed-title"
],
// plugin is required to add aspect-ratio and with this fix embeds when used inside iFrame
// https://www.documentcloud.org/help/api#oembed
getLink: function(url, oembed, options) {
if (oembed.type === 'rich' && oembed.html) { // else: fallback to generic
var html = oembed.html.replace(/\r?\n|\r/g, '');
var aspect = /padding\-bottom:(\d+.\d+)%/.test(html) && 100 / parseFloat(html.match(/padding\-bottom:(\d+.\d+)%/)[1])
|| oembed.width && oembed.height && oembed.width / oembed.height
|| CONFIG.DOC_ASPECT_RATIO;
var link = {
type: CONFIG.T.text_html,
rel: [CONFIG.R.reader, CONFIG.R.ssl],
'aspect-ratio': aspect
};
if (!/DC\-note/.test(html) && !/DC\-embed(?:\-page)?/.test(html)) {
var page = options.getRequestOptions('documentcloud.page', '1');
var showTitle = options.getRequestOptions('documentcloud.title', true);
try {
var iframe = oembed.getIframe();
var href = !showTitle ? iframe.replaceQuerystring({ title: 0 }) : iframe.src;
if (page && page !== '1') {
if (href) {
href += '#document/p' + page;
} else {
html = html.replace (/"\s+title="/i, '#document/p' + page + '" title="');
}
}
link.href = href;
link['padding-bottom'] = 80;
link.options = {
page: {
label: CONFIG.L.page,
value: parseInt (page)
},
title: {
label: 'Show title',
value: showTitle
}
}
} catch (ex) {}
}
if (!link.href) {
link.html = html;
}
if (!/DC\-note/.test(html)) {
link.rel.push(CONFIG.R.inline);
}
return link;
}
},
// Pages and comments are covered by known providers in providers.json
getData: function(url, __noOembedLinks, cb) {
/** Fix for unicode characters in url causes 400 at provider oEmbed api */
var uri = encodeURI(
url.indexOf('%') === -1
? url
: url.replace(/(\d+\-)[^./#?]+/i, '$1-')
);
return cb(null, {
oembedLinks: ['json', 'xml'].map(function (format) {
return {
href: `https://api.www.documentcloud.org/api/oembed.${format}?url=${encodeURIComponent(uri)}`,
rel: 'alternate',
type: `application/${format}+oembed`
}
})
});
},
tests: [{skipMethods: ['getData']},
{skipMixins: [
'domain-icon',
'og-description',
'author',
'canonical',
'og-title',
'og-image',
'oembed-title'
]},
"https://www.documentcloud.org/documents/73991-day-three-documents",
"https://www.documentcloud.org/documents/5766398-ASRS-Reports-for-737-max8.html#document/p2/a486265",
"https://embed.documentcloud.org/documents/5766398-ASRS-Reports-for-737-max8",
"https://www.documentcloud.org/documents/5766398-ASRS-Reports-for-737-max8/pages/2.html",
"https://www.documentcloud.org/documents/7203159-Joaqu%C3%ADn-El-Chapo-Guzm%C3%A1n-Appeal.html",
"https://www.documentcloud.org/documents/7203159-Joaqu%C3%ADn-El-Chapo-Guzm%C3%A1n-Appeal",
"https://embed.documentcloud.org/documents/7203159-Joaqu%C3%ADn-El-Chapo-Guzm%C3%A1n-Appeal/?embed=1",
"https://www.documentcloud.org/documents/7203159-Joaqu%C3%ADn-El-Chapo-Guzm%C3%A1n-Appeal/pages/2.html",
"https://www.documentcloud.org/documents/20059068-the-mueller-report#document/p17/a2001254",
"https://www.documentcloud.org/documents/20059068-the-mueller-report",
{
noFeeds: true
}
]
};