diff --git a/index.js b/index.js index 5a1aeb2..b87fd17 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,6 @@ var path = require( "path" ); var phantomjs = require( "phantomjs-prebuilt" ); var childProcess = require( "child_process" ); var chalk = require( "chalk" ); -var binPath = phantomjs.path; var argv = require( "minimist" )( process.argv.slice(2) ); var pluginName = "glyphhanger"; @@ -68,7 +67,7 @@ function phantomGlyphhanger( urls ) { console.log( prefix + urls.join( "\n" + prefix ) ); } - childProcess.execFile( binPath, childArgs.concat( urls ), function( error, stdout, stderr ) { + childProcess.execFile( phantomjs.path, childArgs.concat( urls ), function( error, stdout, stderr ) { if( error ) { throw error; } @@ -80,7 +79,7 @@ function phantomGlyphhanger( urls ) { if( !argv.spider ) { phantomGlyphhanger( argv._ ); } else { - childProcess.execFile( binPath, urlsChildArgs, function( error, stdout, stderr ) { + childProcess.execFile( phantomjs.path, urlsChildArgs, function( error, stdout, stderr ) { if( error ) { throw error; } diff --git a/phantomjs-glyphhanger.js b/phantomjs-glyphhanger.js index b5f92e0..d0e0ced 100644 --- a/phantomjs-glyphhanger.js +++ b/phantomjs-glyphhanger.js @@ -7,23 +7,34 @@ var args = require( "system" ).args; var pluginName = "glyphhanger"; function requestUrl( url ) { - var page = webpage.create(); + return new Rsvp.Promise(function( resolve, reject ) { + var page = webpage.create(); - page.onConsoleMessage = function( msg ) { - console.log( pluginName + " phantom console:", msg ); - }; + page.onConsoleMessage = function( msg ) { + console.log( pluginName + " phantom console:", msg ); + }; - return new Rsvp.Promise(function( resolve, reject ) { - page.open( url, function( status ) { - if ( status === "success" && page.injectJs( "node_modules/characterset/lib/characterset.js" ) && page.injectJs( "glyphhanger.js" ) ) { - resolve( page.evaluate( function() { + page.onLoadFinished = function( status ) { + if( status !== "success" ) { + reject( "onLoadFinished error", status ); + } + if( page.injectJs( "node_modules/characterset/lib/characterset.js" ) && + page.injectJs( "glyphhanger.js" ) ) { + + resolve( page.evaluate( function() { var hanger = new GlyphHanger(); hanger.init( document.body ); return hanger.getGlyphs(); }) ); } else { + reject( "injectJs error" ); + } + }; + + page.open( url, function( status ) { + if( status !== "success" ) { reject( url, status ); } }); diff --git a/test/test.html b/test/test.html index e26b066..4c1dd54 100644 --- a/test/test.html +++ b/test/test.html @@ -1,11 +1,24 @@ -
- - -