PDF export

This commit is contained in:
benweet 2013-09-22 23:16:59 +01:00
parent ffaf85f502
commit cb467ed9dd
14 changed files with 421 additions and 311 deletions

View File

@ -1,5 +1,5 @@
CACHE MANIFEST
#Date Sat Sep 21 2013 16:28:43
#Date Sun Sep 22 2013 23:14:34
CACHE:
index.html

File diff suppressed because one or more lines are too long

View File

@ -1665,5 +1665,6 @@ div.jGrowl div.jGrowl-notification{min-height:80px}
.viewer .document-panel .search-bar{padding:20px 20px 10px}
.viewer .document-panel .search-bar .input-group-btn{display:none}
.viewer .ui-layout-toggler{display:none !important}
body.pdf{background-color:transparent}
.navbar .working-indicator.show{background-image:url("../img/loader-blue-gray.gif")}
@media only screen and (-webkit-min-device-pixel-ratio:2),only screen and (min--moz-device-pixel-ratio:2),only screen and (-o-min-device-pixel-ratio:2/1),only screen and (min-device-pixel-ratio:2),only screen and (min-resolution:192dpi),only screen and (min-resolution:2dppx){.navbar .working-indicator.show{background-image:url("../img/loader-blue-gray2x.gif");background-size:50px 17px}}@media only screen and (-webkit-min-device-pixel-ratio:2),only screen and (min--moz-device-pixel-ratio:2),only screen and (-o-min-device-pixel-ratio:2/1),only screen and (min-device-pixel-ratio:2),only screen and (min-resolution:192dpi),only screen and (min-resolution:2dppx){.navbar .working-indicator.show{background-image:url("../img/loader-blue-gray2x.gif");background-size:50px 17px}}

View File

@ -1665,3 +1665,4 @@ div.jGrowl div.jGrowl-notification{min-height:80px}
.viewer .document-panel .search-bar{padding:20px 20px 10px}
.viewer .document-panel .search-bar .input-group-btn{display:none}
.viewer .ui-layout-toggler{display:none !important}
body.pdf{background-color:transparent}

View File

