angularjs-file-upload-rails 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eebaf468ac5a74e0da00f5db6a8d40267a39b712
4
- data.tar.gz: a700b2c4e863e97ef119d064cba43fc64933b68f
3
+ metadata.gz: 4d75e239c01c206babcb6a20daadd072f18d7aeb
4
+ data.tar.gz: 73eda9a4f0029589e4f24b401bafcecf818502ed
5
5
  SHA512:
6
- metadata.gz: aaa843b398eae0f2d35372b1c8a8a15ce5b2f9939a05e61d11ff85bb505f47a820a7c57b695f46ab5fe4bde28183e581d3e2689410d81aab39dd73725b606a41
7
- data.tar.gz: 4ff131e06d45a8d509442e3a39ab03dd74048d02560bab2aea4d6763b06be9d331bf5458ab521741a548d169229cd9a2f4e0d12dd88a28557b516ef5f34b1847
6
+ metadata.gz: ba697fcd751277949893077876d04e50997ddcf64b1f10c9ef71cd3a71f671aa3a1b5c843f2077bc4f8e2781568b0fcf9fef24847f43f02ea76c20cbb39fb89b
7
+ data.tar.gz: 6832503e9ae59085135d6bd39dcb29fe054491fe43aab950c4b9e8f275690e580f4583c5738b5c60e07811a504ddd273c1c1c29333ca982f63948150d54c4e35
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Angularjs::File::Upload
1
+ [![Gem Version](https://badge.fury.io/rb/angularjs-file-upload-rails.svg)](http://badge.fury.io/rb/angularjs-file-upload-rails)
2
+
3
+ # AngularJS File Upload
2
4
 
3
5
  A gem that uses [angular-file-upload](https://github.com/nervgh/angular-file-upload) as an asset in the Rails Asset Pipeline.
4
6
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- angular-file-upload v1.0.1
2
+ angular-file-upload v1.1.0
3
3
  https://github.com/nervgh/angular-file-upload
4
4
  */
5
5
  (function(angular, factory) {
@@ -10,9 +10,10 @@
10
10
  } else {
11
11
  return factory(angular);
12
12
  }
13
- }(typeof angular === 'undefined' ? null : angular || null, function(angular) {
13
+ }(typeof angular === 'undefined' ? null : angular, function(angular) {
14
14
 
15
15
  var module = angular.module('angularFileUpload', []);
16
+
16
17
  'use strict';
17
18
 
18
19
  /**
@@ -77,28 +78,27 @@ module
77
78
  FileUploader.prototype.isHTML5 = !!($window.File && $window.FormData);
78
79
  /**
79
80
  * Adds items to the queue
80
- * @param {FileList|File|HTMLInputElement} files
81
+ * @param {File|HTMLInputElement|Object|FileList|Array<Object>} files
81
82
  * @param {Object} [options]
82
83
  * @param {Array<Function>|String} filters
83
84
  */
84
85
  FileUploader.prototype.addToQueue = function(files, options, filters) {
85
- var list = angular.isElement(files) ? [files]: files;
86
+ var list = this.isArrayLikeObject(files) ? files: [files];
86
87
  var arrayOfFilters = this._getFilters(filters);
87
88
  var count = this.queue.length;
88
89
  var addedFileItems = [];
89
90
 
90
- angular.forEach(list, function(file) {
91
- var item = this._getFileOrFileLikeObject(file);
91
+ angular.forEach(list, function(some /*{File|HTMLInputElement|Object}*/) {
92
+ var temp = new FileUploader.FileLikeObject(some);
92
93
 
93
- if (this._isValidFile(item, arrayOfFilters, options)) {
94
- var input = this.isFile(item) ? null : file;
95
- var fileItem = new FileUploader.FileItem(this, item, options, input);
94
+ if (this._isValidFile(temp, arrayOfFilters, options)) {
95
+ var fileItem = new FileUploader.FileItem(this, some, options);
96
96
  addedFileItems.push(fileItem);
97
97
  this.queue.push(fileItem);
98
98
  this._onAfterAddingFile(fileItem);
99
99
  } else {
100
100
  var filter = this.filters[this._failFilterIndex];
101
- this._onWhenAddingFileFailed(item, filter, options);
101
+ this._onWhenAddingFileFailed(temp, filter, options);
102
102
  }
103
103
  }, this);
104
104
 
@@ -198,6 +198,14 @@ module
198
198
  FileUploader.prototype.isFileLikeObject = function(value) {
199
199
  return value instanceof FileUploader.FileLikeObject;
200
200
  };
201
+ /**
202
+ * Returns "true" if value is array like object
203
+ * @param {*} value
204
+ * @returns {Boolean}
205
+ */
206
+ FileUploader.prototype.isArrayLikeObject = function(value) {
207
+ return (angular.isObject(value) && 'length' in value);
208
+ };
201
209
  /**
202
210
  * Returns a index of item from the queue
203
211
  * @param {Item|Number} value
@@ -380,16 +388,6 @@ module
380
388
  return filter.fn.call(this, file, options);
381
389
  }, this);
382
390
  };
383
- /**
384
- * Returns a file or a file-like object
385
- * @param {File|HTMLInputElement} some
386
- * @returns {File|Object}
387
- * @private
388
- */
389
- FileUploader.prototype._getFileOrFileLikeObject = function(some) {
390
- if (this.isFile(some) || this.isFileLikeObject(some)) return some;
391
- return new FileUploader.FileLikeObject(some.value);
392
- };
393
391
  /**
394
392
  * Checks whether upload successful
395
393
  * @param {Number} status
@@ -694,6 +692,10 @@ module
694
692
  * @borrows FileUploader.prototype.isFileLikeObject
695
693
  */
696
694
  FileUploader.isFileLikeObject = FileUploader.prototype.isFileLikeObject;
695
+ /**
696
+ * @borrows FileUploader.prototype.isArrayLikeObject
697
+ */
698
+ FileUploader.isArrayLikeObject = FileUploader.prototype.isArrayLikeObject;
697
699
  /**
698
700
  * @borrows FileUploader.prototype.isHTML5
699
701
  */
@@ -719,29 +721,53 @@ module
719
721
 
720
722
  /**
721
723
  * Creates an instance of FileLikeObject
722
- * @param {String} fakePath
724
+ * @param {File|HTMLInputElement|Object} fileOrInput
723
725
  * @constructor
724
726
  */
725
- function FileLikeObject(fakePath) {
726
- var path = fakePath;
727
+ function FileLikeObject(fileOrInput) {
728
+ var isInput = angular.isElement(fileOrInput);
729
+ var fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
730
+ var postfix = angular.isString(fakePathOrObject) ? 'FakePath' : 'Object';
731
+ var method = '_createFrom' + postfix;
732
+ this[method](fakePathOrObject);
733
+ }
734
+
735
+ /**
736
+ * Creates file like object from fake path string
737
+ * @param {String} path
738
+ * @private
739
+ */
740
+ FileLikeObject.prototype._createFromFakePath = function(path) {
727
741
  this.lastModifiedDate = null;
728
742
  this.size = null;
729
743
  this.type = 'like/' + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
730
744
  this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
731
- }
745
+ };
746
+ /**
747
+ * Creates file like object from object
748
+ * @param {File|FileLikeObject} object
749
+ * @private
750
+ */
751
+ FileLikeObject.prototype._createFromObject = function(object) {
752
+ this.lastModifiedDate = angular.copy(object.lastModifiedDate);
753
+ this.size = object.size;
754
+ this.type = object.type;
755
+ this.name = object.name;
756
+ };
732
757
 
733
758
  // ---------------------------
734
759
 
735
760
  /**
736
761
  * Creates an instance of FileItem
737
762
  * @param {FileUploader} uploader
738
- * @param {File|FileLikeObject|HTMLInputElement} file
739
- * @param {File|Object} options
740
- * @param {HTMLInputElement} [input]
763
+ * @param {File|HTMLInputElement|Object} some
764
+ * @param {Object} options
741
765
  * @constructor
742
766
  */
743
- function FileItem(uploader, file, options, input) {
744
- file = uploader._getFileOrFileLikeObject(file);
767
+ function FileItem(uploader, some, options) {
768
+ var isInput = angular.isElement(some);
769
+ var input = isInput ? angular.element(some) : null;
770
+ var file = !isInput ? some : null;
745
771
 
746
772
  angular.extend(this, {
747
773
  url: uploader.url,
@@ -753,7 +779,7 @@ module
753
779
  method: uploader.method
754
780
  }, options, {
755
781
  uploader: uploader,
756
- file: angular.copy(file),
782
+ file: new FileUploader.FileLikeObject(some),
757
783
  isReady: false,
758
784
  isUploading: false,
759
785
  isUploaded: false,
@@ -762,13 +788,11 @@ module
762
788
  isError: false,
763
789
  progress: 0,
764
790
  index: null,
765
- _file: file
791
+ _file: file,
792
+ _input: input
766
793
  });
767
794
 
768
- if (input) {
769
- this._input = angular.element(input);
770
- this._replaceNode(this._input);
771
- }
795
+ if (input) this._replaceNode(input);
772
796
  }
773
797
  /**********************
774
798
  * PUBLIC
@@ -1048,6 +1072,13 @@ module
1048
1072
  * @return {Array<Function>|String|undefined}
1049
1073
  */
1050
1074
  FileSelect.prototype.getFilters = function() {};
1075
+ /**
1076
+ * If returns "true" then HTMLInputElement will be cleared
1077
+ * @returns {Boolean}
1078
+ */
1079
+ FileSelect.prototype.isEmptyAfterSelection = function() {
1080
+ return !!this.element.attr('multiple');
1081
+ };
1051
1082
  /**
1052
1083
  * Event handler
1053
1084
  */
@@ -1058,7 +1089,7 @@ module
1058
1089
 
1059
1090
  if (!this.uploader.isHTML5) this.destroy();
1060
1091
  this.uploader.addToQueue(files, options, filters);
1061
- if (this.uploader.isHTML5) this.element.prop('value', null);
1092
+ if (this.isEmptyAfterSelection()) this.element.prop('value', null);
1062
1093
  };
1063
1094
 
1064
1095
  // ---------------------------
@@ -1,3 +1,3 @@
1
1
  module AngularjsFileUpload
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angularjs-file-upload-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marthyn Olthof
@@ -97,3 +97,4 @@ summary: It supports drag-n-drop upload, upload progress, validation filters and
97
97
  upload method for older browsers. Works with any server side platform which supports
98
98
  standard HTML form uploads.
99
99
  test_files: []
100
+ has_rdoc: