diff --git a/Gruntfile.js b/Gruntfile.js index 0306fd1..6bc14fa 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -35,6 +35,7 @@ module.exports = function(grunt) { waisenkinder : { options : { indexPath : 'photobox/', + timeOut : 1000, screenSizes : [ '960', '350', '1200' ], template : { name : 'canvas', diff --git a/README.md b/README.md index cdc4b8b..725c3d2 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,26 @@ Default value: `default` - `darker` - image information in diff image will be changed to a darker image - `brighter` - image information in diff image will be change to a brighter image + +#### options.timeOut + +Type: `Integer` + +Default value: 1000 + +An Integer representing the delay in milliseconds after the screenshot should be taken. + + +#### options.hashBang + +Type: `String` + +Default value: `#!` + +The hashbang used to navigate through a single page application. + +http://example.com/#!/hash/bang + ### Usage Examples #### Default Options diff --git a/tasks/lib/photobox.js b/tasks/lib/photobox.js index ee53b58..7b1985a 100644 --- a/tasks/lib/photobox.js +++ b/tasks/lib/photobox.js @@ -82,7 +82,7 @@ PhotoBox.prototype.createDiffImages = function() { this.grunt.log.subhead( 'PHOTOBOX STARTED DIFF GENERATION.'); this.pictures.forEach( function( picture ) { - picture = this.getUrlFilename( picture.replace('#', '-') ); + picture = this.getUrlFilename( picture.replace('@', '-') ); this.grunt.log.writeln( 'started diff for ' + picture ); @@ -125,10 +125,10 @@ PhotoBox.prototype.createIndexFile = function() { var templateData = this.pictures.map( function( picture ) { - var split = picture.split('#'); + var split = picture.split('@'); return { - url : this.getUrlFilename( split[0] ), + url : this.getUrlFilename( split[0].replace(this.options.hashBang, '_') ), size: split[1] }; }.bind(this) @@ -311,7 +311,7 @@ PhotoBox.prototype.getPreparedPictures = function() { this.options.urls.forEach( function( url ) { this.options.screenSizes.forEach( function( size ) { - pictures.push( url + '#' + size ); + pictures.push( url + '@' + size ); if ( size.match( /x/gi ) ) { this.grunt.log.warn( @@ -493,7 +493,8 @@ PhotoBox.prototype.getUrlFilename = function( url ) { var finalImage = ( ( !this.options.relativePaths ? parsedImage.host + '/' : '' ) + ( ( parsedImage.path !== '/' || !this.options.relativePaths ) ? parsedImage.path : 'index' ).replace( /^\//, '' ) + - ( parsedImage.query ? '/' + parsedImage.query : '' ) + ( parsedImage.query ? '/' + parsedImage.query : '' ) + + ( parsedImage.hash ? '/' + parsedImage.hash : '' ) ).replace( /^www\./g, '' ); return filenamify( finalImage, { replacement: '-' } ); @@ -515,7 +516,9 @@ PhotoBox.prototype.startPhotoSession = function() { localToRemoteUrlAccessEnabled : this.options.localToRemoteUrlAccessEnabled, password : this.options.password, userAgent : this.options.userAgent, - userName : this.options.userName + userName : this.options.userName, + timeOut : this.options.timeOut, + hashBang : this.options.hashBang } ); this.pictures.forEach( function( picture ) { @@ -524,7 +527,7 @@ PhotoBox.prototype.startPhotoSession = function() { var args = [ '--ssl-protocol=any', path.resolve( __dirname, 'photoboxScript.js' ), - picture + '#' + this.getUrlFilename( picture ), + picture + '@' + this.getUrlFilename( picture ), this.options.indexPath, this.options.indexPath + 'options.json' ]; diff --git a/tasks/lib/photoboxScript.js b/tasks/lib/photoboxScript.js index 0d904c1..565b3cd 100644 --- a/tasks/lib/photoboxScript.js +++ b/tasks/lib/photoboxScript.js @@ -15,7 +15,7 @@ var system = require ( 'system' ), fs = require( 'fs' ), page = webpage.create(), picture = system.args[ 1 ], - split = picture.split( '#' ), + split = picture.split( '@' ), url = split[ 0 ], width = +split[ 1 ], image = split[ 2 ], @@ -64,6 +64,8 @@ page.open( url, function( status ) { height : height, width : width }; + + image = image.replace(page.settings.hashBang, '_'); var imgPath = indexPath + 'img/current/' + @@ -75,5 +77,5 @@ page.open( url, function( status ) { page.render( imgPath ); phantom.exit(); - }, 1000 ); + }, page.settings.timeOut ); } ); diff --git a/tasks/photobox.js b/tasks/photobox.js index 5fbed8e..16e17d7 100644 --- a/tasks/photobox.js +++ b/tasks/photobox.js @@ -26,7 +26,9 @@ module.exports = function( grunt ) { template : 'canvas', userAgent : 'Photobox', userName : '', - urls : [ 'http://4waisenkinder.de' ] + urls : [ 'http://4waisenkinder.de' ], + timeOut : 1000, + hashBang : '#!' } ), Photobox = require( './lib/photobox' ), pb = new Photobox( grunt, options, done ); diff --git a/test/lib/photoboxTest.js b/test/lib/photoboxTest.js index e57280a..caea487 100644 --- a/test/lib/photoboxTest.js +++ b/test/lib/photoboxTest.js @@ -235,23 +235,28 @@ exports.photoBox = { template : { name : 'canvas', options : { + hashBang: '#!', highlightColor : '#ff0000', // template.options.hightlightColor || highlightcolor || default diffFilter : 'default' // default == no filter 'grayscale' | 'darker' | 'brighter' } }, screenSizes : [ '1000', '1200' ], - urls : [ 'http://google.com', 'http://4waisenkinder.de' ] + urls : [ 'http://google.com', 'http://4waisenkinder.de', 'http://4waisenkinder.de#myhash', 'http://4waisenkinder.de/#!/myhash' ] }, pb = new Photobox( grunt, options, cbFunction ), pictures; pictures = pb.getPreparedPictures(); - test.strictEqual( pictures.length, 4 ); - test.strictEqual( pictures[ 0 ], 'http://google.com#1000' ); - test.strictEqual( pictures[ 1 ], 'http://google.com#1200' ); - test.strictEqual( pictures[ 2 ], 'http://4waisenkinder.de#1000' ); - test.strictEqual( pictures[ 3 ], 'http://4waisenkinder.de#1200' ); + test.strictEqual( pictures.length, 8 ); + test.strictEqual( pictures[ 0 ], 'http://google.com@1000' ); + test.strictEqual( pictures[ 1 ], 'http://google.com@1200' ); + test.strictEqual( pictures[ 2 ], 'http://4waisenkinder.de@1000' ); + test.strictEqual( pictures[ 3 ], 'http://4waisenkinder.de@1200' ); + test.strictEqual( pictures[ 4 ], 'http://4waisenkinder.de#myhash@1000' ); + test.strictEqual( pictures[ 5 ], 'http://4waisenkinder.de#myhash@1200' ); + test.strictEqual( pictures[ 6 ], 'http://4waisenkinder.de/#!/myhash@1000' ); + test.strictEqual( pictures[ 7 ], 'http://4waisenkinder.de/#!/myhash@1200' ); test.done(); },