@ -1665,6 +1665,7 @@ div.jGrowl div.jGrowl-notification{min-height:80px}
.viewer .document-panel .search-bar{padding:20px 20px 10px}
.viewer .document-panel .search-bar .input-group-btn{display:none}
.viewer .ui-layout-toggler{display:none !important}
body.pdf{background-color:transparent}
.form-control:focus{-webkit-box-shadow:inset 0 1px 1px rgba(255,255,255,0),0 0 8px rgba(255,255,255,0.75);box-shadow:inset 0 1px 1px rgba(255,255,255,0),0 0 8px rgba(255,255,255,0.75)}
.navbar .working-indicator.show{background-image:url("../img/loader-night.gif")}
@media only screen and (-webkit-min-device-pixel-ratio:2),only screen and (min--moz-device-pixel-ratio:2),only screen and (-o-min-device-pixel-ratio:2/1),only screen and (min-device-pixel-ratio:2),only screen and (min-resolution:192dpi),only screen and (min-resolution:2dppx){.navbar .working-indicator.show{background-image:url("../img/loader-night2x.gif");background-size:50px 17px}}@media only screen and (-webkit-min-device-pixel-ratio:2),only screen and (min--moz-device-pixel-ratio:2),only screen and (-o-min-device-pixel-ratio:2/1),only screen and (min-device-pixel-ratio:2),only screen and (min-resolution:192dpi),only screen and (min-resolution:2dppx){.navbar .working-indicator.show{background-image:url("../img/loader-night2x.gif");background-size:50px 17px}}.ace-tm .ace_cursor{border-left-color:#fff}

View File

@ -1665,6 +1665,7 @@ div.jGrowl div.jGrowl-notification{min-height:80px}
.viewer .document-panel .search-bar{padding:20px 20px 10px}
.viewer .document-panel .search-bar .input-group-btn{display:none}
.viewer .ui-layout-toggler{display:none !important}
body.pdf{background-color:transparent}
@font-face{font-family:'cursive_standardregular';src:url('../font/cursive_standard-webfont.eot');src:url('../font/cursive_standard-webfont.eot?#iefix') format('embedded-opentype'),url('../font/cursive_standard-webfont.woff') format('woff'),url('../font/cursive_standard-webfont.ttf') format('truetype'),url('../font/cursive_standard-webfont.svg#cursive_standardregular') format('svg');font-weight:normal;font-style:normal}.navbar{background-image:-webkit-gradient(linear, left 0, left 100%, from(#385e50), to(#34584b));background-image:-webkit-linear-gradient(top, #385e50, 0, #34584b, 100%);background-image:-moz-linear-gradient(top, #385e50 0, #34584b 100%);background-image:linear-gradient(to bottom, #385e50 0, #34584b 100%);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff385e50', endColorstr='#ff34584b', GradientType=0)}
.ui-layout-resizer-north .resizer-decorator{position:absolute;width:100%;height:7px;background-color:#b9aa9f;-webkit-box-shadow:0 -1px 15px rgba(0,0,0,0.3);box-shadow:0 -1px 15px rgba(0,0,0,0.3);z-index:10;display:block !important}
.ui-layout-resizer-east{z-index:1 !important}

View File

@ -32,6 +32,7 @@ var PICASA_PROXY_URL = "http://stackedit-picasa-proxy.herokuapp.com/";
var WORDPRESS_CLIENT_ID = '3185';
var WORDPRESS_PROXY_URL = "http://stackedit-wordpress-proxy.herokuapp.com/";
var SSH_PROXY_URL = "http://stackedit-ssh-proxy.herokuapp.com/";
var HTMLTOPDF_URL = "http://benweet.insomnia247.nl/stackedit-htmltopdf/";
// Use by Google's client.js
var delayedFunction = undefined;

View File

@ -713,6 +713,11 @@ define([
}
});
// Hide menu panel when clicking 'Save as' button
$('.collapse-save-as a').click(function() {
$menuPanelElt.collapse('hide');
});
// Configure Mousetrap
mousetrap.stopCallback = function(e, element, combo) {
return isMenuPanelShown || isDocumentPanelShown || isModalShown || $(element).is("input, select, textarea:not(.ace_text-input)");

View File

@ -79,6 +79,7 @@
<li><a class="action-download-html" href="#">Save as HTML</a></li>
<li><a class="action-download-template" href="#">Save
using template</a></li>
<li><a class="action-download-pdf" href="#">Save as PDF</a></li>
</ul>
</div>
</div>

View File

@ -21,6 +21,7 @@
<li><a class="action-download-html" href="#">Save as HTML</a></li>
<li><a class="action-download-template" href="#">Save
using template</a></li>
<li><a class="action-download-pdf" href="#">Save as PDF</a></li>
</ul>
</li>
</ul>

View File

@ -8,6 +8,8 @@ define([
"fileMgr",
"sharing",
"classes/Provider",
"classes/AsyncTask",
"config",
"providers/bloggerProvider",
"providers/dropboxProvider",
"providers/gistProvider",
@ -16,7 +18,7 @@ define([
"providers/sshProvider",
"providers/tumblrProvider",
"providers/wordpressProvider"
], function($, _, utils, settings, eventMgr, fileSystem, fileMgr, sharing, Provider) {
], function($, _, utils, settings, eventMgr, fileSystem, fileMgr, sharing, Provider, AsyncTask) {
var publisher = {};
@ -243,6 +245,12 @@ define([
localStorage[provider.providerId + ".publishPreferences"] = JSON.stringify(publishPreferences);
}
// Listen to offline status changes
var isOffline = false;
eventMgr.addListener("onOfflineChanged", function(isOfflineParam) {
isOffline = isOfflineParam;
});
var initPublishButtonTmpl = [
'<li>',
' <a href="#"',
@ -308,6 +316,43 @@ define([
var content = publisher.applyTemplate(fileDesc, undefined, previewHtml);
utils.saveAs(content, fileDesc.title + (settings.template.indexOf("documentHTML") === -1 ? ".md" : ".html"));
});
$(".action-download-pdf").click(function() {
var fileDesc = fileMgr.currentFile;
var content = publisher.applyTemplate(fileDesc, {
customTmpl: settings.pdfTemplate
}, previewHtml);
var task = new AsyncTask();
var pdf = undefined;
task.onRun(function() {
if(isOffline === true) {
eventMgr.onError("Operation not available in offline mode.");
task.chain();
return;
}
var xhr = new XMLHttpRequest();
xhr.open('POST', HTMLTOPDF_URL, true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.responseType = 'blob';
xhr.onreadystatechange = function() {
if(this.readyState == 4) {
if(this.status == 200) {
pdf = this.response;
}
else {
eventMgr.onError("Error when trying to generate PDF: " + this.status);
}
task.chain();
}
};
xhr.send(content);
});
task.onSuccess(function() {
if(pdf !== undefined) {
utils.saveAs(pdf, fileMgr.currentFile.title + ".pdf");
}
});
task.enqueue();
});
});
eventMgr.onPublisherCreated(publisher);

View File

@ -13,6 +13,22 @@ define([
defaultContent: "\n\n\n> Written with [StackEdit](" + MAIN_URL + ").",
commitMsg: "Published with " + MAIN_URL,
template: [
'<!DOCTYPE html>\n',
'<html>\n',
'<head>\n',
'<meta charset="utf-8">\n',
'<title><%= documentTitle %></title>\n',
'<link rel="stylesheet" href="',
MAIN_URL,
'res-min/themes/default.css" />\n',
'<script type="text/javascript" src="',
MAIN_URL,
'lib/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>\n',
'</head>\n',
'<body><div class="container"><%= documentHTML %></div></body>\n',
'</html>'
].join(""),
pdfTemplate: [
'<!DOCTYPE html>\n',
'<html>\n',
'<head>\n',
@ -21,11 +37,19 @@ define([
'<link rel="stylesheet" href="',
MAIN_URL,
'res-min/themes/default.css" />\n',
'<script type="text/javascript" src="',
MAIN_URL,
'lib/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>\n',
'<style type="text/css">\n',
"@font-face {font-family: MathJax_Main; src: url('", MAIN_URL, "lib/MathJax/fonts/HTML-CSS/TeX/woff/MathJax_Main-Regular.woff') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Main-Regular.otf') format('opentype')}\n",
"@font-face {font-family: MathJax_Main; src: url('", MAIN_URL, "lib/MathJax/fonts/HTML-CSS/TeX/woff/MathJax_Main-Bold.woff') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Main-Bold.otf') format('opentype'); font-weight: bold}\n",
"@font-face {font-family: MathJax_Main; src: url('", MAIN_URL, "lib/MathJax/fonts/HTML-CSS/TeX/woff/MathJax_Main-Italic.woff') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Main-Italic.otf') format('opentype'); font-style: italic}\n",
"@font-face {font-family: MathJax_Math; src: url('", MAIN_URL, "lib/MathJax/fonts/HTML-CSS/TeX/woff/MathJax_Math-Italic.woff') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Math-Italic.otf') format('opentype'); font-style: italic}\n",
"@font-face {font-family: MathJax_Caligraphic; src: url('", MAIN_URL, "lib/MathJax/fonts/HTML-CSS/TeX/woff/MathJax_Caligraphic-Regular.woff') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Caligraphic-Regular.otf') format('opentype')}\n",
"@font-face {font-family: MathJax_Size1; src: url('", MAIN_URL, "lib/MathJax/fonts/HTML-CSS/TeX/woff/MathJax_Size1-Regular.woff') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Size1-Regular.otf') format('opentype')}\n",
"@font-face {font-family: MathJax_Size2; src: url('", MAIN_URL, "lib/MathJax/fonts/HTML-CSS/TeX/woff/MathJax_Size2-Regular.woff') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Size2-Regular.otf') format('opentype')}\n",
"@font-face {font-family: MathJax_Size3; src: url('", MAIN_URL, "lib/MathJax/fonts/HTML-CSS/TeX/woff/MathJax_Size3-Regular.woff') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Size3-Regular.otf') format('opentype')}\n",
"@font-face {font-family: MathJax_Size4; src: url('", MAIN_URL, "lib/MathJax/fonts/HTML-CSS/TeX/woff/MathJax_Size4-Regular.woff') format('woff'), url('http://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS/TeX/otf/MathJax_Size4-Regular.otf') format('opentype')}\n",
'</style>\n',
'</head>\n',
'<body><div class="container"><%= documentHTML %></div></body>\n',
'<body class="pdf"><%= documentHTML %></body>\n',
'</html>'
].join(""),
sshProxy: SSH_PROXY_URL,

View File

@ -1243,3 +1243,10 @@ div.jGrowl {
display: none !important;
}
}
/*******************
* PDF
*******************/
body.pdf {
background-color: transparent;
}

View File

@ -150,9 +150,9 @@ define([
utils.slugify = function(text) {
return text.toLowerCase().replace(/\s/g, '-') // Replace spaces with -
.replace(/![\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}]/g, '') // Remove
// all
// non-word
// chars
// all
// non-word
// chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
@ -215,12 +215,14 @@ define([
// Export data on disk
utils.saveAs = function(content, filename) {
if(saveAs !== undefined) {
var blob = new Blob([
content
], {
type: "text/plain;charset=utf-8"
});
saveAs(blob, filename);
if(_.isString(content)) {
content = new Blob([
content
], {
type: "text/plain;charset=utf-8"
});
}
saveAs(content, filename);
}
else {
var uriContent = "data:application/octet-stream;base64," + utils.encodeBase64(content);