Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
141 lines (112 loc) · 2.63 KB
/
Copy pathutils.js
File metadata and controls
141 lines (112 loc) · 2.63 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function byId(elementId) {
return document.getElementById(elementId);
}
function isIE() {
return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
function isFF() {
return /firefox/i.test(navigator.userAgent);
}
function isChrome() {
return /chrom/i.test(navigator.userAgent);
}
function addEvent(obj, evType, fn, useCapture){
if (obj.addEventListener){
obj.addEventListener(evType, fn, useCapture);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
}
}
function mixin(dest,src) {
for (var p in src) {
dest[p]=src[p];
}
return dest;
}
var bind;
if (Function.prototype.bind) {
bind=function(theThis,f) {
return Function.prototype.bind.call(f,theThis);
};
} else {
bind=function(theThis,f) {
return function() {
return f.apply(theThis,[].slice.apply(arguments));
}
};
}
function newEle(tagname,text,className,id) {
var ele=document.createElement(tagname);
if (typeof text!='undefined') {
ele.appendChild(document.createTextNode(text));
}
if (id) {
ele.id=id;
}
if (className) {
ele.className=className;
}
return ele;
}
Array.prototype.each=function(f) {
for(var i=0;i<this.length;i++) {
f(this[i],i);
}
}
Array.prototype.find=function(f) {
for(var i=0;i<this.length;i++) {
if (f(this[i],i)) return this[i];
}
return null;
}
function Class(body,inherit) {
var thisClass=function() {
this.thisClass=thisClass;
this.inheritFrom=inherit;
if (this.init) {
this.init.apply(this,[].slice.apply(arguments));
}
};
if (inherit) {
inherit.reverse().each(function(i) {
mixin(thisClass.prototype,i.prototype);
});
}
mixin(thisClass.prototype,body);
return thisClass;
}
var trimRE=/^\s*(.*?)\s*$/;
function trim(s) {
return trimRE.exec(s)[1];
}
var isArray= Array.isArray || function(a) {
return (a && Object.prototype.toString.call(a) === '[object Array]');
}
function isFunc(f) {
return (f && Object.prototype.toString.call(f) === '[object Function]');
}
function zeroPad(s,l) {
while (s.length < 4) {
s='0' + s;
}
return s;
}
function getFromUrl(url,cb,errCb) {
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function() {
if (xhr.readyState==4) {
if (xhr.status==200) {
if (cb) cb(xhr.responseText);
} else {
if (errCb) errCb(xhr.responseText);
}
}
};
xhr.open('GET',url,true);
xhr.send();
}
function text2html(text) {
return text.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/\n/g,'<br/>');
}