Commit c55f5fcf authored by Fred Chasen's avatar Fred Chasen

Add polyfill config

parent 8bdd6ac7
......@@ -25,6 +25,38 @@ Add the the `paged.polyfill.js` script to replace all `@page` css and render the
Try the [polyfill with Aurorae](https://s3.amazonaws.com/pagedmedia/pagedjs/examples/polyfill.html).
By default the polyfill will run automatically as soon as the DOM is ready.
However, you can add an async `before` function or return a Promise to delay the polyfill starting.
```html
<script>
window.PagedConfig = {
before: () => {
return new Promise(resolve, reject) {
setTimeout(() => { resolve() }, 1000);
}
},
after: (flow) => { console.log("after", flow) },
};
</script>
```
Otherwise you can disable `auto` running the previewer and call `window.PagedPolyfill.preview();`
whenever you want to start.
```html
<script>
window.PagedConfig = {
auto: false
after: (flow) => { console.log("after", flow) },
};
setTimeout(() => {
window.PagedPolyfill.preview();
}, 1000);
</script>
```
## Chunker
Chunks up a document into paged media flows and applies print classes.
......
......@@ -12,68 +12,22 @@
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true
},
skipStartupTypeset: true,
messageStyle: "none"
}
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script>
window.PagedConfig = {
auto: false
};
</script>
<script src="../dist/paged.polyfill.js"></script>
<script>
MathJax.Hub.Register.StartupHook("onLoad",function () {
console.log("*** The onLoad handler has run, page is ready to process ***");
});
MathJax.Hub.Queue(function () {
// let previewer = new Paged.Previewer();
// previewer.preview();
window.PagedPolyfill.preview();
});
class MyHandler extends Paged.Handler {
constructor(chunker, polisher, caller) {
super(chunker, polisher, caller);
}
// beforeChunking(content) {
// var hiddenRender = document.createElement("div");
// hiddenRender.style.display = "none";
// document.body.appendChild(hiddenRender);
//
// var clone = document.importNode(content, true);
// hiddenRender.appendChild(clone);
//
// return new Promise((resolve, reject) => {
// MathJax.Hub.Queue(["Typeset", MathJax.Hub, hiddenRender, () => {
// document.querySelector("template").innerHTML = hiddenRender.innerHTML;
// resolve();
// }]);
// });
// }
layout(pageElement) {
return new Promise((resolve, reject) => {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, pageElement, () => {
resolve();
}]);
});
}
// afterRendered(pages) {
// console.log(pages);
// return new Promise((resolve, reject) => {
// MathJax.Hub.Queue(["Typeset", MathJax.Hub, document.body, () => {
// resolve();
// }]);
// });
// }
}
Paged.registerHandlers(MyHandler);
</script>
......@@ -82,25 +36,9 @@
size: A4;
border: 1px solid black;
}
.math {
break-inside: avoid;
}
</style>
<!-- <script>
window.onload = function() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML";
document.getElementsByTagName("head")[0].appendChild(script);
};
</script> -->
</head>
<body>
......
import Previewer from './previewer';
import * as Paged from '../index';
window.Paged = Paged;
let ready = new Promise(function(resolve, reject){
if (document.readyState === "interactive" || document.readyState === "complete") {
resolve(document.readyState);
......@@ -14,11 +16,32 @@ let ready = new Promise(function(resolve, reject){
}
});
let previewer = new Previewer();
let config = window.PagedConfig || {
auto: true,
before: undefined,
after: undefined,
content: undefined,
stylesheets: undefined,
renderTo: undefined
};
let previewer = new Previewer(config.content, config.stylesheets, config.renderTo);
window.PagedPolyfill = previewer;
window.Paged = Paged;
ready.then(async function () {
await previewer.preview();
let done;
if (config.before) {
await config.before();
}
if(config.auto !== false) {
done = await previewer.preview();
}
if (config.after) {
await config.after(done);
}
});
export default previewer;
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