Skip to content

Instantly share code, notes, and snippets.

@jeremi
Created February 7, 2011 10:16
Show Gist options
  • Save jeremi/814210 to your computer and use it in GitHub Desktop.
Save jeremi/814210 to your computer and use it in GitHub Desktop.
Fix upload.js
diff --git a/frameworks/foundation/views/upload.js b/frameworks/foundation/views/upload.js
index 0447687..90f534f 100644
--- a/frameworks/foundation/views/upload.js
+++ b/frameworks/foundation/views/upload.js
@@ -11,6 +11,46 @@
@author Evin Grano
*/
+// Add the bind() function to the Function prototype.
+SC.mixin(Function.prototype, {
+
+ /**
+ * This bind method was ported from the prototype for use in the AJAX callbacks.
+ *
+ * Function#bind(object[, args...]) -> Function
+ * - object (Object): The object to bind to.
+ *
+ * Wraps the function in another, locking its execution scope to an object
+ * specified by `object`.
+ */
+ bind: function (context) {
+ var slice = Array.prototype.slice;
+
+ var update = function(array, args) {
+ var arrayLength = array.length, length = args.length;
+ while (length--) array[arrayLength + length] = args[length];
+ return array;
+ };
+
+ var merge = function(array, args) {
+ array = slice.call(array, 0);
+ return update(array, args);
+ };
+
+ if (arguments.length < 2 && SC.none(arguments[0])) return this;
+ var __method = this, args = slice.call(arguments, 1);
+
+ return function() {
+ var a = merge(args, arguments);
+ // var a = args.concat(arguments);
+ return __method.apply(context, a);
+ };
+ }
+
+});
+
+
+
SCUI.UploadView = SC.View.extend(
/** @scope Scui.Upload.prototype */ {
@@ -202,7 +242,8 @@ SCUI.UploadView = SC.View.extend(
file = input.files[0];
fd = new FormData();
fd.append(this.get('inputName'), file);
- xhr = rp.copy();
+ xhr = rp.create();
+ xhr.set('type', 'POST');
xhr.set('isJSON', false);
xhr.set('isXML', false);
xhr.set('address', this.get('uploadTarget'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment