Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
drop IE8 and IE9 support; v2.0.0
Browse files Browse the repository at this point in the history
+ remove component.json
  • Loading branch information
desandro committed Dec 28, 2015
1 parent 2d7702e commit 7582db4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 86 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Install with [Bower](http://bower.io): `bower install matches-selector`

Install with [Component](https://github.com/component/component): `component install desandro/matches-selector`

## Browser support

IE10+, all modern browsers

Use [matchesSelector v1](https://github.com/desandro/matches-selector/releases/tag/v1.0.3) for IE8 and IE9 support.

## MIT license

matchesSelector is released under the [MIT license](http://desandro.mit-license.org)
3 changes: 1 addition & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "matches-selector",
"version": "1.0.3",
"version": "2.0.0",
"description": "matches/matchesSelector helper",
"main": "matches-selector.js",
"devDependencies": {
Expand Down Expand Up @@ -28,7 +28,6 @@
"test",
"tests",
"tests.*",
"component.json",
"package.json"
]
}
8 changes: 0 additions & 8 deletions component.json

This file was deleted.

96 changes: 21 additions & 75 deletions matches-selector.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
/**
* matchesSelector v1.0.3
* matchesSelector v2.0.0
* matchesSelector( element, '.selector' )
* MIT license
*/

/*jshint browser: true, strict: true, undef: true, unused: true */
/*global define: false, module: false */

( function( ElemProto ) {
( function( window, factory ) {
/*global define: false, module: false */
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( factory() );
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory();
} else {
// browser global
window.matchesSelector = factory();
}

}( window, function factory() {
'use strict';

var matchesMethod = ( function() {
var ElemProto = Element.prototype;
// check for the standard method name first
if ( ElemProto.matches ) {
return 'matches';
Expand All @@ -23,7 +37,7 @@
// check vendor prefixes
var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];

for ( var i=0, len = prefixes.length; i < len; i++ ) {
for ( var i=0; i < prefixes.length; i++ ) {
var prefix = prefixes[i];
var method = prefix + 'MatchesSelector';
if ( ElemProto[ method ] ) {
Expand All @@ -32,76 +46,8 @@
}
})();

// ----- match ----- //

function match( elem, selector ) {
return function matchesSelector( elem, selector ) {
return elem[ matchesMethod ]( selector );
}

// ----- appendToFragment ----- //

function checkParent( elem ) {
// not needed if already has parent
if ( elem.parentNode ) {
return;
}
var fragment = document.createDocumentFragment();
fragment.appendChild( elem );
}

// ----- query ----- //

// fall back to using QSA
// thx @jonathantneal https://gist.github.com/3062955
function query( elem, selector ) {
// append to fragment if no parent
checkParent( elem );

// match elem with all selected elems of parent
var elems = elem.parentNode.querySelectorAll( selector );
for ( var i=0, len = elems.length; i < len; i++ ) {
// return true if match
if ( elems[i] === elem ) {
return true;
}
}
// otherwise return false
return false;
}

// ----- matchChild ----- //

function matchChild( elem, selector ) {
checkParent( elem );
return match( elem, selector );
}

// ----- matchesSelector ----- //

var matchesSelector;

if ( matchesMethod ) {
// IE9 supports matchesSelector, but doesn't work on orphaned elems
// check for that
var div = document.createElement('div');
var supportsOrphans = match( div, 'div' );
matchesSelector = supportsOrphans ? match : matchChild;
} else {
matchesSelector = query;
}

// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( function() {
return matchesSelector;
});
} else if ( typeof exports === 'object' ) {
module.exports = matchesSelector;
}
else {
// browser global
window.matchesSelector = matchesSelector;
}
};

})( Element.prototype );
}));
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "desandro-matches-selector",
"version": "1.0.3",
"version": "2.0.0",
"description": "matches/matchesSelector helper",
"main": "matches-selector.js",
"scripts": {
Expand Down

0 comments on commit 7582db4

Please sign in to comment.