forked from ISIA-DASHR/DASHR-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
80 lines (71 loc) · 2.06 KB
/
utils.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
define(function() {
var clone = function clone(src) {
function mixin(dest, source, copyFunc) {
var name, s, i, empty = {};
for(name in source){
// the (!(name in empty) || empty[name] !== s) condition avoids copying properties in "source"
// inherited from Object.prototype. For example, if dest has a custom toString() method,
// don't overwrite it with the toString() method that source inherited from Object.prototype
s = source[name];
if(!(name in dest) || (dest[name] !== s && (!(name in empty) || empty[name] !== s))){
dest[name] = copyFunc ? copyFunc(s) : s;
}
}
return dest;
}
if(!src || typeof src != "object" || Object.prototype.toString.call(src) === "[object Function]"){
// null, undefined, any non-object, or function
return src; // anything
}
if(src.nodeType && "cloneNode" in src){
// DOM Node
return src.cloneNode(true); // Node
}
if(src instanceof Date){
// Date
return new Date(src.getTime()); // Date
}
if(src instanceof RegExp){
// RegExp
return new RegExp(src); // RegExp
}
var r, i, l;
if(src instanceof Array){
// array
r = [];
for(i = 0, l = src.length; i < l; ++i){
if(i in src){
r.push(clone(src[i]));
}
}
// we don't clone functions for performance reasons
// }else if(d.isFunction(src)){
// // function
// r = function(){ return src.apply(this, arguments); };
}else{
// generic objects
r = src.constructor ? new src.constructor() : {};
}
return mixin(r, src, clone);
};
var mr = function(start,end)
{
return 'bytes='+start+'-'+end;
};
var absolutizeURL = function(base, target)
{
if (target.match(/^[a-z]*:\/\//)) return target;
var rel_url;
if (target[0] == '/') {
target = target.slice(1, target.length);
}
i = base.lastIndexOf('/');
if(i+1<= base.length)
{
rel_url = base.slice(0,i+1);
}
console.log(rel_url + target);
return rel_url + target;
}
return { make_range : mr, absURL : absolutizeURL, clone : clone };
} );