Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add print to pdf button ...

  • Loading branch information...
commit e32dcc8b990da2c21226d2e63091f1d6c97123f0 1 parent a4386a9
@kindy kindy authored
View
2  bin/render-template 100644 → 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/sbin/env perl
use strict;
use warnings;
View
4 css/sporx.css
@@ -40,6 +40,10 @@
sans-serif !important;
}
+body.in-print #canvas,
+body.in-print #canvasToolbar {
+ display: none;
+}
#canvas * {
cursor: text !important;
}
View
92 lib/sporx.js 100644 → 100755
@@ -3,42 +3,6 @@ window._profile=function(){window.console && (arguments.length?console.profile:c
var image_total_height = 0;
-function addEv(elm, typ, fn) {
- /*
- if ( elm.nodeType == 3 || elm.nodeType == 8 )
- return;
- */
-
- if (elm && elm.addEventListener) {
- //_log("add event!" + typ);
- elm.addEventListener(typ, fn, false);
- } else if (elm && elm.attachEvent) {
- elm.attachEvent('on' + typ, fn);
- } else {
- try {
- elm['on' + typ] = fn;
- } catch(ex) {}
- }
- return fn;
-}
-
-function rmEv(elm, typ, fn) {
- if ( elm.nodeType == 3 || elm.nodeType == 8 )
- return;
-
- if (elm && elm.removeEventListener) {
- elm.removeEventListener(typ, fn, false);
- } else if (elm && elm.detachEvent) {
- elm.detachEvent('on' + typ, fn);
- } else {
- try {
- elm['on' + typ] = null;
- } catch(ex) {}
- }
- return fn;
-}
-
-
function l_i(a){if(a in l_ma)return l_ma[a];return l_ma[a]=navigator.userAgent.toLowerCase().indexOf(a)!=-1}
var l_ma={};
function l_h(){return l_i("msie")&&!window.opera}
@@ -134,7 +98,7 @@ Sporx.prototype = {
sporx.adjustCanvasSize();
}
resize_canvas();
- addEv(window, 'resize', resize_canvas);
+ $(window).resize(resize_canvas);
// 存储显示数据
this.content = document.getElementById('content');
@@ -208,7 +172,7 @@ Sporx.prototype = {
);
},
- takahashi: function() {
+ takahashi: function(cb) {
var num = this.current;
this.updateUrl();
@@ -237,7 +201,7 @@ Sporx.prototype = {
var labelId = 0;
- //for (var i = 0; i < text.length; i++) {
+ //for (var i = 0; i < text.length; i++)
while (line = text.shift()) {
this.content.appendChild(document.createElement('div'));
@@ -283,6 +247,7 @@ Sporx.prototype = {
// 调整 slide 适应屏幕尺寸
setTimeout(function () {
sporx.adjustCanvasSize();
+ cb && cb();
}, 0);
this.canvas.rendering = null;
@@ -486,6 +451,35 @@ Sporx.prototype = {
}
},
+ printPdf: function() {
+ var me = this;
+ var xx = $('<div/>');
+ var cont = $(me.content);
+ var h = $(me.canvas).height();
+ var i = this.slides.length - 1;
+
+ function step() {
+ xx.prepend(cont.clone().css({'height': h, 'page-break-after': 'always'}));
+ // console.log(me.content, h);
+
+ if (i > 0) {
+ me.current = --i;
+ setTimeout(proc, 0);
+ } else {
+ xx.prependTo(document.body);
+ $(document.body).addClass('in-print');
+ window.print();
+ $(document.body).removeClass('in-print');
+ }
+ }
+ function proc() {
+ me.takahashi(step);
+ }
+
+ me.current = i;
+ proc();
+ },
+
firstSlide: function() {
if (this.current != 0) {
this.current = 0;
@@ -667,20 +661,20 @@ $(window).ready(function () {
setInterval(sporx.dispatch, 500);
- addEv(document.body, 'mousemove', function(e){
+ $(document.body).mousemove(function(e){
sporx.onMouseMoveOnCanvas(e);
});
- addEv(document, 'keydown', function(e){
+ $(document).keydown(function(e){
//alert("Hi");
if (String(location.hash).match(/^#edit$/))
- return true;
+ return;
if (e.altKey || e.ctrlKey) {
- return true;
+ return;
}
- key = (e || window.event).keyCode;
+ key = e.keyCode;
//alert("key: " + key);
//_log("key: " + key);
@@ -690,9 +684,7 @@ $(window).ready(function () {
case 37:
case 38:
case 112:
- if (e.preventDefault) {
- e.preventDefault();
- }
+ e.preventDefault();
sporx.prevSlide();
break;
case 13:
@@ -701,16 +693,13 @@ $(window).ready(function () {
case 39:
case 40:
case 110:
- if (e.preventDefault) {
- e.preventDefault();
- }
+ e.preventDefault();
sporx.nextSlide();
break;
default:
//xxx(e.which)
break;
}
- return false;
});
});
@@ -911,3 +900,4 @@ var JSON = function () {
- ***** END LICENSE BLOCK ***** -->
*/
+// vim: se ts=4 sts=4 sw=4 :
View
3  template/sporx.html 100644 → 100755
@@ -8,7 +8,7 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title></title>
- <link href="[% css_location %]" media="screen" rel="stylesheet" type="text/css" />
+ <link href="[% css_location %]" rel="stylesheet" type="text/css" />
<script src="[% jquery_path %]"></script>
<script src="[% javascript_runtime %]"></script>
@@ -24,6 +24,7 @@
</div-->
<div>
+ <button onclick="sporx.printPdf()">pdf</button>
<button onclick="sporx.firstSlide()">|&lt;&lt;</button>
<button onclick="sporx.prevSlide()">&lt;</button>
<button onclick="sporx.nextSlide()">&gt;</button>
Please sign in to comment.
Something went wrong with that request. Please try again.