Skip to content

Commit 81717f6

Browse files
committed
Random shits
1 parent bef4df7 commit 81717f6

File tree

12 files changed

+1401
-3
lines changed

12 files changed

+1401
-3
lines changed

.flowconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[ignore]
2+
3+
[include]
4+
5+
[libs]
6+
7+
[options]

assets/maps/DOM.js.map

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

assets/maps/index.js.map

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

dist/DOM.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
(function (global, factory) {
2+
if (typeof define === "function" && define.amd) {
3+
define(['exports', './assert'], factory);
4+
} else if (typeof exports !== "undefined") {
5+
factory(exports, require('./assert'));
6+
} else {
7+
var mod = {
8+
exports: {}
9+
};
10+
factory(mod.exports, global.assert);
11+
global.DOM = mod.exports;
12+
}
13+
})(this, function (exports, _assert) {
14+
'use strict';
15+
'use babel';
16+
17+
Object.defineProperty(exports, "__esModule", {
18+
value: true
19+
});
20+
exports.properties = undefined;
21+
exports.prepend = prepend;
22+
exports.append = append;
23+
exports.insert = insert;
24+
exports.insertAt = insertAt;
25+
exports.insertChild = insertChild;
26+
var properties = exports.properties = ['append', 'prepend', 'insert'];
27+
28+
/**
29+
* Insert an element as a first child among
30+
* the caller's children
31+
*
32+
* @method prepend
33+
* @param {string | HTMLElement} el Element to be inserted
34+
* @return {HTMLElement} Inserted element
35+
*/
36+
37+
function prepend(el) {
38+
return insertAt(this, (0, _assert.assertElement)(el), 'first');
39+
}
40+
41+
/**
42+
* Insert an element as a last child among
43+
* the calling element's children
44+
*
45+
* @method prepend
46+
* @param {string | HTMLElement} el Element to be inserted
47+
* @return {HTMLElement} Appended element
48+
*/
49+
50+
function append(el) {
51+
el = (0, _assert.assertElement)(el);
52+
if (this !== window && this !== insert) return insertAt(this, (0, _assert.assertElement)(el));
53+
return null;
54+
}
55+
56+
function insert(el, index) {
57+
el = (0, _assert.assertElement)(el);
58+
if (this !== window && this !== insert) return insertAt(this, (0, _assert.assertElement)(el), index);
59+
return null;
60+
}
61+
62+
/**
63+
* Insert an element as a child to the calling element
64+
*
65+
* @method prepend
66+
* @param {string | HTMLElement} el Element to be inserted
67+
* @param {string} pos Position into which the element is inserted;
68+
* first to insert as a first child,
69+
* last to insert as a last child.
70+
* If an instance of HTMLElement is given,
71+
* the element is inserted after the given element.
72+
* @return {HTMLElement} Inserted element
73+
*/
74+
75+
function insertAt(parent, el) {
76+
var pos = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'last';
77+
78+
79+
var DOM_INSERT_MAP = {
80+
'first': 'afterBegin',
81+
'last': 'beforeEnd'
82+
};
83+
// Reassign the arguments if this function is
84+
// is called from within any HTMLElement
85+
86+
if (this !== window && this !== insertAt) {
87+
pos = el;
88+
el = parent;
89+
parent = this;
90+
}
91+
el = (0, _assert.assertElement)(el);
92+
if (!el || !parent) return null;
93+
94+
var insertionPt = (0, _assert.isNumber)(pos) ? parent.children.item(pos) : typeof pos === 'string' ? DOM_INSERT_MAP[pos.toString()] || 0 : 0;
95+
96+
if (pos === 'last') return parent.appendChild(el);
97+
98+
if ((0, _assert.isElement)(el) || (0, _assert.isNumber)(el) || (0, _assert.isHTMLTag)(el)) return insertChild(parent, el, pos);
99+
100+
if (typeof insertionPt === 'string')
101+
// TODO: Polyfill this
102+
parent.insertAdjacentElement(insertionPt, el);
103+
104+
return el;
105+
}
106+
107+
function insertChild(parent, el) {
108+
var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
109+
110+
111+
// Reassign the arguments if this function is
112+
// is called from within any HTMLElement
113+
if (this !== window && this !== insertChild) {
114+
index = el;
115+
el = parent;
116+
parent = this;
117+
}
118+
119+
el = (0, _assert.assertElement)(el);
120+
121+
if (typeof index === 'number') {
122+
var _parent = parent,
123+
children = _parent.children,
124+
childElementCount = _parent.childElementCount;
125+
126+
if (index >= childElementCount) return parent.appendChild(el);
127+
128+
return parent.insertBefore(el, children.item(index));
129+
}
130+
131+
return parent.insertBefore(el, index);
132+
}
133+
});

