",
options: {
- disabled: false,
-
- // callbacks
- create: null
+ disabled: false
},
_createWidget: function( options, element ) {
- element = $( element || this.defaultElement || this )[ 0 ];
+ // $.widget.bridge stores the plugin instance, but we do it anyway
+ // so that it's stored even before the _create function runs
+ $.data( element, this.widgetName, this );
this.element = $( element );
- this.uuid = uuid++;
- this.eventNamespace = "." + this.widgetName + this.uuid;
- this.options = $.widget.extend( {},
+ this.options = $.extend( true, {},
this.options,
this._getCreateOptions(),
options );
- this.bindings = $();
- this.hoverable = $();
- this.focusable = $();
-
- if ( element !== this ) {
- // 1.9 BC for #7810
- // TODO remove dual storage
- $.data( element, this.widgetName, this );
- $.data( element, this.widgetFullName, this );
- this._on( this.element, {
- remove: function( event ) {
- if ( event.target === element ) {
- this.destroy();
- }
- }
- });
- this.document = $( element.style ?
- // element within the document
- element.ownerDocument :
- // element is window or document
- element.document || element );
- this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
- }
+ var self = this;
+ this.element.bind( "remove." + this.widgetName, function() {
+ self.destroy();
+ });
this._create();
- this._trigger( "create", null, this._getCreateEventData() );
+ this._trigger( "create" );
this._init();
},
- _getCreateOptions: $.noop,
- _getCreateEventData: $.noop,
- _create: $.noop,
- _init: $.noop,
+ _getCreateOptions: function() {
+ return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
+ },
+ _create: function() {},
+ _init: function() {},
destroy: function() {
- this._destroy();
- // we can probably remove the unbind calls in 2.0
- // all event bindings should go through this._on()
this.element
- .unbind( this.eventNamespace )
- // 1.9 BC for #7810
- // TODO remove dual storage
- .removeData( this.widgetName )
- .removeData( this.widgetFullName )
- // support: jquery <1.6.3
- // http://bugs.jquery.com/ticket/9413
- .removeData( $.camelCase( this.widgetFullName ) );
+ .unbind( "." + this.widgetName )
+ .removeData( this.widgetName );
this.widget()
- .unbind( this.eventNamespace )
+ .unbind( "." + this.widgetName )
.removeAttr( "aria-disabled" )
.removeClass(
- this.widgetFullName + "-disabled " +
+ this.widgetBaseClass + "-disabled " +
"ui-state-disabled" );
-
- // clean up events and states
- this.bindings.unbind( this.eventNamespace );
- this.hoverable.removeClass( "ui-state-hover" );
- this.focusable.removeClass( "ui-state-focus" );
},
- _destroy: $.noop,
widget: function() {
return this.element;
},
option: function( key, value ) {
- var options = key,
- parts,
- curOption,
- i;
+ var options = key;
if ( arguments.length === 0 ) {
// don't return a reference to the internal hash
- return $.widget.extend( {}, this.options );
+ return $.extend( {}, this.options );
}
- if ( typeof key === "string" ) {
- // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
- options = {};
- parts = key.split( "." );
- key = parts.shift();
- if ( parts.length ) {
- curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
- for ( i = 0; i < parts.length - 1; i++ ) {
- curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
- curOption = curOption[ parts[ i ] ];
- }
- key = parts.pop();
- if ( value === undefined ) {
- return curOption[ key ] === undefined ? null : curOption[ key ];
- }
- curOption[ key ] = value;
- } else {
- if ( value === undefined ) {
- return this.options[ key ] === undefined ? null : this.options[ key ];
- }
- options[ key ] = value;
+ if (typeof key === "string" ) {
+ if ( value === undefined ) {
+ return this.options[ key ];
}
+ options = {};
+ options[ key ] = value;
}
this._setOptions( options );
@@ -341,11 +220,10 @@ $.Widget.prototype = {
return this;
},
_setOptions: function( options ) {
- var key;
-
- for ( key in options ) {
- this._setOption( key, options[ key ] );
- }
+ var self = this;
+ $.each( options, function( key, value ) {
+ self._setOption( key, value );
+ });
return this;
},
@@ -354,10 +232,10 @@ $.Widget.prototype = {
if ( key === "disabled" ) {
this.widget()
- .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
+ [ value ? "addClass" : "removeClass"](
+ this.widgetBaseClass + "-disabled" + " " +
+ "ui-state-disabled" )
.attr( "aria-disabled", value );
- this.hoverable.removeClass( "ui-state-hover" );
- this.focusable.removeClass( "ui-state-focus" );
}
return this;
@@ -370,88 +248,6 @@ $.Widget.prototype = {
return this._setOption( "disabled", true );
},
- _on: function( element, handlers ) {
- var delegateElement,
- instance = this;
- // no element argument, shuffle and use this.element
- if ( !handlers ) {
- handlers = element;
- element = this.element;
- delegateElement = this.widget();
- } else {
- // accept selectors, DOM elements
- element = delegateElement = $( element );
- this.bindings = this.bindings.add( element );
- }
-
- $.each( handlers, function( event, handler ) {
- function handlerProxy() {
- // allow widgets to customize the disabled handling
- // - disabled as an array instead of boolean
- // - disabled class as method for disabling individual parts
- if ( instance.options.disabled === true ||
- $( this ).hasClass( "ui-state-disabled" ) ) {
- return;
- }
- return ( typeof handler === "string" ? instance[ handler ] : handler )
- .apply( instance, arguments );
- }
-
- // copy the guid so direct unbinding works
- if ( typeof handler !== "string" ) {
- handlerProxy.guid = handler.guid =
- handler.guid || handlerProxy.guid || $.guid++;
- }
-
- var match = event.match( /^(\w+)\s*(.*)$/ ),
- eventName = match[1] + instance.eventNamespace,
- selector = match[2];
- if ( selector ) {
- delegateElement.delegate( selector, eventName, handlerProxy );
- } else {
- element.bind( eventName, handlerProxy );
- }
- });
- },
-
- _off: function( element, eventName ) {
- eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
- element.unbind( eventName ).undelegate( eventName );
- },
-
- _delay: function( handler, delay ) {
- function handlerProxy() {
- return ( typeof handler === "string" ? instance[ handler ] : handler )
- .apply( instance, arguments );
- }
- var instance = this;
- return setTimeout( handlerProxy, delay || 0 );
- },
-
- _hoverable: function( element ) {
- this.hoverable = this.hoverable.add( element );
- this._on( element, {
- mouseenter: function( event ) {
- $( event.currentTarget ).addClass( "ui-state-hover" );
- },
- mouseleave: function( event ) {
- $( event.currentTarget ).removeClass( "ui-state-hover" );
- }
- });
- },
-
- _focusable: function( element ) {
- this.focusable = this.focusable.add( element );
- this._on( element, {
- focusin: function( event ) {
- $( event.currentTarget ).addClass( "ui-state-focus" );
- },
- focusout: function( event ) {
- $( event.currentTarget ).removeClass( "ui-state-focus" );
- }
- });
- },
-
_trigger: function( type, event, data ) {
var prop, orig,
callback = this.options[ type ];
@@ -476,53 +272,11 @@ $.Widget.prototype = {
}
this.element.trigger( event, data );
- return !( $.isFunction( callback ) &&
- callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
+
+ return !( $.isFunction(callback) &&
+ callback.call( this.element[0], event, data ) === false ||
event.isDefaultPrevented() );
}
};
-$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
- $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
- if ( typeof options === "string" ) {
- options = { effect: options };
- }
- var hasOptions,
- effectName = !options ?
- method :
- options === true || typeof options === "number" ?
- defaultEffect :
- options.effect || defaultEffect;
- options = options || {};
- if ( typeof options === "number" ) {
- options = { duration: options };
- }
- hasOptions = !$.isEmptyObject( options );
- options.complete = callback;
- if ( options.delay ) {
- element.delay( options.delay );
- }
- if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) {
- element[ method ]( options );
- } else if ( effectName !== method && element[ effectName ] ) {
- element[ effectName ]( options.duration, options.easing, callback );
- } else {
- element.queue(function( next ) {
- $( this )[ method ]();
- if ( callback ) {
- callback.call( element[ 0 ] );
- }
- next();
- });
- }
- };
-});
-
-// DEPRECATED
-if ( $.uiBackCompat !== false ) {
- $.Widget.prototype._getCreateOptions = function() {
- return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
- };
-}
-
}));
diff --git a/fileupload/static/js/main.js b/fileupload/static/js/main.js
index dbabd8f..01c86fe 100644
--- a/fileupload/static/js/main.js
+++ b/fileupload/static/js/main.js
@@ -1,5 +1,5 @@
/*
- * jQuery File Upload Plugin JS Example 7.0
+ * jQuery File Upload Plugin JS Example 6.7
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
@@ -16,11 +16,7 @@ $(function () {
'use strict';
// Initialize the jQuery File Upload widget:
- $('#fileupload').fileupload({
- // Uncomment the following to send cross-domain cookies:
- //xhrFields: {withCredentials: true},
- url: 'server/php/'
- });
+ $('#fileupload').fileupload();
// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
@@ -68,15 +64,14 @@ $(function () {
}
} else {
// Load existing files:
- $.ajax({
- // Uncomment the following to send cross-domain cookies:
- //xhrFields: {withCredentials: true},
- url: $('#fileupload').fileupload('option', 'url'),
- dataType: 'json',
- context: $('#fileupload')[0]
- }).done(function (result) {
- $(this).fileupload('option', 'done')
- .call(this, null, {result: result});
+ $('#fileupload').each(function () {
+ var that = this;
+ $.getJSON(this.action, function (result) {
+ if (result && result.length) {
+ $(that).fileupload('option', 'done')
+ .call(that, null, {result: result});
+ }
+ });
});
}
From f3d32a864682708146ca166240bc5c59c406f14d Mon Sep 17 00:00:00 2001
From: ET-CS
Date: Mon, 21 Jan 2013 01:11:41 +0200
Subject: [PATCH 11/72] default url route added
---
urls.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/urls.py b/urls.py
index 535dd84..e57a6ec 100644
--- a/urls.py
+++ b/urls.py
@@ -9,7 +9,8 @@
# Examples:
# url(r'^$', 'upload.views.home', name='home'),
- url(r'^$', redirect(‘url-name’)),
+
+ url(r'^$', redirect(‘url-name’)),
url(r'^upload/', include('fileupload.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
From 961f48168521e78f6b9b8d7f24ffd2c48b7882af Mon Sep 17 00:00:00 2001
From: ET-CS
Date: Mon, 21 Jan 2013 01:18:16 +0200
Subject: [PATCH 12/72] fix invalid char. route fix.
---
fileupload/models.py | 2 +-
urls.py | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/fileupload/models.py b/fileupload/models.py
index 66fe2ed..63a3b0e 100644
--- a/fileupload/models.py
+++ b/fileupload/models.py
@@ -12,7 +12,7 @@ class Picture(models.Model):
slug = models.SlugField(max_length=50, blank=True)
def __unicode__(self):
- return '%s' % (self.file)
+ return self.file.name
@models.permalink
def get_absolute_url(self):
diff --git a/urls.py b/urls.py
index e57a6ec..3a8fe65 100644
--- a/urls.py
+++ b/urls.py
@@ -1,5 +1,5 @@
from django.conf.urls.defaults import patterns, include, url
-from django.shortcuts import redirect
+from django.http import HttpResponseRedirect
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
@@ -9,8 +9,7 @@
# Examples:
# url(r'^$', 'upload.views.home', name='home'),
-
- url(r'^$', redirect(‘url-name’)),
+ url(r'^$', lambda x: HttpResponseRedirect('/upload/new/')),
url(r'^upload/', include('fileupload.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
From 720a6f09bc769ae6b2206d30e7edee2c6d84b5c7 Mon Sep 17 00:00:00 2001
From: Sigurd Gartmann
Date: Sat, 26 Jan 2013 14:37:42 +0100
Subject: [PATCH 13/72] the unicode representation now uses the file's name
---
fileupload/models.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fileupload/models.py b/fileupload/models.py
index 64cf98b..eb5d0a5 100644
--- a/fileupload/models.py
+++ b/fileupload/models.py
@@ -12,7 +12,7 @@ class Picture(models.Model):
slug = models.SlugField(max_length=50, blank=True)
def __unicode__(self):
- return self.file
+ return self.file.name
@models.permalink
def get_absolute_url(self):
From a427ea2f6ddb1a79d37efff6817b0a04540ea209 Mon Sep 17 00:00:00 2001
From: Sigurd Gartmann
Date: Wed, 3 Apr 2013 17:31:18 +0200
Subject: [PATCH 14/72] Also ignore environment placed in env dir
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 06f5f1d..25e7e00 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
/lib
/local
/share
+/env
From 3cc64c4d738101a618152b4ed54a7de1428a4bba Mon Sep 17 00:00:00 2001
From: Sigurd Gartmann
Date: Wed, 3 Apr 2013 17:31:38 +0200
Subject: [PATCH 15/72] Show already uploaded files on page reload. With delete
button as well.
---
.../templates/fileupload/picture_form.html | 23 +++++++++++++++++++
fileupload/views.py | 5 ++++
2 files changed, 28 insertions(+)
diff --git a/fileupload/templates/fileupload/picture_form.html b/fileupload/templates/fileupload/picture_form.html
index 89b764a..65a5be2 100644
--- a/fileupload/templates/fileupload/picture_form.html
+++ b/fileupload/templates/fileupload/picture_form.html
@@ -42,6 +42,29 @@ Django Jquery file upload demo
+
+