220 lines
7.9 KiB
HTML
Executable File
220 lines
7.9 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>examples/js/test_harness.js - Documentation</title>
|
|
|
|
<script src="scripts/prettify/prettify.js"></script>
|
|
<script src="scripts/prettify/lang-css.js"></script>
|
|
<!--[if lt IE 9]>
|
|
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
<![endif]-->
|
|
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
</head>
|
|
<body>
|
|
|
|
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
<label for="nav-trigger" class="navicon-button x">
|
|
<div class="navicon"></div>
|
|
</label>
|
|
|
|
<label for="nav-trigger" class="overlay"></label>
|
|
|
|
<nav>
|
|
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="FontObject.html">FontObject</a></li><li><a href="jsPDF.html">jsPDF</a></li><li><a href="PubSub.html">PubSub</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addFont">addFont</a></li><li><a href="global.html#addMetadata">addMetadata</a></li><li><a href="global.html#addPage">addPage</a></li><li><a href="global.html#CapJoinStyles">CapJoinStyles</a></li><li><a href="global.html#circle">circle</a></li><li><a href="global.html#CssColors">CssColors</a></li><li><a href="global.html#ellipse">ellipse</a></li><li><a href="global.html#getFontList">getFontList</a></li><li><a href="global.html#html2pdf">html2pdf</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#jsPDFEditor">jsPDFEditor</a></li><li><a href="global.html#lines">lines</a></li><li><a href="global.html#output">output</a></li><li><a href="global.html#pdf_test_harness_init">pdf_test_harness_init</a></li><li><a href="global.html#rect">rect</a></li><li><a href="global.html#requirejs">requirejs</a></li><li><a href="global.html#reset">reset</a></li><li><a href="global.html#roundedRect">roundedRect</a></li><li><a href="global.html#save">save</a></li><li><a href="global.html#setDrawColor">setDrawColor</a></li><li><a href="global.html#setFillColor">setFillColor</a></li><li><a href="global.html#setFont">setFont</a></li><li><a href="global.html#setFontSize">setFontSize</a></li><li><a href="global.html#setFontStyle">setFontStyle</a></li><li><a href="global.html#setLineCap">setLineCap</a></li><li><a href="global.html#setLineJoin">setLineJoin</a></li><li><a href="global.html#setLineWidth">setLineWidth</a></li><li><a href="global.html#setProperties">setProperties</a></li><li><a href="global.html#setTextColor">setTextColor</a></li><li><a href="global.html#text">text</a></li><li><a href="global.html#toUrl">toUrl</a></li><li><a href="global.html#triangle">triangle</a></li><li><a href="global.html#triggerEvent">triggerEvent</a></li><li><a href="global.html#update">update</a></li></ul>
|
|
</nav>
|
|
|
|
<div id="main">
|
|
|
|
<h1 class="page-title">examples/js/test_harness.js</h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section>
|
|
<article>
|
|
<pre class="prettyprint source linenums"><code>/**
|
|
* jsPDF PDF Test Harness
|
|
* Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv
|
|
*
|
|
* Licensed under the MIT License.
|
|
* http://opensource.org/licenses/mit-license
|
|
*/
|
|
|
|
/**
|
|
* An easy way to view PDF and PDF source code side by side.
|
|
*/
|
|
pdf_test_harness_init = function(pdf, message) {
|
|
|
|
var harness = new pdf_test_harness();
|
|
|
|
var body = document.getElementsByTagName('body')[0];
|
|
body.style.display = 'flex';
|
|
|
|
var div = document.createElement('div');
|
|
div.setAttribute('style', 'position:fixed;height:20px;left:0;right:0;background:lightblue');
|
|
body.appendChild(div);
|
|
harness.header = div;
|
|
|
|
var div2 = document.createElement('div');
|
|
div2.setAttribute('style', 'position:fixed;display:flex;top:20px; bottom:0;left:0;right:0');
|
|
body.appendChild(div2);
|
|
harness.body = div2;
|
|
|
|
var btn1 = document.createElement('input');
|
|
btn1.setAttribute('type', 'radio');
|
|
btn1.setAttribute('name', 'view');
|
|
div.appendChild(btn1);
|
|
btn1.checked = true;
|
|
|
|
var lbl1 = document.createElement('label');
|
|
lbl1.setAttribute('for', 'btn1');
|
|
lbl1.innerHTML = 'PDF'
|
|
div.appendChild(lbl1);
|
|
|
|
var btn2 = document.createElement('input');
|
|
btn2.setAttribute('type', 'radio');
|
|
btn2.setAttribute('name', 'view');
|
|
div.appendChild(btn2);
|
|
|
|
var lbl2 = document.createElement('label');
|
|
lbl2.setAttribute('for', 'btn2');
|
|
lbl2.innerHTML = 'Source'
|
|
div.appendChild(lbl2);
|
|
|
|
var btn3 = document.createElement('input');
|
|
btn3.setAttribute('type', 'radio');
|
|
btn3.setAttribute('name', 'view');
|
|
div.appendChild(btn3);
|
|
|
|
var lbl3 = document.createElement('label');
|
|
lbl3.setAttribute('for', 'btn3');
|
|
lbl3.innerHTML = 'Both'
|
|
div.appendChild(lbl3);
|
|
|
|
harness.source = document.createElement('pre');
|
|
harness.source.setAttribute('style', 'margin-top:0;width:100%;height:100%;position:absolute;top:0px;bottom:0px;overflow:auto');
|
|
div2.appendChild(harness.source);
|
|
|
|
harness.iframe = document.createElement('iframe');
|
|
harness.iframe.setAttribute('style', 'width:100%;height:100%;position:absolute;overflow:auto;top:0px;bottom:0px');
|
|
div2.appendChild(harness.iframe);
|
|
|
|
//if (pdf_test_harness.onload) {
|
|
//harness.pdf = pdf_test_harness.onload(harness);
|
|
if (message) {
|
|
message += "<p style='text-align:center;font-style:italic;font-size:.8em'>click to close</p>";
|
|
var popup = document.createElement('div');
|
|
popup.setAttribute('style', 'z-index:100;margin:100px auto;cursor:pointer;font-size:1.3em;top:50px;background-color:rgb(243, 224, 141);padding:1em;border:1px solid black');
|
|
popup.innerHTML = message;
|
|
body.appendChild(popup);
|
|
popup.onclick = function() {
|
|
popup.parentNode.removeChild(popup);
|
|
}
|
|
}
|
|
//}
|
|
|
|
harness.pdf = pdf;
|
|
harness.render('pdf');
|
|
|
|
btn1.onclick = function() {
|
|
harness.render('pdf');
|
|
}
|
|
btn2.onclick = function() {
|
|
harness.render('source');
|
|
}
|
|
btn3.onclick = function() {
|
|
harness.render('both');
|
|
}
|
|
|
|
return harness;
|
|
}
|
|
|
|
pdf_test_harness = function(pdf) {
|
|
this.pdf = pdf;
|
|
this.onload = undefined;
|
|
this.iframe = undefined;
|
|
|
|
this.entityMap = {
|
|
"&" : "&amp;",
|
|
"<" : "&lt;",
|
|
">" : "&gt;",
|
|
'"' : '&quot;',
|
|
"'" : '&#39;',
|
|
"/" : '&#x2F;'
|
|
};
|
|
|
|
this.escapeHtml = function(string) {
|
|
return String(string).replace(/[&<>"'\/]/g, function(s) {
|
|
return this.entityMap[s];
|
|
}.bind(this));
|
|
};
|
|
|
|
this.getParameterByName = function(name) {
|
|
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
|
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search);
|
|
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
|
};
|
|
|
|
this.setPdf = function(pdf) {
|
|
this.pdf = pdf;
|
|
this.rendered = undefined;
|
|
this.render(this.view);
|
|
};
|
|
|
|
// generate the pdf, the source code, or both
|
|
this.render = function(view) {
|
|
this.view = view;
|
|
//Current code only lets us render one time.
|
|
if (!this.rendered) {
|
|
this.rendered = this.pdf.output('datauristring');
|
|
this.iframe.src = this.rendered;
|
|
var raw = this.pdf.output();
|
|
raw = this.escapeHtml(raw);
|
|
this.source.innerHTML = raw;
|
|
}
|
|
if ('pdf' === view) {
|
|
this.source.style.display = 'none';
|
|
this.iframe.style.display = 'block';
|
|
this.iframe.style.width = '100%';
|
|
} else if ('source' === view) {
|
|
this.iframe.style.display = 'none';
|
|
this.source.style.display = 'block';
|
|
this.source.style.width = '100%';
|
|
}
|
|
|
|
if ('both' === view) {
|
|
raw = this.escapeHtml(raw);
|
|
this.iframe.style.width = '50%';
|
|
this.iframe.style.position = 'relative';
|
|
this.iframe.style.display = 'inline-block';
|
|
this.source.style.width = '50%';
|
|
this.source.style.position = 'relative';
|
|
this.source.style.display = 'inline-block';
|
|
}
|
|
}
|
|
}
|
|
</code></pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<br class="clear">
|
|
|
|
<footer>
|
|
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.1</a> on Mon Oct 03 2016 12:36:18 GMT+0100 (BST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
</footer>
|
|
|
|
<script>prettyPrint();</script>
|
|
<script src="scripts/linenumber.js"></script>
|
|
</body>
|
|
</html>
|