Skip to content

Instantly share code, notes, and snippets.

@jahudka
Last active November 2, 2018 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahudka/a40adf8a9f47a7b48dc506a77b977818 to your computer and use it in GitHub Desktop.
Save jahudka/a40adf8a9f47a7b48dc506a77b977818 to your computer and use it in GitHub Desktop.
Nittro integration with Nextras Datagrid: prevent Datagrid requests from being saved in browser history
_context.invoke('Nextras', function(DOM) {
var Datagrid = _context.extend(function(snippetManager, page) {
this._ = {
snippetManager: snippetManager,
page: page,
hasGrid: false
};
this._.snippetManager.on('after-update', this._handleUpdate.bind(this));
this._.page.on('transaction-created', this._handleTransaction.bind(this));
}, {
_handleUpdate: function() {
this._.hasGrid = DOM.getByClassName('grid').some(function(elem) {
return elem.hasAttribute('data-grid-name');
});
},
_handleTransaction: function(evt) {
var grid, elem = evt.data.context.element;
if (
this._.hasGrid
&& !evt.data.context.fromHistory
&& !('history' in evt.data.context)
&& elem
&& !elem.hasAttribute('data-history')
&& (grid = DOM.closest(elem, null, 'grid'))
&& grid.hasAttribute('data-grid-name')
) {
evt.data.transaction.setIsHistoryState(false);
evt.data.context.history = false;
}
}
});
_context.register(Datagrid, 'Datagrid');
}, {
DOM: 'Utils.DOM'
});
// ...
var builder = new nittro.Builder({
// ...
libraries: {
js: [
'path/to/Datagrid.js'
]
},
// ...
bootstrap: {
services: {
datagrid: 'Nextras.Datagrid()!'
// , ...
}
// , ...
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment