X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fjquery%2Fjquery.autoEllipsis.js;h=49a932a1e6a53bb42cac7c44565cfc928bdf4c4e;hb=7af7ba2f05dd802d6ff8615364dd874862ebc4be;hp=04bb301c2334410f814ae8ad4373a8b300b6cfdf;hpb=e9186da841917ec3055dbeb44aacd03d44f33fde;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/jquery/jquery.autoEllipsis.js b/resources/jquery/jquery.autoEllipsis.js index 04bb301c23..49a932a1e6 100644 --- a/resources/jquery/jquery.autoEllipsis.js +++ b/resources/jquery/jquery.autoEllipsis.js @@ -1,14 +1,15 @@ /** - * 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( { @@ -18,30 +19,30 @@ $.fn.autoEllipsis = function ( options ) { 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 = $( '' ) .css( 'whiteSpace', 'nowrap' ) - .text( $el.text() ); - $el + .text( $container.text() ); + $container .empty() .append( $trimmableText ); }