mirror of
https://github.com/jasny/bootstrap.git
synced 2026-01-22 12:48:10 -05:00
Fixes for fileupload
- Clear file input when pressing input button - Cancel event when pressing dismiss (before init) - Don't clear name when no file is selected in IE New feature: data-trigger="fileupload"
This commit is contained in:
21
js/bootstrap-fileupload.js
vendored
21
js/bootstrap-fileupload.js
vendored
@@ -1,5 +1,5 @@
|
||||
/* ===========================================================
|
||||
* bootstrap-fileupload.js j1a
|
||||
* bootstrap-fileupload.js j2
|
||||
* http://jasny.github.com/bootstrap/javascript.html#fileupload
|
||||
* ===========================================================
|
||||
* Copyright 2012 Jasny BV, Netherlands.
|
||||
@@ -44,7 +44,9 @@
|
||||
if (this.$preview.css('display') != 'inline' && height != '0px' && height != 'none') this.$preview.css('line-height', height)
|
||||
|
||||
this.$remove = this.$element.find('[data-dismiss="fileupload"]')
|
||||
|
||||
|
||||
this.$element.find('[data-trigger="fileupload"]').on('click.fileupload', $.proxy(this.trigger, this))
|
||||
|
||||
this.listen()
|
||||
}
|
||||
|
||||
@@ -56,7 +58,7 @@
|
||||
},
|
||||
|
||||
change: function(e, invoked) {
|
||||
var file = e.target.files !== undefined ? e.target.files[0] : { name: e.target.value.replace(/^.+\\/, '') }
|
||||
var file = e.target.files !== undefined ? e.target.files[0] : (e.target.value ? { name: e.target.value.replace(/^.+\\/, '') } : null)
|
||||
if (!file || invoked === 'clear') return
|
||||
|
||||
this.$hidden.val('')
|
||||
@@ -84,6 +86,7 @@
|
||||
this.$hidden.val('')
|
||||
this.$hidden.attr('name', this.name)
|
||||
this.$input.attr('name', '')
|
||||
this.$input.val('') // Doesn't work in IE, which causes issues when selecting the same file twice
|
||||
|
||||
this.$preview.html('')
|
||||
this.$element.addClass('fileupload-new').removeClass('fileupload-exists')
|
||||
@@ -91,7 +94,11 @@
|
||||
this.$input.trigger('change', [ 'clear' ])
|
||||
|
||||
e.preventDefault()
|
||||
return false
|
||||
},
|
||||
|
||||
trigger: function(e) {
|
||||
this.$input.trigger('click')
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +126,11 @@
|
||||
if ($this.data('fileupload')) return
|
||||
$this.fileupload($this.data())
|
||||
|
||||
if ($(e.target).data('dismiss') == 'fileupload') $(e.target).trigger('click.fileupload')
|
||||
var $target = $(e.target).parents('[data-dismiss=fileupload],[data-trigger=fileupload]').first()
|
||||
if ($target.length > 0) {
|
||||
$target.trigger('click.fileupload')
|
||||
e.preventDefault()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user