Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow option passing to resumable.js #2

Merged
merged 2 commits into from

2 participants

@EnTeQuAk

Allow passing options to resumable.js

Smaller cleanups and fixes:

  • errorList in getErrorList can be 'null' some times
  • Use hasOwnProperty in .extends instead of null check
EnTeQuAk added some commits
@EnTeQuAk EnTeQuAk Small cleanup c89deda
@EnTeQuAk EnTeQuAk Allow passing options to resumable.js
Smaller cleanups and fixes:
 * errorList in getErrorList can be 'null' some times
 * Use hasOwnProperty in .extends instead of null check
8510c7e
@jeanphix jeanphix merged commit 689cb86 into jeanphix:master

1 check passed

Details default The Travis build passed
@jeanphix
Owner

Thanks again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 25, 2012
  1. @EnTeQuAk

    Small cleanup

    EnTeQuAk authored
  2. @EnTeQuAk

    Allow passing options to resumable.js

    EnTeQuAk authored
    Smaller cleanups and fixes:
     * errorList in getErrorList can be 'null' some times
     * Use hasOwnProperty in .extends instead of null check
This page is out of date. Refresh to see the latest.
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)
Something went wrong with that request. Please try again.