Skip to content

Commit 5ca84a4

Browse files
committed
Add raw HTML to newPageReady event
1 parent cb170d6 commit 5ca84a4

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/Pjax/Dom.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ var Dom = {
3232
*/
3333
containerClass: 'barba-container',
3434

35+
/**
36+
* Full HTML String of the current page.
37+
* By default is the innerHTML of the initial loaded page.
38+
*
39+
* Each time a new page is loaded, the value is the response of the xhr call.
40+
*
41+
* @memberOf Barba.Pjax.Dom
42+
* @type {String}
43+
*/
44+
currentHTML: document.documentElement.innerHTML,
45+
3546
/**
3647
* Parse the responseText obtained from the xhr call
3748
*
@@ -41,6 +52,8 @@ var Dom = {
4152
* @return {HTMLElement}
4253
*/
4354
parseResponse: function(responseText) {
55+
this.currentHTML = responseText;
56+
4457
var wrapper = document.createElement('div');
4558
wrapper.innerHTML = responseText;
4659

src/Pjax/Pjax.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ var Pjax = {
7373

7474
//Fire for the current view.
7575
Dispatcher.trigger('initStateChange', this.History.currentStatus());
76-
Dispatcher.trigger('newPageReady', this.History.currentStatus(), {}, container);
76+
Dispatcher.trigger('newPageReady',
77+
this.History.currentStatus(),
78+
{},
79+
container,
80+
this.Dom.currentHTML
81+
);
7782
Dispatcher.trigger('transitionCompleted', this.History.currentStatus());
7883

7984
this.bindEvents();
@@ -308,7 +313,8 @@ var Pjax = {
308313
Dispatcher.trigger('newPageReady',
309314
this.History.currentStatus(),
310315
this.History.prevStatus(),
311-
container
316+
container,
317+
this.Dom.currentHTML
312318
);
313319
},
314320

tests/dom-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ describe('Dom', function() {
3737
expect(dom.getNamespace()).toBeFalsy();
3838
expect(namespace).toBe('test');
3939
});
40+
41+
it('should have a default currentHTML', function() {
42+
var html = dom.currentHTML;
43+
44+
expect(html).toBeTruthy();
45+
expect(html).toContain('titlepage');
46+
});
4047
});

0 commit comments

Comments
 (0)