mirror of
https://github.com/zamentur/libreto.git
synced 2025-11-05 22:05:00 +05:30
Add support for book.js and book.css -> enable user to change book size and more
This commit is contained in:
parent
d40a7d4080
commit
e0d5f06508
5 changed files with 33 additions and 9 deletions
|
|
@ -34,7 +34,7 @@ $(document ).ready( function() {
|
|||
});
|
||||
|
||||
$("header .btn-about").click(function(){
|
||||
$(".modal-about, .modal-cover").removeClass('hide');
|
||||
$(".modal, .modal-cover").removeClass('hide');
|
||||
});
|
||||
|
||||
$(".modal .btn-close").click(function(){
|
||||
|
|
|
|||
|
|
@ -191,8 +191,6 @@ class Pad
|
|||
$body = preg_replace('#<a.*?>(.*?)</a>#i', '\1', $body);
|
||||
// convert <br> to newline
|
||||
$body = br2nl($body);
|
||||
// convert to markdown
|
||||
//$markdown = $Markdownify->parseString($body);
|
||||
// parse to html
|
||||
$html = $Parsedown->text($body);
|
||||
// sanitize
|
||||
|
|
@ -204,13 +202,19 @@ class Pad
|
|||
}
|
||||
|
||||
public function css(){
|
||||
if (!$this->url('markdown')) { return; }
|
||||
|
||||
$css = strip_tags(file_get_contents($this->url('txt')));
|
||||
return $css;
|
||||
|
||||
}
|
||||
|
||||
public function js(){
|
||||
|
||||
$js = strip_tags(file_get_contents($this->url('txt')));
|
||||
return $js;
|
||||
|
||||
}
|
||||
|
||||
public function visible($filter = false){
|
||||
global $libreto;
|
||||
if($filter) :
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ class Pads
|
|||
|
||||
private $pads = array();
|
||||
private $css = false;
|
||||
private $book_js = false;
|
||||
private $book_css = false;
|
||||
|
||||
public function __construct($pads = array()) {
|
||||
$this->push($pads);
|
||||
|
|
@ -14,7 +16,7 @@ class Pads
|
|||
public function push($pads){
|
||||
$pads = (array)$pads;
|
||||
foreach ($pads as $pad) :
|
||||
if(endsWith($pad, '.css')):
|
||||
if(endsWith($pad, '.css') || endsWith($pad, '.js')):
|
||||
$this->pads[] = new Pad($pad . ' (type: settings visibility: private)');
|
||||
else:
|
||||
$this->pads[] = new Pad($pad);
|
||||
|
|
@ -30,6 +32,20 @@ class Pads
|
|||
return false;
|
||||
}
|
||||
|
||||
public function book_css() {
|
||||
if($book_css = $this->find('book.css')):
|
||||
return $book_css->css();
|
||||
endif;
|
||||
return false;
|
||||
}
|
||||
|
||||
public function book_js() {
|
||||
if($book_js = $this->find('book.js')):
|
||||
return $book_js->js();
|
||||
endif;
|
||||
return false;
|
||||
}
|
||||
|
||||
public function find($p){
|
||||
foreach($this->pads as $pad) :
|
||||
if (strtolower($pad->id()) == strtolower($p)):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?php global $libreto ?>
|
||||
<div class="modal-cover hide"></div>
|
||||
<div class="modal-cover <?= count($libreto->pads()->children()) > 1 ? 'hide' : '' ?>"></div>
|
||||
<div class="modal modal-about <?= count($libreto->pads()->children()) > 1 ? 'hide' : '' ?>">
|
||||
<div class="title"><?= l("modal-help-title") ?></div>
|
||||
<button class="btn-close">×</button>
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ global $libreto;
|
|||
|
||||
<script src="/libreto/assets/js/bindery.umd.js"></script>
|
||||
<script src="/libreto/assets/js/bindery-controls.min.js"></script>
|
||||
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
|
||||
<link rel="stylesheet" href="/libreto/assets/style-reader.css">
|
||||
<style><?= $libreto->pads()->find('book.css') ? $libreto->pads()->find('book.css')->css() : ''; ?></style>
|
||||
<style><?= $libreto->pads()->book_css(); ?></style>
|
||||
<script>
|
||||
Bindery.makeBook({
|
||||
var defaultBook = {
|
||||
content: {
|
||||
selector: '.content',
|
||||
url: '/reader/<?= $libreto->name() ?>/',
|
||||
|
|
@ -67,7 +68,10 @@ global $libreto;
|
|||
}),
|
||||
Bindery.FullBleedPage({ selector: '.fullpage', continue: 'next' }),
|
||||
]
|
||||
})
|
||||
};
|
||||
var customBook = <?= $libreto->pads()->book_js() ?>;
|
||||
var options = $.extend( true, defaultBook, customBook );
|
||||
Bindery.makeBook(options);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue