Skip to content

Instantly share code, notes, and snippets.

@arextar
Created April 7, 2012 01:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arextar/2324454 to your computer and use it in GitHub Desktop.
Save arextar/2324454 to your computer and use it in GitHub Desktop.
adding :visible and :hidden to zepto
;(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