Here is a section of relevant code:
!function($){
const figure = name => f => $(`<figure data-name="${name}"><img src="${URL.createObjectURL(f)}"><figcaption><input type=checkbox checked><br>${f.name}</figcaption></figure>`).data("f",f);
$(document).on("change", "[data-preview-to]", function() {
$($(this).data("preview-to")).append($.map(this.files, figure(this.name)));
$(this).replaceWith(this.outerHTML);
***OTHER CODE FOR SUBMIT****
}(jQuery);
HTML
<input type="file" data-preview-to="#preview" multiple="" name="fileToUpload[]">
First question, the "!function($)", to me this says, I am not a function, since "!" is NOT, but that cannot be it since why would you declare a function, that is not a function, then I thought well, it could be saying "do this, even if the document is not ready" since (I think) function($), is the document ready shorthand.
However, the function ending, has a (jquery), which is needed, if I remove that, the code fails, so this must be doing something, that is not fully JQuery.
Second Question, is the variable "figure", the way I read it, and make no sense is "declare figure as a constant, take the value of name, push it into f then push all of it into the HTML code. However, I do not see how "f", gets assigned. I know it is coming from the "$.map(this.files, figure(this.name))", but it looks like the only thing that is getting sent to figure is the name (fileToUpload[]) of the HTML input tag.
What is this code saying and doing?
Thanks,
Dave