Skip to content

Commit

Permalink
Fixed event handler namespace setting.
Browse files Browse the repository at this point in the history
Added better transition support detection (no browser sniffing).
Call event handler related methods inside of the base event handler methods.
  • Loading branch information
blueimp committed Dec 16, 2011
1 parent 1b335ec commit 9358058
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 76 deletions.
143 changes: 71 additions & 72 deletions jquery.fileupload-ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery File Upload User Interface Plugin 6.0.1
* jQuery File Upload User Interface Plugin 6.0.2
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand Down Expand Up @@ -378,39 +378,45 @@
});
},

_initEventHandlers: function () {
$.blueimp.fileupload.prototype._initEventHandlers.call(this);
var eventData = {fileupload: this};
this._files
.delegate(
'.start button',
'click.' + this.options.namespace,
eventData,
this._startHandler
)
.delegate(
'.cancel button',
'click.' + this.options.namespace,
eventData,
this._cancelHandler
)
.delegate(
'.delete button',
'click.' + this.options.namespace,
eventData,
this._deleteHandler
_transitionCallback: function (node, callback) {
var that = this;
if (this._transition && node.hasClass('fade')) {
node.bind(
this._transitionEnd,
function (e) {
// Make sure we don't respond to other transitions events
// in the container element, e.g. from button elements:
if (e.target === node[0]) {
node.unbind(that._transitionEnd);
callback.call(that, node);
}
}
);
} else {
callback.call(this, node);
}
},

_destroyEventHandlers: function () {
this._files
.undelegate('.start button', 'click.' + this.options.namespace)
.undelegate('.cancel button', 'click.' + this.options.namespace)
.undelegate('.delete button', 'click.' + this.options.namespace);
$.blueimp.fileupload.prototype._destroyEventHandlers.call(this);
_initTransitionSupport: function () {
var that = this,
style = (document.body || document.documentElement).style,
suffix = '.' + that.options.namespace;
that._transition = style.transition !== undefined ||
style.WebkitTransition !== undefined ||
style.MozTransition !== undefined ||
style.MsTransition !== undefined ||
style.OTransition !== undefined;
if (that._transition) {
that._transitionEnd = [
'TransitionEnd',
'webkitTransitionEnd',
'transitionend',
'oTransitionEnd'
].join(suffix + ' ') + suffix;
}
},

_initFileUploadButtonBar: function () {
_initButtonBarEventHandlers: function () {
var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
filesList = this._files,
ns = this.options.namespace;
Expand Down Expand Up @@ -439,13 +445,48 @@
});
},

_destroyFileUploadButtonBar: function () {
_destroyButtonBarEventHandlers: function () {
this.element.find('.fileupload-buttonbar button')
.unbind('click.' + this.options.namespace);
this.element.find('.fileupload-buttonbar .toggle')
.unbind('change.' + this.options.namespace);
},

_initEventHandlers: function () {
$.blueimp.fileupload.prototype._initEventHandlers.call(this);
var eventData = {fileupload: this};
this._files
.delegate(
'.start button',
'click.' + this.options.namespace,
eventData,
this._startHandler
)
.delegate(
'.cancel button',
'click.' + this.options.namespace,
eventData,
this._cancelHandler
)
.delegate(
'.delete button',
'click.' + this.options.namespace,
eventData,
this._deleteHandler
);
this._initButtonBarEventHandlers();
this._initTransitionSupport();
},

_destroyEventHandlers: function () {
this._destroyButtonBarEventHandlers();
this._files
.undelegate('.start button', 'click.' + this.options.namespace)
.undelegate('.cancel button', 'click.' + this.options.namespace)
.undelegate('.delete button', 'click.' + this.options.namespace);
$.blueimp.fileupload.prototype._destroyEventHandlers.call(this);
},

_enableFileInputButton: function () {
this.element.find('.fileinput-button input')
.prop('disabled', false)
Expand All @@ -470,55 +511,13 @@
this._files = this.element.find('.files');
},

_transitionCallback: function (node, callback) {
var that = this;
if (this._transition && node.hasClass('fade')) {
node.bind(
this._transitionEnd + '.' + this.options.namespace,
function (e) {
// Make sure we don't respond to other transitions events
// in the container element, e.g. from button elements:
if (e.target === node[0]) {
node.unbind(
that._transitionEnd + '.' + that.options.namespace
);
callback.call(that, node);
}
}
);
} else {
callback.call(this, node);
}
},

_initTransitionSupport: function () {
var that = this;
// Load after DOM is ready, to wait for the Modal plugin:
$(function () {
that._transition = $.support.transition;
if ($.support.transition) {
that._transitionEnd = 'TransitionEnd';
if ($.browser.webkit) {
that._transitionEnd = 'webkitTransitionEnd';
} else if ($.browser.mozilla) {
that._transitionEnd = 'transitionend';
} else if ($.browser.opera) {
that._transitionEnd = 'oTransitionEnd';
}
}
});
},

_create: function () {
this._initFiles();
$.blueimp.fileupload.prototype._create.call(this);
this._initTransitionSupport();
this._initTemplates();
this._initFileUploadButtonBar();
},

destroy: function () {
this._destroyFileUploadButtonBar();
$.blueimp.fileupload.prototype.destroy.call(this);
},

Expand Down
7 changes: 4 additions & 3 deletions jquery.fileupload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery File Upload Plugin 5.5.2
* jQuery File Upload Plugin 5.5.3
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand Down Expand Up @@ -716,7 +716,7 @@
},

_initEventHandlers: function () {
var ns = this.options.namespace || this.widgetName;
var ns = this.options.namespace;
this.options.dropZone
.bind('dragover.' + ns, {fileupload: this}, this._onDragOver)
.bind('drop.' + ns, {fileupload: this}, this._onDrop)
Expand All @@ -726,7 +726,7 @@
},

_destroyEventHandlers: function () {
var ns = this.options.namespace || this.widgetName;
var ns = this.options.namespace;
this.options.dropZone
.unbind('dragover.' + ns, this._onDragOver)
.unbind('drop.' + ns, this._onDrop)
Expand Down Expand Up @@ -763,6 +763,7 @@

_create: function () {
var options = this.options;
options.namespace = options.namespace || this.widgetName;
if (options.fileInput === undefined) {
options.fileInput = this.element.is('input:file') ?
this.element : this.element.find('input:file');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blueimp-file-upload",
"version": "6.0.1",
"version": "6.0.2",
"title": "jQuery File Upload",
"description": "File Upload widget with multiple file selection, drag&drop support, progress bar and preview images for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.",
"keywords": [
Expand Down

0 comments on commit 9358058

Please sign in to comment.