Skip to content

Instantly share code, notes, and snippets.

@cheeaun
Created March 3, 2009 14:34

Revisions

  1. cheeaun revised this gist Jun 29, 2009. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions Element.isVisibleHidden.js
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,19 @@
    /*
    * Inspired from http://github.com/jeresig/sizzle/commit/7631f9c3f85e5fa72ac51532399cb593c2cdc71f
    * and this http://github.com/jeresig/sizzle/commit/5716360040a440041da19823964f96d025ca734b
    * and then http://dev.jquery.com/ticket/4512
    */

    Element.implement({

    isVisible: function(){
    var w = this.offsetWidth, h = this.offsetHeight;
    return (w===0 && h===0) ? false : (w>0 && h>0) ? true : this.getStyle('display') !== 'none';
    isHidden: function(){
    var w = this.offsetWidth, h = this.offsetHeight,
    force = /^tr$/i.test(this.tagName);
    return (w===0 && h===0 && !force) ? true : (w!==0 && h!==0 && !force) ? false : this.getStyle('display') === 'none';
    },

    isHidden: function(){
    var w = this.offsetWidth, h = this.offsetHeight;
    return (w===0 && h===0) ? true : (w!==0 && h!==0) ? false : this.getStyle('display') === 'none';
    isVisible: function(){
    return !this.isHidden();
    }

    });
  2. cheeaun revised this gist May 18, 2009. 1 changed file with 17 additions and 14 deletions.
    31 changes: 17 additions & 14 deletions Element.isVisibleHidden.js
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,18 @@
    /*
    * Inspired from http://github.com/jeresig/sizzle/commit/7631f9c3f85e5fa72ac51532399cb593c2cdc71f
    */

    Element.implement({

    isVisible: function(){
    return elem.offsetWidth > 0 || elem.offsetHeight > 0;
    },

    isHidden: function(){
    return elem.offsetWidth === 0 || elem.offsetHeight === 0;
    }

    /*
    * Inspired from http://github.com/jeresig/sizzle/commit/7631f9c3f85e5fa72ac51532399cb593c2cdc71f
    * and this http://github.com/jeresig/sizzle/commit/5716360040a440041da19823964f96d025ca734b
    */

    Element.implement({

    isVisible: function(){
    var w = this.offsetWidth, h = this.offsetHeight;
    return (w===0 && h===0) ? false : (w>0 && h>0) ? true : this.getStyle('display') !== 'none';
    },

    isHidden: function(){
    var w = this.offsetWidth, h = this.offsetHeight;
    return (w===0 && h===0) ? true : (w!==0 && h!==0) ? false : this.getStyle('display') === 'none';
    }

    });
  3. cheeaun created this gist Mar 3, 2009.
    15 changes: 15 additions & 0 deletions Element.isVisibleHidden.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    /*
    * Inspired from http://github.com/jeresig/sizzle/commit/7631f9c3f85e5fa72ac51532399cb593c2cdc71f
    */

    Element.implement({

    isVisible: function(){
    return elem.offsetWidth > 0 || elem.offsetHeight > 0;
    },

    isHidden: function(){
    return elem.offsetWidth === 0 || elem.offsetHeight === 0;
    }

    });