Skip to content

Commit f477f40

Browse files
committed
Release: 1.0.0
1 parent be4bbe4 commit f477f40

6 files changed

Lines changed: 255 additions & 139 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# ShortQuery.js [![GitHub version](https://badge.fury.io/gh/S--Minecraft%2FShortQuery.js.svg)](https://badge.fury.io/gh/S--Minecraft%2FShortQuery.js)
22
jsをほぼバニラで使用するためのただのショートハンドの集合体
33

4-
Now only 3306Bytes!
4+
Now only 5352Bytes!
5+
(ChromeVer: 4153Bytes)
56

67
## 対応ブラウザ
78
Edge12~

bin/shortQuery.chrome.js

Lines changed: 86 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
/*!
2-
* ShortQuery.js v0.3.1-chrome MIT License
2+
* ShortQuery.js v1.0.0-chrome MIT License
33
* (C) 2015 S <https://github.com/S--Minecraft>
44
*/
5-
/*
6-
DOM Extention
7-
*/
8-
95
(function() {
6+
/*
7+
DOM Extention
8+
*/
109
var d;
1110

1211
d = Document;
1312

1413
d.prototype.id = d.prototype.getElementById;
1514

16-
d.prototype["class"] = d.prototype.getElementsByClassName;
15+
d.prototype.class = d.prototype.getElementsByClassName;
1716

1817
d.prototype.tag = d.prototype.getElementsByTagName;
1918

@@ -23,7 +22,7 @@
2322

2423
d.prototype.I = d.prototype.id;
2524

26-
d.prototype.C = d.prototype["class"];
25+
d.prototype.C = d.prototype.class;
2726

2827
d.prototype.T = d.prototype.tag;
2928

@@ -41,16 +40,15 @@
4140

4241
}).call(this);
4342

44-
45-
/*
46-
DOM Extention
47-
*/
48-
4943
(function() {
44+
/*
45+
DOM Extention
46+
*/
5047
var d;
5148

5249
d = DocumentFragment;
5350

51+
// child node search
5452
d.prototype.id = d.prototype.getElementById;
5553

5654
d.prototype.query = d.prototype.querySelector;
@@ -63,33 +61,40 @@
6361

6462
d.prototype.$$ = d.prototype.queryAll;
6563

66-
d.prototype.addLast = d.prototype.appendChild;
64+
// add/remove node
65+
d.prototype.addLast = d.prototype.append;
6766

68-
d.prototype.addFirst = function(a) {
69-
return this.insertBefore(a, this.firstChild);
70-
};
67+
d.prototype.addFirst = d.prototype.prepend;
7168

7269
d.prototype.removeChildren = function() {
7370
this.textContent = null;
7471
return this;
7572
};
7673

74+
// get/set family
7775
d.prototype.child = function() {
7876
return this.children;
7977
};
8078

81-
}).call(this);
79+
d.prototype.first = function() {
80+
return this.firstElementChild;
81+
};
8282

83+
d.prototype.last = function() {
84+
return this.lastElementChild;
85+
};
8386

84-
/*
85-
DOM Extention
86-
*/
87+
}).call(this);
8788

