Re-use Fine Uploader Code For Multi Instance
I am have multiple instances of fine uploader in a page. I do not want to repeat/duplicate fine uploader script and template for every uploader instance as it is lot of code in my
Solution 1:
Here is a function that you can call to create a set of Fine Uploader S3 instances attached to unique elements w/ varying endpoints and templates:
functioncreateUploader(uploaderInfo) {
returnnew qq.s3.FineUploader({
element: document.querySelector(uploaderInfo.elementSelector),
template: document.querySelector(uploaderInfo.templateSelector),
request: {
endpoint: uploaderInfo.endpoint
}
})
}
...and you can call this function like this:
[
{
elementSelector: '#element1',
templateSelector: '#template1',
endpoint: 'endpoint/1'
},
{
elementSelector: '#element2',
templateSelector: '#template2',
endpoint: 'endpoint/2'
}
...
].forEach(function(uploaderInfo) {
createUploader(uploaderInfo)
})
That's the general idea. You may, of course, modify the code to more closely suit your needs. If you need to track uploader instances, you can do that inside of the forEach
loop too.
Post a Comment for "Re-use Fine Uploader Code For Multi Instance"