Commit 3b893392 authored by Fred Chasen's avatar Fred Chasen

Merge branch 'add_previewer_settings' into 'master'

Add settings options in previewer, chunker and layout

See merge request tools/pagedjs!73
parents 5b2060ba f0fdaeeb
...@@ -83,9 +83,11 @@ const TEMPLATE = ` ...@@ -83,9 +83,11 @@ const TEMPLATE = `
* @class * @class
*/ */
class Chunker { class Chunker {
constructor(content, renderTo) { constructor(content, renderTo, options) {
// this.preview = preview; // this.preview = preview;
this.settings = options || {};
this.hooks = {}; this.hooks = {};
this.hooks.beforeParsed = new Hook(this); this.hooks.beforeParsed = new Hook(this);
this.hooks.afterParsed = new Hook(this); this.hooks.afterParsed = new Hook(this);
...@@ -197,7 +199,7 @@ class Chunker { ...@@ -197,7 +199,7 @@ class Chunker {
// } // }
async render(parsed, startAt) { async render(parsed, startAt) {
let renderer = this.layout(parsed, startAt); let renderer = this.layout(parsed, startAt, this.settings);
let done = false; let done = false;
let result; let result;
......
...@@ -35,7 +35,7 @@ const MAX_CHARS_PER_BREAK = 1500; ...@@ -35,7 +35,7 @@ const MAX_CHARS_PER_BREAK = 1500;
*/ */
class Layout { class Layout {
constructor(element, hooks, maxChars) { constructor(element, hooks, options) {
this.element = element; this.element = element;
this.bounds = this.element.getBoundingClientRect(); this.bounds = this.element.getBoundingClientRect();
...@@ -52,7 +52,9 @@ class Layout { ...@@ -52,7 +52,9 @@ class Layout {
this.hooks.onBreakToken = new Hook(); this.hooks.onBreakToken = new Hook();
} }
this.maxChars = maxChars || MAX_CHARS_PER_BREAK; this.settings = options || {};
this.maxChars = this.settings.maxChars || MAX_CHARS_PER_BREAK;
} }
async renderTo(wrapper, source, breakToken, bounds=this.bounds) { async renderTo(wrapper, source, breakToken, bounds=this.bounds) {
...@@ -589,11 +591,11 @@ class Layout { ...@@ -589,11 +591,11 @@ class Layout {
// Add a hyphen if previous character is a letter or soft hyphen // Add a hyphen if previous character is a letter or soft hyphen
if ( if (
(breakLetter && /^\w|\u00AD$/.test(prevLetter) && /^\w|\u00AD$/.test(breakLetter)) || (breakLetter && /^\w|\u00AD$/.test(prevLetter) && /^\w|\u00AD$/.test(breakLetter)) ||
(!breakLetter && /^\w|\u00AD$/.test(prevLetter)) (!breakLetter && /^\w|\u00AD$/.test(prevLetter))
) { ) {
startContainer.parentNode.classList.add("pagedjs_hyphen"); startContainer.parentNode.classList.add("pagedjs_hyphen");
startContainer.textContent += "\u2011"; startContainer.textContent += this.settings.hyphenGlyph || "\u2011";
} }
} }
} }
......
...@@ -22,10 +22,11 @@ let config = window.PagedConfig || { ...@@ -22,10 +22,11 @@ let config = window.PagedConfig || {
after: undefined, after: undefined,
content: undefined, content: undefined,
stylesheets: undefined, stylesheets: undefined,
renderTo: undefined renderTo: undefined,
settings: undefined
}; };
let previewer = new Previewer(); let previewer = new Previewer(config.settings);
ready.then(async function () { ready.then(async function () {
let done; let done;
......
...@@ -7,14 +7,16 @@ import Polisher from "../polisher/polisher"; ...@@ -7,14 +7,16 @@ import Polisher from "../polisher/polisher";
import { registerHandlers, initializeHandlers } from "../utils/handlers"; import { registerHandlers, initializeHandlers } from "../utils/handlers";
class Previewer { class Previewer {
constructor() { constructor(options) {
// this.preview = this.getParams("preview") !== "false"; // this.preview = this.getParams("preview") !== "false";
this.settings = options || {};
// Process styles // Process styles
this.polisher = new Polisher(false); this.polisher = new Polisher(false);
// Chunk contents // Chunk contents
this.chunker = new Chunker(); this.chunker = new Chunker(undefined, undefined, this.settings);
// Hooks // Hooks
this.hooks = {}; this.hooks = {};
......
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