Permalink
Browse files

Merge pull request #28 from WickyNilliams/master

Add support for match -> unmatch transition, fix for #27
  • Loading branch information...
2 parents 5e557c9 + d003d45 commit 6b26010adb298aca718b0912b1452ea7e502b871 Scott Jehl committed Jan 14, 2013
Showing with 7 additions and 3 deletions.
  1. +7 −3 matchMedia.addListener.js
View
@@ -10,8 +10,12 @@
last = false,
timer,
check = function(){
- var list = oldMM( q );
- if( list.matches && !last ){
+ var list = oldMM( q ),
+ unmatchToMatch = list.matches && !last,
+ matchToUnmatch = !list.matches && last;
+
+ //fire callbacks only if transitioning to or from matched state
+ if( unmatchToMatch || matchToUnmatch ){
for( var i =0, il = listeners.length; i< il; i++ ){
listeners[ i ].call( ret, list );
}
@@ -40,4 +44,4 @@
return ret;
};
}
-}());
+}());

0 comments on commit 6b26010

Please sign in to comment.