From 935805821f308c796c03d3c1f018d6414dd540cd Mon Sep 17 00:00:00 2001 From: Sebastian Tschan Date: Fri, 16 Dec 2011 17:33:36 +0900 Subject: [PATCH] Fixed event handler namespace setting. Added better transition support detection (no browser sniffing). Call event handler related methods inside of the base event handler methods. --- jquery.fileupload-ui.js | 143 ++++++++++++++++++++-------------------- jquery.fileupload.js | 7 +- package.json | 2 +- 3 files changed, 76 insertions(+), 76 deletions(-) diff --git a/jquery.fileupload-ui.js b/jquery.fileupload-ui.js index cffa606dc..3cc21f377 100644 --- a/jquery.fileupload-ui.js +++ b/jquery.fileupload-ui.js @@ -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 @@ -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; @@ -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) @@ -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); }, diff --git a/jquery.fileupload.js b/jquery.fileupload.js index e8bbde959..d1e3bc5b0 100644 --- a/jquery.fileupload.js +++ b/jquery.fileupload.js @@ -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 @@ -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) @@ -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) @@ -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'); diff --git a/package.json b/package.json index 6dc41e340..37868dc77 100644 --- a/package.json +++ b/package.json @@ -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": [