FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript-code/object-oriented/Introduction/Library.js at master · sunjun81/javascript-code · GitHub
sunjun81
javascript-code
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript-code
/
object-oriented
/
Introduction
/
Library.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
167 lines (152 loc) · 4.4 KB
Breadcrumbs
javascript-code
/
object-oriented
/
Introduction
/
Library.js
Copy path
File metadata and controls
167 lines (152 loc) · 4.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* Reference Article: http://www.dustindiaz.com/top-ten-javascript/ */
/* addEvent: simplified event attachment */
function
addEvent
(
obj
,
type
,
fn
)
{
if
(
obj
.
addEventListener
)
{
obj
.
addEventListener
(
type
,
fn
,
false
)
;
EventCache
.
add
(
obj
,
type
,
fn
)
;
}
else
if
(
obj
.
attachEvent
)
{
obj
[
"e"
+
type
+
fn
]
=
fn
;
obj
[
type
+
fn
]
=
function
(
)
{
obj
[
"e"
+
type
+
fn
]
(
window
.
event
)
;
}
obj
.
attachEvent
(
"on"
+
type
,
obj
[
type
+
fn
]
)
;
EventCache
.
add
(
obj
,
type
,
fn
)
;
}
else
{
obj
[
"on"
+
type
]
=
obj
[
"e"
+
type
+
fn
]
;
}
}
var
EventCache
=
function
(
)
{
var
listEvents
=
[
]
;
return
{
listEvents
:
listEvents
,
add
:
function
(
node
,
sEventName
,
fHandler
)
{
listEvents
.
push
(
arguments
)
;
}
,
flush
:
function
(
)
{
var
i
,
item
;
for
(
i
=
listEvents
.
length
-
1
;
i
>=
0
;
i
=
i
-
1
)
{
item
=
listEvents
[
i
]
;
if
(
item
[
0
]
.
removeEventListener
)
{
item
[
0
]
.
removeEventListener
(
item
[
1
]
,
item
[
2
]
,
item
[
3
]
)
;
}
;
if
(
item
[
1
]
.
substring
(
0
,
2
)
!=
"on"
)
{
item
[
1
]
=
"on"
+
item
[
1
]
;
}
;
if
(
item
[
0
]
.
detachEvent
)
{
item
[
0
]
.
detachEvent
(
item
[
1
]
,
item
[
2
]
)
;
}
;
item
[
0
]
[
item
[
1
]
]
=
null
;
}
;
}
}
;
}
(
)
;
addEvent
(
window
,
'unload'
,
EventCache
.
flush
)
;
/* window 'load' attachment */
function
addLoadEvent
(
func
)
{
var
oldonload
=
window
.
onload
;
if
(
typeof
window
.
onload
!=
'function'
)
{
window
.
onload
=
func
;
}
else
{
window
.
onload
=
function
(
)
{
oldonload
(
)
;
func
(
)
;
}
}
}
/* grab Elements from the DOM by className */
function
getElementsByClass
(
searchClass
,
node
,
tag
)
{
var
classElements
=
new
Array
(
)
;
if
(
node
==
null
)
node
=
document
;
if
(
tag
==
null
)
tag
=
'*'
;
var
els
=
node
.
getElementsByTagName
(
tag
)
;
var
elsLen
=
els
.
length
;
var
pattern
=
new
RegExp
(
"(^|\\s)"
+
searchClass
+
"(\\s|$)"
)
;
for
(
i
=
0
,
j
=
0
;
i
<
elsLen
;
i
++
)
{
if
(
pattern
.
test
(
els
[
i
]
.
className
)
)
{
classElements
[
j
]
=
els
[
i
]
;
j
++
;
}
}
return
classElements
;
}
/* insert an element after a particular node */
function
insertAfter
(
parent
,
node
,
referenceNode
)
{
parent
.
insertBefore
(
node
,
referenceNode
.
nextSibling
)
;
}
/* get, set, and delete cookies */
function
getCookie
(
name
)
{
var
start
=
document
.
cookie
.
indexOf
(
name
+
"="
)
;
var
len
=
start
+
name
.
length
+
1
;
if
(
(
!
start
)
&&
(
name
!=
document
.
cookie
.
substring
(
0
,
name
.
length
)
)
)
{
return
null
;
}
if
(
start
==
-
1
)
return
null
;
var
end
=
document
.
cookie
.
indexOf
(
";"
,
len
)
;
if
(
end
==
-
1
)
end
=
document
.
cookie
.
length
;
return
unescape
(
document
.
cookie
.
substring
(
len
,
end
)
)
;
}
function
setCookie
(
name
,
value
,
expires
,
path
,
domain
,
secure
)
{
var
today
=
new
Date
(
)
;
today
.
setTime
(
today
.
getTime
(
)
)
;
if
(
expires
)
{
expires
=
expires
*
1000
*
60
*
60
*
24
;
}
var
expires_date
=
new
Date
(
today
.
getTime
(
)
+
(
expires
)
)
;
document
.
cookie
=
name
+
"="
+
escape
(
value
)
+
(
(
expires
)
?
";expires="
+
expires_date
.
toGMTString
(
)
:
""
)
+
(
(
path
)
?
";path="
+
path
:
""
)
+
(
(
domain
)
?
";domain="
+
domain
:
""
)
+
(
(
secure
)
?
";secure"
:
""
)
;
}
function
deleteCookie
(
name
,
path
,
domain
)
{
if
(
getCookie
(
name
)
)
document
.
cookie
=
name
+
"="
+
(
(
path
)
?
";path="
+
path
:
""
)
+
(
(
domain
)
?
";domain="
+
domain
:
""
)
+
";expires=Thu, 01-Jan-1970 00:00:01 GMT"
;
}
/* quick getElement reference */
function
$
(
)
{
var
elements
=
new
Array
(
)
;
for
(
var
i
=
0
;
i
<
arguments
.
length
;
i
++
)
{
var
element
=
arguments
[
i
]
;
if
(
typeof
element
==
'string'
)
element
=
document
.
getElementById
(
element
)
;
if
(
arguments
.
length
==
1
)
return
element
;
elements
.
push
(
element
)
;
}
return
elements
;
}
/* Object-oriented Helper functions. */
function
clone
(
object
)
{
function
F
(
)
{
}
F
.
prototype
=
object
;
return
new
F
;
}
function
extend
(
subClass
,
superClass
)
{
var
F
=
function
(
)
{
}
;
F
.
prototype
=
superClass
.
prototype
;
subClass
.
prototype
=
new
F
(
)
;
subClass
.
prototype
.
constructor
=
subClass
;
subClass
.
superclass
=
superClass
.
prototype
;
if
(
superClass
.
prototype
.
constructor
==
Object
.
prototype
.
constructor
)
{
superClass
.
prototype
.
constructor
=
superClass
;
}
}
function
augment
(
receivingClass
,
givingClass
)
{
if
(
arguments
[
2
]
)
{
// Only give certain methods.
for
(
var
i
=
2
,
len
=
arguments
.
length
;
i
<
len
;
i
++
)
{
receivingClass
.
prototype
[
arguments
[
i
]
]
=
givingClass
.
prototype
[
arguments
[
i
]
]
;
}
}
else
{
// Give all methods.
for
(
methodName
in
givingClass
.
prototype
)
{
if
(
!
receivingClass
.
prototype
[
methodName
]
)
{
receivingClass
.
prototype
[
methodName
]
=
givingClass
.
prototype
[
methodName
]
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL