Created
April 7, 2012 01:45
-
-
Save arextar/2324454 to your computer and use it in GitHub Desktop.
adding :visible and :hidden to zepto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function($){ | |
var _is = $.fn.is, _filter = $.fn.filter; | |
function visible(elem){ | |
elem = $(elem); | |
return !!(elem.width() || elem.height()) && elem.css("display") !== "none"; | |
} | |
$.fn.is = function(sel){ | |
if(sel === ":visible"){ | |
return visible(this); | |
} | |
if(sel === ":hidden"){ | |
return !visible(this); | |
} | |
return _is.call(this, sel); | |
} | |
$.fn.filter = function(sel){ | |
if(sel === ":visible"){ | |
return $([].filter.call(this, visible)); | |
} | |
if(sel === ":hidden"){ | |
return $([].filter.call(this, function(elem){ | |
return !visible(elem); | |
})); | |
} | |
return _filter.call(this, sel); | |
} | |
})(Zepto); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment