138 | | river.active = true; |
139 | | waiting.show(); |
140 | | |
141 | | wpLink.linkAJAX( t, { page : river.page }, function(r) { |
142 | | river.page++; |
143 | | river.active = false; |
144 | | river.allLoaded = !r; |
145 | | waiting.hide(); |
146 | | }, true); |
| 140 | setTimeout(function() { |
| 141 | var newTop = t.scrollTop(), |
| 142 | newBottom = newTop + t.height(), |
| 143 | waiting = t.find('.river-waiting'); |
| 144 | |
| 145 | if ( bottom != newBottom || newBottom != ul.height() || river.active || river.allLoaded ) |
| 146 | return; |
| 147 | |
| 148 | river.active = true; |
| 149 | waiting.show(); |
| 150 | t.scrollTop( newTop + waiting.outerHeight() ); |
| 151 | |
| 152 | wpLink.linkAJAX( t, { page : river.page }, function(r) { |
| 153 | river.page++; |
| 154 | river.active = false; |
| 155 | river.allLoaded = !r; |
| 156 | waiting.hide(); |
| 157 | }, { |
| 158 | append : true, |
| 159 | delay : wpLink.minRiverAJAXDuration |
| 160 | }); |
| 161 | }, wpLink.timeToTriggerRiver ); |
182 | | }, params ), function( results ) { |
183 | | var list = ''; |
184 | | |
185 | | if ( !results ) { |
186 | | if ( !append ) { |
187 | | list += '<li class="no-matches-found unselectable"><span class="item-title"><em>' |
188 | | + wpLinkL10n.noMatchesFound |
189 | | + '</em></span></li>'; |
190 | | } |
191 | | } else { |
192 | | $.each( results, function() { |
193 | | list += '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />'; |
194 | | list += '<span class="item-title">'; |
195 | | list += this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>'; |
196 | | list += '</span><span class="item-info">' + this['info'] + '</span></li>'; |
197 | | }); |
| 203 | }, params ), response, "json" ); |
| 204 | }, |
| 205 | |
| 206 | processAJAXResponse: function( $panel, results, callback, opts ) { |
| 207 | var list = ''; |
| 208 | |
| 209 | if ( !results ) { |
| 210 | if ( !opts.append ) { |
| 211 | list += '<li class="no-matches-found unselectable"><span class="item-title"><em>' |
| 212 | + wpLinkL10n.noMatchesFound |
| 213 | + '</em></span></li>'; |
199 | | |
200 | | // Set results |
201 | | $panel.children('ul')[ append ? 'append' : 'html' ]( list ); |
202 | | |
203 | | // Run callback |
204 | | if ( callback ) |
205 | | callback( results ); |
206 | | }, "json" ); |
| 215 | } else { |
| 216 | $.each( results, function() { |
| 217 | list += '<li><input type="hidden" class="item-permalink" value="' + this['permalink'] + '" />'; |
| 218 | list += '<span class="item-title">'; |
| 219 | list += this['title'] ? this['title'] : '<em>'+ wpLinkL10n.untitled + '</em>'; |
| 220 | list += '</span><span class="item-info">' + this['info'] + '</span></li>'; |
| 221 | }); |
| 222 | } |
| 223 | |
| 224 | // Set results |
| 225 | $panel.children('ul')[ opts.append ? 'append' : 'html' ]( list ); |
| 226 | |
| 227 | // Run callback |
| 228 | if ( callback ) |
| 229 | callback( results ); |
| 230 | }, |
| 231 | |
| 232 | delayedCallback : function( func, delay ) { |
| 233 | var timeoutTriggered, funcTriggered, funcArgs, funcContext; |
| 234 | |
| 235 | if ( ! delay ) |
| 236 | return func; |
| 237 | |
| 238 | setTimeout( function() { |
| 239 | if ( funcTriggered ) |
| 240 | return func.apply( funcContext, funcArgs ); |
| 241 | // Otherwise, wait. |
| 242 | timeoutTriggered = true; |
| 243 | }, delay); |
| 244 | |
| 245 | return function() { |
| 246 | if ( timeoutTriggered ) |
| 247 | return func.apply( this, arguments ); |
| 248 | // Otherwise, wait. |
| 249 | funcArgs = arguments; |
| 250 | funcContext = this; |
| 251 | funcTriggered = true; |
| 252 | }; |