Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Fix issue related to matches and jQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Jan 15, 2014
1 parent 88dc315 commit df3bde2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/wrappers/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
var defineWrapGetter = scope.defineWrapGetter;
var elementFromPoint = scope.elementFromPoint;
var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
var matchesName = scope.matchesName;
var matchesNames = scope.matchesNames;
var mixin = scope.mixin;
var registerWrapper = scope.registerWrapper;
var unwrap = scope.unwrap;
Expand Down Expand Up @@ -221,8 +221,7 @@
'querySelectorAll',
'removeChild',
'replaceChild',
matchesName,
]);
].concat(matchesNames));

forwardMethodsToWrapper([
window.HTMLDocument || window.Document, // Gecko adds these to HTMLDocument
Expand Down
24 changes: 15 additions & 9 deletions src/wrappers/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@

var OriginalElement = window.Element;

var matchesName = oneOf(OriginalElement.prototype, [
'matches',
var matchesNames = [
'matches', // needs to come first.
'mozMatchesSelector',
'msMatchesSelector',
'webkitMatchesSelector',
]);
].filter(function(name) {
return OriginalElement.prototype[name];
});

var matchesName = matchesNames[0];

var originalMatches = OriginalElement.prototype[matchesName];

Expand Down Expand Up @@ -88,11 +92,13 @@
}
});

if (matchesName != "matches") {
Element.prototype[matchesName] = function(selector) {
return this.matches(selector);
};
}
matchesNames.forEach(function(name) {
if (name !== 'matches') {
Element.prototype[name] = function(selector) {
return this.matches(selector);
};
}
});

if (OriginalElement.prototype.webkitCreateShadowRoot) {
Element.prototype.webkitCreateShadowRoot =
Expand Down Expand Up @@ -131,6 +137,6 @@

// TODO(arv): Export setterDirtiesAttribute and apply it to more bindings
// that reflect attributes.
scope.matchesName = matchesName;
scope.matchesNames = matchesNames;
scope.wrappers.Element = Element;
})(window.ShadowDOMPolyfill);

0 comments on commit df3bde2

Please sign in to comment.