From 945937ccddac463eefce996966760ca0ac186889 Mon Sep 17 00:00:00 2001 From: Sergey Fayngold Date: Wed, 18 Nov 2015 15:00:15 +0100 Subject: [PATCH 1/5] Add JetBrains IDE coverage to .gitignore --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b9816a3..d1e474b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ *.swp node_modules -.ds_store \ No newline at end of file +.ds_store + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio +*.iml +.idea/ \ No newline at end of file From 778884ced451903cab09b7f698a4f9a72c45d875 Mon Sep 17 00:00:00 2001 From: Sergey Fayngold Date: Wed, 18 Nov 2015 15:18:22 +0100 Subject: [PATCH 2/5] Add object.assign ass package dependency --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4fd7500..be235e3 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,9 @@ "node >=0.7.00" ], "dependencies": { - "graceful-fs": "~3.0.4", "cross-spawn": "^0.2.3", + "graceful-fs": "~3.0.4", + "object.assign": "^4.0.3", "tmp": "~0.0.25" }, "optionalDependencies": { From dd9bf1c7bd46bc1234ab03672f4efc255b09b7ad Mon Sep 17 00:00:00 2001 From: Sergey Fayngold Date: Wed, 18 Nov 2015 15:19:06 +0100 Subject: [PATCH 3/5] Allow options overriding in the takeShot callback --- lib/webshot.phantom.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/webshot.phantom.js b/lib/webshot.phantom.js index d548ee2..2efd951 100644 --- a/lib/webshot.phantom.js +++ b/lib/webshot.phantom.js @@ -70,13 +70,18 @@ optUtils.phantomPage.forEach(function(key) { }); // The function that actually performs the screen rendering -var _takeScreenshot = function(status) { +var _takeScreenshot = function(status, optionsOverride) { if (status === 'fail') { page.close(); phantom.exit(1); return; } + if (typeof optionsOverride == 'object') { + var assign = require('object.assign').getPolyfill(); + assign(options, optionsOverride); + } + // Wait `options.renderDelay` seconds for the page's JS to kick in window.setTimeout(function () { @@ -136,6 +141,9 @@ if (options.onCallback && options.takeShotOnCallback) { if (data == 'takeShot') { _takeScreenshot(); } + else if (data.event == 'takeShot') { + _takeScreenshot(null, data.options); + } }; } else if (options.onLoadFinished && !options.takeShotOnCallback) { takeScreenshot = function(status) { From 0a8584bc5fd5bc972d13c82293c295e8b3c3b020 Mon Sep 17 00:00:00 2001 From: Sergey Fayngold Date: Wed, 18 Nov 2015 15:45:13 +0100 Subject: [PATCH 4/5] Update README.md --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 6ec5ea7..3280ac0 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,23 @@ var options = { }; ``` +### Override options in takeShotOnCallback +When using the takeShotOnCallback option, the page can override the options by +providing an object instead of the string as follows: + +```javascript +window.callPhantom({ + event: 'takeShot', + options: { + shotSize: { + width: document.getElementsByTagName('html')[0].offsetWidth, + height: document.getElementsByTagName('html')[0].offsetHeight + } + } +}); +``` +In this example the shot size will be set to the real size of the document. + ## Tests Tests are written with [Mocha](http://visionmedia.github.com/mocha/) and can be run with `npm test`. The tests use [node-imagemagick](http://github.com/rsms/node-imagemagick) and thus require From c8d3a027ab3851ee55b32842d57c70df10737a10 Mon Sep 17 00:00:00 2001 From: Sergey Fayngold Date: Wed, 18 Nov 2015 15:45:55 +0100 Subject: [PATCH 5/5] Update contributors in package.json --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index be235e3..8fb0763 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,10 @@ { "name": "Matthew Chase Whittemore", "email": "mcwhittemore@gmail.com" + }, + { + "name": "Sergey Fayngold", + "email": "sergey@faynhost.com" } ], "license": "MIT",