Files
OfficialSite/assets/scripts/transitions/DefaultTransition.js
2017-05-30 12:16:13 -04:00

53 lines
1.6 KiB
JavaScript

/* jshint esnext: true */
import { APP_NAME, $document, $html } from '../utils/environment';
import { EVENT as APP_EVENT } from '../App';
function DefaultTransition(options) {
options = options || {};
const startCallback = (typeof options.startCallback === 'function') ? options.startCallback : function(){};
const overrideClass = (typeof options.overrideClass === 'string') ? options.overrideClass : '';
return Barba.BaseTransition.extend({
start: function() {
$html
.removeClass('dom-is-loaded dom-is-animated')
.addClass(`dom-is-loading ${overrideClass}`);
startCallback();
/* Close any overlays */
setTimeout(() => {
Promise
.all([this.newContainerLoading])
.then(this.finish.bind(this));
}, 1000);
},
finish: function() {
this.done();
const $el = $(this.newContainer);
// Get the template name of the new container and set it to the DOM
$html.attr('data-template', $el.data('template'));
$document.triggerHandler({
type: APP_EVENT.INIT_MODULES,
isBarba: true
});
$html
.addClass('dom-is-loaded')
.removeClass('dom-is-loading');
setTimeout(() => {
$html
.removeClass(overrideClass)
.addClass('dom-is-animated');
}, 1000);
}
});
}
export default DefaultTransition;