|
1 | 1 | /** @preserve |
2 | 2 | * jsPDF - PDF Document creation from JavaScript |
3 | | - * Version 1.0.203-git Built on 2014-07-22T04:20 |
4 | | - * CommitID ed1c917abb |
| 3 | + * Version 1.0.209-git Built on 2014-07-28T16:27 |
| 4 | + * CommitID 8f9d6cd5cb |
5 | 5 | * |
6 | 6 | * Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF |
7 | 7 | * 2010 Aaron Spike, https://github.com/acspike |
@@ -1703,7 +1703,7 @@ var jsPDF = (function(global) { |
1703 | 1703 | * pdfdoc.mymethod() // <- !!!!!! |
1704 | 1704 | */ |
1705 | 1705 | jsPDF.API = {events:[]}; |
1706 | | - jsPDF.version = "1.0.203-debug 2014-07-22T04:20:diegocr"; |
| 1706 | + jsPDF.version = "1.0.209-debug 2014-07-28T16:27:diegocr"; |
1707 | 1707 |
|
1708 | 1708 | if (typeof define === 'function' && define.amd) { |
1709 | 1709 | define('jsPDF', function() { |
@@ -1990,8 +1990,8 @@ var jsPDF = (function(global) { |
1990 | 1990 | return typeof value === 'undefined' || value === null; |
1991 | 1991 | } |
1992 | 1992 | , generateAliasFromData = function(data) { |
1993 | | - // TODO: Alias dynamic generation from imageData's checksum/hash |
1994 | | - return undefined; |
| 1993 | + return typeof data === 'string' && Array.prototype.reduce && |
| 1994 | + data.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0); |
1995 | 1995 | } |
1996 | 1996 | , doesNotSupportImageType = function(type) { |
1997 | 1997 | return supported_image_types.indexOf(type) === -1; |
@@ -2029,11 +2029,11 @@ var jsPDF = (function(global) { |
2029 | 2029 |
|
2030 | 2030 | return canvas.toDataURL((''+format).toLowerCase() == 'png' ? 'image/png' : 'image/jpeg'); |
2031 | 2031 | } |
2032 | | - ,checkImagesForAlias = function(imageData, images) { |
| 2032 | + ,checkImagesForAlias = function(alias, images) { |
2033 | 2033 | var cached_info; |
2034 | 2034 | if(images) { |
2035 | 2035 | for(var e in images) { |
2036 | | - if(imageData === images[e].alias) { |
| 2036 | + if(alias === images[e].alias) { |
2037 | 2037 | cached_info = images[e]; |
2038 | 2038 | break; |
2039 | 2039 | } |
@@ -2321,61 +2321,67 @@ var jsPDF = (function(global) { |
2321 | 2321 | format = tmp; |
2322 | 2322 | } |
2323 | 2323 |
|
2324 | | - var images = getImages.call(this),//initalises internals and events on first run |
2325 | | - dataAsBinaryString; |
| 2324 | + var images = getImages.call(this), info; |
2326 | 2325 |
|
2327 | | - compression = checkCompressValue(compression); |
| 2326 | + if (!(info = checkImagesForAlias(imageData, images))) { |
| 2327 | + var dataAsBinaryString; |
2328 | 2328 |
|
2329 | | - if(notDefined(alias)) |
2330 | | - alias = generateAliasFromData(imageData); |
| 2329 | + if(isDOMElement(imageData)) |
| 2330 | + imageData = createDataURIFromElement(imageData, format); |
2331 | 2331 |
|
2332 | | - if(isDOMElement(imageData)) |
2333 | | - imageData = createDataURIFromElement(imageData, format); |
| 2332 | + if(notDefined(alias)) |
| 2333 | + alias = generateAliasFromData(imageData); |
2334 | 2334 |
|
2335 | | - if(this.isString(imageData)) { |
| 2335 | + if (!(info = checkImagesForAlias(alias, images))) { |
2336 | 2336 |
|
2337 | | - var base64Info = this.extractInfoFromBase64DataURI(imageData); |
| 2337 | + if(this.isString(imageData)) { |
2338 | 2338 |
|
2339 | | - if(base64Info) { |
| 2339 | + var base64Info = this.extractInfoFromBase64DataURI(imageData); |
2340 | 2340 |
|
2341 | | - format = base64Info[2]; |
2342 | | - imageData = atob(base64Info[3]);//convert to binary string |
| 2341 | + if(base64Info) { |
2343 | 2342 |
|
2344 | | - } else { |
| 2343 | + format = base64Info[2]; |
| 2344 | + imageData = atob(base64Info[3]);//convert to binary string |
2345 | 2345 |
|
2346 | | - if (imageData.charCodeAt(0) === 0x89 && |
2347 | | - imageData.charCodeAt(1) === 0x50 && |
2348 | | - imageData.charCodeAt(2) === 0x4e && |
2349 | | - imageData.charCodeAt(3) === 0x47 ) format = 'png'; |
2350 | | - } |
2351 | | - } |
2352 | | - format = (format || 'JPEG').toLowerCase(); |
| 2346 | + } else { |
2353 | 2347 |
|
2354 | | - if(doesNotSupportImageType(format)) |
2355 | | - throw new Error('addImage currently only supports formats ' + supported_image_types + ', not \''+format+'\''); |
| 2348 | + if (imageData.charCodeAt(0) === 0x89 && |
| 2349 | + imageData.charCodeAt(1) === 0x50 && |
| 2350 | + imageData.charCodeAt(2) === 0x4e && |
| 2351 | + imageData.charCodeAt(3) === 0x47 ) format = 'png'; |
| 2352 | + } |
| 2353 | + } |
| 2354 | + format = (format || 'JPEG').toLowerCase(); |
2356 | 2355 |
|
2357 | | - if(processMethodNotEnabled(format)) |
2358 | | - throw new Error('please ensure that the plugin for \''+format+'\' support is added'); |
| 2356 | + if(doesNotSupportImageType(format)) |
| 2357 | + throw new Error('addImage currently only supports formats ' + supported_image_types + ', not \''+format+'\''); |
2359 | 2358 |
|
2360 | | - /* |
2361 | | - * need to test if it's more efficent to convert all binary strings |
2362 | | - * to TypedArray - or should we just leave and process as string? |
2363 | | - */ |
2364 | | - if(this.supportsArrayBuffer()) { |
2365 | | - dataAsBinaryString = imageData; |
2366 | | - imageData = this.binaryStringToUint8Array(imageData); |
2367 | | - } |
| 2359 | + if(processMethodNotEnabled(format)) |
| 2360 | + throw new Error('please ensure that the plugin for \''+format+'\' support is added'); |
2368 | 2361 |
|
2369 | | - var imageIndex = getImageIndex(images), |
2370 | | - info = checkImagesForAlias(dataAsBinaryString || imageData, images); |
| 2362 | + /** |
| 2363 | + * need to test if it's more efficent to convert all binary strings |
| 2364 | + * to TypedArray - or should we just leave and process as string? |
| 2365 | + */ |
| 2366 | + if(this.supportsArrayBuffer()) { |
| 2367 | + dataAsBinaryString = imageData; |
| 2368 | + imageData = this.binaryStringToUint8Array(imageData); |
| 2369 | + } |
2371 | 2370 |
|
2372 | | - if(!info) |
2373 | | - info = this['process' + format.toUpperCase()](imageData, imageIndex, alias, compression, dataAsBinaryString); |
| 2371 | + info = this['process' + format.toUpperCase()]( |
| 2372 | + imageData, |
| 2373 | + getImageIndex(images), |
| 2374 | + alias, |
| 2375 | + checkCompressValue(compression), |
| 2376 | + dataAsBinaryString |
| 2377 | + ); |
2374 | 2378 |
|
2375 | | - if(!info) |
2376 | | - throw new Error('An unkwown error occurred whilst processing the image'); |
| 2379 | + if(!info) |
| 2380 | + throw new Error('An unkwown error occurred whilst processing the image'); |
| 2381 | + } |
| 2382 | + } |
2377 | 2383 |
|
2378 | | - writeImageToPDF.call(this, x, y, w, h, info, imageIndex, images); |
| 2384 | + writeImageToPDF.call(this, x, y, w, h, info, info.i, images); |
2379 | 2385 |
|
2380 | 2386 | return this |
2381 | 2387 | }; |
@@ -5415,7 +5421,7 @@ jsPDFAPI.putTotalPages = function(pageExpression) { |
5415 | 5421 | })(jsPDF.API); |
5416 | 5422 | /* Blob.js |
5417 | 5423 | * A Blob implementation. |
5418 | | - * 2014-07-01 |
| 5424 | + * 2014-07-24 |
5419 | 5425 | * |
5420 | 5426 | * By Eli Grey, http://eligrey.com |
5421 | 5427 | * By Devin Samarin, https://github.com/eboyjr |
@@ -5477,13 +5483,31 @@ jsPDFAPI.putTotalPages = function(pageExpression) { |
5477 | 5483 |
|
5478 | 5484 | , ArrayBuffer = view.ArrayBuffer |
5479 | 5485 | , Uint8Array = view.Uint8Array |
| 5486 | + |
| 5487 | + , origin = /^[\w-]+:\/*\[?[\w\.:-]+\]?(?::[0-9]+)?/ |
5480 | 5488 | ; |
5481 | 5489 | FakeBlob.fake = FB_proto.fake = true; |
5482 | 5490 | while (file_ex_code--) { |
5483 | 5491 | FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1; |
5484 | 5492 | } |
| 5493 | + // Polyfill URL |
5485 | 5494 | if (!real_URL.createObjectURL) { |
5486 | | - URL = view.URL = {}; |
| 5495 | + URL = view.URL = function(uri) { |
| 5496 | + var |
| 5497 | + uri_info = document.createElementNS("http://www.w3.org/1999/xhtml", "a") |
| 5498 | + , uri_origin |
| 5499 | + ; |
| 5500 | + uri_info.href = uri; |
| 5501 | + if (!("origin" in uri_info)) { |
| 5502 | + if (uri_info.protocol.toLowerCase() === "data:") { |
| 5503 | + uri_info.origin = null; |
| 5504 | + } else { |
| 5505 | + uri_origin = uri.match(origin); |
| 5506 | + uri_info.origin = uri_origin && uri_origin[1]; |
| 5507 | + } |
| 5508 | + } |
| 5509 | + return uri_info; |
| 5510 | + }; |
5487 | 5511 | } |
5488 | 5512 | URL.createObjectURL = function(blob) { |
5489 | 5513 | var |
@@ -5594,7 +5618,7 @@ jsPDFAPI.putTotalPages = function(pageExpression) { |
5594 | 5618 | }(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this)); |
5595 | 5619 | /* FileSaver.js |
5596 | 5620 | * A saveAs() FileSaver implementation. |
5597 | | - * 2014-07-21 |
| 5621 | + * 2014-07-25 |
5598 | 5622 | * |
5599 | 5623 | * By Eli Grey, http://eligrey.com |
5600 | 5624 | * License: X11/MIT |
@@ -5647,13 +5671,18 @@ var saveAs = saveAs |
5647 | 5671 | // the reasoning behind the timeout and revocation flow |
5648 | 5672 | , arbitrary_revoke_timeout = 10 |
5649 | 5673 | , revoke = function(file) { |
5650 | | - setTimeout(function() { |
| 5674 | + var revoker = function() { |
5651 | 5675 | if (typeof file === "string") { // file is an object URL |
5652 | 5676 | get_URL().revokeObjectURL(file); |
5653 | 5677 | } else { // file is a File |
5654 | 5678 | file.remove(); |
5655 | 5679 | } |
5656 | | - }, arbitrary_revoke_timeout); |
| 5680 | + }; |
| 5681 | + if (view.chrome) { |
| 5682 | + revoker(); |
| 5683 | + } else { |
| 5684 | + setTimeout(revoker, arbitrary_revoke_timeout); |
| 5685 | + } |
5657 | 5686 | } |
5658 | 5687 | , dispatch = function(filesaver, event_types, event) { |
5659 | 5688 | event_types = [].concat(event_types); |
@@ -5689,7 +5718,11 @@ var saveAs = saveAs |
5689 | 5718 | if (target_view) { |
5690 | 5719 | target_view.location.href = object_url; |
5691 | 5720 | } else { |
5692 | | - view.open(object_url, "_blank"); |
| 5721 | + var new_tab = view.open(object_url, "_blank"); |
| 5722 | + if (new_tab == undefined && typeof safari !== "undefined") { |
| 5723 | + //Apple do not allow window.open, see http://bit.ly/1kZffRI |
| 5724 | + view.location.href = object_url |
| 5725 | + } |
5693 | 5726 | } |
5694 | 5727 | filesaver.readyState = filesaver.DONE; |
5695 | 5728 | dispatch_all(); |
|
0 commit comments