More independent.

This commit is contained in:
Hyunje Alex Jun
2015-02-11 15:53:41 +00:00
parent ff5ca3d804
commit 1541f73add
3 changed files with 46 additions and 14 deletions
+24
View File
@@ -49,3 +49,27 @@ exports.css = function (element, styleNameOrObject, styleValue) {
}
}
};
exports.matches = function (element, query) {
if (typeof element.matches !== 'undefined') {
return element.matches(query);
} else {
if (typeof element.matchesSelector !== 'undefined') {
return element.matchesSelector(query);
} else if (element.webkitMatchesSelector !== 'undefined') {
return element.webkitMatchesSelector(query);
} else if (element.mozMatchesSelector !== 'undefined') {
return element.mozMatchesSelector(query);
} else if (element.msMatchesSelector !== 'undefined') {
return element.msMatchesSelector(query);
}
}
};
exports.remove = function (element) {
if (typeof element.remove !== 'undefined') {
element.remove();
} else {
element.parentNode.removeChild(element);
}
};
+9
View File
@@ -3,6 +3,8 @@
*/
'use strict';
var d = require('./dom');
exports.toInt = function (x) {
if (typeof x === 'string') {
return parseInt(x, 10);
@@ -34,3 +36,10 @@ exports.extend = function (original, source) {
}
return result;
};
exports.isEditable = function (el) {
return d.matches(el, "input,[contenteditable]") ||
d.matches(el, "select,[contenteditable]") ||
d.matches(el, "textarea,[contenteditable]") ||
d.matches(el, "button,[contenteditable]");
};