Index: polymer_0.5.0/bower_components/core-ajax/core-ajax.html |
diff --git a/bower_components/core-ajax/core-ajax.html b/polymer_0.5.0/bower_components/core-ajax/core-ajax.html |
similarity index 79% |
rename from bower_components/core-ajax/core-ajax.html |
rename to polymer_0.5.0/bower_components/core-ajax/core-ajax.html |
index b74901f67d3cee36442a9e85e0aa7b8669b65863..c0ca0adbc25f5919da4c0f25131b4a5e5ed1f01f 100644 |
--- a/bower_components/core-ajax/core-ajax.html |
+++ b/polymer_0.5.0/bower_components/core-ajax/core-ajax.html |
@@ -20,7 +20,7 @@ The `core-ajax` element exposes `XMLHttpRequest` functionality. |
on-core-response="{{handleResponse}}"></core-ajax> |
With `auto` set to `true`, the element performs a request whenever |
-its `url` or `params` properties are changed. |
+its `url`, `params` or `body` properties are changed. |
Note: The `params` attribute must be double quoted JSON. |
@@ -32,7 +32,7 @@ element. |
@homepage github.io |
--> |
<link rel="import" href="core-xhr.html"> |
-<polymer-element name="core-ajax" hidden attributes="url handleAs auto params response error method headers body contentType withCredentials"> |
+<polymer-element name="core-ajax" hidden attributes="url handleAs auto params response error method headers body contentType withCredentials progress loading"> |
<script> |
Polymer('core-ajax', { |
@@ -106,7 +106,7 @@ element. |
params: '', |
/** |
- * The response for the most recently made request, or null if it hasn't |
+ * The response for the current request, or null if it hasn't |
* completed yet or the request resulted in error. |
* |
* @attribute response |
@@ -116,7 +116,7 @@ element. |
response: null, |
/** |
- * The error for the most recently made request, or null if it hasn't |
+ * The error for the current request, or null if it hasn't |
* completed yet or the request resulted in success. |
* |
* @attribute error |
@@ -126,6 +126,24 @@ element. |
error: null, |
/** |
+ * Whether the current request is currently loading. |
+ * |
+ * @attribute loading |
+ * @type boolean |
+ * @default false |
+ */ |
+ loading: false, |
+ |
+ /** |
+ * The progress of the current request. |
+ * |
+ * @attribute progress |
+ * @type {loaded: number, total: number, lengthComputable: boolean} |
+ * @default {} |
+ */ |
+ progress: null, |
+ |
+ /** |
* The HTTP method to use such as 'GET', 'POST', 'PUT', or 'DELETE'. |
* Default is 'GET'. |
* |
@@ -199,6 +217,10 @@ element. |
*/ |
xhrArgs: null, |
+ created: function() { |
+ this.progress = {}; |
+ }, |
+ |
ready: function() { |
this.xhr = document.createElement('core-xhr'); |
}, |
@@ -233,7 +255,26 @@ element. |
this.fire('core-error', {response: response, xhr: xhr}); |
}, |
+ processProgress: function(progress, xhr) { |
+ if (xhr !== this.activeRequest) { |
+ return; |
+ } |
+ // We create a proxy object here because these fields |
+ // on the progress event are readonly properties, which |
+ // causes problems in common use cases (e.g. binding to |
+ // <paper-progress> attributes). |
+ var progressProxy = { |
+ lengthComputable: progress.lengthComputable, |
+ loaded: progress.loaded, |
+ total: progress.total |
+ } |
+ this.progress = progressProxy; |
+ }, |
+ |
complete: function(xhr) { |
+ if (xhr === this.activeRequest) { |
+ this.loading = false; |
+ } |
this.fire('core-complete', {response: xhr.status, xhr: xhr}); |
}, |
@@ -289,6 +330,10 @@ element. |
this.autoGo(); |
}, |
+ bodyChanged: function() { |
+ this.autoGo(); |
+ }, |
+ |
autoChanged: function() { |
this.autoGo(); |
}, |
@@ -322,7 +367,12 @@ element. |
var hasContentType = Object.keys(args.headers).some(function (header) { |
return header.toLowerCase() === 'content-type'; |
}); |
- if (!hasContentType && this.contentType) { |
+ // No Content-Type should be specified if sending `FormData`. |
+ // The UA must set the Content-Type w/ a calculated multipart boundary ID. |
+ if (args.body instanceof FormData) { |
+ delete args.headers['Content-Type']; |
+ } |
+ else if (!hasContentType && this.contentType) { |
args.headers['Content-Type'] = this.contentType; |
} |
if (this.handleAs === 'arraybuffer' || this.handleAs === 'blob' || |
@@ -334,8 +384,24 @@ element. |
args.url = this.url; |
args.method = this.method; |
- this.response = this.error = null; |
+ this.response = this.error = this.progress = null; |
this.activeRequest = args.url && this.xhr.request(args); |
+ if (this.activeRequest) { |
+ this.loading = true; |
+ var activeRequest = this.activeRequest; |
+ // IE < 10 doesn't support progress events. |
+ if ('onprogress' in activeRequest) { |
+ this.activeRequest.addEventListener( |
+ 'progress', |
+ function(progress) { |
+ this.processProgress(progress, activeRequest); |
+ }.bind(this), false); |
+ } else { |
+ this.progress = { |
+ lengthComputable: false, |
+ } |
+ } |
+ } |
return this.activeRequest; |
} |