Skip to content

Commit

Permalink
netteForms: removed Nette.addEvent()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 11, 2019
1 parent b6b27a3 commit 82e9980
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,18 @@


/**
* Attaches a handler to an event for the element.
* Function to execute when the DOM is fully loaded.
* @private
*/
Nette.addEvent = function(element, on, callback) {
if (on === 'DOMContentLoaded' && element.readyState !== 'loading') {
Nette.onDocumentReady = function(callback) {
if (document.readyState !== 'loading') {
callback.call(this);
} else if (element.addEventListener) {
element.addEventListener(on, callback);
} else if (on === 'DOMContentLoaded') {
element.attachEvent('onreadystatechange', function() {
if (element.readyState === 'complete') {
callback.call(this);
}
});
} else {
element.attachEvent('on' + on, getHandler(callback));
document.addEventListener('DOMContentLoaded', callback);
}
};


function getHandler(callback) {
return function(e) {
return callback.call(this, e);
};
}


/**
* Returns the value of form element.
*/
Expand Down Expand Up @@ -634,7 +620,7 @@

for (var i = 0; i < els.length; i++) {
if (els[i].name === name && handled.indexOf(els[i]) < 0) {
Nette.addEvent(els[i], 'change', handler);
els[i].addEventListener('change', handler);
handled.push(els[i]);
}
}
Expand Down Expand Up @@ -676,7 +662,7 @@

form.noValidate = true;

Nette.addEvent(form, 'submit', function(e) {
form.addEventListener('submit', function(e) {
if (!Nette.validateForm(form)) {
e.stopPropagation();
e.preventDefault();
Expand All @@ -689,7 +675,7 @@
* @private
*/
Nette.initOnLoad = function() {
Nette.addEvent(document, 'DOMContentLoaded', function() {
Nette.onDocumentReady(function() {
for (var i = 0; i < document.forms.length; i++) {
var form = document.forms[i];
for (var j = 0; j < form.elements.length; j++) {
Expand All @@ -700,7 +686,7 @@
}
}

Nette.addEvent(document.body, 'click', function(e) {
document.body.addEventListener('click', function(e) {
var target = e.target;
while (target) {
if (target.form && target.type in {submit: 1, image: 1}) {
Expand Down

0 comments on commit 82e9980

Please sign in to comment.