Created by @chemix in Q&As
@chemix
@chemix

Hi, I needed simple toggle implementation from Nette.js so this is my simple service

build configuration

...
     libraries:
       js: [
         'public/js/nittro/NetteBasicFormToggle.js',
       ]
...
       services:
         netteBasicFormToggle: 'App.NetteBasicFormToggle()!'          
...            

NetteBasicFormToggle.js

_context.invoke('App', function (Nette) {

    var NetteBasicFormToggle = _context.extend(function(snippetManager) {
        this._ = {
            snippetManager: snippetManager
        };

        this._.snippetManager.on('after-update', this._handleUpdate.bind(this));
    }, {
        _handleUpdate: function() {
            var forms = [].slice.call(document.getElementsByTagName('form'));
            forms.forEach(Nette.toggleForm);
        }
    });

    _context.register(NetteBasicFormToggle, 'NetteBasicFormToggle');

}, {
    Nette: 'Nittro.Forms.Vendor'
});

thanks @jahudka for help 🙏

@gliny
@gliny

Hi, i cant make it work. I just copied the "context.invoke....." code into my global js file, i have nittro from bower (nette 3.0,nittro 2.0.43). Is there any magic behind? It says: "e" not found in context.

For now i solved it like this: (function() { var origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function() { console.log('request started!'); this.addEventListener('load', function() { $('form').each(function( index ) { Nette.toggleForm(this); }); }); origOpen.apply(this, arguments); }; })();

@jahudka
@jahudka

Hi @gliny, for starters, don't use Nittro from Bower - the Bower packages are unmaintained and quite probably a number of updates and bugfixes behind.

What this looks like is a minification issue. Are using something like uglify to minify your scripts? Some minification utilities strategically shorten identifiers in code to save space, so e.g. function showMessage(message, type, dismiss) { ... } could be minified to function a(b,c,d) { ... } - and this breaks Nittro. If you use uglify then the relevant option is called mangle and you need to set it to false.

Sign in to post a reply