8889
(function() {
90+
/*
91+
DOM Extention
92+
*/
8993
var ele;
9094

9195
ele = Element;
9296

97+
// child node search
9398
ele.prototype.childClass = ele.prototype.getElementsByClassName;
9499

95100
ele.prototype.childTag = ele.prototype.getElementsByTagName;
@@ -106,25 +111,21 @@
106111

107112
ele.prototype.$$ = ele.prototype.queryAll;
108113

109-
ele.prototype.addLast = ele.prototype.appendChild;
114+
// add/remove node
115+
ele.prototype.addLast = ele.prototype.append;
110116

111-
ele.prototype.addFirst = function(a) {
112-
return this.insertBefore(a, this.firstChild);
113-
};
117+
ele.prototype.addFirst = ele.prototype.prepend;
114118

115-
ele.prototype.addBefore = function(a) {
116-
return this.parentNode.insertBefore(a, this);
117-
};
119+
ele.prototype.addBefore = ele.prototype.before;
118120

119-
ele.prototype.addAfter = function(a) {
120-
return this.parentNode.insertBefore(a, this.nextSibling);
121-
};
121+
ele.prototype.addAfter = ele.prototype.after;
122122

123123
ele.prototype.removeChildren = function() {
124124
this.textContent = null;
125125
return this;
126126
};
127127

128+
// get/set family
128129
ele.prototype.parent = function() {
129130
return this.parentElement;
130131
};
@@ -141,6 +142,15 @@
141142
return this.nextElementSibling;
142143
};
143144

145+
ele.prototype.first = function() {
146+
return this.firstElementChild;
147+
};
148+
149+
ele.prototype.last = function() {
150+
return this.lastElementChild;
151+
};
152+
153+
// get/set node
144154
ele.prototype.getAttr = ele.prototype.getAttribute;
145155

146156
ele.prototype.setAttr = ele.prototype.setAttribute;
@@ -149,6 +159,8 @@
149159

150160
ele.prototype.rmvAttr = ele.prototype.removeAttr;
151161

162+
ele.prototype.hasAttr = ele.prototype.hasAttribute;
163+
152164
ele.prototype.attr = function(a, b) {
153165
if (b != null) {
154166
return this.setAttr(a, b);
@@ -161,37 +173,48 @@
161173
return this.classList;
162174
};
163175

164-
ele.prototype.setClass = function(a) {
165-
if (Array.isArray(a)) {
166-
this.className = a.join(" ");
167-
return this.classList;
168-
} else if (a != null) {
169-
this.className = a;
170-
return this.classList;
171-
}
176+
ele.prototype.setClass = function(...a) {
177+
this.className = a.join(" ");
178+
return this;
172179
};
173180

174-
ele.prototype["class"] = function(a) {
181+
ele.prototype.class = function(a) {
175182
if (a != null) {
176183
return this.setClass(a);
177184
} else {
178185
return this.getClass();
179186
}
180187
};
181188

182-
ele.prototype.addClass = function(a) {
183-
this.classList.add(a);
184-
return this.classList;
189+
// extention
190+
ele.prototype.addClass = function(...a) {
191+
this.classList.add(...a);
192+
return this;
185193
};
186194

187-
ele.prototype.removeClass = function(a) {
188-
this.classList.remove(a);
189-
return this.classList;
195+
ele.prototype.removeClass = function(...a) {
196+
this.classList.remove(...a);
197+
return this;
190198
};
191199

200+
if (DOMTokenList.prototype.replace != null) {
201+
ele.prototype.replaceClass = function(a, b) {
202+
this.classList.replace(a, b);
203+
return this;
204+
};
205+
} else {
206+
ele.prototype.replaceClass = function(a, b) {
207+
if (this.classList.has(a)) {
208+
this.classList.remove(a);
209+
this.classList.add(b);
210+
}
211+
return this;
212+
};
213+
}
214+
192215
ele.prototype.toggleClass = function(a) {
193216
this.classList.toggle(a);
194-
return this.classList;
217+
return this;
195218
};
196219

197220
ele.prototype.hasClass = function(a) {
@@ -200,12 +223,10 @@
200223

201224
}).call(this);
202225

203-
204-
/*
205-
Event
206-
*/
207-
208226
(function() {
227+
/*
228+
Event
229+
*/
209230
var e;
210231

211232
e = EventTarget;
@@ -221,25 +242,27 @@
221242

222243
exports = this;
223244

245+
// shorthands
224246
d = document;
225247

226-
227-
/*
228-
shortQuery
229-
*/
230-
231248
exports.shortQuery = (function() {
232249
var ctor;
233250

234-
function shortQuery() {
235-
return ctor.apply(this, arguments);
236-
}
251+
/*
252+
shortQuery
253+
*/
254+
class shortQuery {
255+
constructor() {
256+
return ctor.apply(this, arguments);
257+
}
258+
259+
};
237260

238261
ctor = d.querySelectorAll.bind(d);
239262

240263
shortQuery.id = d.getElementById.bind(d);
241264

242-
shortQuery["class"] = d.getElementsByClassName.bind(d);
265+
shortQuery.class = d.getElementsByClassName.bind(d);
243266

244267
shortQuery.tag = d.getElementsByTagName.bind(d);
245268

@@ -249,21 +272,22 @@
249272

250273
shortQuery.I = shortQuery.id;
251274

252-
shortQuery.C = shortQuery["class"];
275+
shortQuery.C = shortQuery.class;
253276

254277
shortQuery.T = shortQuery.tag;
255278

256279
shortQuery.$ = shortQuery.query;
257280

258281
shortQuery.$$ = shortQuery.queryAll;
259282

283+
// create node
260284
shortQuery.create = d.createElement.bind(d);
261285

262286
shortQuery.createFragment = d.createDocumentFragment.bind(d);
263287

264288
return shortQuery;
265289

266-
})();
290+
}).call(this);
267291

268292
exports.$$ = shortQuery;
269293

bin/shortQuery.chrome.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)