| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602 | /*	 *	jQuery dotdotdot 1.5.9 *	 *	Copyright (c) 2013 Fred Heusschen *	www.frebsite.nl * *	Plugin website: *	dotdotdot.frebsite.nl * *	Dual licensed under the MIT and GPL licenses. *	http://en.wikipedia.org/wiki/MIT_License *	http://en.wikipedia.org/wiki/GNU_General_Public_License */(function( $ ){	if ( $.fn.dotdotdot )	{		return;	}	$.fn.dotdotdot = function( o )	{		if ( this.length == 0 )		{			if ( !o || o.debug !== false )			{				debug( true, 'No element found for "' + this.selector + '".' );							}			return this;		}		if ( this.length > 1 )		{			return this.each(				function()				{					$(this).dotdotdot( o );				}			);		}		var $dot = this;		if ( $dot.data( 'dotdotdot' ) )		{			$dot.trigger( 'destroy.dot' );		}		$dot.data( 'dotdotdot-style', $dot.attr( 'style' ) );		$dot.css( 'word-wrap', 'break-word' );		$dot.bind_events = function()		{			$dot.bind(				'update.dot',				function( e, c )				{					e.preventDefault();					e.stopPropagation();					opts.maxHeight = ( typeof opts.height == 'number' ) 						? opts.height 						: getTrueInnerHeight( $dot );					opts.maxHeight += opts.tolerance;					if ( typeof c != 'undefined' )					{						if ( typeof c == 'string' || c instanceof HTMLElement )						{					 		c = $('<div />').append( c ).contents();						}						if ( c instanceof $ )						{							orgContent = c;						}					}					$inr = $dot.wrapInner( '<div class="dotdotdot" />' ).children();					$inr.empty()						.append( orgContent.clone( true ) )						.css({							'height'	: 'auto',							'width'		: 'auto',							'border'	: 'none',							'padding'	: 0,							'margin'	: 0						});					var after = false,						trunc = false;					if ( conf.afterElement )					{						after = conf.afterElement.clone( true );						conf.afterElement.remove();					}					if ( test( $inr, opts ) )					{						if ( opts.wrap == 'children' )						{							trunc = children( $inr, opts, after );						}						else						{							trunc = ellipsis( $inr, $dot, $inr, opts, after );						}					}					$inr.replaceWith( $inr.contents() );					$inr = null;										if ( $.isFunction( opts.callback ) )					{						opts.callback.call( $dot[ 0 ], trunc, orgContent );					}					conf.isTruncated = trunc;					return trunc;				}			).bind(				'isTruncated.dot',				function( e, fn )				{					e.preventDefault();					e.stopPropagation();					if ( typeof fn == 'function' )					{						fn.call( $dot[ 0 ], conf.isTruncated );					}					return conf.isTruncated;				}			).bind(				'originalContent.dot',				function( e, fn )				{					e.preventDefault();					e.stopPropagation();					if ( typeof fn == 'function' )					{						fn.call( $dot[ 0 ], orgContent );					}					return orgContent;				}			).bind(				'destroy.dot',				function( e )				{					e.preventDefault();					e.stopPropagation();					$dot.unwatch()						.unbind_events()						.empty()						.append( orgContent )						.attr( 'style', $dot.data( 'dotdotdot-style' ) )						.data( 'dotdotdot', false );				}			);			return $dot;		};	//	/bind_events		$dot.unbind_events = function()		{			$dot.unbind('.dot');			return $dot;		};	//	/unbind_events		$dot.watch = function()		{			$dot.unwatch();			if ( opts.watch == 'window' )			{				var $window = $(window),					_wWidth = $window.width(),					_wHeight = $window.height(); 				$window.bind(					'resize.dot' + conf.dotId,					function()					{						if ( _wWidth != $window.width() || _wHeight != $window.height() || !opts.windowResizeFix )						{							_wWidth = $window.width();							_wHeight = $window.height();								if ( watchInt )							{								clearInterval( watchInt );							}							watchInt = setTimeout(								function()								{									$dot.trigger( 'update.dot' );								}, 10							);						}					}				);			}			else			{				watchOrg = getSizes( $dot );				watchInt = setInterval(					function()					{						var watchNew = getSizes( $dot );						if ( watchOrg.width  != watchNew.width ||							 watchOrg.height != watchNew.height )						{							$dot.trigger( 'update.dot' );							watchOrg = getSizes( $dot );						}					}, 100				);			}			return $dot;		};		$dot.unwatch = function()		{			$(window).unbind( 'resize.dot' + conf.dotId );			if ( watchInt )			{				clearInterval( watchInt );			}			return $dot;		};		var	orgContent	= $dot.contents(),			opts 		= $.extend( true, {}, $.fn.dotdotdot.defaults, o ),			conf		= {},			watchOrg	= {},			watchInt	= null,			$inr		= null;		conf.afterElement	= getElement( opts.after, $dot );		conf.isTruncated	= false;		conf.dotId			= dotId++;		$dot.data( 'dotdotdot', true )			.bind_events()			.trigger( 'update.dot' );		if ( opts.watch )		{			$dot.watch();		}		return $dot;	};	//	public	$.fn.dotdotdot.defaults = {		'ellipsis'	: '... ',		'wrap'		: 'word',		'lastCharacter': {			'remove'		: [ ' ', ',', ';', '.', '!', '?' ],			'noEllipsis'	: []		},		'tolerance'	: 0,		'callback'	: null,		'after'		: null,		'height'	: null,		'watch'		: false,		'windowResizeFix': true,		'debug'		: false	};		//	private	var dotId = 1;	function children( $elem, o, after )	{		var $elements 	= $elem.children(),			isTruncated	= false;		$elem.empty();		for ( var a = 0, l = $elements.length; a < l; a++ )		{			var $e = $elements.eq( a );			$elem.append( $e );			if ( after )			{				$elem.append( after );			}			if ( test( $elem, o ) )			{				$e.remove();				isTruncated = true;				break;			}			else			{				if ( after )				{					after.remove();				}			}		}		return isTruncated;	}	function ellipsis( $elem, $d, $i, o, after )	{		var $elements 	= $elem.contents(),			isTruncated	= false;		$elem.empty();		var notx = 'table, thead, tbody, tfoot, tr, col, colgroup, object, embed, param, ol, ul, dl, select, optgroup, option, textarea, script, style';		for ( var a = 0, l = $elements.length; a < l; a++ )		{			if ( isTruncated )			{				break;			}			var e	= $elements[ a ],				$e	= $(e);			if ( typeof e == 'undefined' )			{				continue;			}			$elem.append( $e );			if ( after )			{				$elem[ ( $elem.is( notx ) ) ? 'after' : 'append' ]( after );			}			if ( e.nodeType == 3 )			{				if ( test( $i, o ) )				{					isTruncated = ellipsisElement( $e, $d, $i, o, after );				}			}			else			{				isTruncated = ellipsis( $e, $d, $i, o, after );			}			if ( !isTruncated )			{				if ( after )				{					after.remove();				}			}		}		return isTruncated;	}	function ellipsisElement( $e, $d, $i, o, after )	{		var isTruncated	= false,			e = $e[ 0 ];		if ( typeof e == 'undefined' )		{			return false;		}		var seporator	= ( o.wrap == 'letter' ) ? '' : ' ',			textArr		= getTextContent( e ).split( seporator ),			position 	= -1,			midPos		= -1,			startPos	= 0,			endPos		= textArr.length - 1;		while ( startPos <= endPos )		{			var m = Math.floor( ( startPos + endPos ) / 2 );			if ( m == midPos ) 			{				break;			}			midPos = m;			setTextContent( e, textArr.slice( 0, midPos + 1 ).join( seporator ) + o.ellipsis );			if ( !test( $i, o ) )			{				position = midPos;				startPos = midPos; 			}			else			{				endPos = midPos;			}						}				if ( position != -1 && !( textArr.length == 1 && textArr[ 0 ].length == 0 ) )		{			var txt = addEllipsis( textArr.slice( 0, position + 1 ).join( seporator ), o );			isTruncated = true;			setTextContent( e, txt );		}		else		{			var $w = $e.parent();			$e.remove();			var afterLength = ( after ) ? after.length : 0 ;			if ( $w.contents().size() > afterLength )			{				var $n = $w.contents().eq( -1 - afterLength );				isTruncated = ellipsisElement( $n, $d, $i, o, after );			}			else			{				var $p = $w.prev()				var e = $p.contents().eq( -1 )[ 0 ];				if ( typeof e != 'undefined' )				{					var txt = addEllipsis( getTextContent( e ), o );					setTextContent( e, txt );					if ( after )					{						$p.append( after );					}					$w.remove();					isTruncated = true;				}			}		}		return isTruncated;	}	function test( $i, o )	{		return $i.innerHeight() > o.maxHeight;	}	function addEllipsis( txt, o )	{		while( $.inArray( txt.slice( -1 ), o.lastCharacter.remove ) > -1 )		{			txt = txt.slice( 0, -1 );		}		if ( $.inArray( txt.slice( -1 ), o.lastCharacter.noEllipsis ) < 0 )		{			txt += o.ellipsis;		}		return txt;	}	function getSizes( $d )	{		return {			'width'	: $d.innerWidth(),			'height': $d.innerHeight()		};	}	function setTextContent( e, content )	{		if ( e.innerText )		{			e.innerText = content;		}		else if ( e.nodeValue )		{			e.nodeValue = content;		}		else if (e.textContent)		{			e.textContent = content;		}	}	function getTextContent( e )	{		if ( e.innerText )		{			return e.innerText;		}		else if ( e.nodeValue )		{			return e.nodeValue;		}		else if ( e.textContent )		{			return e.textContent;		}		else		{			return "";		}	}	function getElement( e, $i )	{		if ( typeof e == 'undefined' )		{			return false;		}		if ( !e )		{			return false;		}		if ( typeof e == 'string' )		{			e = $(e, $i);			return ( e.length )				? e 				: false;		}		if ( typeof e == 'object' )		{			return ( typeof e.jquery == 'undefined' )				? false				: e;		}		return false;	}	function getTrueInnerHeight( $el )	{		var h = $el.innerHeight(),			a = [ 'paddingTop', 'paddingBottom' ];		for ( var z = 0, l = a.length; z < l; z++ ) {			var m = parseInt( $el.css( a[ z ] ), 10 );			if ( isNaN( m ) )			{				m = 0;			}			h -= m;		}		return h;	}	function debug( d, m )	{		if ( !d )		{			return false;		}		if ( typeof m == 'string' )		{			m = 'dotdotdot: ' + m;		}		else		{			m = [ 'dotdotdot:', m ];		}		if ( typeof window.console != 'undefined' )		{			if ( typeof window.console.log != 'undefined' )			{				window.console.log( m );			}		}		return false;	}		//	override jQuery.html	var _orgHtml = $.fn.html;    $.fn.html = function( str ) {		if ( typeof str != 'undefined' )		{			if ( this.data( 'dotdotdot' ) )			{				if ( typeof str != 'function' )				{					return this.trigger( 'update', [ str ] );				}			}			return _orgHtml.call( this, str );		}		return _orgHtml.call( this );    };	//	override jQuery.text	var _orgText = $.fn.text;    $.fn.text = function( str ) {		if ( typeof str != 'undefined' )		{			if ( this.data( 'dotdotdot' ) )			{				var temp = $( '<div />' );				temp.text( str );				str = temp.html();				temp.remove();				return this.trigger( 'update', [ str ] );			}			return _orgText.call( this, str );		}        return _orgText.call( this );    };})( jQuery );
 |