Skip to content

Commit d848d43

Browse files
committed
As-you-type demo editor
1 parent 3b05233 commit d848d43

2 files changed

Lines changed: 22 additions & 41 deletions

File tree

examples/editor.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

examples/js/editor.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
/**
22
* jsPDFEditor
3-
*
4-
* This is the demo interface for jsPDF.
3+
* @return {[type]} [description]
54
*/
65
var jsPDFEditor = function() {
7-
6+
7+
var editor;
8+
89
return {
910
init: function() {
1011

12+
var timeout = setTimeout(function(){ }, 0);
1113

12-
var editor = ace.edit("editor");
14+
editor = ace.edit("editor");
1315

1416
editor.setTheme("ace/theme/monokai");
15-
editor.getSession().setMode("ace/mode/javascript");
17+
editor.getSession().setMode("ace/mode/javascript");
18+
19+
editor.getSession().on('change', function() {
20+
if ($('#auto-refresh').is(':checked')) {
21+
clearTimeout(timeout);
22+
timeout = setTimeout(function() {
23+
jsPDFEditor.update();
24+
25+
}, 200);
26+
}
1627

17-
console.log('hello');
18-
var doc = new jsPDF();
19-
doc.text(10, 10, 'Hello world.');
20-
var string = doc.output('datauristring');
28+
});
2129

22-
$('iframe').attr('src', string);
2330

2431
},
2532
update: function() {
33+
setTimeout(function() {
34+
eval(editor.getValue());
35+
var string = doc.output('datauristring');
2636

37+
$('iframe').attr('src', string);
38+
}, 0);
2739

2840
}
2941
};

0 commit comments

Comments
 (0)