Every now and then whenever i see any code for plugin, i could not understand the 80% of code.
I know some jquery as well and have been successful with it but i could not find those ways of doing things which they have done in plugins.
usually the code which i do in 10 lines , they do some shortcuts and finish in 1 one with advanced methods.
eg this is the code from jquery fileupload plugin
// Callback for uploads start, equivalent to the global ajaxStart event:
start: function (e) {
var that = $(this).data('fileupload');
that._transition($(this).find('.fileupload-progress')).done(
function () {
that._trigger('started', e);
}
);
},
I have no idea what the heck is going on , why the function name starts with underscore. what done is doing and all that.
Where i can find that sort of stuff fully explained with examples so that i can also reduce my code
This is how I understand it:
startis callback function, as comment saysCallback for uploads start, equivalent to the global ajaxStart eventvar thatis eq. to:Returns value at named data store for the element, as set by jQuery.data(element, name, value), or the full data store for the element.
When variable
thatis set, there is a call for function named_transitionwhich I guess is some extension of Ajax call as we later on calldonefunction. Probably author owns work, so you’ll need to search through code.This function gets as a parameter object list returned by
$(this).find('.fileupload-progress')selector.At last, we call
donefunction which I guess is eq. to jQuery.ajax().done(), called after sucessfull Ajax request. Inside done there is another callback for annonymous functionWhere there’s fired another function called
_triggerwith stringstartedand callback event of main function starte.And answer for your last question:
Where i can find that sort of stuff fully explained with examples so that i can also reduce my code?The truth is that without writting own stuff, you’ll probably never learn that. Experience and coding is the key here. By searching for certain solutions, you’ll find out new stuff like this one for example. So keep coding mate!