dist/assert.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
(function (global, factory) {
2+
if (typeof define === "function" && define.amd) {
3+
define(['exports', 'babel-runtime/helpers/typeof'], factory);
4+
} else if (typeof exports !== "undefined") {
5+
factory(exports, require('babel-runtime/helpers/typeof'));
6+
} else {
7+
var mod = {
8+
exports: {}
9+
};
10+
factory(mod.exports, global._typeof);
11+
global.assert = mod.exports;
12+
}
13+
})(this, function (exports, _typeof2) {
14+
'use strict';
15+
'use babel';
16+
17+
Object.defineProperty(exports, "__esModule", {
18+
value: true
19+
});
20+
exports.isHTMLTag = exports.isNumber = exports.isElement = undefined;
21+
exports.assertElement = assertElement;
22+
23+
var _typeof3 = _interopRequireDefault(_typeof2);
24+
25+
function _interopRequireDefault(obj) {
26+
return obj && obj.__esModule ? obj : {
27+
default: obj
28+
};
29+
}
30+
31+
var isElement = exports.isElement = function isElement(o) {
32+
return (typeof o === 'undefined' ? 'undefined' : (0, _typeof3.default)(o)) === 'object' && o.tagName;
33+
};
34+
35+
var isNumber = exports.isNumber = function isNumber(o) {
36+
return typeof o === 'number';
37+
};
38+
39+
// TODO: Check the given object is within the valid tag names
40+
var isHTMLTag = exports.isHTMLTag = function isHTMLTag(o) {
41+
return typeof o === 'string';
42+
};
43+
44+
function assertElement(el) {
45+
46+
el = this !== window && this !== assertElement ? this : el;
47+
48+
return isElement(el) ? el : isHTMLTag(el) ? document.createElement(el) : null;
49+
}
50+
});

dist/className.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
(function (global, factory) {
2+
if (typeof define === "function" && define.amd) {
3+
define(['exports', 'babel-runtime/core-js/get-iterator', 'babel-runtime/helpers/toConsumableArray'], factory);
4+
} else if (typeof exports !== "undefined") {
5+
factory(exports, require('babel-runtime/core-js/get-iterator'), require('babel-runtime/helpers/toConsumableArray'));
6+
} else {
7+
var mod = {
8+
exports: {}
9+
};
10+
factory(mod.exports, global.getIterator, global.toConsumableArray);
11+
global.className = mod.exports;
12+
}
13+
})(this, function (exports, _getIterator2, _toConsumableArray2) {
14+
'use strict';
15+
'use babel';
16+
17+
Object.defineProperty(exports, "__esModule", {
18+
value: true
19+
});
20+
exports.properties = undefined;
21+
exports.getClassList = getClassList;
22+
exports.toggleClass = toggleClass;
23+
exports.addClass = addClass;
24+
exports.removeClass = removeClass;
25+
exports.hasClass = hasClass;
26+
exports.hasClasses = hasClasses;
27+
exports.toggleItems = toggleItems;
28+
29+
var _getIterator3 = _interopRequireDefault(_getIterator2);
30+
31+
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
32+
33+
function _interopRequireDefault(obj) {
34+
return obj && obj.__esModule ? obj : {
35+
default: obj
36+
};
37+
}
38+
39+
var properties = exports.properties = ['toggleClass', 'addClass', 'removeClass', 'hasClass', 'hasClasses', 'getClassList'];
40+
41+
function getClassList() {
42+
return this.classList || (this.getAttribute('class') || '').split(/\s/) || [];
43+
}
44+
45+
function toggleClass() {
46+
var list = getClassList.call(this);
47+
48+
for (var _len = arguments.length, cls = Array(_len), _key = 0; _key < _len; _key++) {
49+
cls[_key] = arguments[_key];
50+
}
51+
52+
this.setAttribute('class', toggleItems.apply(undefined, [list || []].concat(cls)).join(' '));
53+
return this;
54+
}
55+
56+
function addClass() {
57+
var _getClassList$call;
58+
59+
(_getClassList$call = getClassList.call(this)).add.apply(_getClassList$call, arguments);
60+
return this;
61+
}
62+
63+
function removeClass() {
64+
var _getClassList$call2;
65+
66+
(_getClassList$call2 = getClassList.call(this)).remove.apply(_getClassList$call2, arguments);
67+
return this;
68+
}
69+
70+
function hasClass(value) {
71+
return hasClasses.call(this, value);
72+
}
73+
74+
function hasClasses() {
75+
var classList = [].concat((0, _toConsumableArray3.default)(getClassList.call(this)));
76+
77+
for (var _len2 = arguments.length, value = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
78+
value[_key2] = arguments[_key2];
79+
}
80+
81+
var has = value.reduce(function (res, current) {
82+
return res && classList.indexOf(current) > -1;
83+
}, true);
84+
return has;
85+
}
86+
87+
function toggleItems(list) {
88+
var copy = [].concat((0, _toConsumableArray3.default)(list));
89+
90+
for (var _len3 = arguments.length, items = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
91+
items[_key3 - 1] = arguments[_key3];
92+
}
93+
94+
var _iteratorNormalCompletion = true;
95+
var _didIteratorError = false;
96+
var _iteratorError = undefined;
97+
98+
try {
99+
var _loop = function _loop() {
100+
var item = _step.value;
101+
102+
var index = copy.findIndex(function (o) {
103+
return o === item;
104+
});
105+
var arg = index === -1 ? [0, 0, item] : [index, 1];
106+
copy.splice.apply(copy, arg);
107+
};
108+
109+
for (var _iterator = (0, _getIterator3.default)(items), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
110+
_loop();
111+
}
112+
} catch (err) {
113+
_didIteratorError = true;
114+
_iteratorError = err;
115+
} finally {
116+
try {
117+
if (!_iteratorNormalCompletion && _iterator.return) {
118+
_iterator.return();
119+
}
120+
} finally {
121+
if (_didIteratorError) {
122+
throw _iteratorError;
123+
}
124+
}
125+
}
126+
127+
return copy;
128+
}
129+
});

0 commit comments

Comments
 (0)