Last active
November 2, 2018 16:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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