bludit/plugins/simplemde/plugin.php

96 lines
2.2 KiB
PHP
Raw Normal View History

2015-08-27 07:05:59 +02:00
<?php
class pluginsimpleMDE extends Plugin {
private $loadWhenController = array(
'new-post',
'new-page',
'edit-post',
'edit-page'
);
2015-09-04 02:46:17 +02:00
public function init()
{
$this->dbFields = array(
'tabSize'=>'2',
'toolbar'=>'"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen", "guide"'
);
}
public function form()
2015-08-27 07:05:59 +02:00
{
global $Language;
2015-09-04 02:46:17 +02:00
$html = '<div>';
$html .= '<label>'.$Language->get('Toolbar').'</label>';
$html .= '<input name="toolbar" id="jstoolbar" type="text" value="'.$this->getDbField('toolbar').'">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$Language->get('Tab size').'</label>';
$html .= '<input name="tabSize" id="jstabSize" type="text" value="'.$this->getDbField('tabSize').'">';
$html .= '</div>';
return $html;
}
public function adminHead()
{
2015-08-27 07:05:59 +02:00
global $layout;
$html = '';
// Load CSS and JS only on Controllers in array.
if(in_array($layout['controller'], $this->loadWhenController))
{
2015-09-04 02:46:17 +02:00
// Path plugin.
2015-08-27 07:05:59 +02:00
$pluginPath = $this->htmlPath();
2015-09-04 02:46:17 +02:00
// Load CSS
2015-08-29 07:02:09 +02:00
$html .= '<link rel="stylesheet" href="'.$pluginPath.'css/simplemde.min.css">';
2015-09-04 02:46:17 +02:00
// Load Javascript
$html .= '<script src="'.$pluginPath.'js/simplemde.min.js"></script>';
2015-08-29 07:02:09 +02:00
2015-09-04 02:46:17 +02:00
// Hack for Bludit
$html .= '<style>
.editor-toolbar::before { margin-bottom: 2px !important }
.editor-toolbar::after { margin-top: 2px !important }
</style>';
2015-08-27 07:05:59 +02:00
}
return $html;
}
public function adminBodyEnd()
{
global $layout;
$html = '';
// Load CSS and JS only on Controllers in array.
if(in_array($layout['controller'], $this->loadWhenController))
{
$pluginPath = $this->htmlPath();
$html = '<script>$(document).ready(function() { ';
$html .=
'var simplemde = new SimpleMDE({
element: document.getElementById("jscontent"),
2015-08-29 07:02:09 +02:00
status: false,
2015-08-27 07:05:59 +02:00
toolbarTips: true,
toolbarGuideIcon: true,
2015-08-29 20:07:47 +02:00
autofocus: false,
2015-08-27 07:05:59 +02:00
lineWrapping: false,
indentWithTabs: true,
2015-09-04 02:46:17 +02:00
tabSize: '.$this->getDbField('tabSize').',
spellChecker: false,
toolbar: ['.Sanitize::htmlDecode($this->getDbField('toolbar')).']
2015-08-27 07:05:59 +02:00
});';
$html .= '}); </script>';
}
return $html;
}
2015-09-04 02:46:17 +02:00
}