]> BookStack Code Mirror - bookstack/blob - resources/views/pages/show.blade.php
Added link functionality
[bookstack] / resources / views / pages / show.blade.php
1 @extends('base')
2
3 @section('content')
4
5     <div class="row">
6         <div class="page-menu col-md-3">
7             <div class="page-nav">
8                 <h4>Navigation</h4>
9                 <ul class="page-nav-list"></ul>
10             </div>
11             <div class="page-actions">
12                 <h4>Actions</h4>
13                 <a href="{{$page->getUrl() . '/edit'}}" class="muted"><i class="fa fa-pencil"></i>Edit this page</a>
14             </div>
15         </div>
16
17         <div class="page-content right col-md-9">
18             <h1>{{$page->name}}</h1>
19             {!! $page->html !!}
20         </div>
21     </div>
22
23     <script>
24         $(document).ready(function() {
25
26             // Set up fixed side menu
27             $('.page-menu').affix({
28                 offset: {
29                     top: 10,
30                     bottom: function () {
31                         return (this.bottom = $('.footer').outerHeight(true))
32                     }
33                 }
34             });
35
36             // Set up document navigation
37             var pageNav = $('.page-nav-list');
38             var pageContent = $('.page-content');
39             var headers = pageContent.find('h1, h2, h3, h4, h5, h6');
40             var sortedHeaders = [];
41             headers.each(function() {
42                 var header = $(this);
43                 var tag = header.prop('tagName');
44                 var listElem = $('<li></li>').addClass('nav-'+tag);
45                 var link = $('<a></a>').text(header.text().trim()).attr('href', '#');
46                 listElem.append(link);
47                 pageNav.append(listElem);
48                 link.click(function(e) {
49                     e.preventDefault();
50                     header.smoothScrollTo();
51                 })
52             });
53
54             // Set up link hooks
55             var pageId = {{$page->id}};
56             headers.each(function() {
57                 var text = $(this).text().trim();
58                 var link = '/link/' + pageId + '#' + encodeURIComponent(text);
59                 var linkHook = $('<a class="link-hook"><i class="fa fa-link"></i></a>')
60                         .attr({"data-content": link, href: link, target: '_blank'});
61                 linkHook.click(function(e) {
62                     e.preventDefault();
63                     goToText(text);
64                 });
65                 $(this).append(linkHook);
66             });
67
68             function goToText(text) {
69                 $('.page-content').find(':contains("'+text+'")').smoothScrollTo();
70             }
71
72             if(window.location.hash) {
73                 var text = window.location.hash.replace(/\%20/g, ' ').substr(1);
74                 goToText(text);
75             }
76
77             //$('[data-toggle="popover"]').popover()
78         });
79     </script>
80 @stop