Guest User

Untitled

a guest
Jan 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. (function ( ElementProto ) {
  2.  
  3. if ( typeof ElementProto.matches !== 'function' ) {
  4.  
  5. ElementProto.matches = ElementProto.msMatchesSelector || ElementProto.mozMatchesSelector || ElementProto.webkitMatchesSelector || function matches( selector ) {
  6.  
  7. var element = this,
  8. elements = ( element.document || element.ownerDocument ).querySelectorAll( selector ),
  9. index = 0;
  10.  
  11. while ( elements[index] && elements[index] !== element ) {
  12. ++index;
  13. }
  14.  
  15. return Boolean( elements[index] );
  16. };
  17.  
  18. }
  19.  
  20. if ( typeof ElementProto.closest !== 'function' ) {
  21.  
  22. ElementProto.closest = function closest( selector ) {
  23.  
  24. var element = this;
  25.  
  26. while ( element && element.nodeType === 1 ) {
  27.  
  28. if ( element.matches( selector ) ) return element;
  29.  
  30. element = element.parentNode;
  31.  
  32. }
  33.  
  34. return null;
  35.  
  36. };
  37.  
  38. }
  39.  
  40. })( window.Element.prototype );
Add Comment
Please, Sign In to add comment