mirror of
https://github.com/astefanutti/decktape.git
synced 2024-12-12 13:49:13 +03:00
Promise-based Web page open callback
This commit is contained in:
parent
560cfb71c6
commit
5222c9837a
27
decktape.js
27
decktape.js
@ -163,19 +163,24 @@ page.onConsoleMessage = function (msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
page.open(options.url, function (status) {
|
||||
if (status !== 'success') {
|
||||
console.log('Unable to load the address: ' + options.url);
|
||||
openUrl(page, options.url)
|
||||
.then(delay(options.loadPause))
|
||||
.then(exportSlides)
|
||||
.catch(function (url) {
|
||||
console.log('Unable to load the URL: ' + url);
|
||||
phantom.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
if (options.loadPause > 0)
|
||||
Promise.resolve()
|
||||
.then(delay(options.loadPause))
|
||||
.then(exportSlides);
|
||||
else
|
||||
exportSlides();
|
||||
});
|
||||
function openUrl(page, url) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
page.open(url, function (status) {
|
||||
if (status !== 'success')
|
||||
reject(url);
|
||||
else
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function exportSlides() {
|
||||
var plugin;
|
||||
|
Loading…
Reference in New Issue
Block a user