/
check.js
125 lines (120 loc) · 2.88 KB
/
check.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
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
daylight.extend({
/**
* @method
* @name daylight.nodeName
*
* @param {element} Element
* @param {element} compareElement
* @retruns {String|Boolean} element의 노드이름을 보여주거나 2번째 인자가 들어오면 비교해서 같으면 true 틀리면 false를 리턴한다.
* @desc element의 노드이름을 보여주거나 2번째 인자가 들어오면 비교해서 같으면 true 틀리면 false를 리턴한다.
*/
nodeName : function(element, compare) {
var nodeName = element.nodeName;
var type = typeof element;
if(compare !== undefined) {
if(type === "object")//비교 대상이 있으면 비교값을 리턴 true, false;
return nodeName === compare.nodeName;
else
return nodeName === compare;
}
return nodeName;//비교 대상이 없으면 노드 이름만 반환.
},
/**
* @func : daylight.isNode(Node)
* @description : 해당 객체가 Node인지 확인
* @param : Node
* @return : Boolean(노드이면 true 아니면 false)
*/
isNode : function(o) {
if(typeof o !== "object")
return false;
if(o instanceof _Node)
return true;
return false;
},
/**
* @method
* @name daylight.isElement
*
* @description : 해당 객체가 Element인지 확인
* @param : Element
* @return : Boolean(Element이면 true 아니면 false)
*/
/**
* @param {*} All
* @retruns {Boolean} if All is Element, True
* @desc element인지 검사한다.
*/
isElement : function(o) {
if(!o)
return false;
//nodeType 이 1이면 HTMLElement이다.
if(o.nodeType === 1)
return true;
return false;
},
/**
* @method
* @name daylight.isFunction
*
* @param {*} All
* @retruns {Boolean} if All is Function, True
* @desc Function인지 검사한다.
*/
isFunction : function(o) {
return typeof o === "function";
},
/**
* @method
* @name daylight.isPlainObject
*
* @param {*} All
* @retruns {Boolean} if All is PlainObject, True
* @desc PlainObject인지 검사한다.
*/
isPlainObject: function(n) {
if(!n)
return false;
//PlainObject의 생성자는 Object이다???
if(n.constructor === Object)
return true;
},
/**
* @method
* @name daylight.isList
*
* @param {*} obj
* @retruns {Boolean} if obj is List, True
* @desc List인지 검사한다.
*/
isList: function(obj) {
var type = daylight.type(obj);
return this.isListType(type);
},
isListType: function(type) {
return type === "array" || type === "nodelist" || type === "elementlist" || type === "htmlcollection";
},
isDaylight: function(obj) {
var type = _checkType(obj);
return this.isDaylightType(type);
},
isDaylightType: function(type) {
if(type === "daylight")
return true;
if(type === "nodelist")
return true;
if(type === "elementlist")
return true;
if(type === "htmlcollection")
return true;
return false;
}
});
prototype.extend({
nodeName: function() {
return daylight.nodeName(this.get(0));
},
empty: function() {
return (this.length === 0);
}
})