1
|
|
|
// var HomeMessage = function (name, success, error) { |
2
|
|
|
// this.name = name; |
3
|
|
|
// this.success = success; |
4
|
|
|
// this.error = error; |
5
|
|
|
// |
6
|
|
|
// this.create = function (data) { |
7
|
|
|
// restSubmit(this.name, 'GET', data, this.success, this.error); |
8
|
|
|
// } |
9
|
|
|
// |
10
|
|
|
// }; |
11
|
|
|
|
12
|
|
|
// example: element('body').first(). |
13
|
|
|
|
14
|
|
View Code Duplication |
var E = function (selector, area, error, success) { |
|
|
|
|
15
|
|
|
this.cfg = {}; |
16
|
|
|
this.cfg.area = document; |
17
|
|
|
this.cfg.selector = selector; |
18
|
|
|
this.cfg.exist = false; |
19
|
|
|
|
20
|
|
|
this.success = function (elem) { |
21
|
|
|
console.log("Element elem: ", elem); |
|
|
|
|
22
|
|
|
}; |
23
|
|
|
|
24
|
|
|
this.error = function (elem) { |
25
|
|
|
console.error("! Element elem: ", elem); |
26
|
|
|
}; |
27
|
|
|
|
28
|
|
|
if (typeof success === 'function') { |
29
|
|
|
this.success = success; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
if (typeof error === 'function') { |
33
|
|
|
this.error = error; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
var self = this; |
38
|
|
|
|
39
|
|
|
this.selector = function (selector) { |
40
|
|
|
self.cfg.selector = selector; |
41
|
|
|
return this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
this.first = function (error, success) { |
45
|
|
|
if (typeof success !== 'function') { |
46
|
|
|
success = self.success; |
47
|
|
|
} |
48
|
|
|
if (typeof error !== 'function') { |
49
|
|
|
error = self.error; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
const elem = document.querySelector(self.cfg.selector); |
53
|
|
|
|
54
|
|
|
console.log('E first self.cfg.selector', self.cfg.selector); |
|
|
|
|
55
|
|
|
console.log('E first elem', elem); |
56
|
|
|
|
57
|
|
|
if (elem !== null) { |
58
|
|
|
self.cfg.exist = true; |
59
|
|
|
success(elem); |
60
|
|
|
return elem; |
61
|
|
|
} else { |
|
|
|
|
62
|
|
|
self.cfg.exist = false; |
63
|
|
|
error(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return elem; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
this.all = function (error, success) { |
70
|
|
|
if (typeof success !== 'function') { |
71
|
|
|
success = self.success; |
72
|
|
|
} |
73
|
|
|
if (typeof error !== 'function') { |
74
|
|
|
error = self.error; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
const elem = document.querySelectorAll(self.cfg.selector); |
78
|
|
|
|
79
|
|
|
console.log('E all self.cfg.selector', self.cfg.selector); |
|
|
|
|
80
|
|
|
console.log('E all elem', elem); |
81
|
|
|
|
82
|
|
|
if (elem !== null) { |
83
|
|
|
self.cfg.exist = true; |
84
|
|
|
success(elem); |
85
|
|
|
} else { |
86
|
|
|
self.cfg.exist = false; |
87
|
|
|
error(elem); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return elem; |
91
|
|
|
} |
92
|
|
|
}; |
93
|
|
|
|
94
|
|
|
// |
95
|
|
|
// function getElement(id) { |
96
|
|
|
// if (document.getElementById) { |
97
|
|
|
// return document.getElementById(id); |
98
|
|
|
// } else if (document.all) { |
99
|
|
|
// return window.document.all[id]; |
100
|
|
|
// } else if (document.layers) { |
101
|
|
|
// return window.document.layers[id]; |
102
|
|
|
// } |
103
|
|
|
// } |
104
|
|
|
// |
105
|
|
|
// function getElement() { |
106
|
|
|
// const element = document.querySelector("#box"); |
107
|
|
|
// |
108
|
|
|
// element.classList.contains("highlighted"); |
109
|
|
|
// |
110
|
|
|
// return element; |
111
|
|
|
// } |
112
|
|
|
// |
113
|
|
|
// |
114
|
|
|
// function getElement() { |
115
|
|
|
// const element = document.querySelector("#box"); |
116
|
|
|
// |
117
|
|
|
// element.classList.contains("highlighted"); |
118
|
|
|
// |
119
|
|
|
// return element; |
120
|
|
|
// } |
121
|
|
|
|