( function( $ ) { /** jQuery helper functions. */ $.fn.extend( { toggleText : function( a, b ) { return this.text( this.text() === b ? a : b ); }, inViewport : function( curr ) { return this.each( function( idx, elem ) { function visPx() { var elH = $( elem ).outerHeight(), wH = $( window ).height(), rct = elem.getBoundingClientRect(), top = rct.top, bot = rct.bottom; return curr.call( elem, Math.max( 0, top > 0 ? Math.min( elH, wH - top ) : Math.min( bot, wH ) ) ); } visPx(); $( window ).on( 'resize scroll', visPx ); } ); } } ); } ) ( jQuery );