Skip to content
This repository was archived by the owner on Aug 21, 2022. It is now read-only.

Commit c6c187f

Browse files
committed
build 0.7.0
1 parent 89423b9 commit c6c187f

12 files changed

+276
-798
lines changed

dev/jscore-ie10.js

Lines changed: 48 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* jsCore JavaScript library v0.6.1 IE10+
1+
/* jsCore JavaScript library v0.7.0 IE10+
22
* © 2014 Dmitry Korobkin
33
* Released under the MIT license
44
* github.com/Octane/jsCore
@@ -159,7 +159,7 @@ if (!Array.prototype.contains) {
159159
}
160160
return false;
161161
}
162-
return -1 != this.indexOf(anything, position);
162+
return -1 != Array.prototype.indexOf.call(this, anything, position);
163163
};
164164
}
165165

@@ -1043,138 +1043,52 @@ Object.defineProperty(HTMLElement.prototype, 'dataset', {
10431043

10441044
};
10451045

1046-
//DOM4 w3c.github.io/dom
1047-
'append' in document.createDocumentFragment() || new function () {
1046+
document.documentElement.matches || new function () {
10481047

1049-
var ELEMENT_NODE = 1,
1050-
proto = HTMLElement.prototype,
1051-
api = {
1052-
1053-
before: function (/* ...nodes */) {
1054-
//todo IE8 removedNode.parentNode ≠ null
1055-
var parentNode = this.parentNode;
1056-
if (parentNode) {
1057-
parentNode.insertBefore(mutationMacro(arguments), this);
1058-
}
1059-
},
1060-
1061-
after: function (/* ...nodes */) {
1062-
var parentNode = this.parentNode,
1063-
nextSibling,
1064-
nodes;
1065-
if (parentNode) {
1066-
nodes = mutationMacro(arguments);
1067-
nextSibling = this.nextSibling;
1068-
if (nextSibling) {
1069-
parentNode.insertBefore(nodes, nextSibling);
1070-
} else {
1071-
parentNode.appendChild(nodes);
1072-
}
1073-
}
1074-
},
1075-
1076-
replace: function (/* ...nodes */) {
1077-
var parentNode = this.parentNode;
1078-
if (parentNode) {
1079-
parentNode.replaceChild(mutationMacro(arguments), this);
1080-
}
1081-
},
1082-
1083-
remove: function () {
1084-
var parentNode = this.parentNode;
1085-
if (parentNode) {
1086-
parentNode.removeChild(this);
1087-
}
1088-
},
1089-
1090-
append: function (/* ...nodes */) {
1091-
this.appendChild(mutationMacro(arguments));
1092-
},
1048+
var proto = HTMLElement.prototype;
10931049

1094-
prepend: function () {
1095-
this.insertBefore(mutationMacro(arguments), this.firstChild);
1096-
},
1050+
proto.matches = [
1051+
proto.matchesSelector,
1052+
proto.oMatchesSelector,
1053+
proto.msMatchesSelector,
1054+
proto.mozMatchesSelector,
1055+
proto.webkitMatchesSelector
1056+
].find(Boolean);
10971057

