PDF Embedder - Version 2.0

Version Description

Added zoom feature. Toolbars can be fixed instead of appearing on hover.

Download this release

Release Info

Developer danlester
Plugin Icon 128x128 PDF Embedder
Version 2.0
Comparing to
See all releases

Code changes from version 1.2.1 to 2.0

core/core_pdf_embedder.php CHANGED
@@ -81,7 +81,7 @@ class core_pdf_embedder {
81
  $width = isset($atts['width']) ? $atts['width'] : 'max';
82
  $height = isset($atts['height']) ? $atts['height'] : 'auto';
83
 
84
- $extra_style = isset($atts['border']) ? "border: ".esc_attr($atts['border']).";" : "border:1px solid black; ";
85
  if (is_numeric($width)) {
86
  $extra_style .= "width: ".$width."px; ";
87
  }
@@ -91,8 +91,14 @@ class core_pdf_embedder {
91
 
92
  $toolbar = isset($atts['toolbar']) && in_array($atts['toolbar'], array('top', 'bottom', 'both')) ? $atts['toolbar'] : 'bottom';
93
 
 
 
94
  $returnhtml = '<div class="pdfemb-viewer" data-pdf-url="'.esc_attr($this->modify_pdfurl($url)).'" style="'.esc_attr($extra_style).'" '
95
- .'data-width="'.esc_attr($width).'" data-height="'.esc_attr($height).'" data-toolbar="'.$toolbar.'"></div>';
 
 
 
 
96
 
97
  if (!is_null($content)) {
98
  $returnhtml .= do_shortcode($content);
@@ -100,6 +106,10 @@ class core_pdf_embedder {
100
  return $returnhtml;
101
  }
102
 
 
 
 
 
103
  // ADMIN OPTIONS
104
  // *************
105
 
81
  $width = isset($atts['width']) ? $atts['width'] : 'max';
82
  $height = isset($atts['height']) ? $atts['height'] : 'auto';
83
 
84
+ $extra_style = "";
85
  if (is_numeric($width)) {
86
  $extra_style .= "width: ".$width."px; ";
87
  }
91
 
92
  $toolbar = isset($atts['toolbar']) && in_array($atts['toolbar'], array('top', 'bottom', 'both')) ? $atts['toolbar'] : 'bottom';
93
 
94
+ $toolbar_fixed = isset($atts['toolbarfixed']) && $atts['toolbarfixed'] == 'on' ? 'on' : 'off';
95
+
96
  $returnhtml = '<div class="pdfemb-viewer" data-pdf-url="'.esc_attr($this->modify_pdfurl($url)).'" style="'.esc_attr($extra_style).'" '
97
+ .'data-width="'.esc_attr($width).'" data-height="'.esc_attr($height).'" ';
98
+
99
+ $returnhtml .= $this->extra_shortcode_attrs($atts, $content);
100
+
101
+ $returnhtml .= ' data-toolbar="'.$toolbar.'" data-toolbar-fixed="'.$toolbar_fixed.'"></div>';
102
 
103
  if (!is_null($content)) {
104
  $returnhtml .= do_shortcode($content);
106
  return $returnhtml;
107
  }
108
 
109
+ protected function extra_shortcode_attrs($atts, $content=null) {
110
+ return '';
111
+ }
112
+
113
  // ADMIN OPTIONS
114
  // *************
115
 
css/pdfemb-embed-pdf.css CHANGED
@@ -4,20 +4,108 @@ div.pdfemb-viewer {
4
  line-height: 1;
5
  margin: 0px;
6
  padding: 0px;
 
7
  position: relative;
8
  }
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  div.pdfemb-loadingmsg {
11
  text-align: center;
12
  padding: 5px;
13
  }
14
 
15
  div.pdfemb-viewer canvas {
16
-
17
  top: 0px;
18
  bottom: 0px;
19
  margin: 0px;
20
  padding: 0px;
 
21
  }
22
 
23
  div.pdfemb-toolbar {
@@ -28,18 +116,26 @@ div.pdfemb-toolbar {
28
 
29
  background-color: grey;
30
  width: 100%;
31
-
32
- display: none;
 
 
 
 
 
 
 
 
33
  }
34
 
35
  div.pdfemb-toolbar-top {
36
- position: absolute;
37
  top: 0px;
38
  left: 0px;
39
  }
40
 
41
  div.pdfemb-toolbar-bottom {
42
- position: absolute;
43
  bottom: 0px;
44
  left: 0px;
45
  }
@@ -92,3 +188,25 @@ div.pdfemb-errormsg {
92
  text-align: center;
93
  vertical-align: middle;
94
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  line-height: 1;
5
  margin: 0px;
6
  padding: 0px;
7
+ border: 1px solid black;
8
  position: relative;
9
  }
10
 
11
+ div.pdfemb-inner-div {
12
+ overflow: hidden;
13
+ line-height: 1;
14
+ margin: 0px;
15
+ padding: 0px;
16
+ border: none;
17
+ position: relative;
18
+ background-color: lightGrey;
19
+ width: 100%;
20
+ height: 100%;
21
+ display: inline-block;
22
+ }
23
+
24
+ div.pdfemb-inner-div-wantmobile {
25
+ position: absolute;
26
+ top: 0px;
27
+ left: 0px;
28
+ width: 100%;
29
+ height: 100%;
30
+ z-index: 50;
31
+ background-color: lightgray;
32
+ opacity: 0.5;
33
+ }
34
+
35
+ div.pdfemb-inner-div-wantmobile-fswrap {
36
+ position: absolute;
37
+ top: 0px;
38
+ left: 0px;
39
+ width: 100%;
40
+ height: 100%;
41
+ z-index: 100;
42
+ }
43
+
44
+ div.pdfemb-wantmobile-fsarea {
45
+ position: relative;
46
+ width: 80%;
47
+ margin: 40% auto 0 auto;
48
+ padding: 10px;
49
+ height: 20%;
50
+ max-height: 35px;
51
+ text-align: center;
52
+ opacity: 1;
53
+ cursor: pointer;
54
+
55
+ -webkit-border-radius: 20px;
56
+ -moz-border-radius: 20px;
57
+ border-radius: 20px;
58
+ border:4px solid #363600;
59
+ background-color:#C5BDCF;
60
+ -webkit-box-shadow: #B3B3B3 8px 8px 8px;
61
+ -moz-box-shadow: #B3B3B3 8px 8px 8px;
62
+ box-shadow: #B3B3B3 8px 8px 8px;
63
+
64
+ color: black;
65
+ font-family: sans-serif;
66
+ letter-spacing: 2px;
67
+ font-size: 16px;
68
+ line-height: 110%;
69
+ }
70
+
71
+ .grab-to-pan-grab {
72
+ cursor: move !important;
73
+ cursor: -webkit-grab !important;
74
+ cursor: -moz-grab !important;
75
+ cursor: grab !important;
76
+ }
77
+
78
+ .grab-to-pan-grab {
79
+ cursor: move !important;
80
+ cursor: -webkit-grab !important;
81
+ cursor: -moz-grab !important;
82
+ cursor: grab !important;
83
+ }
84
+ .grab-to-pan-grab *:not(input):not(textarea):not(button):not(select):not(:link) {
85
+ cursor: inherit !important;
86
+ }
87
+ .grab-to-pan-grab:active,
88
+ .grab-to-pan-grabbing {
89
+ cursor: move !important;
90
+ cursor: -webkit-grabbing !important;
91
+ cursor: -moz-grabbing !important;
92
+ cursor: grabbing !important;
93
+
94
+ z-index: 50000; /* should be higher than anything else in PDF.js! */
95
+ }
96
+
97
  div.pdfemb-loadingmsg {
98
  text-align: center;
99
  padding: 5px;
100
  }
101
 
102
  div.pdfemb-viewer canvas {
103
+ position: relative;
104
  top: 0px;
105
  bottom: 0px;
106
  margin: 0px;
107
  padding: 0px;
108
+ display: inline-block;
109
  }
110
 
111
  div.pdfemb-toolbar {
116
 
117
  background-color: grey;
118
  width: 100%;
119
+ }
120
+
121
+ div.pdfemb-toolbar-fixed {
122
+ display: block;
123
+ position: absolute;
124
+ }
125
+
126
+ div.pdfemb-toolbar-hover {
127
+ display: none;
128
+ position: absolute;
129
  }
130
 
131
  div.pdfemb-toolbar-top {
132
+
133
  top: 0px;
134
  left: 0px;
135
  }
136
 
137
  div.pdfemb-toolbar-bottom {
138
+
139
  bottom: 0px;
140
  left: 0px;
141
  }
188
  text-align: center;
189
  vertical-align: middle;
190
  }
191
+
192
+ .pdfemb-fsp-wrapper {
193
+ background: white;
194
+ position: fixed;
195
+ top: 0;
196
+ left: 0;
197
+ right: 0;
198
+ bottom: 0;
199
+ z-index: 100000;
200
+ overflow-y: auto;
201
+ overflow-x: hidden;
202
+ display: none;
203
+ }
204
+
205
+ .pdfemb-fsp-content {
206
+ overflow: hidden;
207
+ width: 100%;
208
+ height: 100%;
209
+ position: relative;
210
+ top: 0px;
211
+ left: 0px;
212
+ }
js/all-pdfemb-basic.min.js CHANGED
@@ -1,7 +1,17 @@
1
- function pdfembGetPDF(b,a){a(b,!1)};jQuery(document).ready(function(b){b.fn.pdfEmbedder=function(){this.each(function(a,h){var c=b(h);c.append(b("<div></div>",{"class":"pdfemb-loadingmsg"}).append(document.createTextNode("Loading...")));var e=c.attr("data-pdf-url");pdfembGetPDF(e,function(a,e){PDFJS.getDocument(a).then(function(a){c.empty().append(b("<canvas></canvas>",{"class":"the-canvas"}));c.data("pdfDoc",a);var d=c.data("toolbar");"bottom"!=d&&b.fn.pdfEmbedder.addToolbar(c,!0,e);"top"!=d&&b.fn.pdfEmbedder.addToolbar(c,!1,e);c.data("pageNum",
2
- 1);c.data("pageCount",a.numPages);c.data("pageNumPending",null);b.fn.pdfEmbedder.renderPage(c,1);c.find("span.pdfemb-page-count").text(a.numPages);b(window).resize(function(){b.fn.pdfEmbedder.queueRenderPage(c,c.data("pageNum"))})},function(a){c.empty().append(b("<div></div>",{"class":"pdfemb-errormsg"}).append(document.createTextNode(a.message)))})})});return this};b.fn.pdfEmbedder.renderPage=function(a,h){a.data("pageRendering",!0);a.data("pdfDoc").getPage(h).then(function(c){var e=a.find(".the-canvas"),
3
- g,f=c.getViewport(1);g=f.width;f=f.height;(0>=g||0>=f)&&a.empty().append(document.createTextNode("PDF page width or height are invalid"));var k=a.parent().width(),d=g,l=f;if("max"==a.data("width"))d=k;else if("auto"==a.data("width"))d=g;else if(d=parseInt(a.data("width"),10),isNaN(d)||0>=d)d=k;0>=d&&(d=g);d>k&&0<k&&(d=k);g=d/g;l=f*g;d!=e.width()&&e.width(d);d!=a.width()&&a.width(d);d=parseInt(a.data("height"),10);!isNaN(d)&&0<d&&d<l&&(l=d);a.height()!=l+4&&a.height(l+4);e.height()!=f*g&&e.height(f*
4
- g);f=c.getViewport(g);e[0].height=f.height;e[0].width=f.width;e={canvasContext:e[0].getContext("2d"),viewport:f};c.render(e).promise.then(function(){a.data("pageNum",h);a.data("pageRendering",!1);a.find("span.pdfemb-page-num").text(h);h<a.data("pageCount")?a.find(".pdfemb-next").removeAttr("disabled").removeClass("pdfemb-btndisabled"):a.find(".pdfemb-next").attr("disabled","disabled").addClass("pdfemb-btndisabled");1<h?a.find(".pdfemb-prev").removeAttr("disabled").removeClass("pdfemb-btndisabled"):
5
- a.find(".pdfemb-prev").attr("disabled","disabled").addClass("pdfemb-btndisabled");null!==a.data("pageNumPending")&&(b.fn.pdfEmbedder.renderPage(a,a.data("pageNumPending")),a.data("pageNumPending",null))})})};b.fn.pdfEmbedder.queueRenderPage=function(a,h){a.data("pageRendering")?a.data("pageNumPending",h):b.fn.pdfEmbedder.renderPage(a,h)};b.fn.pdfEmbedder.addToolbar=function(a,h,c){var e=b("<div></div>",{"class":"pdfemb-toolbar "+(h?" pdfemb-toolbar-top":"pdfemb-toolbar-bottom")}),g=b('<button class="pdfemb-prev">Prev</button>');
6
- e.append(g);var f=b('<button class="pdfemb-next">Next</button>');e.append(f);e.append(b('<div>Page <span class="pdfemb-page-num">0</span> / <span class="pdfemb-page-count"></span></div>'));c&&e.append(b("<div>Secure</div>"));h?a.prepend(e):a.append(e);g.on("click",function(c){1>=a.data("pageNum")||(a.data("pageNum",a.data("pageNum")-1),b.fn.pdfEmbedder.queueRenderPage(a,a.data("pageNum")))});f.on("click",function(c){a.data("pageNum")>=a.data("pdfDoc").numPages||(a.data("pageNum",a.data("pageNum")+
7
- 1),b.fn.pdfEmbedder.queueRenderPage(a,a.data("pageNum")))});a.on("mouseenter",function(b){a.find("div.pdfemb-toolbar").show()});a.on("mouseleave",function(b){a.find("div.pdfemb-toolbar").hide()})};PDFJS.workerSrc=pdfemb_trans.worker_src;PDFJS.cMapUrl=pdfemb_trans.cmap_url;PDFJS.cMapPacked=!0;b(".pdfemb-viewer").pdfEmbedder()});
 
 
 
 
 
 
 
 
 
 
1
+ function pdfembGetPDF(c,a){a(c,!1)}function pdfembWantMobile(c,a,g,d){return!1}function pdfembMakeMobile(c,a,g){}function pdfembAddMoreToolbar(c,a,g){};jQuery(document).ready(function(c){c.fn.pdfEmbedder=function(){this.each(function(a,g){var d=c(g);d.append(c("<div></div>",{"class":"pdfemb-loadingmsg"}).append(document.createTextNode("Loading...")));var h=function(a,b){d.empty().append(c("<div></div>",{"class":"pdfemb-inner-div"}).append(c("<canvas></canvas>",{"class":"pdfemb-the-canvas"})));d.data("pdfDoc",a);var e=d.data("toolbar");"bottom"!=e&&c.fn.pdfEmbedder.addToolbar(d,!0,"on"==d.data("toolbar-fixed"),b);"top"!=e&&c.fn.pdfEmbedder.addToolbar(d,
2
+ !1,"on"==d.data("toolbar-fixed"),b);d.data("pageCount",a.numPages);d.data("pageNum")||d.data("pageNum",1);d.data("showIsSecure",b);d.data("pageNumPending",null);d.data("zoom",100);c.fn.pdfEmbedder.renderPage(d,d.data("pageNum"));d.find("span.pdfemb-page-count").text(a.numPages);e=new pdfembGrabToPan({element:d.find("div.pdfemb-inner-div")[0]});d.data("grabtopan",e);c(window).resize(function(){c.fn.pdfEmbedder.queueRenderPage(d,d.data("pageNum"))})},e=function(a,b){PDFJS.getDocument(a).then(function(a){h(a,
3
+ b)},function(a){d.empty().append(c("<div></div>",{"class":"pdfemb-errormsg"}).append(document.createTextNode(a.message)))})};if(d.data("pdfDoc"))h(d.data("pdfDoc"),d.data("showIsSecure"));else{var b=d.attr("data-pdf-url");pdfembGetPDF(b,e)}});return this};c.fn.pdfEmbedder.renderPage=function(a,g){a.data("pageRendering",!0);a.data("pdfDoc").getPage(g).then(function(d){var h=a.find(".pdfemb-the-canvas"),e,b=d.getViewport(1),m=b.width,f=b.height;if(0>=m||0>=f)a.empty().append(document.createTextNode("PDF page width or height are invalid"));
4
+ else{e=a.parent().width();var b=m,l=f;if("max"==a.data("width"))b=e;else if("auto"==a.data("width"))b=m;else if(b=parseInt(a.data("width"),10),isNaN(b)||0>=b)b=e;0>=b&&(b=m);b>e&&0<e&&(b=e);e=b/m;var l=f*e,n=a.find("div.pdfemb-toolbar-fixed"),r=(m=pdfembWantMobile(c,a,b,k))?0:n.length,k=parseInt(a.data("height"),10);if(isNaN(k)||0>=k||k>l)k="max"==a.data("height")?a.parent().height()-r*n.height():l;var b=Math.floor(b),l=Math.floor(l),f=100,q=b,p=l,t=0,u=0;m||(f=a.data("zoom"),q=b*f/100,p=l*f/100,
5
+ q<b&&(t=(b-q)/2),p<k&&(u=(k-p)/2));e=d.getViewport(e*f/100);b!=a.width()&&a.width(b);a.height()!=k&&a.height(k+r*n.height());f=a.find("div.pdfemb-inner-div");f.width(b);f.height(k);n=n.filter(".pdfemb-toolbar-top");0<r&&f.css("top",n.height());h[0].width=q;h[0].height=p;h.css("width",q);h.css("height",p);h.css("left",t).css("top",u);(q>b||p>l||p>k)&&!m?(a.data("grabtopan").activate(),k=a.data("fromZoom"),r=a.data("toZoom"),0<k&&0<r&&(q=f.scrollLeft(),p=f.scrollTop()+l/2,f.scrollLeft((q+b/2)*r/k-b/
6
+ 2),f.scrollTop(p*r/k-l/2))):(a.data("grabtopan").deactivate(),a.find("div.pdfemb-inner-div").scrollLeft(0).scrollTop(0));a.data("fromZoom",0).data("toZoom",0);pdfembMakeMobile(c,m,a);h={canvasContext:h[0].getContext("2d"),viewport:e};d.render(h).promise.then(function(){a.data("pageNum",g);a.data("pageRendering",!1);a.find("span.pdfemb-page-num").text(g);g<a.data("pageCount")?a.find(".pdfemb-next").removeAttr("disabled").removeClass("pdfemb-btndisabled"):a.find(".pdfemb-next").attr("disabled","disabled").addClass("pdfemb-btndisabled");
7
+ 1<g?a.find(".pdfemb-prev").removeAttr("disabled").removeClass("pdfemb-btndisabled"):a.find(".pdfemb-prev").attr("disabled","disabled").addClass("pdfemb-btndisabled");null!==a.data("pageNumPending")&&(c.fn.pdfEmbedder.renderPage(a,a.data("pageNumPending")),a.data("pageNumPending",null))})}})};c.fn.pdfEmbedder.queueRenderPage=function(a,g){a.data("pageRendering")?a.data("pageNumPending",g):c.fn.pdfEmbedder.renderPage(a,g)};c.fn.pdfEmbedder.goFullScreen=function(a){a=c('<div class="pdfemb-fs-window"></div>');
8
+ c(document.body).append(a)};c.fn.pdfEmbedder.addToolbar=function(a,g,d,h){var e=c("<div></div>",{"class":"pdfemb-toolbar pdfemb-toolbar"+(d?"-fixed":"-hover")+" "+(g?" pdfemb-toolbar-top":"pdfemb-toolbar-bottom")}),b=c('<button class="pdfemb-prev">Prev</button>');e.append(b);var m=c('<button class="pdfemb-next">Next</button>');e.append(m);e.append(c('<div>Page <span class="pdfemb-page-num">0</span> / <span class="pdfemb-page-count"></span></div>'));var f=c('<button class="pdfemb-zoomout">-</button>');
9
+ e.append(f);var l=c('<button class="pdfemb-zoomin">+</button>');e.append(l);e.append(c('<div>Zoom <span class="pdfemb-zoom">100%</span></div>'));h&&e.append(c("<div>Secure</div>"));g?a.prepend(e):a.append(e);b.on("click",function(b){1>=a.data("pageNum")||(a.data("pageNum",a.data("pageNum")-1),c.fn.pdfEmbedder.queueRenderPage(a,a.data("pageNum")))});m.on("click",function(b){a.data("pageNum")>=a.data("pdfDoc").numPages||(a.data("pageNum",a.data("pageNum")+1),c.fn.pdfEmbedder.queueRenderPage(a,a.data("pageNum")))});
10
+ var n=function(b){var d=a.data("zoom");b=d+b;a.data("zoom",b);a.find("span.pdfemb-zoom").text(b+"%");c.fn.pdfEmbedder.queueRenderPage(a,a.data("pageNum"));a.data("fromZoom",d).data("toZoom",b)};l.on("click",function(b){500<=a.data("zoom")||n(10)});f.on("click",function(b){20>=a.data("zoom")||n(-10)});pdfembAddMoreToolbar(c,e,a);d||(a.on("mouseenter",function(b){b=a.find("div.pdfemb-toolbar-hover");!0!==b.data("no-hover")&&b.show()}),a.on("mouseleave",function(b){a.find("div.pdfemb-toolbar-hover").hide()}))};
11
+ PDFJS.workerSrc=pdfemb_trans.worker_src;PDFJS.cMapUrl=pdfemb_trans.cmap_url;PDFJS.cMapPacked=!0;c(".pdfemb-viewer").pdfEmbedder()});var pdfembGrabToPan=function(){function c(a){this.element=a.element;this.document=a.element.ownerDocument;"function"===typeof a.ignoreTarget&&(this.ignoreTarget=a.ignoreTarget);this.onActiveChanged=a.onActiveChanged;this.activate=this.activate.bind(this);this.deactivate=this.deactivate.bind(this);this.toggle=this.toggle.bind(this);this._onmousedown=this._onmousedown.bind(this);this._onmousemove=this._onmousemove.bind(this);this._onmousewheel=this._onmousewheel.bind(this);this._endPan=this._endPan.bind(this);
12
+ (this.overlay=document.createElement("div")).className="grab-to-pan-grabbing"}c.prototype={CSS_CLASS_GRAB:"grab-to-pan-grab",activate:function(){if(!this.active&&(this.active=!0,this.element.addEventListener("mousedown",this._onmousedown,!0),this.element.addEventListener("DOMMouseScroll",this._onmousewheel),this.element.addEventListener("mousewheel",this._onmousewheel),this.element.classList.add(this.CSS_CLASS_GRAB),this.onActiveChanged))this.onActiveChanged(!0)},deactivate:function(){if(this.active&&
13
+ (this.active=!1,this.element.removeEventListener("mousedown",this._onmousedown,!0),this._endPan(),this.element.classList.remove(this.CSS_CLASS_GRAB),this.onActiveChanged))this.onActiveChanged(!1)},toggle:function(){this.active?this.deactivate():this.activate()},ignoreTarget:function(b){return b[a]("a[href], a[href] *, input, textarea, button, button *, select, option")},_onmousedown:function(a){if(0===a.button&&!this.ignoreTarget(a.target)){this.scrollLeftStart=this.element.scrollLeft;this.scrollTopStart=
14
+ this.element.scrollTop;this.clientXStart=a.clientX;this.clientYStart=a.clientY;this.document.addEventListener("mousemove",this._onmousemove,!0);this.document.addEventListener("mouseup",this._endPan,!0);this.element.addEventListener("scroll",this._endPan,!0);a.preventDefault();a.stopPropagation();this.document.documentElement.classList.add(this.CSS_CLASS_GRABBING);var c=document.activeElement;c&&!c.contains(a.target)&&c.blur()}},_onmousemove:function(a){this.element.removeEventListener("scroll",this._endPan,
15
+ !0);var c;c="buttons"in a&&g?!(a.buttons|1):h||e?0===a.which:void 0;c?this._endPan():(c=a.clientX-this.clientXStart,this.element.scrollTop=this.scrollTopStart-(a.clientY-this.clientYStart),this.element.scrollLeft=this.scrollLeftStart-c,this.overlay.parentNode||document.body.appendChild(this.overlay))},_onmousewheel:function(a){this.element.removeEventListener("scroll",this._endPan,!0);a="DOMMouseScroll"===a.type?-a.detail:a.wheelDelta/40;this.scrollLeftStart=this.element.scrollLeft;this.scrollTopStart=
16
+ this.element.scrollTop;this.element.scrollTop=this.scrollTopStart-40*a;this.overlay.parentNode||document.body.appendChild(this.overlay)},_endPan:function(){this.element.removeEventListener("scroll",this._endPan,!0);this.document.removeEventListener("mousemove",this._onmousemove,!0);this.document.removeEventListener("mouseup",this._endPan,!0);this.overlay.parentNode&&this.overlay.parentNode.removeChild(this.overlay)}};var a;["webkitM","mozM","msM","oM","m"].some(function(b){b+="atches";b in document.documentElement&&
17
+ (a=b);b+="Selector";b in document.documentElement&&(a=b);return a});var g=!document.documentMode||9<document.documentMode,d=window.chrome,h=d&&(d.webstore||d.app),e=/Apple/.test(navigator.vendor)&&/Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);return c}();
js/grabtopan-basic.js ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ var pdfembGrabToPan = (function GrabToPanClosure() {
3
+ /**
4
+ * Construct a GrabToPan instance for a given HTML element.
5
+ * @param options.element {Element}
6
+ * @param options.ignoreTarget {function} optional. See `ignoreTarget(node)`
7
+ * @param options.onActiveChanged {function(boolean)} optional. Called
8
+ * when grab-to-pan is (de)activated. The first argument is a boolean that
9
+ * shows whether grab-to-pan is activated.
10
+ */
11
+ function GrabToPan(options) {
12
+ this.element = options.element;
13
+ this.document = options.element.ownerDocument;
14
+ if (typeof options.ignoreTarget === 'function') {
15
+ this.ignoreTarget = options.ignoreTarget;
16
+ }
17
+ this.onActiveChanged = options.onActiveChanged;
18
+
19
+ // Bind the contexts to ensure that `this` always points to
20
+ // the GrabToPan instance.
21
+ this.activate = this.activate.bind(this);
22
+ this.deactivate = this.deactivate.bind(this);
23
+ this.toggle = this.toggle.bind(this);
24
+ this._onmousedown = this._onmousedown.bind(this);
25
+ this._onmousemove = this._onmousemove.bind(this);
26
+ this._onmousewheel = this._onmousewheel.bind(this);
27
+ this._endPan = this._endPan.bind(this);
28
+
29
+ // This overlay will be inserted in the document when the mouse moves during
30
+ // a grab operation, to ensure that the cursor has the desired appearance.
31
+ var overlay = this.overlay = document.createElement('div');
32
+ overlay.className = 'grab-to-pan-grabbing';
33
+ }
34
+ GrabToPan.prototype = {
35
+ /**
36
+ * Class name of element which can be grabbed
37
+ */
38
+ CSS_CLASS_GRAB: 'grab-to-pan-grab',
39
+
40
+ /**
41
+ * Bind a mousedown event to the element to enable grab-detection.
42
+ */
43
+ activate: function GrabToPan_activate() {
44
+ if (!this.active) {
45
+ this.active = true;
46
+ this.element.addEventListener('mousedown', this._onmousedown, true);
47
+
48
+ this.element.addEventListener('DOMMouseScroll', this._onmousewheel);
49
+ this.element.addEventListener('mousewheel', this._onmousewheel);
50
+
51
+ this.element.classList.add(this.CSS_CLASS_GRAB);
52
+ if (this.onActiveChanged) {
53
+ this.onActiveChanged(true);
54
+ }
55
+ }
56
+ },
57
+
58
+ /**
59
+ * Removes all events. Any pending pan session is immediately stopped.
60
+ */
61
+ deactivate: function GrabToPan_deactivate() {
62
+ if (this.active) {
63
+ this.active = false;
64
+ this.element.removeEventListener('mousedown', this._onmousedown, true);
65
+ this._endPan();
66
+ this.element.classList.remove(this.CSS_CLASS_GRAB);
67
+ if (this.onActiveChanged) {
68
+ this.onActiveChanged(false);
69
+ }
70
+ }
71
+ },
72
+
73
+ toggle: function GrabToPan_toggle() {
74
+ if (this.active) {
75
+ this.deactivate();
76
+ } else {
77
+ this.activate();
78
+ }
79
+ },
80
+
81
+ /**
82
+ * Whether to not pan if the target element is clicked.
83
+ * Override this method to change the default behaviour.
84
+ *
85
+ * @param node {Element} The target of the event
86
+ * @return {boolean} Whether to not react to the click event.
87
+ */
88
+ ignoreTarget: function GrabToPan_ignoreTarget(node) {
89
+ // Use matchesSelector to check whether the clicked element
90
+ // is (a child of) an input element / link
91
+ return node[matchesSelector](
92
+ 'a[href], a[href] *, input, textarea, button, button *, select, option'
93
+ );
94
+ },
95
+
96
+ /**
97
+ * @private
98
+ */
99
+ _onmousedown: function GrabToPan__onmousedown(event) {
100
+ if (event.button !== 0 || this.ignoreTarget(event.target)) {
101
+ return;
102
+ }
103
+ if (event.originalTarget) {
104
+ try {
105
+ /* jshint expr:true */
106
+ var ottn = event.originalTarget.tagName;
107
+ } catch (e) {
108
+ // Mozilla-specific: element is a scrollbar (XUL element)
109
+ return;
110
+ }
111
+ }
112
+
113
+ this.scrollLeftStart = this.element.scrollLeft;
114
+ this.scrollTopStart = this.element.scrollTop;
115
+ this.clientXStart = event.clientX;
116
+ this.clientYStart = event.clientY;
117
+ this.document.addEventListener('mousemove', this._onmousemove, true);
118
+ this.document.addEventListener('mouseup', this._endPan, true);
119
+ // When a scroll event occurs before a mousemove, assume that the user
120
+ // dragged a scrollbar (necessary for Opera Presto, Safari and IE)
121
+ // (not needed for Chrome/Firefox)
122
+ this.element.addEventListener('scroll', this._endPan, true);
123
+ event.preventDefault();
124
+ event.stopPropagation();
125
+ this.document.documentElement.classList.add(this.CSS_CLASS_GRABBING);
126
+
127
+ var focusedElement = document.activeElement;
128
+ if (focusedElement && !focusedElement.contains(event.target)) {
129
+ focusedElement.blur();
130
+ }
131
+ },
132
+
133
+ /**
134
+ * @private
135
+ */
136
+ _onmousemove: function GrabToPan__onmousemove(event) {
137
+ this.element.removeEventListener('scroll', this._endPan, true);
138
+ if (isLeftMouseReleased(event)) {
139
+ this._endPan();
140
+ return;
141
+ }
142
+ var xDiff = event.clientX - this.clientXStart;
143
+ var yDiff = event.clientY - this.clientYStart;
144
+ this.element.scrollTop = this.scrollTopStart - yDiff;
145
+ this.element.scrollLeft = this.scrollLeftStart - xDiff;
146
+ if (!this.overlay.parentNode) {
147
+ document.body.appendChild(this.overlay);
148
+ }
149
+ },
150
+
151
+ /**
152
+ * @private
153
+ */
154
+ _onmousewheel: function GrabToPan__onmousewheel(event) {
155
+ this.element.removeEventListener('scroll', this._endPan, true);
156
+
157
+ var MOUSE_WHEEL_DELTA_FACTOR = 40;
158
+ var ticks = (event.type === 'DOMMouseScroll') ? -event.detail :
159
+ event.wheelDelta / MOUSE_WHEEL_DELTA_FACTOR;
160
+ //var direction = (ticks < 0) ? 'zoomOut' : 'zoomIn';
161
+
162
+ this.scrollLeftStart = this.element.scrollLeft;
163
+ this.scrollTopStart = this.element.scrollTop;
164
+ // var xDiff = event.clientX - this.clientXStart;
165
+ var yDiff = ticks * MOUSE_WHEEL_DELTA_FACTOR;
166
+ this.element.scrollTop = this.scrollTopStart - yDiff;
167
+ // this.element.scrollLeft = this.scrollLeftStart - xDiff;
168
+ if (!this.overlay.parentNode) {
169
+ document.body.appendChild(this.overlay);
170
+ }
171
+ },
172
+
173
+ /**
174
+ * @private
175
+ */
176
+ _endPan: function GrabToPan__endPan() {
177
+ this.element.removeEventListener('scroll', this._endPan, true);
178
+ this.document.removeEventListener('mousemove', this._onmousemove, true);
179
+ this.document.removeEventListener('mouseup', this._endPan, true);
180
+ if (this.overlay.parentNode) {
181
+ this.overlay.parentNode.removeChild(this.overlay);
182
+ }
183
+ }
184
+ };
185
+
186
+ // Get the correct (vendor-prefixed) name of the matches method.
187
+ var matchesSelector;
188
+ ['webkitM', 'mozM', 'msM', 'oM', 'm'].some(function(prefix) {
189
+ var name = prefix + 'atches';
190
+ if (name in document.documentElement) {
191
+ matchesSelector = name;
192
+ }
193
+ name += 'Selector';
194
+ if (name in document.documentElement) {
195
+ matchesSelector = name;
196
+ }
197
+ return matchesSelector; // If found, then truthy, and [].some() ends.
198
+ });
199
+
200
+ // Browser sniffing because it's impossible to feature-detect
201
+ // whether event.which for onmousemove is reliable
202
+ var isNotIEorIsIE10plus = !document.documentMode || document.documentMode > 9;
203
+ var chrome = window.chrome;
204
+ var isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
205
+ // ^ Chrome 15+ ^ Opera 15+
206
+ var isSafari6plus = /Apple/.test(navigator.vendor) &&
207
+ /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
208
+
209
+ /**
210
+ * Whether the left mouse is not pressed.
211
+ * @param event {MouseEvent}
212
+ * @return {boolean} True if the left mouse button is not pressed.
213
+ * False if unsure or if the left mouse button is pressed.
214
+ */
215
+ function isLeftMouseReleased(event) {
216
+ if ('buttons' in event && isNotIEorIsIE10plus) {
217
+ // http://www.w3.org/TR/DOM-Level-3-Events/#events-MouseEvent-buttons
218
+ // Firefox 15+
219
+ // Internet Explorer 10+
220
+ return !(event.buttons | 1);
221
+ }
222
+ if (isChrome15OrOpera15plus || isSafari6plus) {
223
+ // Chrome 14+
224
+ // Opera 15+
225
+ // Safari 6.0+
226
+ return event.which === 0;
227
+ }
228
+ }
229
+
230
+ return GrabToPan;
231
+ })();
js/pdfemb-basic.js CHANGED
@@ -5,3 +5,12 @@ function pdfembGetPDF(url, callback) {
5
 
6
  };
7
 
 
 
 
 
 
 
 
 
 
5
 
6
  };
7
 
8
+ function pdfembWantMobile($, divContainer, wantWidth, wantHeight) {
9
+ return false;
10
+ }
11
+
12
+ function pdfembMakeMobile($, wantMobile, innerdiv) {
13
+ }
14
+
15
+ function pdfembAddMoreToolbar($, toolbar, divContainer) {
16
+ }
js/pdfemb-embed-pdf.js CHANGED
@@ -9,8 +9,48 @@ jQuery(document).ready(function ($) {
9
  var divContainer = $(rawDivContainer);
10
 
11
  divContainer.append($('<div></div>', {'class': 'pdfemb-loadingmsg'}).append(document.createTextNode('Loading...')));
12
-
13
- var url = divContainer.attr('data-pdf-url');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  var callback = function(pdf, showIsSecure) {
16
 
@@ -18,41 +58,24 @@ jQuery(document).ready(function ($) {
18
  * Asynchronously downloads PDF.
19
  */
20
 
21
- PDFJS.getDocument(pdf).then(function (pdfDoc_) {
22
- divContainer.empty().append($('<canvas></canvas>', {'class': 'the-canvas'})); //style: 'border:1px solid black',
23
-
24
- divContainer.data('pdfDoc', pdfDoc_);
25
-
26
- var toolbar_location = divContainer.data('toolbar');
27
-
28
- if (toolbar_location != 'bottom') {
29
- $.fn.pdfEmbedder.addToolbar(divContainer, true, showIsSecure);
30
- }
31
-
32
- if (toolbar_location != 'top') {
33
- $.fn.pdfEmbedder.addToolbar(divContainer, false, showIsSecure);
34
- }
35
-
36
- // Initial/first page rendering
37
- divContainer.data('pageNum', 1);
38
- divContainer.data('pageCount', pdfDoc_.numPages);
39
- divContainer.data('pageNumPending', null);
40
- $.fn.pdfEmbedder.renderPage(divContainer, 1);
41
-
42
- divContainer.find('span.pdfemb-page-count').text( pdfDoc_.numPages );
43
-
44
- $(window).resize(function() {
45
- $.fn.pdfEmbedder.queueRenderPage(divContainer, divContainer.data('pageNum'));
46
- });
47
- },
48
- function(e) {
49
- divContainer.empty().append($('<div></div>', {'class': 'pdfemb-errormsg'}).append(document.createTextNode(e.message)));
50
- });
51
 
52
  };
53
-
54
- pdfembGetPDF(url, callback);
55
 
 
 
 
 
 
 
 
56
  });
57
 
58
  return this;
@@ -68,7 +91,7 @@ jQuery(document).ready(function ($) {
68
 
69
  pdfDoc.getPage(pageNum).then(function(page) {
70
 
71
- var canvas = divContainer.find('.the-canvas');
72
  var scale = 1.0;
73
 
74
  var vp = page.getViewport(scale);
@@ -78,6 +101,7 @@ jQuery(document).ready(function ($) {
78
 
79
  if (pageWidth <= 0 || pageHeight <= 0) {
80
  divContainer.empty().append(document.createTextNode("PDF page width or height are invalid"));
 
81
  }
82
 
83
  // Max out at parent container width
@@ -109,35 +133,116 @@ jQuery(document).ready(function ($) {
109
  }
110
 
111
  scale = wantWidth / pageWidth;
112
- wantHeight = pageHeight * scale;
 
 
 
 
 
 
113
 
114
- if (wantWidth != canvas.width()) {
115
- canvas.width( wantWidth );
116
- }
117
-
118
- if (wantWidth != divContainer.width()) {
119
- divContainer.width(wantWidth);
120
- }
121
-
122
  // Height can be overridden by user
123
  var userHeight = parseInt(divContainer.data('height'), 10);
124
- if (!isNaN(userHeight) && userHeight > 0 && userHeight < wantHeight) {
125
- wantHeight = userHeight;
 
 
 
 
 
126
  }
127
-
128
- if (divContainer.height() != wantHeight + 4) {
129
- divContainer.height(wantHeight + 4);
130
- }
131
- if (canvas.height() != pageHeight * scale) {
132
- canvas.height(pageHeight * scale);
133
- }
134
-
135
-
136
- var viewport = page.getViewport(scale);
137
- canvas[0].height = viewport.height;
138
- canvas[0].width = viewport.width;
139
-
140
- // Render PDF page into canvas context
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  var ctx = canvas[0].getContext('2d');
142
  var renderContext = {
143
  canvasContext: ctx,
@@ -184,10 +289,15 @@ jQuery(document).ready(function ($) {
184
  $.fn.pdfEmbedder.renderPage(divContainer, num);
185
  }
186
  };
 
 
 
 
 
187
 
188
- $.fn.pdfEmbedder.addToolbar = function(divContainer, atTop, showIsSecure){
189
 
190
- var toolbar = $('<div></div>', {'class': 'pdfemb-toolbar '+(atTop ? ' pdfemb-toolbar-top' : 'pdfemb-toolbar-bottom')});
191
  var prevbtn = $('<button class="pdfemb-prev">Prev</button>');
192
  toolbar.append(prevbtn);
193
  var nextbtn = $('<button class="pdfemb-next">Next</button>');
@@ -195,15 +305,23 @@ jQuery(document).ready(function ($) {
195
 
196
  toolbar.append($('<div>Page <span class="pdfemb-page-num">0</span> / <span class="pdfemb-page-count"></span></div>'));
197
 
 
 
 
 
 
 
 
 
198
  if (showIsSecure) {
199
  toolbar.append($('<div>Secure</div>'));
200
  }
201
 
202
  if (atTop) {
203
- divContainer.prepend(toolbar);
204
  }
205
  else {
206
- divContainer.append(toolbar);
207
  }
208
 
209
  // Add button functions
@@ -222,19 +340,49 @@ jQuery(document).ready(function ($) {
222
  divContainer.data('pageNum', divContainer.data('pageNum')+1);
223
  $.fn.pdfEmbedder.queueRenderPage(divContainer, divContainer.data('pageNum'));
224
  });
 
 
 
 
 
 
 
 
 
 
225
 
226
- divContainer.on('mouseenter', function(e) {
227
- var toolbar = divContainer.find('div.pdfemb-toolbar');
228
- toolbar.show();
229
- }
230
- );
231
- divContainer.on('mouseleave',
232
- function(e) {
233
- var toolbar = divContainer.find('div.pdfemb-toolbar');
234
- toolbar.hide();
235
- }
236
- );
 
 
 
 
 
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  };
239
 
240
  // Apply plugin to relevant divs/};
9
  var divContainer = $(rawDivContainer);
10
 
11
  divContainer.append($('<div></div>', {'class': 'pdfemb-loadingmsg'}).append(document.createTextNode('Loading...')));
12
+
13
+ var initPdfDoc = function(pdfDoc_, showIsSecure) {
14
+ divContainer.empty().append(
15
+ $('<div></div>', {'class': 'pdfemb-inner-div'}).append(
16
+ $('<canvas></canvas>', {'class': 'pdfemb-the-canvas'})
17
+ )); //style: 'border:1px solid black',
18
+
19
+ divContainer.data('pdfDoc', pdfDoc_);
20
+
21
+ var toolbar_location = divContainer.data('toolbar');
22
+
23
+ if (toolbar_location != 'bottom') {
24
+ $.fn.pdfEmbedder.addToolbar(divContainer, true, divContainer.data('toolbar-fixed') == 'on', showIsSecure);
25
+ }
26
+
27
+ if (toolbar_location != 'top') {
28
+ $.fn.pdfEmbedder.addToolbar(divContainer, false, divContainer.data('toolbar-fixed') == 'on', showIsSecure);
29
+ }
30
+
31
+ // Initial/first page rendering
32
+
33
+ divContainer.data('pageCount', pdfDoc_.numPages);
34
+
35
+ if (!divContainer.data('pageNum')) {
36
+ divContainer.data('pageNum', 1);
37
+ }
38
+
39
+ divContainer.data('showIsSecure', showIsSecure);
40
+ divContainer.data('pageNumPending', null);
41
+ divContainer.data('zoom', 100);
42
+ $.fn.pdfEmbedder.renderPage(divContainer, divContainer.data('pageNum'));
43
+
44
+ divContainer.find('span.pdfemb-page-count').text( pdfDoc_.numPages );
45
+
46
+ var grabtopan = new pdfembGrabToPan({
47
+ element: divContainer.find('div.pdfemb-inner-div')[0]});
48
+ divContainer.data('grabtopan', grabtopan);
49
+
50
+ $(window).resize(function() {
51
+ $.fn.pdfEmbedder.queueRenderPage(divContainer, divContainer.data('pageNum'));
52
+ });
53
+ };
54
 
55
  var callback = function(pdf, showIsSecure) {
56
 
58
  * Asynchronously downloads PDF.
59
  */
60
 
61
+ PDFJS.getDocument(pdf).then(
62
+ function(pdfDoc_) {
63
+ initPdfDoc(pdfDoc_, showIsSecure)
64
+ },
65
+ function(e) {
66
+ divContainer.empty().append($('<div></div>', {'class': 'pdfemb-errormsg'}).append(document.createTextNode(e.message)));
67
+ }
68
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  };
 
 
71
 
72
+ if (divContainer.data('pdfDoc')) {
73
+ initPdfDoc(divContainer.data('pdfDoc'), divContainer.data('showIsSecure'));
74
+ }
75
+ else {
76
+ var url = divContainer.attr('data-pdf-url');
77
+ pdfembGetPDF(url, callback);
78
+ }
79
  });
80
 
81
  return this;
91
 
92
  pdfDoc.getPage(pageNum).then(function(page) {
93
 
94
+ var canvas = divContainer.find('.pdfemb-the-canvas');
95
  var scale = 1.0;
96
 
97
  var vp = page.getViewport(scale);
101
 
102
  if (pageWidth <= 0 || pageHeight <= 0) {
103
  divContainer.empty().append(document.createTextNode("PDF page width or height are invalid"));
104
+ return;
105
  }
106
 
107
  // Max out at parent container width
133
  }
134
 
135
  scale = wantWidth / pageWidth;
136
+ wantHeight = pageHeight * scale;
137
+
138
+ var fixedToolbars = divContainer.find('div.pdfemb-toolbar-fixed');
139
+
140
+ var wantMobile = pdfembWantMobile($, divContainer, wantWidth, userHeight);
141
+
142
+ var actualFixedToolbars = wantMobile ? 0 : fixedToolbars.length;
143
 
 
 
 
 
 
 
 
 
144
  // Height can be overridden by user
145
  var userHeight = parseInt(divContainer.data('height'), 10);
146
+ if (isNaN(userHeight) || userHeight <= 0 || userHeight > wantHeight) {
147
+ if (divContainer.data('height') == "max") {
148
+ userHeight = divContainer.parent().height() - actualFixedToolbars * fixedToolbars.height();
149
+ }
150
+ else {
151
+ userHeight = wantHeight;
152
+ }
153
  }
154
+
155
+ wantWidth = Math.floor(wantWidth);
156
+ wantHeight = Math.floor(wantHeight);
157
+
158
+
159
+
160
+ var zoom = 100;
161
+
162
+ var wantCanvasWidth = wantWidth;
163
+ var wantCanvasHeight = wantHeight;
164
+
165
+ var canvasHMargin = 0;
166
+ var canvasVMargin = 0;
167
+
168
+ if (!wantMobile) {
169
+
170
+ zoom = divContainer.data('zoom');
171
+
172
+ wantCanvasWidth = wantWidth * zoom / 100;
173
+ wantCanvasHeight = wantHeight * zoom / 100;
174
+
175
+ if (wantCanvasWidth < wantWidth) {
176
+ canvasHMargin = (wantWidth - wantCanvasWidth) / 2;
177
+ }
178
+ if (wantCanvasHeight < userHeight) {
179
+ canvasVMargin = (userHeight - wantCanvasHeight) / 2;
180
+ }
181
+
182
+ }
183
+
184
+ var viewport = page.getViewport(scale * zoom / 100);
185
+
186
+ // Set values
187
+
188
+ if (wantWidth != divContainer.width()) {
189
+ divContainer.width(wantWidth);
190
+ }
191
+
192
+ if (divContainer.height() != userHeight) {
193
+ divContainer.height(userHeight + actualFixedToolbars * fixedToolbars.height());
194
+ }
195
+
196
+ var innerdiv = divContainer.find('div.pdfemb-inner-div');
197
+ innerdiv.width(wantWidth);
198
+ innerdiv.height(userHeight);
199
+
200
+ var fixedTopToolbars = fixedToolbars.filter('.pdfemb-toolbar-top');
201
+ if (actualFixedToolbars > 0) {
202
+ innerdiv.css('top', fixedTopToolbars.height());
203
+ }
204
+
205
+
206
+ canvas[0].width = wantCanvasWidth;
207
+ canvas[0].height = wantCanvasHeight;
208
+
209
+ canvas.css('width', wantCanvasWidth);
210
+ canvas.css('height', wantCanvasHeight);
211
+
212
+ canvas.css('left', canvasHMargin).css('top', canvasVMargin);
213
+
214
+ // Need to pan?
215
+
216
+ if ((wantCanvasWidth > wantWidth || wantCanvasHeight > wantHeight || wantCanvasHeight > userHeight) && !wantMobile) {
217
+ divContainer.data('grabtopan').activate();
218
+
219
+ // Adjust panning offset to ensure a recent zoom change centres the doc?
220
+
221
+ var fromZoom = divContainer.data('fromZoom');
222
+ var toZoom = divContainer.data('toZoom');
223
+
224
+ if (fromZoom > 0 && toZoom > 0) {
225
+
226
+ var oldScrollLeft = innerdiv.scrollLeft();
227
+ var oldScrollTop = innerdiv.scrollTop();
228
+
229
+ var oldMidX = oldScrollLeft + wantWidth / 2;
230
+ var oldMidY = oldScrollTop + wantHeight / 2;
231
+
232
+ innerdiv.scrollLeft((oldMidX * toZoom / fromZoom) - wantWidth/2);
233
+ innerdiv.scrollTop((oldMidY * toZoom / fromZoom) - wantHeight/2);
234
+ }
235
+ }
236
+ else {
237
+ divContainer.data('grabtopan').deactivate();
238
+ divContainer.find('div.pdfemb-inner-div').scrollLeft(0).scrollTop(0); // reset
239
+ }
240
+
241
+ divContainer.data('fromZoom',0).data('toZoom', 0);
242
+
243
+ pdfembMakeMobile($, wantMobile, divContainer);
244
+
245
+ // Render PDF page into canvas context
246
  var ctx = canvas[0].getContext('2d');
247
  var renderContext = {
248
  canvasContext: ctx,
289
  $.fn.pdfEmbedder.renderPage(divContainer, num);
290
  }
291
  };
292
+
293
+ $.fn.pdfEmbedder.goFullScreen = function(divContainer) {
294
+ var fsWindow = $('<div class="pdfemb-fs-window"></div>');
295
+ $(document.body).append(fsWindow);
296
+ };
297
 
298
+ $.fn.pdfEmbedder.addToolbar = function(divContainer, atTop, fixed, showIsSecure){
299
 
300
+ var toolbar = $('<div></div>', {'class': 'pdfemb-toolbar pdfemb-toolbar'+(fixed ? '-fixed' : '-hover')+' '+(atTop ? ' pdfemb-toolbar-top' : 'pdfemb-toolbar-bottom')});
301
  var prevbtn = $('<button class="pdfemb-prev">Prev</button>');
302
  toolbar.append(prevbtn);
303
  var nextbtn = $('<button class="pdfemb-next">Next</button>');
305
 
306
  toolbar.append($('<div>Page <span class="pdfemb-page-num">0</span> / <span class="pdfemb-page-count"></span></div>'));
307
 
308
+ var zoomoutbtn = $('<button class="pdfemb-zoomout">-</button>');
309
+ toolbar.append(zoomoutbtn);
310
+
311
+ var zoominbtn = $('<button class="pdfemb-zoomin">+</button>');
312
+ toolbar.append(zoominbtn);
313
+
314
+ toolbar.append($('<div>Zoom <span class="pdfemb-zoom">100%</span></div>'));
315
+
316
  if (showIsSecure) {
317
  toolbar.append($('<div>Secure</div>'));
318
  }
319
 
320
  if (atTop) {
321
+ divContainer.prepend(toolbar);
322
  }
323
  else {
324
+ divContainer.append(toolbar);
325
  }
326
 
327
  // Add button functions
340
  divContainer.data('pageNum', divContainer.data('pageNum')+1);
341
  $.fn.pdfEmbedder.queueRenderPage(divContainer, divContainer.data('pageNum'));
342
  });
343
+
344
+ var changeZoom =function(zoomdelta) {
345
+ var oldzoom = divContainer.data('zoom');
346
+ var newzoom = oldzoom + zoomdelta;
347
+ divContainer.data('zoom', newzoom);
348
+ divContainer.find('span.pdfemb-zoom').text( newzoom + '%' );
349
+ $.fn.pdfEmbedder.queueRenderPage(divContainer, divContainer.data('pageNum'));
350
+
351
+ divContainer.data('fromZoom', oldzoom).data('toZoom', newzoom);
352
+ };
353
 
354
+ zoominbtn.on('click', function (e){
355
+ if (divContainer.data('zoom') >= 500) {
356
+ return;
357
+ }
358
+ changeZoom(10);
359
+ });
360
+
361
+ zoomoutbtn.on('click', function (e){
362
+ if (divContainer.data('zoom') <= 20) {
363
+ return;
364
+ }
365
+ changeZoom(-10);
366
+ });
367
+
368
+
369
+ pdfembAddMoreToolbar($, toolbar, divContainer);
370
 
371
+ if (!fixed) {
372
+ divContainer.on('mouseenter', function (e) {
373
+ var htoolbar = divContainer.find('div.pdfemb-toolbar-hover');
374
+ if (htoolbar.data('no-hover') !== true) {
375
+ htoolbar.show();
376
+ }
377
+ }
378
+ );
379
+ divContainer.on('mouseleave',
380
+ function (e) {
381
+ var htoolbar = divContainer.find('div.pdfemb-toolbar-hover');
382
+ htoolbar.hide();
383
+ }
384
+ );
385
+ }
386
  };
387
 
388
  // Apply plugin to relevant divs/};
pdf_embedder.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: PDF Embedder
5
  * Plugin URI: http://wp-pdf.com/
6
  * Description: Embed PDFs straight into your posts and pages, with flexible width and height. No third-party services required.
7
- * Version: 1.2.1
8
  * Author: Dan Lester
9
  * Author URI: http://wp-pdf.com/
10
  * License: GPL3
@@ -33,7 +33,8 @@ class pdfemb_basic_pdf_embedder extends core_pdf_embedder {
33
  public function pdfemb_wp_enqueue_scripts() {
34
  if (!$this->useminified()) {
35
  wp_register_script( 'pdfemb_versionspecific_pdf_js', $this->my_plugin_url().'js/pdfemb-basic.js');
36
- wp_register_script( 'pdfemb_embed_pdf_js', $this->my_plugin_url().'js/pdfemb-embed-pdf.js', array('pdfemb_versionspecific_pdf_js', 'jquery') );
 
37
  }
38
  else {
39
  wp_register_script( 'pdfemb_embed_pdf_js', $this->my_plugin_url().'js/all-pdfemb-basic.min.js', array('jquery') );
@@ -62,15 +63,35 @@ class pdfemb_basic_pdf_embedder extends core_pdf_embedder {
62
  protected function pdfemb_mainsection_text() {
63
  parent::pdfemb_mainsection_text();
64
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  <h2>Protect your PDFs using PDF Embedder Secure</h2>
66
- <p>Our premium PDF Embedder Secure plugin provides the same simple but elegant viewer for your website visitors, with the added protection that
67
- it is difficult for them to download or print the original PDF document.</p>
68
 
69
  <p>This means that your PDF is unlikely to be shared outside your site where you have no control over who views, prints, or shares it.</p>
70
 
71
- <p>See our website <a href="http://wp-pdf.com/secure/?utm_source=PDF%20Settings&utm_medium=freemium&utm_campaign=Freemium">wp-pdf.com</a> for more
72
  details and purchase options.
73
  </p>
 
74
  <?php
75
  }
76
 
4
  * Plugin Name: PDF Embedder
5
  * Plugin URI: http://wp-pdf.com/
6
  * Description: Embed PDFs straight into your posts and pages, with flexible width and height. No third-party services required.
7
+ * Version: 2.0
8
  * Author: Dan Lester
9
  * Author URI: http://wp-pdf.com/
10
  * License: GPL3
33
  public function pdfemb_wp_enqueue_scripts() {
34
  if (!$this->useminified()) {
35
  wp_register_script( 'pdfemb_versionspecific_pdf_js', $this->my_plugin_url().'js/pdfemb-basic.js');
36
+ wp_register_script( 'pdfemb_grabtopan_js', $this->my_plugin_url().'js/grabtopan-basic.js');
37
+ wp_register_script( 'pdfemb_embed_pdf_js', $this->my_plugin_url().'js/pdfemb-embed-pdf.js', array('pdfemb_versionspecific_pdf_js', 'pdfemb_grabtopan_js', 'jquery') );
38
  }
39
  else {
40
  wp_register_script( 'pdfemb_embed_pdf_js', $this->my_plugin_url().'js/all-pdfemb-basic.min.js', array('jquery') );
63
  protected function pdfemb_mainsection_text() {
64
  parent::pdfemb_mainsection_text();
65
  ?>
66
+
67
+ <hr /><br />
68
+
69
+ <h2>Mobile-friendly embedding using PDF Embedder Premium</h2>
70
+ <p>This free version of the plugin should work on most mobile browsers, but it will be cumbersome for users with small screens - it is difficult to position
71
+ the document entirely within the screen, and your users' fingers may catch the entire browser page when they're trying only to move about the document...</p>
72
+
73
+ <p>Our <b>PDF Embedder Premium</b> plugin solves this problem with an intelligent 'full screen' mode.
74
+ When the document is smaller than a certain width, the document displays only as a 'thumbnail' with a large 'View in Full Screen' button for the
75
+ user to click when they want to study your document.
76
+ This opens up the document so it has the full focus of the mobile browser, and the user can move about the document without hitting other parts of
77
+ the web page by mistake. Click Exit to return to the regular web page.
78
+ </p>
79
+
80
+ <p>See our website <a href="http://wp-pdf.com/premium/?utm_source=PDF%20Settings%20Premium&utm_medium=freemium&utm_campaign=Freemium">wp-pdf.com</a> for more
81
+ details and purchase options.
82
+ </p>
83
+
84
+ <br />
85
  <h2>Protect your PDFs using PDF Embedder Secure</h2>
86
+ <p>Our <b>PDF Embedder Premium Secure</b> plugin provides the same simple but elegant viewer for your website visitors, with the added protection that
87
+ it is difficult for users to download or print the original PDF document.</p>
88
 
89
  <p>This means that your PDF is unlikely to be shared outside your site where you have no control over who views, prints, or shares it.</p>
90
 
91
+ <p>See our website <a href="http://wp-pdf.com/secure/?utm_source=PDF%20Settings%20Secure&utm_medium=freemium&utm_campaign=Freemium">wp-pdf.com</a> for more
92
  details and purchase options.
93
  </p>
94
+
95
  <?php
96
  }
97
 
readme.txt CHANGED
@@ -3,51 +3,80 @@ Contributors: danlester
3
  Tags: doc, docx, pdf, office, powerpoint, google, document, embed, intranet
4
  Requires at least: 3.3
5
  Tested up to: 4.2
6
- Stable tag: 1.2.1
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
10
- Embed PDFs straight into your posts and pages, with intelligent resizing of width and height. No third-party services required.
11
 
12
  == Description ==
13
 
14
- Upload PDFs and embed them straight into your site - just like adding images! PDFs will be automatically sized to their natural size and shape (or just fill the width available if they are too big). Optionally, you can specify a width and the correct height will be calculated automatically. The shape will be recalculated if the page is resized by the user.
15
 
16
- The plugin has a unique method for embedding PDFs, using Javascript only, and _not_ using iframes or third-party services. This gives a lot of flexibility over the appearance of your document, and for development of the viewer going forward.
17
 
18
- The viewer currently has Next/Prev buttons to page through the document, and more viewer functionality will follow. There is no button to download the entire PDF (but of course a savvy user will be able to obtain the content since it is displayed to them).
19
 
20
  It uses a customized version of Mozilla's PDF.js project, but embeds it within your existing WordPress pages so we have full control over appearance. Other plugins may use similar technology, but they will insert the PDF itself into an 'iframe' which means they do not get the flexibility over sizing.
21
 
22
- = Secure PDF Embedder =
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- **Protect your PDFs with our premium version - PDF Embedder Secure**
25
 
26
- Our premium PDF Embedder Secure plugin provides the same simple but elegant viewer for your website visitors, with the added protection that it is difficult for them to
 
 
27
  download or print the original PDF document.
28
 
29
  This means that your PDF is unlikely to be shared outside your site where you have no control over who views, prints, or shares it.
30
 
31
- See our website [wp-pdf.com](http://wp-pdf.com/secure/?utm_source=PDF%20Readme&utm_medium=freemium&utm_campaign=Freemium) for more details and purchase options.
32
 
33
- = Usage =
34
 
35
- Once installed and Activated, click Add Media from any page or post, just like adding an image, but drag and drop a PDF file instead.
36
 
37
- When you insert into your post, it will appear in the editor as a 'shortcode' as follows:
 
38
 
39
- [pdf-embedder url="https://mysite.com/wp-content/uploads/2015/01/Plan-Summary.pdf"]
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  You can optionally override width and height as follows:
42
 
43
- [pdf-embedder url="https://mysite.com/wp-content/uploads/2015/01/Plan-Summary.pdf" **width="auto"**]
44
 
45
  Note the default value for width is 'max'.
46
 
47
  Resizing works as follows:
48
 
49
  * If width='max' the width will take as much space as possible within its parent container (e.g. column within your page).
50
- * If width='auto' the width will be equal to the 'natural' width of the PDF document contents (i.e. however width the PDF says it should be by default).
51
  * If width is a number (e.g. width='500') then it will display at that number of pixels wide.
52
 
53
  *In all cases, if the parent container is narrower than the width calculated above, then the document width will be reduced to the size of the container.*
@@ -57,35 +86,38 @@ The height will be calculated so that the document fits naturally, given the wid
57
  It is possible to specify a fixed height (e.g. height="200"), in which case the document may be cut off vertically.
58
  The height will be reduced to fit if it is larger than needed to display the document correctly.
59
 
60
- Toolbar Location
 
 
61
 
62
  Add toolbar="[top|bottom|both]" to the shortcode to change the location of the Next/Prev toolbar (default is 'bottom').
63
 
64
  E.g. [pdf-embedder url="https://mysite.com/wp-content/uploads/2015/01/Plan-Summary.pdf" **toolbar="top"**]
65
 
66
- == Screenshots ==
67
-
68
- 1. Uploaded PDF is displayed within your page/post at the correct size to fit.
69
- 2. User hovers over document to see Next/Prev page butons.
70
 
71
- == Frequently Asked Questions ==
 
72
 
73
- = How can I obtain support for this product? =
74
 
75
- Please feel free to email [contact@wp-pdf.com](mailto:contact@wp-pdf.com) with any questions.
76
 
77
- Always include your full shortcode, plus links to the relevant pages, and screenshots if they would be helpful too.
 
 
 
78
 
79
- We may occasionally be able to respond to support queries posted on the 'Support' forum here on the wordpress.org
80
- plugin page, but we recommend sending us an email instead if possible.
81
 
82
  = Can I protect my PDFs so they are difficult for viewers to download directly? =
83
 
84
- Not with the free version - it is relatively easy to find the link to download the file directly.
 
 
85
 
86
- A premium version is available that encrypts the PDF during transmission, so it is difficult for a casual user to save or print the file for use outside your site.
87
 
88
- See our website [wp-pdf.com](http://wp-pdf.com/secure/?utm_source=PDF%20Readme%20FAQ&utm_medium=freemium&utm_campaign=Freemium) for more details and purchase options.
89
 
90
  == Installation ==
91
 
@@ -104,6 +136,10 @@ the Plugins section of your Wordpress admin
104
 
105
  == Changelog ==
106
 
 
 
 
 
107
  = 1.2.1 =
108
 
109
  Fixed 'scrollbars' in IE.
3
  Tags: doc, docx, pdf, office, powerpoint, google, document, embed, intranet
4
  Requires at least: 3.3
5
  Tested up to: 4.2
6
+ Stable tag: 2.0
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
10
+ Embed PDFs straight into your posts and pages, with intelligent resizing of width and height. No third-party services or iframes required.
11
 
12
  == Description ==
13
 
14
+ Upload PDFs and embed them straight into your site - just like adding images! PDFs will be automatically sized to their natural size and shape (or just fill the width available if they are too big). Optionally, you can specify a width and the correct height will be calculated automatically. The shape will be recalculated whenever the page is resized by the user.
15
 
16
+ The plugin has a unique method for embedding PDFs, using Javascript only, and _not_ using iframes or third-party services. This gives a lot of flexibility over the appearance of your document.
17
 
18
+ The viewer currently has Next/Prev buttons to page through the document, and zoom buttons. There is no button to download the entire PDF (but of course a savvy user will be able to obtain the content since it is displayed to them).
19
 
20
  It uses a customized version of Mozilla's PDF.js project, but embeds it within your existing WordPress pages so we have full control over appearance. Other plugins may use similar technology, but they will insert the PDF itself into an 'iframe' which means they do not get the flexibility over sizing.
21
 
22
+ = Usage =
23
+
24
+ Once installed and Activated, click Add Media from any page or post, just like adding an image, but drag and drop a PDF file instead.
25
+
26
+ When you insert into your post, it will appear in the editor as a 'shortcode' as follows:
27
+
28
+ [pdf-embedder url="https://mysite.com/wp-content/uploads/2015/01/Plan-Summary.pdf"]
29
+
30
+ See [Frequently Asked Questions](https://wordpress.org/plugins/pdf-embedder/faq/) for information about sizing options plus other ways to customize the shortcodes.
31
+
32
+ = Mobile-friendly embedding using PDF Embedder Premium =
33
+
34
+ The free version of the plugin should work on most mobile browsers, but it will be cumbersome for users with small screens - it is difficult to position the document entirely within the screen, and your users' fingers may catch the entire browser page when they're trying only to move about the document...
35
+
36
+ Our **PDF Embedder Premium** plugin solves this problem with an intelligent 'full screen' mode.
37
+ When the document is smaller than a certain width, the document displays only as a 'thumbnail' with a large 'View in Full Screen' button for the user to click when they want to study your document.
38
+ This opens up the document so it has the full focus of the mobile browser, and the user can move about the document without hitting other parts of the web page by mistake. Click Exit to return to the regular web page.
39
 
40
+ See our website [wp-pdf.com](http://wp-pdf.com/premium/?utm_source=PDF%20Readme%20Premium&utm_medium=freemium&utm_campaign=Freemium) for more details and purchase options.
41
 
42
+ = Protect your PDFs with our secure premium version =
43
+
44
+ Our **PDF Embedder Premium Secure** plugin provides the same simple but elegant viewer as the premium version, with the added protection that it is difficult for users to
45
  download or print the original PDF document.
46
 
47
  This means that your PDF is unlikely to be shared outside your site where you have no control over who views, prints, or shares it.
48
 
49
+ See our website [wp-pdf.com](http://wp-pdf.com/secure/?utm_source=PDF%20Readme%20Secure&utm_medium=freemium&utm_campaign=Freemium) for more details and purchase options.
50
 
 
51
 
52
+ == Screenshots ==
53
 
54
+ 1. Uploaded PDF is displayed within your page/post at the correct size to fit.
55
+ 2. User hovers over document to see Next/Prev page butons.
56
 
57
+ == Frequently Asked Questions ==
58
+
59
+ = How can I obtain support for this product? =
60
+
61
+ Please feel free to email [contact@wp-pdf.com](mailto:contact@wp-pdf.com) with any questions.
62
+
63
+ Always include your full shortcode, plus links to the relevant pages, and screenshots if they would be helpful too.
64
+
65
+ We may occasionally be able to respond to support queries posted on the 'Support' forum here on the wordpress.org
66
+ plugin page, but we recommend sending us an email instead if possible.
67
+
68
+ = How can I change the Size? =
69
 
70
  You can optionally override width and height as follows:
71
 
72
+ [pdf-embedder url="https://mysite.com/wp-content/uploads/2015/01/Plan-Summary.pdf" **width="500"**]
73
 
74
  Note the default value for width is 'max'.
75
 
76
  Resizing works as follows:
77
 
78
  * If width='max' the width will take as much space as possible within its parent container (e.g. column within your page).
79
+ * If width='auto' the width will be equal to the 'natural' width of the PDF document contents (i.e. whatever width the PDF says it should be by default).
80
  * If width is a number (e.g. width='500') then it will display at that number of pixels wide.
81
 
82
  *In all cases, if the parent container is narrower than the width calculated above, then the document width will be reduced to the size of the container.*
86
  It is possible to specify a fixed height (e.g. height="200"), in which case the document may be cut off vertically.
87
  The height will be reduced to fit if it is larger than needed to display the document correctly.
88
 
89
+ = Can I customize the Toolbar? =
90
+
91
+ _Toolbar Location_
92
 
93
  Add toolbar="[top|bottom|both]" to the shortcode to change the location of the Next/Prev toolbar (default is 'bottom').
94
 
95
  E.g. [pdf-embedder url="https://mysite.com/wp-content/uploads/2015/01/Plan-Summary.pdf" **toolbar="top"**]
96
 
97
+ _Toolbar Fixed/Hover_
 
 
 
98
 
99
+ Add toolbarfixed="on" (default is 'off') to keep the toolbar open at all times rather than only when the user hovers over the document.
100
+ Note this of course extends the length of your embedded area.
101
 
102
+ E.g. [pdf-embedder url="https://mysite.com/wp-content/uploads/2015/01/Plan-Summary.pdf" **toolbarfixed="on"**]
103
 
104
+ = Can I improve the viewing experience for mobile users? =
105
 
106
+ Yes, our **PDF Embedder Premium** plugin has an intelligent 'full screen' mode.
107
+ When the document is smaller than a certain width, the document displays only as a 'thumbnail' with a large 'View in Full Screen' button for the user to click when they want to study your document.
108
+ This opens up the document so it has the full focus of the mobile browser, and the user can move about the document without hitting other parts of the web page by mistake.
109
+ Click Exit to return to the regular web page.
110
 
111
+ See our website [wp-pdf.com](http://wp-pdf.com/premium/?utm_source=PDF%20Readme%20FAQ%20Premium&utm_medium=freemium&utm_campaign=Freemium) for more details and purchase options.
 
112
 
113
  = Can I protect my PDFs so they are difficult for viewers to download directly? =
114
 
115
+ Not with the free or (regular) premium versions - it is relatively easy to find the link to download the file directly.
116
+
117
+ A **secure premium** version is available that encrypts the PDF during transmission, so it is difficult for a casual user to save or print the file for use outside your site.
118
 
119
+ See our website [wp-pdf.com](http://wp-pdf.com/secure/?utm_source=PDF%20Readme%20FAQ%20Secure&utm_medium=freemium&utm_campaign=Freemium) for more details and purchase options.
120
 
 
121
 
122
  == Installation ==
123
 
136
 
137
  == Changelog ==
138
 
139
+ = 2.0 =
140
+
141
+ Added zoom feature. Toolbars can be fixed instead of appearing on hover.
142
+
143
  = 1.2.1 =
144
 
145
  Fixed 'scrollbars' in IE.