Skip to content
Browse files

Merge pull request #2 from EnTeQuAk/allow_resumable_option_passing

Allow option passing to resumable.js
  • Loading branch information...
2 parents 213f519 + 8510c7e commit 689cb86ffe3eef1db5b7da9fbd455a732e4f9f45 @jeanphix committed Oct 25, 2012
Showing with 19 additions and 16 deletions.
  1. +15 −11 resumable/static/resumable/js/django-resumable.js
  2. +1 −1 resumable/views.py
  3. +3 −4 resumable/widgets.py
View
26 resumable/static/resumable/js/django-resumable.js
@@ -10,7 +10,8 @@ var DjangoResumable = function (options) {
onFileError: this.onFileError,
onFileAdded: this.onFileAdded,
onFileSuccess: this.onFileSuccess,
- onProgress: this.onProgress
+ onProgress: this.onProgress,
+ resumableOptions: {}
};
this.options = this.extend(defaults, options);
this.csrfToken = document.querySelector('input[name=' + this.options.csrfInputName + ']').value;
@@ -32,10 +33,10 @@ DjangoResumable.prototype.each = function (elements, fn) {
DjangoResumable.prototype.extend = function (target, source) {
"use strict";
- var key;
- for (key in source) {
- if (source[key] !== undefined) {
- target[key] = source[key];
+ var property;
+ for (property in source) {
+ if (source.hasOwnProperty(property)) {
+ target[property] = source[property];
}
}
return target;
@@ -45,10 +46,10 @@ DjangoResumable.prototype.extend = function (target, source) {
DjangoResumable.prototype.getErrorList = function (el, create) {
"use strict";
var errorList = el.parentNode.previousSibling;
- while (errorList.tagName === undefined) {
+ while (errorList && errorList.tagName === undefined) {
errorList = errorList.previousSibling;
}
- if (!errorList.classList.contains(this.options.errorListClass)) {
+ if (errorList && !errorList.classList.contains(this.options.errorListClass)) {
if (create === true) {
errorList = document.createElement('ul');
errorList.classList.add(this.options.errorListClass);
@@ -104,12 +105,15 @@ DjangoResumable.prototype.initResumable = function (el, progress, filePath, file
"use strict";
var elements = Array.prototype.slice.call(arguments),
self = this,
- r = new Resumable({
- target : el.getAttribute(this.options.urlAttribute),
+ opts = {
+ target: el.getAttribute(this.options.urlAttribute),
query: {
'csrfmiddlewaretoken': this.csrfToken
}
- });
+ };
+
+ opts = this.extend(this.options.resumableOptions, opts);
+ var r = new Resumable(opts);
r.assignBrowse(el);
this.each(['fileAdded', 'progress', 'fileSuccess', 'fileError'], function (eventType) {
var callback = this.options['on' + eventType.substring(0, 1).toUpperCase() + eventType.substring(1)];
@@ -154,4 +158,4 @@ DjangoResumable.prototype.onFileSuccess = function (r, file, message, el, progre
DjangoResumable.prototype.onProgress = function (r, el, progress, filePath, fileName) {
"use strict";
progress.setAttribute('value', r.progress());
-};
+};
View
2 resumable/views.py
@@ -2,7 +2,7 @@
from django.conf import settings
from django.views.generic import View
-from django.http import Http404, HttpResponse
+from django.http import HttpResponse
from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import FileSystemStorage
View
7 resumable/widgets.py
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
import magic
-from django.forms.widgets import FileInput, HiddenInput
+from django.forms.widgets import FileInput
from django.core.files.storage import FileSystemStorage
from django.core.files.uploadedfile import UploadedFile
-from django.utils.safestring import mark_safe
from django.template import loader
@@ -37,9 +36,9 @@ def value_from_datadict(self, data, files, name):
self.filename = filepath.lstrip('%s_' % unicode(size))
return UploadedFile(
file=file,
- name = self.filename,
+ name=self.filename,
content_type=self.guess_type(file.name),
- size = size
+ size=size
)
return files.get(name, None)

0 comments on commit 689cb86

Please sign in to comment.
Something went wrong with that request. Please try again.