1098-
querySelector: proto.querySelector,
1099-
1100-
querySelectorAll: proto.querySelectorAll,
1101-
1102-
matches: [
1103-
proto.matchesSelector,
1104-
proto.oMatchesSelector,
1105-
proto.msMatchesSelector,
1106-
proto.mozMatchesSelector,
1107-
proto.webkitMatchesSelector,
1108-
function (selector) {
1109-
var contains,
1110-
root;
1111-
if (this === document) {
1112-
//if docFragment.constructor ≡ document.constructor
1113-
return false;
1114-
}
1058+
if (!proto.matches) {
1059+
proto.matches = new function () {
1060+
var ELEMENT_NODE = 1;
1061+
function isContains(root, element, selector) {
1062+
return Array.contains(root.querySelectorAll(selector), element);
1063+
}
1064+
return function (selector) {
1065+
var contains,
11151066
root = this.parentNode;
1116-
if (root) {
1117-
if (ELEMENT_NODE == root.nodeType) {
1118-
root = root.ownerDocument;
1119-
}
1120-
return isContains(root, this, selector);
1067+
if (root) {
1068+
if (ELEMENT_NODE == root.nodeType) {
1069+
root = root.ownerDocument;
11211070
}
1122-
root = document.createDocumentFragment();
1123-
root.appendChild(this);
1124-
contains = isContains(root, this, selector);
1125-
root.removeChild(this);
1071+
return isContains(root, this, selector);
11261072
}
1127-
].find(Boolean)
1128-
1073+
root = document.createDocumentFragment();
1074+
root.appendChild(this);
1075+
contains = isContains(root, this, selector);
1076+
root.removeChild(this);
1077+
};
11291078
};
1130-
1131-
function isContains(root, element, selector) {
1132-
return -1 != Array.indexOf(root.querySelectorAll(selector), element);
11331079
}
11341080

1135-
function mutationMacro(nodes) {
1136-
var node,
1137-
fragment,
1138-
length = nodes.length,
1139-
i;
1140-
if (1 == length) {
1141-
node = nodes[0];
1142-
if ('string' == typeof node) {
1143-
return document.createTextNode(node);
1144-
}
1145-
return node;
1146-
}
1147-
fragment = document.createDocumentFragment();
1148-
nodes = Array.from(nodes);
1149-
i = 0;
1150-
while (i < length) {
1151-
node = nodes[i];
1152-
if ('string' == typeof node) {
1153-
node = document.createTextNode(node);
1154-
}
1155-
fragment.appendChild(node);
1156-
i++;
1157-
}
1158-
return fragment;
1159-
}
1160-
1161-
function implement(key) {
1162-
if (!(key in proto)) {
1163-
proto[key] = api[key];
1164-
}
1165-
}
1166-
1167-
Object.keys(api).forEach(implement);
1081+
};
11681082

1169-
proto = document.constructor.prototype;
1170-
['querySelector', 'querySelectorAll'].forEach(implement);
1083+
new function () {
11711084

1172-
proto = document.createDocumentFragment().constructor.prototype;
1173-
[
1174-
'append', 'prepend',
1175-
'querySelector', 'querySelectorAll',
1176-
'matches'
1177-
].forEach(implement);
1085+
var docFragment = document.createDocumentFragment(),
1086+
target = docFragment.constructor.prototype,
1087+
source = HTMLElement.prototype;
1088+
if (!docFragment.querySelector) {
1089+
target.querySelector = source.querySelector;
1090+
target.querySelectorAll = source.querySelectorAll;
1091+
}
11781092

11791093
};
11801094

@@ -1332,26 +1246,24 @@ lib.html = {
13321246

13331247
};
13341248

1335-
//example: new lib.Template('Hi, {NAME}').match({name: 'John'}) → 'Hi, John'
1249+
//example: var tmpl = new lib.Template('Hi, {NAME}');
1250+
// tmpl({name: 'John'}) → 'Hi, John'
13361251
lib.Template = new function () {
13371252

1338-
function Template(template) {
1339-
this.template = template;
1340-
}
1341-
1342-
Template.match = function (template, replacements) {
1343-
if (Array.isArray(template)) {
1344-
template = template.join('');
1345-
}
1253+
function match(template, replacements) {
13461254
return Object.keys(replacements).reduceRight(function (template, key) {
13471255
var value = replacements[key];
13481256
return template.split('{' + key.toUpperCase() + '}').join(value);
13491257
}, template);
1350-
};
1258+
}
13511259

1352-
Template.prototype.match = function (replacements) {
1353-
return Template.match(this.template, replacements);
1354-
};
1260+
function Template(template) {
1261+
return function (replacements) {
1262+
return match(template, replacements)
1263+
};
1264+
}
1265+
1266+
Template.match = match;
13551267

13561268
return Template;
13571269

0 commit comments

Comments
 (0)