/**
- * Plugin that automatically truncates the plain text contents of an element and adds an ellipsis
+ * Plugin that automatically truncates the plain text contents of an element
+ * and adds an ellipsis.
*/
( function ( $ ) {
var
// Cache ellipsed substrings for every string-width-position combination
- cache = { },
+ cache = {},
// Use a separate cache when match highlighting is enabled
- matchTextCache = { };
+ matchTextCache = {};
$.fn.autoEllipsis = function ( options ) {
options = $.extend( {
hasSpan: false,
matchText: null
}, options );
- $(this).each( function () {
- var $container, $trimmableText,
+
+ return this.each( function () {
+ var $trimmableText,
text, trimmableText, w, pw,
l, r, i, side, m,
- $el = $(this);
+ // container element - used for measuring against
+ $container = $(this);
+
if ( options.restoreText ) {
- if ( !$el.data( 'autoEllipsis.originalText' ) ) {
- $el.data( 'autoEllipsis.originalText', $el.text() );
+ if ( !$container.data( 'autoEllipsis.originalText' ) ) {
+ $container.data( 'autoEllipsis.originalText', $container.text() );
} else {
- $el.text( $el.data( 'autoEllipsis.originalText' ) );
+ $container.text( $container.data( 'autoEllipsis.originalText' ) );
}
}
- // container element - used for measuring against
- $container = $el;
-
// trimmable text element - only the text within this element will be trimmed
if ( options.hasSpan ) {
- $trimmableText = $el.children( options.selector );
+ $trimmableText = $container.children( options.selector );
} else {
$trimmableText = $( '<span>' )
.css( 'whiteSpace', 'nowrap' )
- .text( $el.text() );
- $el
+ .text( $container.text() );
+ $container
.empty()
.append( $trimmableText );
}
var jqXhr = $(this).data( 'request' );
// If the delay setting has caused the fetch to have not even happened
// yet, the jqXHR object will have never been set.
- if ( jqXhr && $.isFunction ( jqXhr.abort ) ) {
+ if ( jqXhr && $.isFunction( jqXhr.abort ) ) {
jqXhr.abort();
$(this).removeData( 'request' );
}
.append(
$( '<div>' )
.addClass( 'special-label' )
- .text( mw.msg( 'searchsuggest-containing' ) )
- )
- .append(
+ .text( mw.msg( 'searchsuggest-containing' ) ),
$( '<div>' )
.addClass( 'special-query' )
.text( query )
.show();
} else {
$el.find( '.special-query' )
- .empty()
.text( query )
.autoEllipsis();
}