Here he created a kind of class, actually an object with functions. So he can centralize what projeto
can do and use anywhere else.
var projeto = {
methods: {
funcao1: function() {
},
funcao2: function() {
},
init: function() {
this.funcao1(), this.funcao2()
},
init_ajax: function() {}
},
ajax: function() {
return this.methods.init_ajax()
},
mounted: function() {
return this.methods.init()
}
};
This $(document)
takes the document itself, which is read by the browser. What it does with .ready()
and ajaxStop()
is to get events triggered by the document at times when the document is read and some ajax call is terminated, respectively.
With this, he defined methods that should be executed in those moments.
When the document is read (page loaded) execute projeto.mounted()
$(document).ready(function() {
projeto.mounted()
})
When the ajax load stops, run projeto.ajax()
$(document).ajaxStop(function() {
projeto.ajax()
});
Notice that projeto
is the variable that has methods ajax
and mounted
.
You probably already have used something like element.on('click')
or element.click()
to capture button clicks or something, the process here is the same, however, instead of capturing the click, you are capturando
other things. It could be a hover, a keyup, etc.
I will list some links here that will help in general understanding, your doubt and good and will help a lot of people.
Working with JavaScript events
Organizing your JavaScript code
About document.ready