|
23 | 23 | previewTimeout, |
24 | 24 | previewContainer = $('<div id="topic_preview" class="topic_preview_container"></div>').css('width', settings.width).appendTo('body'); |
25 | 25 |
|
26 | | - // Do not allow delay times less than 300ms to prevent tooltip madness |
| 26 | + // Do not allow delay times less than 300 ms to prevent tooltip madness |
27 | 27 | settings.delay = Math.max(settings.delay, 300); |
28 | 28 |
|
29 | 29 | $('.topic_preview_avatar') |
30 | 30 | // Add rtl class for right-to-left languages to avatar images |
31 | 31 | .toggleClass('rtl', (settings.dir === 'rtl')) |
32 | 32 | .children('img') |
33 | | - .brokenImage({ replacement: settings.noavatar }) |
| 33 | + .brokenImage({}) |
34 | 34 | ; |
35 | 35 |
|
36 | 36 | // Display the topic preview tooltip |
|
67 | 67 | // Pointer offset |
68 | 68 | var pointerOffset = 8; |
69 | 69 |
|
70 | | - // Window bottom edge detection, invert topic preview if needed |
| 70 | + // Window bottom-edge detection, invert topic preview if needed |
71 | 71 | var previewTop = obj.offset().top + settings.position.top, |
72 | 72 | previewBottom = previewTop + previewContainer.height() + pointerOffset; |
73 | 73 | previewContainer.toggleClass('invert', edgeDetect(previewBottom)); |
|
112 | 112 | obj.restoreTitles('dt').restoreTitles('dl'); // reinstate original title attributes |
113 | 113 | }; |
114 | 114 |
|
115 | | - // Check if y coordinate is within 50 pixels of bottom edge of browser window |
| 115 | + // Check if y coordinate is within 50 pixels of the bottom edge of a browser window |
116 | 116 | var edgeDetect = function(y) { |
117 | 117 | return (y >= ($(window).scrollTop() + $(window).height() - 50)); |
118 | 118 | }; |
|
122 | 122 | .on('mouseenter', showTopicPreview) |
123 | 123 | .on('mouseleave', hideTopicPreview) |
124 | 124 | .on('click', function() { |
125 | | - // Remove topic preview immediately on click as failsafe |
| 125 | + // Remove the topic preview immediately on click as failsafe |
126 | 126 | previewContainer.hide(); |
127 | 127 | // clear any existing timeouts |
128 | 128 | if (previewTimeout) { |
|
157 | 157 | }); |
158 | 158 |
|
159 | 159 | setTimeout(function() { |
160 | | - var test = new Image(); // Virgin image with no styles to affect dimensions |
161 | | - test.src = image.src; |
162 | | - |
163 | | - if (test.height === 0) { |
| 160 | + // Check if the image failed to load with fallback for older browsers |
| 161 | + var isIncomplete = image.complete !== undefined ? !image.complete : false; |
| 162 | + var hasNoHeight = image.naturalHeight !== undefined ? image.naturalHeight === 0 : image.height === 0; |
| 163 | + if (isIncomplete || hasNoHeight) { |
164 | 164 | insertPlaceholder(); |
165 | 165 | } |
166 | 166 | }, options.timeout); |
167 | 167 |
|
168 | 168 | function insertPlaceholder() { |
169 | | - if (options.replacement) { |
170 | | - image.src = options.replacement; |
171 | | - } else { |
172 | | - $(image).css('visibility', 'hidden'); |
173 | | - } |
| 169 | + $(image).replaceWith('<div class="topic_preview_no_avatar"></div>'); |
174 | 170 | } |
175 | 171 | }); |
176 | 172 | }, |
|
0 commit comments