2017-03-08 18:41:05 +00:00
|
|
|
/* eslint-env browser, jquery */
|
2017-03-21 12:44:12 +00:00
|
|
|
/* global serverurl, Reveal, RevealMarkdown */
|
2016-10-10 00:25:35 +00:00
|
|
|
|
2017-03-08 18:41:05 +00:00
|
|
|
require('../css/extra.css')
|
|
|
|
require('../css/site.css')
|
2016-10-10 00:25:35 +00:00
|
|
|
|
2017-09-27 10:21:28 +00:00
|
|
|
import { preventXSS } from './render'
|
2017-03-14 08:27:55 +00:00
|
|
|
import { md, updateLastChange, removeDOMEvents, finishView } from './extra'
|
2016-10-10 00:25:35 +00:00
|
|
|
|
2017-09-27 10:21:28 +00:00
|
|
|
const body = preventXSS($('.slides').text())
|
2016-07-02 08:09:26 +00:00
|
|
|
|
2017-03-08 18:41:05 +00:00
|
|
|
window.createtime = window.lastchangeui.time.attr('data-createtime')
|
|
|
|
window.lastchangetime = window.lastchangeui.time.attr('data-updatetime')
|
|
|
|
updateLastChange()
|
|
|
|
const url = window.location.pathname
|
|
|
|
$('.ui-edit').attr('href', `${url}/edit`)
|
2018-06-24 21:50:19 +00:00
|
|
|
$('.ui-print').attr('href', `${url}?print-pdf`)
|
2016-08-15 03:25:27 +00:00
|
|
|
|
2017-01-05 08:17:28 +00:00
|
|
|
$(document).ready(() => {
|
2017-03-08 18:41:05 +00:00
|
|
|
// tooltip
|
|
|
|
$('[data-toggle="tooltip"]').tooltip()
|
|
|
|
})
|
|
|
|
|
|
|
|
function extend () {
|
|
|
|
const target = {}
|
|
|
|
|
|
|
|
for (const source of arguments) {
|
|
|
|
for (const key in source) {
|
|
|
|
if (source.hasOwnProperty(key)) {
|
|
|
|
target[key] = source[key]
|
|
|
|
}
|
2016-07-02 08:09:26 +00:00
|
|
|
}
|
2017-03-08 18:41:05 +00:00
|
|
|
}
|
2017-01-05 08:17:28 +00:00
|
|
|
|
2017-03-08 18:41:05 +00:00
|
|
|
return target
|
2016-07-02 08:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Optional libraries used to extend on reveal.js
|
2017-01-05 08:17:28 +00:00
|
|
|
const deps = [{
|
2017-03-08 18:41:05 +00:00
|
|
|
src: `${serverurl}/build/reveal.js/lib/js/classList.js`,
|
|
|
|
condition () {
|
|
|
|
return !document.body.classList
|
|
|
|
}
|
2016-07-02 08:09:26 +00:00
|
|
|
}, {
|
2017-03-08 18:41:05 +00:00
|
|
|
src: `${serverurl}/build/reveal.js/plugin/notes/notes.js`,
|
|
|
|
async: true,
|
|
|
|
condition () {
|
|
|
|
return !!document.body.classList
|
|
|
|
}
|
|
|
|
}]
|
2016-07-02 08:09:26 +00:00
|
|
|
|
2017-03-21 12:44:12 +00:00
|
|
|
const slideOptions = {
|
|
|
|
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
|
|
|
|
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
|
|
|
|
}
|
|
|
|
const slides = RevealMarkdown.slidify(body, slideOptions)
|
|
|
|
$('.slides').html(slides)
|
|
|
|
RevealMarkdown.initialize()
|
|
|
|
removeDOMEvents($('.slides'))
|
|
|
|
$('.slides').show()
|
|
|
|
|
2016-07-02 08:09:26 +00:00
|
|
|
// default options to init reveal.js
|
2017-01-05 08:17:28 +00:00
|
|
|
const defaultOptions = {
|
2017-03-08 18:41:05 +00:00
|
|
|
controls: true,
|
|
|
|
progress: true,
|
|
|
|
slideNumber: true,
|
|
|
|
history: true,
|
|
|
|
center: true,
|
|
|
|
transition: 'none',
|
|
|
|
dependencies: deps
|
|
|
|
}
|
2016-07-02 08:09:26 +00:00
|
|
|
|
2016-07-31 16:08:22 +00:00
|
|
|
// options from yaml meta
|
2017-03-08 18:41:05 +00:00
|
|
|
const meta = JSON.parse($('#meta').text())
|
|
|
|
var options = meta.slideOptions || {}
|
2016-08-14 07:02:05 +00:00
|
|
|
|
2017-03-08 18:41:05 +00:00
|
|
|
const view = $('.reveal')
|
2016-08-14 07:02:05 +00:00
|
|
|
|
2017-03-08 18:41:05 +00:00
|
|
|
// text language
|
|
|
|
if (meta.lang && typeof meta.lang === 'string') {
|
|
|
|
view.attr('lang', meta.lang)
|
2016-08-14 07:02:05 +00:00
|
|
|
} else {
|
2017-03-08 18:41:05 +00:00
|
|
|
view.removeAttr('lang')
|
2016-08-14 07:02:05 +00:00
|
|
|
}
|
2017-03-08 18:41:05 +00:00
|
|
|
// text direction
|
|
|
|
if (meta.dir && typeof meta.dir === 'string' && meta.dir === 'rtl') {
|
|
|
|
options.rtl = true
|
2016-08-14 07:02:05 +00:00
|
|
|
} else {
|
2017-03-08 18:41:05 +00:00
|
|
|
options.rtl = false
|
2016-08-14 07:02:05 +00:00
|
|
|
}
|
2017-03-08 18:41:05 +00:00
|
|
|
// breaks
|
2016-08-14 07:02:05 +00:00
|
|
|
if (typeof meta.breaks === 'boolean' && !meta.breaks) {
|
2017-03-08 18:41:05 +00:00
|
|
|
md.options.breaks = false
|
2016-08-14 07:02:05 +00:00
|
|
|
} else {
|
2017-03-08 18:41:05 +00:00
|
|
|
md.options.breaks = true
|
2016-08-14 07:02:05 +00:00
|
|
|
}
|
2016-07-31 16:08:22 +00:00
|
|
|
|
2016-07-02 08:09:26 +00:00
|
|
|
// options from URL query string
|
2017-03-08 18:41:05 +00:00
|
|
|
const queryOptions = Reveal.getQueryHash() || {}
|
2016-07-02 08:09:26 +00:00
|
|
|
|
2017-03-08 18:41:05 +00:00
|
|
|
options = extend(defaultOptions, options, queryOptions)
|
|
|
|
Reveal.initialize(options)
|
2016-07-02 08:09:26 +00:00
|
|
|
|
2017-01-05 08:17:28 +00:00
|
|
|
window.viewAjaxCallback = () => {
|
2017-03-08 18:41:05 +00:00
|
|
|
Reveal.layout()
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderSlide (event) {
|
|
|
|
if (window.location.search.match(/print-pdf/gi)) {
|
|
|
|
const slides = $('.slides')
|
|
|
|
let title = document.title
|
|
|
|
finishView(slides)
|
|
|
|
document.title = title
|
|
|
|
Reveal.layout()
|
|
|
|
} else {
|
|
|
|
const markdown = $(event.currentSlide)
|
|
|
|
if (!markdown.attr('data-rendered')) {
|
|
|
|
let title = document.title
|
|
|
|
finishView(markdown)
|
|
|
|
markdown.attr('data-rendered', 'true')
|
|
|
|
document.title = title
|
|
|
|
Reveal.layout()
|
2016-07-30 12:33:32 +00:00
|
|
|
}
|
2017-03-08 18:41:05 +00:00
|
|
|
}
|
2016-07-02 08:09:26 +00:00
|
|
|
}
|
|
|
|
|
2017-01-05 08:17:28 +00:00
|
|
|
Reveal.addEventListener('ready', event => {
|
2017-03-08 18:41:05 +00:00
|
|
|
renderSlide(event)
|
|
|
|
const markdown = $(event.currentSlide)
|
2016-08-15 03:28:48 +00:00
|
|
|
// force browser redraw
|
2017-03-08 18:41:05 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
markdown.hide().show(0)
|
|
|
|
}, 0)
|
|
|
|
})
|
|
|
|
Reveal.addEventListener('slidechanged', renderSlide)
|
2016-08-15 03:30:12 +00:00
|
|
|
|
2017-06-14 04:12:28 +00:00
|
|
|
const isWinLike = navigator.platform.indexOf('Win') > -1
|
2016-08-15 03:30:12 +00:00
|
|
|
|
2017-06-14 04:12:28 +00:00
|
|
|
if (isWinLike) $('.container').addClass('hidescrollbar')
|