Skip to content

Commit 33c5ec8

Browse files
author
Kenneth Glassey
committed
Generalized delete page function
Prior implementation did not handle case n === page
1 parent aaafe1d commit 33c5ec8

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

jspdf.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* 2014 James Makes, https://github.com/dollaruw
1919
* 2014 Diego Casorran, https://github.com/diegocr
2020
* 2014 Steven Spungin, https://github.com/Flamenco
21+
* 2014 Kenneth Glassey, https://github.com/Gavvers
2122
*
2223
* Permission is hereby granted, free of charge, to any person obtaining
2324
* a copy of this software and associated documentation files (the
@@ -711,6 +712,15 @@ var jsPDF = (function(global) {
711712
}
712713
events.publish('addPage', { pageNumber : page });
713714
},
715+
_deletePage = function( n ) {
716+
pages.splice(n, 1);
717+
pagedim.splice(n, 1);
718+
page--;
719+
if (currentPage > page){
720+
currentPage = page;
721+
}
722+
this.setPage(currentPage);
723+
},
714724
_setPage = function(n) {
715725
if (n > 0 && n <= page) {
716726
currentPage = n;
@@ -1022,16 +1032,8 @@ var jsPDF = (function(global) {
10221032
}
10231033
return this;
10241034
};
1025-
API.deletePage = function(targetPage) {
1026-
for (var i=targetPage; i< page; i++){
1027-
pages[i] = pages[i+1];
1028-
pagedim[i] = pagedim[i+1];
1029-
}
1030-
page--;
1031-
if (currentPage > page){
1032-
currentPage = page;
1033-
}
1034-
this.setPage(currentPage);
1035+
API.deletePage = function() {
1036+
_deletePage.apply( this, arguments );
10351037
return this;
10361038
};
10371039
API.setDisplayMode = function(zoom, layout, pmode) {

0 commit comments

Comments
 (0)