X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1a09d88891e646de0610de0d75edb8752ae85bc3..refs/pull/524/head:/resources/assets/js/pages/page-show.js diff --git a/resources/assets/js/pages/page-show.js b/resources/assets/js/pages/page-show.js index 4a4724b85..14437cd68 100644 --- a/resources/assets/js/pages/page-show.js +++ b/resources/assets/js/pages/page-show.js @@ -1,9 +1,12 @@ -"use strict"; -// Configure ZeroClipboard const Clipboard = require("clipboard"); +const Code = require('../code'); let setupPageShow = window.setupPageShow = function (pageId) { + Code.highlight(); + + if (!pageId) return; + // Set up pointer let $pointer = $('#pointer').detach(); let pointerShowing = false; @@ -78,15 +81,7 @@ let setupPageShow = window.setupPageShow = function (pageId) { let idElem = document.getElementById(text); $('.page-content [data-highlighted]').attr('data-highlighted', '').css('background-color', ''); if (idElem !== null) { - let $idElem = $(idElem); - let color = $('#custom-styles').attr('data-color-light'); - $idElem.css('background-color', color).attr('data-highlighted', 'true').smoothScrollTo(); - setTimeout(() => { - $idElem.addClass('anim').addClass('selectFade').css('background-color', ''); - setTimeout(() => { - $idElem.removeClass('selectFade'); - }, 3000); - }, 100); + window.scrollAndHighlight(idElem); } else { $('.page-content').find(':contains("' + text + '")').smoothScrollTo(); } @@ -103,25 +98,25 @@ let setupPageShow = window.setupPageShow = function (pageId) { goToText(event.target.getAttribute('href').substr(1)); }); - // Make the book-tree sidebar stick in view on scroll + // Make the sidebar stick in view on scroll let $window = $(window); - let $bookTree = $(".book-tree"); - let $bookTreeParent = $bookTree.parent(); + let $sidebar = $("#sidebar .scroll-body"); + let $bookTreeParent = $sidebar.parent(); // Check the page is scrollable and the content is taller than the tree - let pageScrollable = ($(document).height() > $window.height()) && ($bookTree.height() < $('.page-content').height()); + let pageScrollable = ($(document).height() > $window.height()) && ($sidebar.height() < $('.page-content').height()); // Get current tree's width and header height let headerHeight = $("#header").height() + $(".toolbar").height(); let isFixed = $window.scrollTop() > headerHeight; // Function to fix the tree as a sidebar function stickTree() { - $bookTree.width($bookTreeParent.width() + 15); - $bookTree.addClass("fixed"); + $sidebar.width($bookTreeParent.width() + 15); + $sidebar.addClass("fixed"); isFixed = true; } // Function to un-fix the tree back into position function unstickTree() { - $bookTree.css('width', 'auto'); - $bookTree.removeClass("fixed"); + $sidebar.css('width', 'auto'); + $sidebar.removeClass("fixed"); isFixed = false; } // Checks if the tree stickiness state should change @@ -155,7 +150,6 @@ let setupPageShow = window.setupPageShow = function (pageId) { unstickTree(); } }); - }; module.exports = setupPageShow; \ No newline at end of file