From 2dda60707c6ffd947e7e63ada65c7f10bd16f87b Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Tue, 5 Jul 2016 01:12:31 +0530 Subject: [PATCH] add event listener for checkbox alongwith file table row --- upload.js | 13 ++++++++++++- upload.min.js | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/upload.js b/upload.js index 386fe34..df3046d 100644 --- a/upload.js +++ b/upload.js @@ -390,8 +390,8 @@ Uploader.prototype = { var selectedRowColor = this.selectedRowColor; row.insertCell().innerHTML = ""; row.style.cursor = "pointer"; + var checkBox = row.getElementsByClassName('fileRowCheckBox')[0]; row.addEventListener('click', function () { - var checkBox = row.getElementsByClassName('fileRowCheckBox')[0]; if (checkBox.checked) { checkBox.checked = false; row.style.backgroundColor = "#ffffff"; @@ -400,6 +400,17 @@ Uploader.prototype = { row.style.backgroundColor = selectedRowColor; } }); + + checkBox.addEventListener('click', function () { + if (checkBox.checked) { + checkBox.checked = false; + row.style.backgroundColor = "#ffffff"; + } else { + checkBox.checked = true; + row.style.backgroundColor = selectedRowColor; + } + }); + var i; for (i in fileDtls) { if (fileDtls.hasOwnProperty(i)) { diff --git a/upload.min.js b/upload.min.js index dd04644..aefdb45 100644 --- a/upload.min.js +++ b/upload.min.js @@ -1,2 +1,2 @@ /*The MIT License (MIT) Copyright (c) 2016 Vivek Kumar /~https://github.com/vivekkr12/uploadjs/blob/master/LICENSE.md */ -"use strict";function Uploader(e){if(this.filesToBeUploaded=[],this.fileTable=document.getElementById(e.fileTableId),this.dropZone=document.getElementById(e.dropZoneId),this.addBtn=document.getElementById(e.addBtnId),this.removeBtn=document.getElementById(e.removeBtnId),this.uploadBtn=document.getElementById(e.uploadBtnId),this.removeAllBtn=document.getElementById(e.removeAllBtnId),this.serverUrl=e.serverUrl,this.wrapperForm=document.getElementById(e.wrapperFormId),this.setProgress=e.setProgress,this.getProgress=e.getProgress,this.getFileDetails=e.getFileDetails,this.selectedRowColor="undefined"==typeof e.selectedRowColor?"#dffff1":e.selectedRowColor,this.customDisplay="undefined"==typeof e.customDisplay?!1:e.customDisplay,this.customDisplay){if("undefined"==typeof e.displayAddedFile||"undefined"==typeof e.removeFileFromDisplay)throw"For custom display, two methods displayAddedFile and removeFileFromDisplay must be implemented";this.displayAddedFile=e.displayAddedFile,this.getSelectedFile=e.getSelectedFile,this.removeFileFromDisplay=e.removeFileFromDisplay}var t=this,i=e.preAdd,o=e.postAdd,s=e.onDuplicateAdd,r=e.validateFile,a=e.onCheckFail,l=e.preRemove,n=e.postRemove,d=e.preUpload,f=e.addPayload,p=e.postUpload,c=e.onSuccess,u=e.onError,v=e.preAddBtnAction,h=e.postAddBtnAction,m=e.preRemoveBtnAction,y=e.postRemoveBtnAction,B=e.preRemoveAllBtnAction,g=e.postRemoveAllBtnAction,F=e.preUploadBtnAction,E=e.postUploadBtnAction;this.chunkSize="undefined"!=typeof e.chunkSize?e.chunkSize:this.DEFAULT_CHUNK_SIZE;var T=function(e){v&&v();var n,d,l=function(e){i&&i(e),t.addFile(e),o&&o(e)};for(d=0;d=0;o-=1)if(s=i[o],s.checked===!0){var r=s.parentElement.parentElement,a=r.rowIndex;e=t.filesToBeUploaded[a-1],l&&l(e),t.remove(e),n&&n(e)}}y&&y()}),this.removeAllBtn.addEventListener("click",function(){B&&B();var e,i;for(i=t.filesToBeUploaded.length;i>0;i-=1)e=t.filesToBeUploaded[i-1],t.remove(e);g&&g()}),this.uploadBtn.addEventListener("click",function(){F&&F();var e;if(t.customDisplay)e=t.getSelectedFile();else{var i=document.getElementsByClassName("fileRowCheckBox");if(1===i.length)e=t.filesToBeUploaded[0];else{var o,s;for(o=i.length-1;o>=0;o-=1)if(s=i[o],s.checked===!0){e=t.filesToBeUploaded[o];break}}}if(e){d&&d(e);var r;f&&(r=f(e)),t.uploadFile(e,c,u,r),p&&p(e)}E&&E()})}File&&(File.prototype.equals=function(e){return this.name===e.name&&this.size===e.size&&this.type===e.type&&this.lastModified===e.lastModified}),Array.prototype.contains=function(e){if(this.indexOf(e)>-1)return!0;var t,i;for(i=0;i-1&&this.splice(t,1)},Array.prototype.removeByIndex=function(e){this.splice(e,1)},Uploader.isSupported=function(){return File&&FileList&&FileReader&&Blob&&XMLHttpRequest},Uploader.prototype={constructor:Uploader,DEFAULT_CHUNK_SIZE:1048576,resetAddBtn:function(){this.wrapperForm.reset()},addFile:function(e){if(this.customDisplay)this.displayAddedFile(e);else{var t;this.getFileDetails?t=this.getFileDetails(e):(t.fileName=e.name,t.fileType=e.type,t.fileSize=e.size,t.fileLastModified=e.lastModified);var i=this.fileTable.insertRow(),o=this.selectedRowColor;i.insertCell().innerHTML="",i.style.cursor="pointer",i.addEventListener("click",function(){var e=i.getElementsByClassName("fileRowCheckBox")[0];e.checked?(e.checked=!1,i.style.backgroundColor="#ffffff"):(e.checked=!0,i.style.backgroundColor=o)});var s;for(s in t)t.hasOwnProperty(s)&&(i.insertCell().innerHTML=t[s])}this.filesToBeUploaded.push(e)},remove:function(e){if(this.customDisplay)this.removeFileFromDisplay(e),this.filesToBeUploaded.removeByElement(e);else{var t=this.filesToBeUploaded.indexOf(e)+1;this.fileTable.deleteRow(t),this.filesToBeUploaded.removeByIndex(t-1)}},uploadFile:function(e,t,i,o){var c,s=this,r=new XMLHttpRequest,a=0,l=this.chunkSize,n=a+l,d=e.size,f=e.size%l===0?parseInt(e.size/l,10):parseInt(e.size/l,10)+1,p=function(){r.open("POST",s.serverUrl,!0);var t=new FormData;if(t.append("name",e.name),t.append("blob",e.slice(a,n)),t.append("totalChunks",f),a=n,n=a+l,d-=l,0>=d){t.append("eof",!0);var i;for(i in o)o.hasOwnProperty(i)&&t.append(i,o[i])}else t.append("eof",!1);r.send(t)},u=100/f,v=0;r.upload.onprogress=function(e){s.setProgress&&e.lengthComputable&&(c=v+e.loaded/e.total*u,s.setProgress(c))},r.upload.onloadend=function(e){v=s.getProgress()},r.onreadystatechange=function(o){var r=o.target;r.readyState===XMLHttpRequest.DONE&&200===r.status?d>0?p(r):(s.setProgress&&s.setProgress(100),t(e,r.response)):r.readyState===XMLHttpRequest.DONE&&200!==r.status&&i(e,r.response,r.statusText)},p(r)}}; \ No newline at end of file +"use strict";function Uploader(e){if(this.filesToBeUploaded=[],this.fileTable=document.getElementById(e.fileTableId),this.dropZone=document.getElementById(e.dropZoneId),this.addBtn=document.getElementById(e.addBtnId),this.removeBtn=document.getElementById(e.removeBtnId),this.uploadBtn=document.getElementById(e.uploadBtnId),this.removeAllBtn=document.getElementById(e.removeAllBtnId),this.serverUrl=e.serverUrl,this.wrapperForm=document.getElementById(e.wrapperFormId),this.setProgress=e.setProgress,this.getProgress=e.getProgress,this.getFileDetails=e.getFileDetails,this.selectedRowColor="undefined"==typeof e.selectedRowColor?"#dffff1":e.selectedRowColor,this.customDisplay="undefined"==typeof e.customDisplay?!1:e.customDisplay,this.customDisplay){if("undefined"==typeof e.displayAddedFile||"undefined"==typeof e.removeFileFromDisplay)throw"For custom display, two methods displayAddedFile and removeFileFromDisplay must be implemented";this.displayAddedFile=e.displayAddedFile,this.getSelectedFile=e.getSelectedFile,this.removeFileFromDisplay=e.removeFileFromDisplay}var t=this,i=e.preAdd,o=e.postAdd,s=e.onDuplicateAdd,r=e.validateFile,a=e.onCheckFail,l=e.preRemove,n=e.postRemove,d=e.preUpload,f=e.addPayload,p=e.postUpload,c=e.onSuccess,u=e.onError,v=e.preAddBtnAction,h=e.postAddBtnAction,m=e.preRemoveBtnAction,y=e.postRemoveBtnAction,B=e.preRemoveAllBtnAction,g=e.postRemoveAllBtnAction,F=e.preUploadBtnAction,E=e.postUploadBtnAction;this.chunkSize="undefined"!=typeof e.chunkSize?e.chunkSize:this.DEFAULT_CHUNK_SIZE;var T=function(e){v&&v();var n,d,l=function(e){i&&i(e),t.addFile(e),o&&o(e)};for(d=0;d=0;o-=1)if(s=i[o],s.checked===!0){var r=s.parentElement.parentElement,a=r.rowIndex;e=t.filesToBeUploaded[a-1],l&&l(e),t.remove(e),n&&n(e)}}y&&y()}),this.removeAllBtn.addEventListener("click",function(){B&&B();var e,i;for(i=t.filesToBeUploaded.length;i>0;i-=1)e=t.filesToBeUploaded[i-1],t.remove(e);g&&g()}),this.uploadBtn.addEventListener("click",function(){F&&F();var e;if(t.customDisplay)e=t.getSelectedFile();else{var i=document.getElementsByClassName("fileRowCheckBox");if(1===i.length)e=t.filesToBeUploaded[0];else{var o,s;for(o=i.length-1;o>=0;o-=1)if(s=i[o],s.checked===!0){e=t.filesToBeUploaded[o];break}}}if(e){d&&d(e);var r;f&&(r=f(e)),t.uploadFile(e,c,u,r),p&&p(e)}E&&E()})}File&&(File.prototype.equals=function(e){return this.name===e.name&&this.size===e.size&&this.type===e.type&&this.lastModified===e.lastModified}),Array.prototype.contains=function(e){if(this.indexOf(e)>-1)return!0;var t,i;for(i=0;i-1&&this.splice(t,1)},Array.prototype.removeByIndex=function(e){this.splice(e,1)},Uploader.isSupported=function(){return File&&FileList&&FileReader&&Blob&&XMLHttpRequest},Uploader.prototype={constructor:Uploader,DEFAULT_CHUNK_SIZE:1048576,resetAddBtn:function(){this.wrapperForm.reset()},addFile:function(e){if(this.customDisplay)this.displayAddedFile(e);else{var t;this.getFileDetails?t=this.getFileDetails(e):(t.fileName=e.name,t.fileType=e.type,t.fileSize=e.size,t.fileLastModified=e.lastModified);var i=this.fileTable.insertRow(),o=this.selectedRowColor;i.insertCell().innerHTML="",i.style.cursor="pointer";var s=i.getElementsByClassName("fileRowCheckBox")[0];i.addEventListener("click",function(){s.checked?(s.checked=!1,i.style.backgroundColor="#ffffff"):(s.checked=!0,i.style.backgroundColor=o)}),s.addEventListener("click",function(){s.checked?(s.checked=!1,i.style.backgroundColor="#ffffff"):(s.checked=!0,i.style.backgroundColor=o)});var r;for(r in t)t.hasOwnProperty(r)&&(i.insertCell().innerHTML=t[r])}this.filesToBeUploaded.push(e)},remove:function(e){if(this.customDisplay)this.removeFileFromDisplay(e),this.filesToBeUploaded.removeByElement(e);else{var t=this.filesToBeUploaded.indexOf(e)+1;this.fileTable.deleteRow(t),this.filesToBeUploaded.removeByIndex(t-1)}},uploadFile:function(e,t,i,o){var c,s=this,r=new XMLHttpRequest,a=0,l=this.chunkSize,n=a+l,d=e.size,f=e.size%l===0?parseInt(e.size/l,10):parseInt(e.size/l,10)+1,p=function(){r.open("POST",s.serverUrl,!0);var t=new FormData;if(t.append("name",e.name),t.append("blob",e.slice(a,n)),t.append("totalChunks",f),a=n,n=a+l,d-=l,0>=d){t.append("eof",!0);var i;for(i in o)o.hasOwnProperty(i)&&t.append(i,o[i])}else t.append("eof",!1);r.send(t)},u=100/f,v=0;r.upload.onprogress=function(e){s.setProgress&&e.lengthComputable&&(c=v+e.loaded/e.total*u,s.setProgress(c))},r.upload.onloadend=function(e){v=s.getProgress()},r.onreadystatechange=function(o){var r=o.target;r.readyState===XMLHttpRequest.DONE&&200===r.status?d>0?p(r):(s.setProgress&&s.setProgress(100),t(e,r.response)):r.readyState===XMLHttpRequest.DONE&&200!==r.status&&i(e,r.response,r.statusText)},p(r)}};