Skip to content

Commit

Permalink
[t663] - html snapshotting for export
Browse files Browse the repository at this point in the history
1. Added _page to butter to expose functions
2. Added data-butter-exclude to dialog modal container
3. Added snapshotHTML/eraseSnapshot functions in Page class
4. Added test for html snapshotting
  • Loading branch information
secretrobotron committed Apr 16, 2012
1 parent 3a6cc3e commit 58b0af7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/default.conf
@@ -1,5 +1,6 @@
{
"name": "default-butter-test",
"snapshotHTMLOnReady": true,
"editor": {
"default": "../editors/default-editor.html"
},
Expand Down
28 changes: 24 additions & 4 deletions src/core/page.js
Expand Up @@ -80,10 +80,18 @@ define( [ "core/logger", "core/eventmanager" ], function( Logger, EventManager )
};

this.getHTML = function( popcornStrings ){
var html = document.createElement( "html" ),
head = document.getElementsByTagName( "head" )[ 0 ].cloneNode( true ),
body = document.getElementsByTagName( "body" )[ 0 ].cloneNode( true ),
i, toClean, toExclude, node;
var html, head, body, i, toClean, toExclude, node;

html = document.createElement( "html" );

if( !_snapshot ){
head = document.getElementsByTagName( "head" )[ 0 ].cloneNode( true );
body = document.getElementsByTagName( "body" )[ 0 ].cloneNode( true );
}
else{
head = _snapshot.head.cloneNode( true );
body = _snapshot.body.cloneNode( true );
}

toExclude = Array.prototype.slice.call( head.querySelectorAll( "*[data-butter-exclude]" ) );
toExclude = toExclude.concat( Array.prototype.slice.call( head.querySelectorAll( "*[data-requiremodule]" ) ) );
Expand All @@ -97,6 +105,7 @@ define( [ "core/logger", "core/eventmanager" ], function( Logger, EventManager )
node = toClean[ i ];
node.removeAttribute( "butter-clean" );
node.removeAttribute( "data-butter" );
node.removeAttribute( "data-butter-default" );

// obviously, classList is preferred (https://developer.mozilla.org/en/DOM/element.classList)
if( node.classList ){
Expand Down Expand Up @@ -128,5 +137,16 @@ define( [ "core/logger", "core/eventmanager" ], function( Logger, EventManager )
return "<html>" + html.innerHTML + "</html>";
}; //getHTML

this.snapshotHTML = function(){
_snapshot = {
head: document.getElementsByTagName( "head" )[ 0 ].cloneNode( true ),
body: document.getElementsByTagName( "body" )[ 0 ].cloneNode( true )
};
};

this.eraseSnapshot = function(){
_snapshot = null;
};

}; // page
});
1 change: 1 addition & 0 deletions src/dialog/modal.js
Expand Up @@ -11,6 +11,7 @@ define( [], function(){
if( !__container ){
__container = document.createElement( "div" );
__container.id = "butter-modal-container";
__container.setAttribute( "data-butter-exclude", true );
document.body.appendChild( __container );
} //if

Expand Down
7 changes: 7 additions & 0 deletions src/main.js
Expand Up @@ -566,6 +566,11 @@
//prepare the page next
preparePage(function(){
moduleCollection.ready(function(){

if( _config.snapshotHTMLOnReady ){
_page.snapshotHTML();
}

//fire the ready event
_em.dispatch( "ready", _this );
});
Expand Down Expand Up @@ -600,6 +605,8 @@
readConfig();
} //if

this.page = _page;

}

Butter.instances = __instances;
Expand Down
25 changes: 25 additions & 0 deletions test/core.js
Expand Up @@ -612,6 +612,30 @@
});
});

asyncTest( "Export HTML snapshotting", function() {
expect( 1 );
createButter( function( butter ){
var m1 = butter.addMedia( { url:"../external/popcorn-js/test/trailer.ogv", target:"mediaDiv" } );

butter.listen( "mediaready", function( e ) {
butter.page.snapshotHTML();

t1 = m1.addTrack();
te1 = t1.addTrackEvent({
popcornOptions: {
start: 0,
end: 6,
text: "OBVIOUS",
target: "stringSanity"
},
type: "footnote"
});

equals( butter.getHTML().match( "OBVIOUS" ).length, 1, "TrackEvent wasn't exported" );
start();
});
});
});
module( "Debug functionality" );
asyncTest( "Debug enables/disables logging", 4, function() {
createButter(function( butter ) {
Expand All @@ -638,4 +662,5 @@
butter.addMedia({ url: "../external/popcorn-js/test/trailer.ogv", target: "mediaDiv" });
});
});

})(window, window.document );

0 comments on commit 58b0af7

Please sign in to comment.