lib/assets/javascripts/unpoly/proxy.coffee in unpoly-rails-0.53.1 vs lib/assets/javascripts/unpoly/proxy.coffee in unpoly-rails-0.53.2

- old
+ new

@@ -563,23 +563,28 @@ ### clear = cache.clear up.bus.renamedEvent('up:proxy:received', 'up:proxy:loaded') - checkPreload = ($link) -> + preloadAfterDelay = ($link) -> delay = parseInt(u.presentAttr($link, 'up-delay')) || config.preloadDelay unless $link.is($waitingLink) $waitingLink = $link cancelPreloadDelay() curriedPreload = -> - preload($link) + u.muteRejection preload($link) $waitingLink = null startPreloadDelay(curriedPreload, delay) - + startPreloadDelay = (block, delay) -> preloadDelayTimer = setTimeout(block, delay) + stopPreload = ($link) -> + if $link.is($waitingLink) + $waitingLink = undefined + cancelPreloadDelay() + ###* Preloads the given link. When the link is clicked later, the response will already be cached, making the interaction feel instant. @@ -629,14 +634,18 @@ The number of milliseconds to wait between hovering and preloading. Increasing this will lower the load in your server, but will also make the interaction feel less instant. @stable ### - up.on 'mouseover mousedown touchstart', 'a[up-preload], [up-href][up-preload]', (event, $link) -> - # Don't do anything if we are hovering over the child of a link. - # The actual link will receive the event and bubble in a second. - if up.link.shouldProcessEvent(event, $link) && up.link.isSafe($link) - checkPreload($link) + up.compiler 'a[up-preload], [up-href][up-preload]', ($link) -> + if up.link.isSafe($link) + $link.on 'mouseenter touchstart', (event) -> + # Don't do anything if we are hovering over the child of a link. + # The actual link will receive the event and bubble in a second. + if up.link.shouldProcessEvent(event, $link) + preloadAfterDelay($link) + $link.on 'mouseleave', -> + stopPreload($link) up.on 'up:framework:reset', reset preload: preload ajax: ajax