Index: trunk/phase3/resources/jquery/jquery.autoEllipsis.js |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | */ |
5 | 5 | ( function( $ ) { |
6 | 6 | |
7 | | -// Cache ellipsed substrings for every string-width combination |
| 7 | +// Cache ellipsed substrings for every string-width-position combination |
8 | 8 | var cache = { }; |
9 | 9 | // Use a seperate cache when match highlighting is enabled |
10 | 10 | var matchTextCache = { }; |
— | — | @@ -49,29 +49,40 @@ |
50 | 50 | var w = $container.width(); |
51 | 51 | var pw = $protectedText ? $protectedText.width() : 0; |
52 | 52 | // Try cache |
53 | | - if ( !( text in cache ) ) { |
54 | | - cache[text] = {}; |
55 | | - } |
56 | | - if ( options.matchText && !( text in matchTextCache ) ) { |
57 | | - matchTextCache[text] = {}; |
58 | | - } |
59 | | - if ( options.matchText && !( options.matchText in matchTextCache[text] ) ) { |
60 | | - matchTextCache[text][options.matchText] = {}; |
61 | | - } |
62 | | - if ( !options.matchText && w in cache[text] ) { |
63 | | - $container.html( cache[text][w] ); |
64 | | - if ( options.tooltip ) { |
65 | | - $container.attr( 'title', text ); |
| 53 | + if ( options.matchText ) { |
| 54 | + if ( !( text in matchTextCache ) ) { |
| 55 | + matchTextCache[text] = {}; |
66 | 56 | } |
67 | | - return; |
68 | | - } |
69 | | - if( options.matchText && options.matchText in matchTextCache[text] && w in matchTextCache[text][options.matchText] ) { |
70 | | - $container.html( matchTextCache[text][options.matchText][w] ); |
71 | | - if ( options.tooltip ) { |
72 | | - $container.attr( 'title', text ); |
| 57 | + if ( !( options.matchText in matchTextCache[text] ) ) { |
| 58 | + matchTextCache[text][options.matchText] = {}; |
73 | 59 | } |
74 | | - return; |
| 60 | + if ( !( w in matchTextCache[text][options.matchText] ) ) { |
| 61 | + matchTextCache[text][options.matchText][w] = {}; |
| 62 | + } |
| 63 | + if ( options.position in matchTextCache[text][options.matchText][w] ) { |
| 64 | + $container.html( matchTextCache[text][options.matchText][w][options.position] ); |
| 65 | + if ( options.tooltip ) { |
| 66 | + $container.attr( 'title', text ); |
| 67 | + } |
| 68 | + return; |
| 69 | + } |
| 70 | + } else { |
| 71 | + if ( !( text in cache ) ) { |
| 72 | + cache[text] = {}; |
| 73 | + } |
| 74 | + if ( !( w in cache[text] ) ) { |
| 75 | + cache[text][w] = {}; |
| 76 | + } |
| 77 | + if ( options.position in cache[text][w] ) { |
| 78 | + $container.html( cache[text][w][options.position] ); |
| 79 | + if ( options.tooltip ) { |
| 80 | + $container.attr( 'title', text ); |
| 81 | + } |
| 82 | + console.log("YAY CACHE HIT"); |
| 83 | + return; |
| 84 | + } |
75 | 85 | } |
| 86 | + |
76 | 87 | if ( $trimmableText.width() + pw > w ) { |
77 | 88 | switch ( options.position ) { |
78 | 89 | case 'right': |
— | — | @@ -122,9 +133,9 @@ |
123 | 134 | } |
124 | 135 | if ( options.matchText ) { |
125 | 136 | $container.highlightText( options.matchText ); |
126 | | - matchTextCache[text][options.matchText][w] = $container.html(); |
| 137 | + matchTextCache[text][options.matchText][w][options.position] = $container.html(); |
127 | 138 | } else { |
128 | | - cache[text][w] = $container.html(); |
| 139 | + cache[text][w][options.position] = $container.html(); |
129 | 140 | } |
130 | 141 | |
131 | 142 | } ); |