X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=node_modules%2Fphantomjs-prebuilt%2Flib%2Fphantom%2Fexamples%2Frender_multi_url.js;fp=node_modules%2Fphantomjs-prebuilt%2Flib%2Fphantom%2Fexamples%2Frender_multi_url.js;h=9f7348debc65e9f0d8e69e72c51a09fa99d7182d;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/node_modules/phantomjs-prebuilt/lib/phantom/examples/render_multi_url.js b/node_modules/phantomjs-prebuilt/lib/phantom/examples/render_multi_url.js new file mode 100644 index 000000000..9f7348deb --- /dev/null +++ b/node_modules/phantomjs-prebuilt/lib/phantom/examples/render_multi_url.js @@ -0,0 +1,74 @@ +// Render Multiple URLs to file + +"use strict"; +var RenderUrlsToFile, arrayOfUrls, system; + +system = require("system"); + +/* +Render given urls +@param array of URLs to render +@param callbackPerUrl Function called after finishing each URL, including the last URL +@param callbackFinal Function called after finishing everything +*/ +RenderUrlsToFile = function(urls, callbackPerUrl, callbackFinal) { + var getFilename, next, page, retrieve, urlIndex, webpage; + urlIndex = 0; + webpage = require("webpage"); + page = null; + getFilename = function() { + return "rendermulti-" + urlIndex + ".png"; + }; + next = function(status, url, file) { + page.close(); + callbackPerUrl(status, url, file); + return retrieve(); + }; + retrieve = function() { + var url; + if (urls.length > 0) { + url = urls.shift(); + urlIndex++; + page = webpage.create(); + page.viewportSize = { + width: 800, + height: 600 + }; + page.settings.userAgent = "Phantom.js bot"; + return page.open("http://" + url, function(status) { + var file; + file = getFilename(); + if (status === "success") { + return window.setTimeout((function() { + page.render(file); + return next(status, url, file); + }), 200); + } else { + return next(status, url, file); + } + }); + } else { + return callbackFinal(); + } + }; + return retrieve(); +}; + +arrayOfUrls = null; + +if (system.args.length > 1) { + arrayOfUrls = Array.prototype.slice.call(system.args, 1); +} else { + console.log("Usage: phantomjs render_multi_url.js [domain.name1, domain.name2, ...]"); + arrayOfUrls = ["www.google.com", "www.bbc.co.uk", "phantomjs.org"]; +} + +RenderUrlsToFile(arrayOfUrls, (function(status, url, file) { + if (status !== "success") { + return console.log("Unable to render '" + url + "'"); + } else { + return console.log("Rendered '" + url + "' at '" + file + "'"); + } +}), function() { + return phantom.exit(); +});