Basic website with home page, contact/feedback forms (project links do nothing)
[ndcode_site.git] / navbar.jst
1 let XDate = require('xdate')
2
3 return async (env, head, body) => {
4   let feedback_form = await _require('/feedback_form.jst')
5   let globals = await env.site.get_json('/_config/globals.json')
6   let icon_search = await env.site.get_min_svg('/_svg/icon_search.svg')
7   let logo_large = await env.site.get_min_svg('/_svg/logo_large.svg')
8   let page = await _require('/page.jst')
9
10   await page(
11     env,
12     head,
13     // body
14     async _out => {
15       div(style="padding-left: calc(100vw - 100%);") {
16         div.container(style="margin-top: 15px; margin-bottom: 15px;") {
17           //div.row {
18           //  div.col-sm-12(style="text-align: right;") {
19           //    a(href="/login.html") {'Login'}
20           //  }
21           //}
22           div.row {
23             div.'col-sm-8'.vbottom {
24               _out.push(logo_large)
25             }
26             div.'col-sm-4'.vbottom(style="padding-bottom: 15px;") {
27               form(action="/search.html") {
28                 div.input-group {
29                   input.form-control(name="query" type="text" placeholder="Search") {}
30                   span.input-group-btn {
31                     button.btn.btn-default(type="submit") {
32                       _out.push(icon_search)
33                     }
34                   }
35                 }
36               }
37             }
38           }
39         }
40       }
41       nav.navbar.navbar-default(style="margin-top: 0px; margin-bottom: 0px;") {
42         div(style="padding-left: calc(100vw - 100%);") {
43           div.container { //-fluid") {
44             //  Brand and toggle get grouped for better mobile display 
45             div.navbar-header {
46               button.navbar-toggle.collapsed(type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false") {
47                 span.sr-only {'Toggle navigation'}
48                 span.icon-bar {}
49                 span.icon-bar {}
50                 span.icon-bar {}
51               }
52               //a.navbar-brand(href="#") {'Brand'}
53             }
54
55             //  Collect the nav links, forms, and other content for toggling 
56             div.collapse.navbar-collapse#bs-example-navbar-collapse-1 {
57               ul.nav.navbar-nav {
58                 let navigation = globals.navigation
59                 for (let i = 0; i < navigation.length; ++i) {
60                   let page = navigation[i]
61                   let title = globals.page_to_title[page] || page
62                   if (page === env.parsed_url.pathname)
63                     li.active {
64                       a(href=page) {
65                         `${title}`
66                         span.sr-only {'(current)'}
67                       }
68                     }
69                   else
70                     li {
71                       a(href=page) {`${title}`}
72                     }
73                 }
74               }
75               ul.nav.navbar-nav.navbar-right {
76                 li {
77                   a#give-feedback {'Give feedback'}
78                 }
79               } 
80             }
81           }
82         }
83       }
84       div(style="padding-left: calc(100vw - 100%);") {
85         div.container {
86           await body(_out)
87         }
88       }
89       br {}
90       div.footer(style="padding-left: calc(100vw - 100%);") {
91         div.container { //-fluid") {
92           div(style="height: 16px;") {}
93           a(rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/") {
94             img(alt="Creative Commons License" style="border-width:0" src="images/by-sa_3.0_88x31.png") {}
95           }
96           p {
97             'This work is licensed under a '
98             a(rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/") {
99               'Creative Commons Attribution-ShareAlike 3.0 Unported License'
100             }
101             '.'
102           }
103
104           p {'Code samples within the page are placed in the public domain unless otherwise noted.'}
105
106           p {`Copyright © ${new XDate().getUTCFullYear()} Integration Logic Pty Ltd trading as NDCODE and contributors.`}
107         }
108       }
109
110       // hidden part
111       div#feedback-modal.modal.fade(role="dialog") {
112         div.modal-dialog {
113           div.modal-content {
114             div.modal-header {
115               button.close(type="button" data-dismiss="modal") {
116                 '×'
117               }
118               h4.modal-title {
119                 'Give feedback'
120               }
121             }
122             div.modal-body {
123               p {
124                 'Did you notice something not quite right, or just want to share your impression of this page?'
125               }
126               await feedback_form(env, _out)
127             }
128             div.modal-footer {
129               button.btn.btn-primary(type="submit" form="feedback-form") {
130                 'Submit'
131               }
132               button.btn.btn-default(type="button" data-dismiss="modal") {
133                 'Close'
134               }
135             }
136           }
137         }
138       }
139
140       div#message-modal.modal.fade(role="dialog") {
141         div.modal-dialog {
142           div.modal-content {
143             div.modal-header {
144               button.close(type="button" data-dismiss="modal") {
145                 '×'
146               }
147               h4.modal-title {
148                 'Message'
149               }
150             }
151             div.modal-body {
152               p#message-modal-message {}
153             }
154             div.modal-footer {
155               button.btn.btn-default(type="button" data-dismiss="modal") {
156                 'Close'
157               }
158             }
159           }
160         }
161       }
162     },
163     // scripts
164     async _out => {
165       // when feedback form is submitted, do not reload the page
166       script {
167         $(document).ready(function() {
168           $('#give-feedback').click(function() {
169             $('#feedback-modal').modal('show')
170             $('#feedback-form-message').text('')
171           })
172           $('#feedback-modal').on('shown.bs.modal', function() {
173             $('#feedback-form-message').focus()
174           })
175           $(document).on('submit', '#feedback-form', function(e) {
176             e.preventDefault()
177             $.ajax({
178               url: '/feedback.html',
179               type: 'POST',
180               data: {
181                 page: window.location.href,
182                 message: $('#feedback-form-message').val()
183               },
184               success: function(data, textStatus, jqXHR) {
185                 $('#feedback-modal').modal('hide')
186                 $('#message-modal-message').text(data)
187                 $('#message-modal').modal('show')
188               },
189               error: function(jqXHR, textStatus, errorThrown) {
190                 $('#feedback-modal').modal('hide')
191                 $('#message-modal-message').text(errorThrown)
192                 $('#message-modal').modal('show')
193               }               
194             })
195           })
196         })
197       }
198     }
199   )
200 }