I'm trying to create another event type extending the $.event.special object. Because I need to change an element different from input type. The problem is that when I launch the page the console gives me this error:
main.js:5 Uncaught TypeError: Cannot read property 'mutationsLists' of undefined
The script is this:
(function($){
$.event.special.changeElement = {
eventType: 'changeElement',
mutationObserver : new MutationObserver($.event.special.changeElement.mutationsLists),
setup: function(data, namespaces) {
var config = { attributes: true, childList: true };
$.event.special.changeElement.mutationObserver.observe(this, config);
},
teardown: function(namespaces) {
$.event.special.changeElement.mutationObserver.disconnect();
},
handler: function(event) {
event.type = $.event.special.changeElement.eventType;
return $.event.dispatch.apply(this, arguments);
},
mutationsLists : function(mutationsList) {
for(var mutation of mutationsList) {
if (mutation.type == 'childList') {
console.log('A child node has been added or removed.');
}
else if (mutation.type == 'attributes') {
console.log('The ' + mutation.attributeName + ' attribute was modified.');
}
}
}
}
})(jQuery);
I checked and it looks that $.event.special.changeElement is defined, but looks undefined when a call its members...