Skip to content

Commit

Permalink
Merge pull request #2 from EnTeQuAk/allow_resumable_option_passing
Browse files Browse the repository at this point in the history
Allow option passing to resumable.js
  • Loading branch information
jeanphix committed Oct 25, 2012
2 parents 213f519 + 8510c7e commit 689cb86
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
26 changes: 15 additions & 11 deletions resumable/static/resumable/js/django-resumable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)];
Expand Down Expand Up @@ -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());
};
};
2 changes: 1 addition & 1 deletion resumable/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions resumable/widgets.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 689cb86

Please sign in to comment.