-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathparser.js
More file actions
74 lines (51 loc) · 1.77 KB
/
parser.js
File metadata and controls
74 lines (51 loc) · 1.77 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
import { createElement } from "./helper.js";
const video_support = {};
const tpl_video = /** @type {HTMLVideoElement} */ (createElement("video"));
/**
*
* @param {HTMLAnchorElement} anchor
* @param {number} size
* @param options
* @param {string} media
* @returns {string}
*/
export default function(anchor, size, options, media){
let src, diff;
if(media !== "node"){
const keys = Object.keys(/** @type {!Object} */ (options));
for(let x = 0, key; x < keys.length; x++){
key = keys[x];
if((key.length > 3) && (key.indexOf("src") === 0)){
if(media === "video"){
const cache = video_support[key];
if(cache){
if(cache > 0){
src = options[key];
break;
}
}
else if(tpl_video.canPlayType("video/" + key.substring(3).replace("-", "").toLowerCase())){
video_support[key] = 1;
src = options[key];
break;
}
else{
video_support[key] = -1;
}
}
else{
// Image Media:
const res = parseInt(key.substring(4), 10);
if(res){
const abs = Math.abs(size - res);
if(!diff || (abs < diff)){
diff = abs;
src = options[key];
}
}
}
}
}
}
return src || options["src"] || options["href"] || anchor["src"] || anchor["href"];
}