Trying to duplicate the jQuery toggle()
function but to use table-row
instead of block
as the display
value.
I took the existing functions and added a jQuery.fn.extend()
as defined below Note: I left showHideRow
unmodified from the showHide
for the test to ensure it would work as toggle()
works now
<script src="/includes/js/jquery.min.js"></script>
<script type="text/javascript">
jQuery.fn.extend( {
showHideRow: function( elements, show ) {
var display, elem,
values = [],
index = 0,
length = elements.length;
// Determine new display value for elements that need to change
for ( ; index < length; index++ ) {
elem = elements[ index ];
if ( !elem.style ) {
continue;
}
display = elem.style.display;
if ( show ) {
// Since we force visibility upon cascade-hidden elements, an immediate (and slow)
// check is required in this first loop unless we have a nonempty display value (either
// inline or about-to-be-restored)
if ( display === "none" ) {
values[ index ] = dataPriv.get( elem, "display" ) || null;
if ( !values[ index ] ) {
elem.style.display = "";
}
}
if ( elem.style.display === "" && isHiddenWithinTree( elem ) ) {
values[ index ] = getDefaultDisplay( elem );
}
} else {
if ( display !== "none" ) {
values[ index ] = "none";
// Remember what we're overwriting
dataPriv.set( elem, "display", display );
}
}
}
// Set the display of the elements in a second loop to avoid constant reflow
for ( index = 0; index < length; index++ ) {
if ( values[ index ] != null ) {
elements[ index ].style.display = values[ index ];
}
}
return elements;
},
showRow: function() {
return showHideRow( this, true );
},
hideRow: function() {
return showHideRow( this );
},
toggleRow: function( state ) {
if ( typeof state === "boolean" ) {
return state ? this.showRow() : this.hideRow();
}
return this.each( function() {
if ( isHiddenWithinTree( this ) ) {
jQuery( this ).showRow();
} else {
jQuery( this ).hideRow();
}
} );
}
} );
jQuery(function($) {
$('.expandChildTable').on('click', function() {
$(this).toggleClass('selected').closest('tr').next().toggleRow();
})
});
</script>
The error received was: Uncaught ReferenceError: isHiddenWithinTree is not defined?
I noticed I was using the .min version and though that must be it, so I redid things using the .min version as below (*Note: On this one I setup the correct display
value to be table-row
:
<script src="/includes/js/jquery.min.js"></script>
<script type="text/javascript">
jQuery.fn.extend( {
showHideRow: function( e, t ) {
for(var n,r,i,o,a,s,u,l=[],c=0,f=e.length;c<f;c++)(r=e[c]).style&&(n=r.style.display,t?("none"===n&&(l[c]=_.get(r,"display")||null,l[c]||(r.style.display="")),""===r.style.display&&ee(r)&&(l[c]=(u=a=o=void 0,a=(i=r).ownerDocument,s=i.nodeName,(u=ne[s])||(o=a.body.appendChild(a.createElement(s)),u=ce.css(o,"display"),o.parentNode.removeChild(o),"none"===u&&(u="table-row"),ne[s]=u)))):"none"!==n&&(l[c]="none",_.set(r,"display",n)));for(c=0;c<f;c++)null!=l[c]&&(e[c].style.display=l[c]);return e
},
showRow: function() {
return showHideRow( this, true );
},
hideRow: function() {
return showHideRow( this );
},
toggleRow:function(e){
return"boolean"==typeof e?e?this.showRow():this.hideRow():this.each(function(){ee(this)?ce(this).showRow():ce(this).hideRow()})
}
});
jQuery(function($) {
$('.expandChildTable').on('click', function() {
$(this).toggleClass('selected').closest('tr').next().toggleRow();
})
});
</script>
However I still get: Uncaught ReferenceError: ee is not defined
Help!! Why can’t it call those functions since jQuery is already loaded and my new functions are in the jQuery extension?
TIA!!