Dan Brown

Fixed page navigation with special chars in id

Also made so it smooth-scrolls and uses app theme color.
Fixes #254
...@@ -61,10 +61,9 @@ Controllers(ngApp, window.Events); ...@@ -61,10 +61,9 @@ Controllers(ngApp, window.Events);
61 // Smooth scrolling 61 // Smooth scrolling
62 jQuery.fn.smoothScrollTo = function () { 62 jQuery.fn.smoothScrollTo = function () {
63 if (this.length === 0) return; 63 if (this.length === 0) return;
64 - let scrollElem = document.documentElement.scrollTop === 0 ? document.body : document.documentElement; 64 + $('html, body').animate({
65 - $(scrollElem).animate({
66 scrollTop: this.offset().top - 60 // Adjust to change final scroll position top margin 65 scrollTop: this.offset().top - 60 // Adjust to change final scroll position top margin
67 - }, 800); // Adjust to change animations speed (ms) 66 + }, 300); // Adjust to change animations speed (ms)
68 return this; 67 return this;
69 }; 68 };
70 69
......
1 "use strict"; 1 "use strict";
2 // Configure ZeroClipboard 2 // Configure ZeroClipboard
3 -import zeroClipBoard from "zeroclipboard"; 3 +import ZeroClipBoard from "zeroclipboard";
4 4
5 export default window.setupPageShow = function (pageId) { 5 export default window.setupPageShow = function (pageId) {
6 6
...@@ -16,10 +16,10 @@ export default window.setupPageShow = function (pageId) { ...@@ -16,10 +16,10 @@ export default window.setupPageShow = function (pageId) {
16 }); 16 });
17 17
18 // Set up copy-to-clipboard 18 // Set up copy-to-clipboard
19 - zeroClipBoard.config({ 19 + ZeroClipBoard.config({
20 swfPath: window.baseUrl('/ZeroClipboard.swf') 20 swfPath: window.baseUrl('/ZeroClipboard.swf')
21 }); 21 });
22 - new zeroClipBoard($pointer.find('button').first()[0]); 22 + new ZeroClipBoard($pointer.find('button').first()[0]);
23 23
24 // Hide pointer when clicking away 24 // Hide pointer when clicking away
25 $(document.body).find('*').on('click focus', function (e) { 25 $(document.body).find('*').on('click focus', function (e) {
...@@ -57,10 +57,12 @@ export default window.setupPageShow = function (pageId) { ...@@ -57,10 +57,12 @@ export default window.setupPageShow = function (pageId) {
57 57
58 // Go to, and highlight if necessary, the specified text. 58 // Go to, and highlight if necessary, the specified text.
59 function goToText(text) { 59 function goToText(text) {
60 - let idElem = $('.page-content #' + text).first(); 60 + let idElem = document.getElementById(text);
61 - if (idElem.length !== 0) { 61 + $('.page-content [data-highlighted]').attr('data-highlighted', '').css('background-color', '');
62 - idElem.smoothScrollTo(); 62 + if (idElem !== null) {
63 - idElem.css('background-color', 'rgba(244, 249, 54, 0.25)'); 63 + let $idElem = $(idElem);
64 + let color = $('#custom-styles').attr('data-color-light');
65 + $idElem.css('background-color', color).attr('data-highlighted', 'true').smoothScrollTo();
64 } else { 66 } else {
65 $('.page-content').find(':contains("' + text + '")').smoothScrollTo(); 67 $('.page-content').find(':contains("' + text + '")').smoothScrollTo();
66 } 68 }
...@@ -72,6 +74,11 @@ export default window.setupPageShow = function (pageId) { ...@@ -72,6 +74,11 @@ export default window.setupPageShow = function (pageId) {
72 goToText(text); 74 goToText(text);
73 } 75 }
74 76
77 + // Sidebar page nav click event
78 + $('.sidebar-page-nav').on('click', 'a', event => {
79 + goToText(event.target.getAttribute('href').substr(1));
80 + });
81 +
75 // Make the book-tree sidebar stick in view on scroll 82 // Make the book-tree sidebar stick in view on scroll
76 let $window = $(window); 83 let $window = $(window);
77 let $bookTree = $(".book-tree"); 84 let $bookTree = $(".book-tree");
......