// [Yihui] Scroll the chapter body to the i-th highlighted string function scrollToHighlighted(d) { var n = $highlighted.length; hi = hi === undefined ? 0 : hi + d; // navignate to the previous/next page in the search results if reached the top/bottom var b = hi < 0; if (d !== 0 && (b || hi >= n)) { var path = currentPath(), n2 = toc_visible.length; if (n2 === 0) return; for (var i = b ? 0 : n2; (b && i < n2) || (!b && i >= 0); i += b ? 1 : -1) { if (toc_visible.eq(i).data('path') === path) break; } i += b ? -1 : 1; if (i < 0) i = n2 - 1; if (i >= n2) i = 0; var lnk = toc_visible.eq(i).find('a[href$=".html"]'); if (lnk.length) lnk[0].click(); return; } if (n === 0) return; var $p = $highlighted.eq(hi); $p[0].scrollIntoView(); $highlighted.css('background-color', ''); // an orange background color on the current item and removed later $p.css('background-color', 'orange'); setTimeout(function() { $p.css('background-color', ''); }, 2000); }