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-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
|
|
|
|
2019-04-12 09:54:34 +00:00
|
|
|
require('../css/extra.css')
|
|
|
|
require('../css/site.css')
|
|
|
|
|
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(() => {
|
2019-04-12 09:54:34 +00:00
|
|
|
// tooltip
|
2017-03-08 18:41:05 +00:00
|
|
|
$('[data-toggle="tooltip"]').tooltip()
|
|
|
|
})
|
|
|
|
|
|
|
|
function extend () {
|
|
|
|
const target = {}
|
|
|
|
|
|
|
|
for (const source of arguments) {
|
|
|
|
for (const key in source) {
|
2019-08-01 17:03:24 +00:00
|
|
|
if (Object.hasOwnProperty.call(source, key)) {
|
2017-03-08 18:41:05 +00:00
|
|
|
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
|
|
|
|
2019-10-20 06:18:21 +00:00
|
|
|
// options from yaml meta
|
|
|
|
const meta = JSON.parse($('#meta').text())
|
|
|
|
// breaks
|
|
|
|
if (typeof meta.breaks === 'boolean') {
|
|
|
|
md.options.breaks = meta.breaks
|
|
|
|
} else {
|
|
|
|
md.options.breaks = window.defaultUseHardbreak
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-03-08 18:41:05 +00:00
|
|
|
var options = meta.slideOptions || {}
|
2021-01-21 05:23:47 +00:00
|
|
|
// delete dependencies to avoid import user defined external resources
|
|
|
|
delete options.dependencies
|
2016-08-14 07:02:05 +00:00
|
|
|
|
2019-08-01 17:03:24 +00:00
|
|
|
if (Object.hasOwnProperty.call(options, 'spotlight')) {
|
2019-04-05 07:05:36 +00:00
|
|
|
defaultOptions.dependencies.push({
|
|
|
|
src: `${serverurl}/build/reveal.js/plugin/spotlight/spotlight.js`
|
2019-06-27 09:37:16 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-08-01 17:03:24 +00:00
|
|
|
if (Object.hasOwnProperty.call(options, 'allottedTime') || Object.hasOwnProperty.call(options, 'allottedMinutes')) {
|
2019-04-05 07:53:10 +00:00
|
|
|
defaultOptions.dependencies.push({
|
|
|
|
src: `${serverurl}/build/reveal.js/plugin/elapsed-time-bar/elapsed-time-bar.js`
|
2019-06-27 09:37:16 +00:00
|
|
|
})
|
2019-08-01 17:03:24 +00:00
|
|
|
if (Object.hasOwnProperty.call(options, 'allottedMinutes')) {
|
2019-06-27 09:37:16 +00:00
|
|
|
options.allottedTime = options.allottedMinutes * 60 * 1000
|
2019-04-05 07:53:10 +00:00
|
|
|
}
|
2019-04-05 07:05:36 +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
|
|
|
}
|
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')
|
2019-08-01 17:03:24 +00:00
|
|
|
const title = document.title
|
2017-03-08 18:41:05 +00:00
|
|
|
finishView(slides)
|
|
|
|
document.title = title
|
|
|
|
Reveal.layout()
|
|
|
|
} else {
|
|
|
|
const markdown = $(event.currentSlide)
|
|
|
|
if (!markdown.attr('data-rendered')) {
|
2019-08-01 17:03:24 +00:00
|
|
|
const title = document.title
|
2017-03-08 18:41:05 +00:00
|
|
|
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)
|
2019-04-12 09:54:34 +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')
|