Commit 08f916d2 authored by Julie Blanc's avatar Julie Blanc
Browse files

documentation: informations about hooks

parent af05929a
......@@ -4,6 +4,7 @@ date: 2020-01-28T16:16:50+01:00
draft: false
weight: 12
part: 10
id: doc-handlers
intro: "You’re now fluent in paged media specs, that quite awesome :). But you may want to do more with the scripts. Here is how you can update some of the script to do what you’d like to do."
---
......@@ -64,6 +65,61 @@ onOverflow(overflow, rendered, bounds)
onBreakToken(breakToken, overflow, rendered)
```
### Some informations about the hooks
Here is some information about some hooks, the documentation remains to be completed. Their execution order is not quite the same as the one presented and corresponds rather to the different modules that constitute Paged.js
#### Previewer
| Hook | Hooks order | Attributes |
| ------------- |:-------------:| -----:|
| `beforePreview(content, renderTo)` | Before pagedjs is launched [Warning : event does not trigger] | |
| `afterPreview(pages)` | After PagedJS finished running (check afterRendered(pages) | `pages` → array that contains all page nodes |
| | | |
#### Chuncker
| Hook | Hooks order | Attributes |
| ------------- |:-------------:| -----:|
| `beforeParsed(content)` | runs on content before it is parsed and given IDs | `content` → document-fragment made from the original DOM |
| `afterParsed(parsed)` | runs after the content has been parsed but before rendering has started | `parsed` → content once parsed and given ids (data-ref and break rules from the css) |
| `beforePageLayout(page)` | runs when a new page has been created | `page` → node of the page that’s gonna be created |
| `afterPageLayout(pageElement, page, breakToken)` | runs after a single page has gone through layout, and allows adjusting the breakToken | `pageElement` → page element that just been rendered, <br> `page` → node of the page being rendered,<br> `breakToken` → location of the beginning of the overflow |
| `afterRendered(pages)` | runs after all pages have finished rendering | `pages` → array that contains all page nodes |
||||
||||
#### Polisher
| Hook | Hooks order | Attributes |
| ------------- |:-------------:| -----:|
| `beforeTreeParse(text, sheet)` | runs every time a style element or a link to a css file is called (worked also on @import) | `text` → innerText of the css, <br> `sheet` → cssTree parsed object (AST object) |
| `beforeTreeWalk(ast)` | runs before the stylesheet has been parsed by csstree | `ast` → csstree parsed object |
| `afterTreeWalk(ast, sheet)` | runs after the stylesheet has been parsed by csstree | `ast` → csstree parsed object, <br> `sheet` → object that contains text and ast |
| `onUrl(urlNode)` | runs any time a CSS URL is parsed | `urlNode` → url origin |
| `onAtPage(atPageNode)` | runs any time a CSS @page is parsed ||
| `onRule(ruleNode)` | runs any time a CSS rule is parsed ||
| `onDeclaration(declaration, dItem, dList, rule)` | runs any time a CSS declaration is parsed ||
| `onContent(contentNode, declarationNode, ruleNode)` | run every time a css content property is found ||
||||
||||
||||
#### Layout
| Hook | Hooks order | Attributes |
| ------------- |:-------------:| -----:|
| `layoutNode(node)` | When a node is layed out <br> (Tips: layoutNode is the original node from the content) ||
| `renderNode(node, sourceNode)` | When a node is rendered <br> (Tips: renderNode is the cloned node that is added to the DOM) ||
| `onOverflow(overflow, rendered, bounds)` | When an element overflows: when it’s bigger than the remaining space on the page ||
| `onBreakToken(breakToken, overflow, rendered)` | When a breakToken is defined ||
## Some examples
### cleaning hyperlinks for the print
......
......@@ -11,4 +11,9 @@
margin-top: 4em;
}
}
#doc-handlers table {
text-align: left!important;
}
\ No newline at end of file
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