forked from svivian/q2a-markdown-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qa-md-layer.php
70 lines (59 loc) · 1.75 KB
/
qa-md-layer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
Question2Answer Markdown editor plugin
License: http://www.gnu.org/licenses/gpl.html
*/
class qa_html_theme_layer extends qa_html_theme_base
{
private $cssopt = 'markdown_editor_css';
private $hljsopt = 'markdown_highlightjs';
function head_custom()
{
parent::head_custom();
$tmpl = array( 'ask', 'question' );
if ( !in_array($this->template, $tmpl) )
return;
$hidecss = qa_opt($this->cssopt) === '1';
$usehljs = qa_opt($this->hljsopt) === '1';
$wmd_buttons = QA_HTML_THEME_LAYER_URLTOROOT . 'pagedown/wmd-buttons.png';
$this->output_raw(
"<style>\n" .
".wmd-button > span { background-image: url('$wmd_buttons') }\n"
);
// display CSS for Markdown Editor
if ( !$hidecss )
{
$cssWMD = file_get_contents( QA_HTML_THEME_LAYER_DIRECTORY . 'pagedown/wmd.css' );
$this->output_raw($cssWMD);
// display CSS for HighlightJS
if ( $usehljs )
{
$cssHJS = file_get_contents( QA_HTML_THEME_LAYER_DIRECTORY . 'pagedown/highlightjs.css' );
$this->output_raw($cssHJS);
}
}
$this->output_raw("</style>\n\n");
// set up HighlightJS
if ( $usehljs )
{
$this->output_raw(
"<script src=\"" . QA_HTML_THEME_LAYER_URLTOROOT . "pagedown/highlight.min.js\"></script>\n" .
"<script type=\"text/javascript\">\n" .
"$(function(){\n" .
" $('.wmd-input').keypress(function(){\n" .
" window.clearTimeout(hljs.Timeout);\n" .
" hljs.Timeout = window.setTimeout(function() {\n" .
" hljs.initHighlighting.called = false;\n" .
" hljs.initHighlighting();\n" .
" }, 500);\n" .
" });\n" .
" window.setTimeout(function() {\n" .
" hljs.initHighlighting.called = false;\n" .
" hljs.initHighlighting();\n" .
" }, 500);\n" .
"});\n" .
"</script>\n\n"
);
}
}
}