Skip to content

Commit

Permalink
Add raw HTML to newPageReady event
Browse files Browse the repository at this point in the history
  • Loading branch information
luruke committed Aug 22, 2016
1 parent cb170d6 commit 5ca84a4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/Pjax/Dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ var Dom = {
*/
containerClass: 'barba-container',

/**
* Full HTML String of the current page.
* By default is the innerHTML of the initial loaded page.
*
* Each time a new page is loaded, the value is the response of the xhr call.
*
* @memberOf Barba.Pjax.Dom
* @type {String}
*/
currentHTML: document.documentElement.innerHTML,

/**
* Parse the responseText obtained from the xhr call
*
Expand All @@ -41,6 +52,8 @@ var Dom = {
* @return {HTMLElement}
*/
parseResponse: function(responseText) {
this.currentHTML = responseText;

var wrapper = document.createElement('div');
wrapper.innerHTML = responseText;

Expand Down
10 changes: 8 additions & 2 deletions src/Pjax/Pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ var Pjax = {

//Fire for the current view.
Dispatcher.trigger('initStateChange', this.History.currentStatus());
Dispatcher.trigger('newPageReady', this.History.currentStatus(), {}, container);
Dispatcher.trigger('newPageReady',
this.History.currentStatus(),
{},
container,
this.Dom.currentHTML
);
Dispatcher.trigger('transitionCompleted', this.History.currentStatus());

this.bindEvents();
Expand Down Expand Up @@ -308,7 +313,8 @@ var Pjax = {
Dispatcher.trigger('newPageReady',
this.History.currentStatus(),
this.History.prevStatus(),
container
container,
this.Dom.currentHTML
);
},

Expand Down
7 changes: 7 additions & 0 deletions tests/dom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ describe('Dom', function() {
expect(dom.getNamespace()).toBeFalsy();
expect(namespace).toBe('test');
});

it('should have a default currentHTML', function() {
var html = dom.currentHTML;

expect(html).toBeTruthy();
expect(html).toContain('titlepage');
});
});

0 comments on commit 5ca84a4

Please sign in to comment.