academic.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*************************************************
  2. * Academic
  3. * https://github.com/gcushen/hugo-academic
  4. *
  5. * Core JS functions and initialization.
  6. **************************************************/
  7. (function($){
  8. /* ---------------------------------------------------------------------------
  9. * Responsive scrolling for URL hashes.
  10. * --------------------------------------------------------------------------- */
  11. // Dynamically get responsive navigation bar height for offsetting Scrollspy.
  12. function getNavBarHeight() {
  13. let $navbar = $('#navbar-main');
  14. let navbar_offset = $navbar.outerHeight();
  15. console.debug('Navbar height: ' + navbar_offset);
  16. return navbar_offset;
  17. }
  18. /**
  19. * Responsive hash scrolling.
  20. * Check for a URL hash as an anchor.
  21. * If it exists on current page, scroll to it responsively.
  22. * If `target` argument omitted (e.g. after event), assume it's the window's hash.
  23. */
  24. function scrollToAnchor(target) {
  25. // If `target` is undefined or HashChangeEvent object, set it to window's hash.
  26. // Decode the hash as browsers can encode non-ASCII characters (e.g. Chinese symbols).
  27. target = (typeof target === 'undefined' || typeof target === 'object') ? decodeURIComponent(window.location.hash) : target;
  28. // If target element exists, scroll to it taking into account fixed navigation bar offset.
  29. if($(target).length) {
  30. // Escape special chars from IDs, such as colons found in Markdown footnote links.
  31. target = '#' + $.escapeSelector(target.substring(1)); // Previously, `target = target.replace(/:/g, '\\:');`
  32. let elementOffset = Math.ceil($(target).offset().top - getNavBarHeight()); // Round up to highlight right ID!
  33. $('body').addClass('scrolling');
  34. $('html, body').animate({
  35. scrollTop: elementOffset
  36. }, 600, function () {
  37. $('body').removeClass('scrolling');
  38. });
  39. }else{
  40. console.debug('Cannot scroll to target `#'+target+'`. ID not found!');
  41. }
  42. }
  43. // Make Scrollspy responsive.
  44. function fixScrollspy() {
  45. let $body = $('body');
  46. let data = $body.data('bs.scrollspy');
  47. if (data) {
  48. data._config.offset = getNavBarHeight();
  49. $body.data('bs.scrollspy', data);
  50. $body.scrollspy('refresh');
  51. }
  52. }
  53. function removeQueryParamsFromUrl() {
  54. if (window.history.replaceState) {
  55. let urlWithoutSearchParams = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.hash;
  56. window.history.replaceState({path:urlWithoutSearchParams}, '', urlWithoutSearchParams);
  57. }
  58. }
  59. // Check for hash change event and fix responsive offset for hash links (e.g. Markdown footnotes).
  60. window.addEventListener("hashchange", scrollToAnchor);
  61. /* ---------------------------------------------------------------------------
  62. * Add smooth scrolling to all links inside the main navbar.
  63. * --------------------------------------------------------------------------- */
  64. $('#navbar-main li.nav-item a.nav-link').on('click', function(event) {
  65. // Store requested URL hash.
  66. let hash = this.hash;
  67. // If we are on a widget page and the navbar link is to a section on the same page.
  68. if ( this.pathname === window.location.pathname && hash && $(hash).length && ($(".js-widget-page").length > 0)) {
  69. // Prevent default click behavior.
  70. event.preventDefault();
  71. // Use jQuery's animate() method for smooth page scrolling.
  72. // The numerical parameter specifies the time (ms) taken to scroll to the specified hash.
  73. let elementOffset = Math.ceil($(hash).offset().top - getNavBarHeight()); // Round up to highlight right ID!
  74. // Uncomment to debug.
  75. // let scrollTop = $(window).scrollTop();
  76. // let scrollDelta = (elementOffset - scrollTop);
  77. // console.debug('Scroll Delta: ' + scrollDelta);
  78. $('html, body').animate({
  79. scrollTop: elementOffset
  80. }, 800);
  81. }
  82. });
  83. /* ---------------------------------------------------------------------------
  84. * Hide mobile collapsable menu on clicking a link.
  85. * --------------------------------------------------------------------------- */
  86. $(document).on('click', '.navbar-collapse.show', function(e) {
  87. //get the <a> element that was clicked, even if the <span> element that is inside the <a> element is e.target
  88. let targetElement = $(e.target).is('a') ? $(e.target) : $(e.target).parent();
  89. if (targetElement.is('a') && targetElement.attr('class') != 'dropdown-toggle') {
  90. $(this).collapse('hide');
  91. }
  92. });
  93. /* ---------------------------------------------------------------------------
  94. * Filter publications.
  95. * --------------------------------------------------------------------------- */
  96. // Active publication filters.
  97. let pubFilters = {};
  98. // Search term.
  99. let searchRegex;
  100. // Filter values (concatenated).
  101. let filterValues;
  102. // Publication container.
  103. let $grid_pubs = $('#container-publications');
  104. // Initialise Isotope.
  105. $grid_pubs.isotope({
  106. itemSelector: '.isotope-item',
  107. percentPosition: true,
  108. masonry: {
  109. // Use Bootstrap compatible grid layout.
  110. columnWidth: '.grid-sizer'
  111. },
  112. filter: function() {
  113. let $this = $(this);
  114. let searchResults = searchRegex ? $this.text().match( searchRegex ) : true;
  115. let filterResults = filterValues ? $this.is( filterValues ) : true;
  116. return searchResults && filterResults;
  117. }
  118. });
  119. // Filter by search term.
  120. let $quickSearch = $('.filter-search').keyup( debounce( function() {
  121. searchRegex = new RegExp( $quickSearch.val(), 'gi' );
  122. $grid_pubs.isotope();
  123. }) );
  124. // Debounce input to prevent spamming filter requests.
  125. function debounce( fn, threshold ) {
  126. let timeout;
  127. threshold = threshold || 100;
  128. return function debounced() {
  129. clearTimeout( timeout );
  130. let args = arguments;
  131. let _this = this;
  132. function delayed() {
  133. fn.apply( _this, args );
  134. }
  135. timeout = setTimeout( delayed, threshold );
  136. };
  137. }
  138. // Flatten object by concatenating values.
  139. function concatValues( obj ) {
  140. let value = '';
  141. for ( let prop in obj ) {
  142. value += obj[ prop ];
  143. }
  144. return value;
  145. }
  146. $('.pub-filters').on( 'change', function() {
  147. let $this = $(this);
  148. // Get group key.
  149. let filterGroup = $this[0].getAttribute('data-filter-group');
  150. // Set filter for group.
  151. pubFilters[ filterGroup ] = this.value;
  152. // Combine filters.
  153. filterValues = concatValues( pubFilters );
  154. // Activate filters.
  155. $grid_pubs.isotope();
  156. // If filtering by publication type, update the URL hash to enable direct linking to results.
  157. if (filterGroup == "pubtype") {
  158. // Set hash URL to current filter.
  159. let url = $(this).val();
  160. if (url.substr(0, 9) == '.pubtype-') {
  161. window.location.hash = url.substr(9);
  162. } else {
  163. window.location.hash = '';
  164. }
  165. }
  166. });
  167. // Filter publications according to hash in URL.
  168. function filter_publications() {
  169. let urlHash = window.location.hash.replace('#','');
  170. let filterValue = '*';
  171. // Check if hash is numeric.
  172. if (urlHash != '' && !isNaN(urlHash)) {
  173. filterValue = '.pubtype-' + urlHash;
  174. }
  175. // Set filter.
  176. let filterGroup = 'pubtype';
  177. pubFilters[ filterGroup ] = filterValue;
  178. filterValues = concatValues( pubFilters );
  179. // Activate filters.
  180. $grid_pubs.isotope();
  181. // Set selected option.
  182. $('.pubtype-select').val(filterValue);
  183. }
  184. /* ---------------------------------------------------------------------------
  185. * Google Maps or OpenStreetMap via Leaflet.
  186. * --------------------------------------------------------------------------- */
  187. function initMap () {
  188. if ($('#map').length) {
  189. let map_provider = $('#map-provider').val();
  190. let lat = $('#map-lat').val();
  191. let lng = $('#map-lng').val();
  192. let zoom = parseInt($('#map-zoom').val());
  193. let address = $('#map-dir').val();
  194. let api_key = $('#map-api-key').val();
  195. if ( map_provider == 1 ) {
  196. let map = new GMaps({
  197. div: '#map',
  198. lat: lat,
  199. lng: lng,
  200. zoom: zoom,
  201. zoomControl: true,
  202. zoomControlOpt: {
  203. style: 'SMALL',
  204. position: 'TOP_LEFT'
  205. },
  206. panControl: false,
  207. streetViewControl: false,
  208. mapTypeControl: false,
  209. overviewMapControl: false,
  210. scrollwheel: true,
  211. draggable: true
  212. });
  213. map.addMarker({
  214. lat: lat,
  215. lng: lng,
  216. click: function (e) {
  217. let url = 'https://www.google.com/maps/place/' + encodeURIComponent(address) + '/@' + lat + ',' + lng +'/';
  218. window.open(url, '_blank')
  219. },
  220. title: address
  221. })
  222. } else {
  223. let map = new L.map('map').setView([lat, lng], zoom);
  224. if ( map_provider == 3 && api_key.length ) {
  225. L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
  226. attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
  227. maxZoom: 18,
  228. id: 'mapbox.streets',
  229. accessToken: api_key
  230. }).addTo(map);
  231. } else {
  232. L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  233. maxZoom: 19,
  234. attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
  235. }).addTo(map);
  236. }
  237. let marker = L.marker([lat, lng]).addTo(map);
  238. let url = lat + ',' + lng +'#map='+ zoom +'/'+ lat +'/'+ lng +'&layers=N';
  239. marker.bindPopup(address + '<p><a href="https://www.openstreetmap.org/directions?engine=osrm_car&route='+ url +'">Routing via OpenStreetMap</a></p>');
  240. }
  241. }
  242. }
  243. /* ---------------------------------------------------------------------------
  244. * GitHub API.
  245. * --------------------------------------------------------------------------- */
  246. function printLatestRelease(selector, repo) {
  247. $.getJSON('https://api.github.com/repos/' + repo + '/tags').done(function (json) {
  248. let release = json[0];
  249. $(selector).append(' '+release.name);
  250. }).fail(function( jqxhr, textStatus, error ) {
  251. let err = textStatus + ", " + error;
  252. console.log( "Request Failed: " + err );
  253. });
  254. }
  255. /* ---------------------------------------------------------------------------
  256. * Toggle search dialog.
  257. * --------------------------------------------------------------------------- */
  258. function toggleSearchDialog() {
  259. if ($('body').hasClass('searching')) {
  260. // Clear search query and hide search modal.
  261. $('[id=search-query]').blur();
  262. $('body').removeClass('searching compensate-for-scrollbar');
  263. // Remove search query params from URL as user has finished searching.
  264. removeQueryParamsFromUrl();
  265. // Prevent fixed positioned elements (e.g. navbar) moving due to scrollbars.
  266. $('#fancybox-style-noscroll').remove();
  267. } else {
  268. // Prevent fixed positioned elements (e.g. navbar) moving due to scrollbars.
  269. if ( !$('#fancybox-style-noscroll').length && document.body.scrollHeight > window.innerHeight ) {
  270. $('head').append(
  271. '<style id="fancybox-style-noscroll">.compensate-for-scrollbar{margin-right:' +
  272. (window.innerWidth - document.documentElement.clientWidth) +
  273. 'px;}</style>'
  274. );
  275. $('body').addClass('compensate-for-scrollbar');
  276. }
  277. // Show search modal.
  278. $('body').addClass('searching');
  279. $('.search-results').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 200);
  280. $('#search-query').focus();
  281. }
  282. }
  283. /* ---------------------------------------------------------------------------
  284. * Toggle day/night mode.
  285. * --------------------------------------------------------------------------- */
  286. function toggleDarkMode(codeHlEnabled, codeHlLight, codeHlDark, diagramEnabled) {
  287. if ($('body').hasClass('dark')) {
  288. $('body').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 500);
  289. $('body').removeClass('dark');
  290. if (codeHlEnabled) {
  291. codeHlLight.disabled = false;
  292. codeHlDark.disabled = true;
  293. }
  294. $('.js-dark-toggle i').removeClass('fa-sun').addClass('fa-moon');
  295. localStorage.setItem('dark_mode', '0');
  296. if (diagramEnabled) {
  297. // TODO: Investigate Mermaid.js approach to re-render diagrams with new theme without reloading.
  298. location.reload();
  299. }
  300. } else {
  301. $('body').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 500);
  302. $('body').addClass('dark');
  303. if (codeHlEnabled) {
  304. codeHlLight.disabled = true;
  305. codeHlDark.disabled = false;
  306. }
  307. $('.js-dark-toggle i').removeClass('fa-moon').addClass('fa-sun');
  308. localStorage.setItem('dark_mode', '1');
  309. if (diagramEnabled) {
  310. // TODO: Investigate Mermaid.js approach to re-render diagrams with new theme without reloading.
  311. location.reload();
  312. }
  313. }
  314. }
  315. /* ---------------------------------------------------------------------------
  316. * Normalize Bootstrap Carousel Slide Heights.
  317. * --------------------------------------------------------------------------- */
  318. function normalizeCarouselSlideHeights() {
  319. $('.carousel').each(function(){
  320. // Get carousel slides.
  321. let items = $('.carousel-item', this);
  322. // Reset all slide heights.
  323. items.css('min-height', 0);
  324. // Normalize all slide heights.
  325. let maxHeight = Math.max.apply(null, items.map(function(){return $(this).outerHeight()}).get());
  326. items.css('min-height', maxHeight + 'px');
  327. })
  328. }
  329. /* ---------------------------------------------------------------------------
  330. * On document ready.
  331. * --------------------------------------------------------------------------- */
  332. $(document).ready(function() {
  333. // Fix Goldmark table of contents.
  334. // - Must be performed prior to initializing ScrollSpy.
  335. $('#TableOfContents').addClass('nav flex-column');
  336. $('#TableOfContents li').addClass('nav-item');
  337. $('#TableOfContents li a').addClass('nav-link');
  338. // Fix Goldmark task lists (remove bullet points).
  339. $("input[type='checkbox'][disabled]").parents('ul').addClass('task-list');
  340. // Fix Mermaid.js clash with Highlight.js.
  341. // Refactor Mermaid code blocks as divs to prevent Highlight parsing them and enable Mermaid to parse them.
  342. let mermaids = [];
  343. [].push.apply(mermaids, document.getElementsByClassName('language-mermaid'));
  344. for (let i = 0; i < mermaids.length; i++) {
  345. $(mermaids[i]).unwrap('pre'); // Remove <pre> wrapper.
  346. $(mermaids[i]).replaceWith(function(){
  347. // Convert <code> block to <div> and add `mermaid` class so that Mermaid will parse it.
  348. return $("<div />").append($(this).contents()).addClass('mermaid');
  349. });
  350. }
  351. // Initialise code highlighting if enabled for this page.
  352. // Note: this block should be processed after the Mermaid code-->div conversion.
  353. if (code_highlighting) {
  354. hljs.initHighlighting();
  355. }
  356. // Get theme variation (day/night).
  357. let defaultThemeVariation;
  358. if ($('body').hasClass('dark')) {
  359. // The `color_theme` of the site is dark.
  360. defaultThemeVariation = 1;
  361. } else if ($('.js-dark-toggle').length && window.matchMedia('(prefers-color-scheme: dark)').matches) {
  362. // The visitor prefers dark themes and switching to the dark variation is allowed by admin.
  363. defaultThemeVariation = 1;
  364. } else {
  365. // Default to day (light) theme.
  366. defaultThemeVariation = 0;
  367. }
  368. let dark_mode = parseInt(localStorage.getItem('dark_mode') || defaultThemeVariation);
  369. // Is code highlighting enabled in site config?
  370. const codeHlEnabled = $('link[title=hl-light]').length > 0;
  371. const codeHlLight = $('link[title=hl-light]')[0];
  372. const codeHlDark = $('link[title=hl-dark]')[0];
  373. const diagramEnabled = $('script[title=mermaid]').length > 0;
  374. if (dark_mode) {
  375. $('body').addClass('dark');
  376. if (codeHlEnabled) {
  377. codeHlLight.disabled = true;
  378. codeHlDark.disabled = false;
  379. }
  380. if (diagramEnabled) {
  381. mermaid.initialize({ theme: 'dark', securityLevel: 'loose' });
  382. }
  383. $('.js-dark-toggle i').removeClass('fa-moon').addClass('fa-sun');
  384. } else {
  385. $('body').removeClass('dark');
  386. if (codeHlEnabled) {
  387. codeHlLight.disabled = false;
  388. codeHlDark.disabled = true;
  389. }
  390. if (diagramEnabled) {
  391. mermaid.initialize({ theme: 'default', securityLevel: 'loose' });
  392. }
  393. $('.js-dark-toggle i').removeClass('fa-sun').addClass('fa-moon');
  394. }
  395. // Toggle day/night mode.
  396. $('.js-dark-toggle').click(function(e) {
  397. e.preventDefault();
  398. toggleDarkMode(codeHlEnabled, codeHlLight, codeHlDark, diagramEnabled);
  399. });
  400. // Live update of day/night mode on system preferences update (no refresh required).
  401. const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
  402. darkModeMediaQuery.addListener((e) => {
  403. if ($('.js-dark-toggle').length) {
  404. const darkModeOn = e.matches;
  405. console.log(`Dark mode is ${darkModeOn ? '🌒 on' : '☀️ off'}.`);
  406. toggleDarkMode(codeHlEnabled, codeHlLight, codeHlDark, diagramEnabled);
  407. }
  408. });
  409. });
  410. /* ---------------------------------------------------------------------------
  411. * On window loaded.
  412. * --------------------------------------------------------------------------- */
  413. $(window).on('load', function() {
  414. // Re-initialize Scrollspy with dynamic navbar height offset.
  415. fixScrollspy();
  416. if (window.location.hash) {
  417. // When accessing homepage from another page and `#top` hash is set, show top of page (no hash).
  418. if (window.location.hash == "#top") {
  419. window.location.hash = ""
  420. } else if (!$('.projects-container').length) {
  421. // If URL contains a hash and there are no dynamically loaded images on the page,
  422. // immediately scroll to target ID taking into account responsive offset.
  423. // Otherwise, wait for `imagesLoaded()` to complete before scrolling to hash to prevent scrolling to wrong
  424. // location.
  425. scrollToAnchor();
  426. }
  427. }
  428. // Call `fixScrollspy` when window is resized.
  429. let resizeTimer;
  430. $(window).resize(function() {
  431. clearTimeout(resizeTimer);
  432. resizeTimer = setTimeout(fixScrollspy, 200);
  433. });
  434. // Filter projects.
  435. $('.projects-container').each(function(index, container) {
  436. let $container = $(container);
  437. let $section = $container.closest('section');
  438. let layout;
  439. if ($section.find('.isotope').hasClass('js-layout-row')) {
  440. layout = 'fitRows';
  441. } else {
  442. layout = 'masonry';
  443. }
  444. $container.imagesLoaded(function() {
  445. // Initialize Isotope after all images have loaded.
  446. $container.isotope({
  447. itemSelector: '.isotope-item',
  448. layoutMode: layout,
  449. masonry: {
  450. gutter: 20
  451. },
  452. filter: $section.find('.default-project-filter').text()
  453. });
  454. // Filter items when filter link is clicked.
  455. $section.find('.project-filters a').click(function() {
  456. let selector = $(this).attr('data-filter');
  457. $container.isotope({filter: selector});
  458. $(this).removeClass('active').addClass('active').siblings().removeClass('active all');
  459. return false;
  460. });
  461. // If window hash is set, scroll to hash.
  462. // Placing this within `imagesLoaded` prevents scrolling to the wrong location due to dynamic image loading
  463. // affecting page layout and position of the target anchor ID.
  464. // Note: If there are multiple project widgets on a page, ideally only perform this once after images
  465. // from *all* project widgets have finished loading.
  466. if (window.location.hash) {
  467. scrollToAnchor();
  468. }
  469. });
  470. });
  471. // Enable publication filter for publication index page.
  472. if ($('.pub-filters-select')) {
  473. filter_publications();
  474. // Useful for changing hash manually (e.g. in development):
  475. // window.addEventListener('hashchange', filter_publications, false);
  476. }
  477. // Scroll to top of page.
  478. $('.back-to-top').click( function(event) {
  479. event.preventDefault();
  480. $('html, body').animate({
  481. 'scrollTop': 0
  482. }, 800, function() {
  483. window.location.hash = "";
  484. });
  485. });
  486. // Load citation modal on 'Cite' click.
  487. $('.js-cite-modal').click(function(e) {
  488. e.preventDefault();
  489. let filename = $(this).attr('data-filename');
  490. let modal = $('#modal');
  491. modal.find('.modal-body code').load( filename , function( response, status, xhr ) {
  492. if ( status == 'error' ) {
  493. let msg = "Error: ";
  494. $('#modal-error').html( msg + xhr.status + " " + xhr.statusText );
  495. } else {
  496. $('.js-download-cite').attr('href', filename);
  497. }
  498. });
  499. modal.modal('show');
  500. });
  501. // Copy citation text on 'Copy' click.
  502. $('.js-copy-cite').click(function(e) {
  503. e.preventDefault();
  504. // Get selection.
  505. let range = document.createRange();
  506. let code_node = document.querySelector('#modal .modal-body');
  507. range.selectNode(code_node);
  508. window.getSelection().addRange(range);
  509. try {
  510. // Execute the copy command.
  511. document.execCommand('copy');
  512. } catch(e) {
  513. console.log('Error: citation copy failed.');
  514. }
  515. // Remove selection.
  516. window.getSelection().removeRange(range);
  517. });
  518. // Initialise Google Maps if necessary.
  519. initMap();
  520. // Print latest version of GitHub projects.
  521. let githubReleaseSelector = '.js-github-release';
  522. if ($(githubReleaseSelector).length > 0)
  523. printLatestRelease(githubReleaseSelector, $(githubReleaseSelector).data('repo'));
  524. // On search icon click toggle search dialog.
  525. $('.js-search').click(function(e) {
  526. e.preventDefault();
  527. toggleSearchDialog();
  528. });
  529. $(document).on('keydown', function(e){
  530. if (e.which == 27) {
  531. // `Esc` key pressed.
  532. if ($('body').hasClass('searching')) {
  533. toggleSearchDialog();
  534. }
  535. } else if (e.which == 191 && e.shiftKey == false && !$('input,textarea').is(':focus')) {
  536. // `/` key pressed outside of text input.
  537. e.preventDefault();
  538. toggleSearchDialog();
  539. }
  540. });
  541. });
  542. // Normalize Bootstrap carousel slide heights.
  543. $(window).on('load resize orientationchange', normalizeCarouselSlideHeights);
  544. // Automatic main menu dropdowns on mouse over.
  545. $('body').on('mouseenter mouseleave', '.dropdown', function (e) {
  546. var dropdown = $(e.target).closest('.dropdown');
  547. var menu = $('.dropdown-menu', dropdown);
  548. dropdown.addClass('show');
  549. menu.addClass('show');
  550. setTimeout(function () {
  551. dropdown[dropdown.is(':hover') ? 'addClass' : 'removeClass']('show');
  552. menu[dropdown.is(':hover') ? 'addClass' : 'removeClass']('show');
  553. }, 300);
  554. });
  555. })(jQuery);