I am using jQuery UI's resizable
function to make a div (bootstrap panel) that displays the contents of the file uploaded resizable. Resizable works on the div initially but after I update it with the contents of the file uploaded it stops working and the resizable cursor doesn't appear. This behavior can be observed in the snippet below and this jsfiddle.
$("#filePreview").resizable({
handles: "n, s",
minHeight: 100
});
function readFile(file) {
var reader = new FileReader();
reader.onload = readSuccess;
function readSuccess(evt) {
$('#filePreview').text(evt.target.result);
};
reader.readAsText(file);
}
$(document).on('change', '#inputFile', function() {
readFile(this.files[0]);
});
.preview-panel {
white-space: pre-line;
overflow-y: scroll;
min-height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.theme.css" rel="stylesheet"/>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<div class="container">
<form class="form-inline">
<div class="form-group">
<label for="inputFile">File Input</label>
<input type="file" class="form-control" id="inputFile">
</div>
</form>
<div class="panel panel-default">
<div class="panel-heading">File Preview</div>
<div class="panel-body preview-panel" id="filePreview"></div>
</div>
</div>
I have seen questions on resizable for dynamically added elements and tried reinitializing resizable after the div is updated with the new file content but it didn't work. How do I make resizable
work on the div even after its content changes to display the preview of the last uploaded file?