diff --git a/src/scripts/controllers/new.js b/src/scripts/controllers/new.js index 694913e..066c788 100644 --- a/src/scripts/controllers/new.js +++ b/src/scripts/controllers/new.js @@ -120,7 +120,7 @@ $scope.changeTab('options'); }, function (error) { ariaNgCommonService.showError(error); - }); + }, angular.element('#file-holder')); }; $scope.openMetalink = function () { @@ -130,7 +130,7 @@ $scope.changeTab('options'); }, function (error) { ariaNgCommonService.showError(error); - }); + }, angular.element('#file-holder')); }; $scope.startDownload = function (pauseOnAdded) { diff --git a/src/scripts/services/ariaNgFileService.js b/src/scripts/services/ariaNgFileService.js index 37b9848..2aa33f0 100644 --- a/src/scripts/services/ariaNgFileService.js +++ b/src/scripts/services/ariaNgFileService.js @@ -46,7 +46,7 @@ }; return { - openFileContent: function (fileFilter, successCallback, errorCallback) { + openFileContent: function (fileFilter, successCallback, errorCallback, element) { if (!isSupportFileReader) { if (errorCallback) { errorCallback('Your browser does not support loading file!'); @@ -57,43 +57,51 @@ var allowedExtensions = getAllowedExtensions(fileFilter); - angular.element('').change(function () { - if (!this.files || this.files.length < 1) { - return; - } + if (!element || !element.change) { + element = angular.element(''); + } - var file = this.files[0]; - var fileName = file.name; - - if (!checkFileExtension(fileName, allowedExtensions)) { - if (errorCallback) { - errorCallback('The selected file type is invalid!'); + if (element.attr('data-ariang-file-initialized') !== 'true') { + element.change(function () { + if (!this.files || this.files.length < 1) { + return; } - return; - } + var file = this.files[0]; + var fileName = file.name; - var reader = new FileReader(); + if (!checkFileExtension(fileName, allowedExtensions)) { + if (errorCallback) { + errorCallback('The selected file type is invalid!'); + } - reader.onload = function () { - var result = { - fileName: fileName, - base64Content: this.result.replace(/.*?base64,/, '') + return; + } + + var reader = new FileReader(); + + reader.onload = function () { + var result = { + fileName: fileName, + base64Content: this.result.replace(/.*?base64,/, '') + }; + + if (successCallback) { + successCallback(result); + } }; - if (successCallback) { - successCallback(result); - } - }; + reader.onerror = function () { + if (errorCallback) { + errorCallback('Failed to load file!'); + } + }; - reader.onerror = function () { - if (errorCallback) { - errorCallback('Failed to load file!'); - } - }; + reader.readAsDataURL(file); + }).attr('data-ariang-file-initialized', 'true'); + } - reader.readAsDataURL(file); - }).trigger('click'); + element.trigger('click'); } }; }]); diff --git a/src/views/new.html b/src/views/new.html index ebeef18..4125fbf 100644 --- a/src/views/new.html +++ b/src/views/new.html @@ -61,6 +61,7 @@ +