Commit 5b2060ba authored by Fred Chasen's avatar Fred Chasen

Merge branch 'preview_hooks' into 'master'

Add beforePreview and afterPreview hooks per #63

See merge request tools/pagedjs!70
parents 489ce7b7 3c6bfca3
......@@ -111,6 +111,10 @@ New handlers can be registered from `import { registerHandlers } from 'pagedjs'`
Handlers have methods that correspond to the hooks for the parsing, layout and rendering of the Chunker and Polisher. Returning an promise or `async` function from a method in a handler will complete that task before continuing with the other registered methods for that hook.
```js
// Previewer
beforePreview(content, renderTo)
afterPreview(pages)
// Chunker
beforeParsed(content)
afterParsed(parsed)
......
import EventEmitter from "event-emitter";
import Hook from "../utils/hook";
import Chunker from "../chunker/chunker";
import Polisher from "../polisher/polisher";
......@@ -17,6 +18,8 @@ class Previewer {
// Hooks
this.hooks = {};
this.hooks.beforePreview = new Hook(this);
this.hooks.afterPreview = new Hook(this);
// default size
this.size = {
......@@ -116,6 +119,8 @@ class Previewer {
async preview(content, stylesheets, renderTo) {
await this.hooks.beforePreview.trigger(content, renderTo);
if (!content) {
content = this.wrapContent();
}
......@@ -142,6 +147,8 @@ class Previewer {
this.emit("rendered", flow);
await this.hooks.afterPreview.trigger(flow.pages);
return flow;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment