ng-angularjs-rails 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/ng/angularjs/rails/version.rb +1 -1
- data/vendor/assets/javascripts/ng-upload.js +107 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 082198f6faef57934c397530786e490cc94882a0
|
4
|
+
data.tar.gz: 5bfa809948e727b4ad9ee276430306f295092745
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c73f153d1d2108f5cfaeb220d1608644b0deaf96700fe61301492f6a785f0612a0bda78081b965b2bd80c4535437c855e414629d482a883738849f90c6dec7c
|
7
|
+
data.tar.gz: c45678879ffe22579fb65bd482fd4242c5c1f19665d88643f4ab2f378f0defbb8bbbce1bf8c8f728661014b6ebac95d6740b0ea847f1d49ab26a874cdaa12930
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Ng::Angularjs::Rails
|
2
2
|
|
3
|
+
## TODO
|
4
|
+
added ng-upload.js
|
3
5
|
|
4
6
|
## Installation
|
5
7
|
|
@@ -22,4 +24,7 @@ If you desire to require (optional) Angular files, you may include them as well
|
|
22
24
|
//= require angular-bootstrap
|
23
25
|
//= require angular-resource
|
24
26
|
//= require i18n/angular-locale_zh-cn
|
27
|
+
|
28
|
+
// if you hava ng-upload.js
|
29
|
+
//= require ng-upload
|
25
30
|
```
|
@@ -0,0 +1,107 @@
|
|
1
|
+
// Version 0.3.2
|
2
|
+
// AngularJS simple file upload directive
|
3
|
+
// this directive uses an iframe as a target
|
4
|
+
// to enable the uploading of files without
|
5
|
+
// losing focus in the ng-app.
|
6
|
+
//
|
7
|
+
// <div ng-app="app">
|
8
|
+
// <div ng-controller="mainCtrl">
|
9
|
+
// <form action="/uploads" ng-upload>
|
10
|
+
// <input type="file" name="avatar"></input>
|
11
|
+
// <input type="submit" value="Upload"
|
12
|
+
// upload-submit="submited(content, completed)"></input>
|
13
|
+
// </form>
|
14
|
+
// </div>
|
15
|
+
// </div>
|
16
|
+
//
|
17
|
+
// angular.module('app', ['ngUpload'])
|
18
|
+
// .controller('mainCtrl', function($scope) {
|
19
|
+
// $scope.submited = function(content, completed) {
|
20
|
+
// if (completed) {
|
21
|
+
// console.log(content);
|
22
|
+
// }
|
23
|
+
// }
|
24
|
+
// });
|
25
|
+
//
|
26
|
+
angular.module('ngUpload', [])
|
27
|
+
.directive('uploadSubmit', ['$parse', function($parse) {
|
28
|
+
return {
|
29
|
+
restrict: 'AC',
|
30
|
+
link: function(scope, element, attrs) {
|
31
|
+
// Options (just 1 for now)
|
32
|
+
// Each option should be prefixed with 'upload-options-' or 'uploadOptions'
|
33
|
+
// {
|
34
|
+
// // specify whether to enable the submit button when uploading forms
|
35
|
+
// enableControls: bool
|
36
|
+
// }
|
37
|
+
var options = {};
|
38
|
+
options.enableControls = attrs.uploadOptionsEnableControls;
|
39
|
+
|
40
|
+
// submit the form - requires jQuery
|
41
|
+
var form = element.parents('form[ng-upload]') || element.parents('form.ng-upload');
|
42
|
+
|
43
|
+
// Retrieve the callback function
|
44
|
+
var fn = $parse(attrs.uploadSubmit);
|
45
|
+
|
46
|
+
if (!angular.isFunction(fn)) {
|
47
|
+
var message = "The expression on the ngUpload directive does not point to a valid function.";
|
48
|
+
throw message + "\n";
|
49
|
+
}
|
50
|
+
|
51
|
+
element.bind('click', function($event) {
|
52
|
+
// prevent default behavior of click
|
53
|
+
$event.preventDefault = true;
|
54
|
+
// create a new iframe
|
55
|
+
var iframe = angular.element("<iframe id='upload_iframe' name='upload_iframe' border='0' width='0' height='0' style='width: 0px; height: 0px; border: none; display: none' />");
|
56
|
+
|
57
|
+
// attach function to load event of the iframe
|
58
|
+
iframe.bind('load', function () {
|
59
|
+
// get content - requires jQuery
|
60
|
+
var content = iframe.contents().find('body').text();
|
61
|
+
// execute the upload response function in the active scope
|
62
|
+
scope.$apply(function () {
|
63
|
+
fn(scope, { content: content, completed: true});
|
64
|
+
});
|
65
|
+
// remove iframe
|
66
|
+
if (content !== "") { // Fixes a bug in Google Chrome that dispose the iframe before content is ready.
|
67
|
+
setTimeout(function () { iframe.remove(); }, 250);
|
68
|
+
}
|
69
|
+
element.attr('disabled', null);
|
70
|
+
element.attr('title', 'Click to start upload.');
|
71
|
+
});
|
72
|
+
|
73
|
+
// add the new iframe to application
|
74
|
+
form.parent().append(iframe);
|
75
|
+
|
76
|
+
scope.$apply(function () {
|
77
|
+
fn(scope, {content: "Please wait...", completed: false });
|
78
|
+
});
|
79
|
+
|
80
|
+
var enabled = true;
|
81
|
+
if (!options.enableControls) {
|
82
|
+
// disable the submit control on click
|
83
|
+
element.attr('disabled', 'disabled');
|
84
|
+
enabled = false;
|
85
|
+
}
|
86
|
+
// why do we need this???
|
87
|
+
element.attr('title', (enabled ? '[ENABLED]: ' : '[DISABLED]: ') + 'Uploading, please wait...');
|
88
|
+
|
89
|
+
form.submit();
|
90
|
+
|
91
|
+
}).attr('title', 'Click to start upload.');
|
92
|
+
}
|
93
|
+
};
|
94
|
+
}])
|
95
|
+
.directive('ngUpload', ['$parse', function ($parse) {
|
96
|
+
return {
|
97
|
+
restrict: 'AC',
|
98
|
+
link: function (scope, element, attrs) {
|
99
|
+
element.attr("target", "upload_iframe");
|
100
|
+
element.attr("method", "post");
|
101
|
+
// Append a timestamp field to the url to prevent browser caching results
|
102
|
+
element.attr("action", element.attr("action") + "?_t=" + new Date().getTime());
|
103
|
+
element.attr("enctype", "multipart/form-data");
|
104
|
+
element.attr("encoding", "multipart/form-data");
|
105
|
+
}
|
106
|
+
};
|
107
|
+
}]);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ng-angularjs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mjason
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -213,6 +213,7 @@ files:
|
|
213
213
|
- vendor/assets/javascripts/i18n/angular-locale_zh.js
|
214
214
|
- vendor/assets/javascripts/jstd-scenario-adapter-config.js
|
215
215
|
- vendor/assets/javascripts/jstd-scenario-adapter.js
|
216
|
+
- vendor/assets/javascripts/ng-upload.js
|
216
217
|
- vendor/assets/javascripts/version.json
|
217
218
|
- LICENSE.txt
|
218
219
|
- README.md
|