From 70d1adb20c3e087820286af1a22bd4f9be091ef7 Mon Sep 17 00:00:00 2001 From: Jack Misteli Date: Sun, 22 May 2022 10:15:21 -0500 Subject: [PATCH 1/4] Add local storage save feature in the demo --- examples/browserify/browser.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/browserify/browser.js b/examples/browserify/browser.js index 7d378616..0ae125c0 100644 --- a/examples/browserify/browser.js +++ b/examples/browserify/browser.js @@ -1,4 +1,4 @@ -var PDFDocument = require('../..'); +var PDFDocument = require('../../'); var blobStream = require('blob-stream'); var ace = require('brace'); require('brace/mode/javascript'); @@ -76,7 +76,7 @@ function makePDF(PDFDocument, blobStream, lorem, iframe) { // end and display the document in the iframe to the right doc.end(); - stream.on('finish', function() { + stream.on('finish', function () { iframe.src = stream.toBlobURL('application/pdf'); }); } @@ -85,6 +85,7 @@ var editor = ace.edit('editor'); editor.setTheme('ace/theme/monokai'); editor.getSession().setMode('ace/mode/javascript'); editor.setValue( + localStorage.getItem('editorText') || makePDF .toString() .split('\n') @@ -102,11 +103,13 @@ makePDF(PDFDocument, blobStream, lorem, iframe); let debounceTimeout; -editor.getSession().on('change', function() { +editor.getSession().on('change', function () { try { if (debounceTimeout) { clearTimeout(debounceTimeout); } + const text = editor.getValue() + localStorage.setItem('editorText', text) var fn = new Function( 'PDFDocument', 'blobStream', From fe8541cf584c1c4b62b9e12c04f45daf9e77a7a2 Mon Sep 17 00:00:00 2001 From: Otomakan Date: Sun, 22 May 2022 10:20:57 -0500 Subject: [PATCH 2/4] Update browser.js --- examples/browserify/browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/browserify/browser.js b/examples/browserify/browser.js index 0ae125c0..d4fb42a8 100644 --- a/examples/browserify/browser.js +++ b/examples/browserify/browser.js @@ -1,4 +1,4 @@ -var PDFDocument = require('../../'); +var PDFDocument = require('../..'); var blobStream = require('blob-stream'); var ace = require('brace'); require('brace/mode/javascript'); From 06e46a0540378b80d8dbc186be88007006f6f5fe Mon Sep 17 00:00:00 2001 From: Otomakan Date: Sun, 22 May 2022 10:21:41 -0500 Subject: [PATCH 3/4] Update browser.js --- examples/browserify/browser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/browserify/browser.js b/examples/browserify/browser.js index d4fb42a8..bd31384f 100644 --- a/examples/browserify/browser.js +++ b/examples/browserify/browser.js @@ -76,7 +76,7 @@ function makePDF(PDFDocument, blobStream, lorem, iframe) { // end and display the document in the iframe to the right doc.end(); - stream.on('finish', function () { + stream.on('finish', function() { iframe.src = stream.toBlobURL('application/pdf'); }); } @@ -103,7 +103,7 @@ makePDF(PDFDocument, blobStream, lorem, iframe); let debounceTimeout; -editor.getSession().on('change', function () { +editor.getSession().on('change', function() { try { if (debounceTimeout) { clearTimeout(debounceTimeout); From 6456e00c1297e58d2ec5bd5dcbe8ecadbea985e1 Mon Sep 17 00:00:00 2001 From: Otomakan Date: Sun, 22 May 2022 10:22:10 -0500 Subject: [PATCH 4/4] Update browser.js --- examples/browserify/browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/browserify/browser.js b/examples/browserify/browser.js index bd31384f..39657960 100644 --- a/examples/browserify/browser.js +++ b/examples/browserify/browser.js @@ -115,7 +115,7 @@ editor.getSession().on('change', function() { 'blobStream', 'lorem', 'iframe', - editor.getValue() + text ); debounceTimeout = setTimeout(() => { fn(PDFDocument, blobStream, lorem, iframe);