Fix bug for edge.
This commit is contained in:
parent
a1848f8ed1
commit
423a2f83db
|
@ -222,8 +222,33 @@
|
||||||
<% content_for :page_specific_javascript do %>
|
<% content_for :page_specific_javascript do %>
|
||||||
<script>
|
<script>
|
||||||
function FileListItems (files) {
|
function FileListItems (files) {
|
||||||
var b = new ClipboardEvent("").clipboardData || new DataTransfer()
|
var b;
|
||||||
for (var i = 0, len = files.length; i<len; i++) b.items.add(files[i])
|
if(window.dataTransfer){
|
||||||
|
b = window.dataTransfer;
|
||||||
|
}else{
|
||||||
|
if(typeof(ClipboardEvent) == "undefined"){ //IE
|
||||||
|
b = new DataTransfer();
|
||||||
|
}else{
|
||||||
|
b = new ClipboardEvent("").clipboardData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(b.items){
|
||||||
|
b.items.clear();
|
||||||
|
}else{
|
||||||
|
if(b.files.length != 0 ){
|
||||||
|
var files_length = b.files.length;
|
||||||
|
for(var i = files_length - 1;i >= 0;i = i - 1){
|
||||||
|
delete b.files[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i = 0, len = files.length; i<len; i++){
|
||||||
|
if(b.items){
|
||||||
|
b.items.add(files[i])
|
||||||
|
}else{
|
||||||
|
b.files[i] = files[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
return b.files
|
return b.files
|
||||||
}
|
}
|
||||||
function change_files_to_file_field(file_field,files){
|
function change_files_to_file_field(file_field,files){
|
||||||
|
@ -232,7 +257,15 @@
|
||||||
fileupload.find(".fileupload-preview").text(files[0].name);
|
fileupload.find(".fileupload-preview").text(files[0].name);
|
||||||
}
|
}
|
||||||
var files_list = new FileListItems(files)
|
var files_list = new FileListItems(files)
|
||||||
$(file_field).prop("files" ,files_list);
|
$(file_field)[0].files = files_list;
|
||||||
|
if($(file_field)[0].files.length == 0){ //Change failed
|
||||||
|
var file_field_values = [];
|
||||||
|
for(var i = 0; i < files_list.length; i++){
|
||||||
|
$(file_field)[0].files[i] = files_list[i];
|
||||||
|
file_field_values.push("C:\\fakepath\\" + files_list[i].name);
|
||||||
|
}
|
||||||
|
$(file_field)[0].value = file_field_values.join(", ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function dragOverHandler(ev) {
|
function dragOverHandler(ev) {
|
||||||
document.activeElement.blur();
|
document.activeElement.blur();
|
||||||
|
@ -241,6 +274,7 @@
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
function dropHandler(ev) {
|
function dropHandler(ev) {
|
||||||
|
window.dataTransfer = ev.dataTransfer;
|
||||||
// Prevent default behavior (Prevent file from being opened)
|
// Prevent default behavior (Prevent file from being opened)
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
var files = [];
|
var files = [];
|
||||||
|
@ -265,7 +299,9 @@
|
||||||
var file_field = add_file_field();
|
var file_field = add_file_field();
|
||||||
change_files_to_file_field(file_field,single_file);
|
change_files_to_file_field(file_field,single_file);
|
||||||
})
|
})
|
||||||
$(ev.target).removeClass("in");
|
window.files = files;
|
||||||
|
var target = ev.target ? ev.target : ev.srcElement;
|
||||||
|
$(target).removeClass("in");
|
||||||
}
|
}
|
||||||
function add_file_field(){
|
function add_file_field(){
|
||||||
var self = $('#add_file');
|
var self = $('#add_file');
|
||||||
|
|
Loading…
Reference in New Issue