Merge "Fixed dependencies for jquery.collapsibleTabs"
[lhc/web/wiklou.git] / resources / jquery / jquery.autoEllipsis.js
index 23ba074..49a932a 100644 (file)
@@ -1,12 +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 ( $ ) {
 
-// Cache ellipsed substrings for every string-width-position combination
-var cache = { };
-// Use a separate cache when match highlighting is enabled
-var matchTextCache = { };
+var
+       // Cache ellipsed substrings for every string-width-position combination
+       cache = {},
+
+       // Use a separate cache when match highlighting is enabled
+       matchTextCache = {};
 
 $.fn.autoEllipsis = function ( options ) {
        options = $.extend( {
@@ -16,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,
-                       $el = $(this);
+                       l, r, i, side, m,
+                       // 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 );
                }
@@ -90,7 +93,7 @@ $.fn.autoEllipsis = function ( options ) {
                                        l = 0;
                                        r = trimmableText.length;
                                        do {
-                                               var m = Math.ceil( ( l + r ) / 2 );
+                                               m = Math.ceil( ( l + r ) / 2 );
                                                $trimmableText.text( trimmableText.substr( 0, m ) + '...' );
                                                if ( $trimmableText.width() + pw > w ) {
                                                        // Text is too long