An enhanced HTML 5 file input for Bootstrap 5.x/4.x./3.x with file preview, multiple selection, and more features.
fork from : https://github.com/kartik-v/bootstrap-fileinput.git
|
11 tahun lalu | |
---|---|---|
css | 11 tahun lalu | |
examples | 11 tahun lalu | |
js | 11 tahun lalu | |
CHANGE.md | 11 tahun lalu | |
LICENSE.md | 11 tahun lalu | |
README.md | 11 tahun lalu | |
bower.json | 11 tahun lalu | |
composer.json | 11 tahun lalu |
An enhanced HTML 5 file input for Bootstrap 3.x with file preview for images and text, multiple selection, and more. This plugin is inspired by this blog article and Jasny's File Input plugin. The plugin enhances these concepts and simplifies the widget initialization with simple HTML markup on a file input. It also offers support for multiple file preview and previewing both images and text types.
type = file
to an advanced file picker input if you set its class = file
. All options to the input can be passed as HTML5 data
attributes.filereset
and fileclear
.View the plugin documentation and plugin demos at Krajee JQuery plugins.
The plugin supports only file input and preview at client level. It does not actually process the upload of the files to the server.
You can use the bower
package manager to install. Run:
bower install bootstrap-fileinput
You can use the composer
package manager to install. Either run:
$ php composer.phar require kartik-v/bootstrap-fileinput "dev-master"
or add:
"kartik-v/bootstrap-fileinput": "dev-master"
to your composer.json file
You can also manually install the plugin easily to your project. Just download the source ZIP or TAR ball and extract the plugin assets (css and js folders) into your project.
Step 1: Load the following assets in your header.
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet">
<link href="path/to/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="path/to/js/fileinput.min.js" type="text/javascript"></script>
If you noticed, you need to load the jquery.min.js
and bootstrap.min.css
in addition to the fileinput.min.css
and fileinput.min.js
.
Step 2: Initialize the plugin on your page. For example,
// initialize with defaults
$("#input-id").fileinput();
// with plugin options
$("#input-id").fileinput({'showUpload':false, 'previewFileType':'any'});
The #input-id
is the identifier for the input (e.g. type = file
) on your page, which is hidden automatically by the plugin.
Alternatively, you can directly call the plugin options by setting data attributes to your input field.
<input id="input-id" type="file" class="file" data-preview-file-type="text" >
The plugin supports these following options:
boolean whether to display the file caption. Defaults to true
.
boolean whether to display the file preview. Defaults to true
.
boolean whether to display the file remove/clear button. Defaults to true
.
boolean whether to display the file upload button. Defaults to true
. This will default to a form submit button, unless the uploadUrl is specified.
string any additional CSS class to append to the caption container.
string any additional CSS class to append to the preview container.
string any additional CSS class to append to the main plugin container.
string the template used to render the widget. The following template variables will be parsed:
{class}
: any additional CSS class to append to the main widget container.{preview}
: the content parsed by the previewTemplate
and will be displayed only if showPreview
is true
.{caption}
: the content parsed by the captionTemplate
and will be displayed only if showCaption
is true
.{remove}
: the file remove/clear button and will be displayed only if showRemove
is true
.{upload}
: the file upload button and will be displayed only if showUpload
is true
.{browse}
: the main file browse button to select your files for input.The mainTemplate
if not passed, will be automatically set based on showCaption
settings.
If showCaption
is set to true
, the mainTemplate
will default to:
{preview}\n
<div class="input-group {class}">\n
{caption}\n
<div class="input-group-btn">\n
{remove}\n
{upload}\n
{browse}\n
</div>\n
</div>\n
showCaption
is set to false
, the mainTemplate
will default to:
html
{preview}\n{remove}\n{upload}\n{browse}\n
string the template used to render the caption. The following template variables will be parsed:
{class}
: any additional CSS class to append to the caption container.The captionTemplate
if not set will default to:
<div class="form-control file-caption {class}">\n
<span class="glyphicon glyphicon-file"></span> <span class="file-caption-name"></span>\n
</div>
string the template used to render the preview. The following template variables will be parsed:
{class}
: any additional CSS class to append to the preview container.The previewTemplate
if not set will default to:
<div class="file-preview {class}">\n
<div class="file-preview-status text-center text-success"></div>\n
<div class="close fileinput-remove text-right">×</div>\n
<div class="file-preview-thumbnails"></div>\n
<div class="clearfix"></div> +
</div>
string the label to display for the file picker/browse button. Defaults to Browse …
.
string the icon to display before the label for the file picker/browse button. Defaults to <i class="glyphicon glyphicon-folder-open"></i>
.
string the CSS class for the file picker/browse button. Defaults to btn btn-primary
.
string the label to display for the file remove button. Defaults to Remove
.
string the icon to display before the label for the file picker/remove button. Defaults to <i class="glyphicon glyphicon-ban-circle"></i>
.
string the CSS class for the file remove button. Defaults to btn btn-default
.
string the label to display for the file upload button. Defaults to Upload
.
string the icon to display before the label for the file upload button. Defaults to <i class="glyphicon glyphicon-upload"></i>
.
string the CSS class for the file upload button. Defaults to btn btn-default
.
string the URL for the upload processing action (typically for ajax based processing). Defaults to null
. If this is not set or null
, then the upload button action will default to form submission.
string the message displayed when the files are getting read and loaded for preview. Defaults to Loading …
.
string the progress message displayed as each file is loaded for preview. Defaults to Loaded {percent}% of {file}
. The following variables will be replaced:
{percent}
: the percentage of file read and loaded.{file}
: the name of the file being loaded.string the progress message displayed in caption window when multiple (more than one) files are selected. Defaults to {n} files selected
. The following variables will be replaced:
{n}
: the number of files selected.string the type of files that are to be displayed in the preview window. Defaults to image
. Can be one of the following:
image
: Only image
type files will be shown in preview.text
: Only text
type files will be shown in preview.any
: Both image
and text
files content will be shown in preview.Files other than image
or text
will be displayed as a thumbnail with the filename in the preview window.
integer the number of characters after which the content will be stripped/wrapped for text preview. Defaults to 250
.
string the type of files that are to be displayed in the preview window. Defaults to <span class="wrap-indicator" title="{title}">[…]</span>
. The following variables will be replaced:
{title}
: the content of the entire text file that will be displayed as a span title element.DOM Element the container element containing the caption. If not set, will default to the container with CSS class file-caption
inside the main plugin container.
DOM Element the container element containing the caption text. If not set, will default to the container with CSS class file-caption-name
inside the main plugin container.
DOM Element the container element containing the preview. If not set, will default to the container with CSS class file-preview
inside the main plugin container.
DOM Element the container element containing the preview image thumbnails. If not set, will default to the container with CSS class file-preview-thumbnails
inside the main plugin container.
DOM Element the container element containing the preview progress status. If not set, will default to the container with CSS class file-preview-status
inside the main plugin container.
The plugin supports these events:
This event is triggered when the file input is cleared with the remove button.
Example:
$('#input-id').on('fileclear', function(event) {
console.log("fileclear");
});
This event is triggered when the file input is reset to initial value.
Example:
$('#input-id').on('filereset', function(event) {
console.log("filereset");
});
The plugin supports these methods:
Reset the file input.
$('#input-id').fileinput('reset');
Clear the file input.
$('#input-id').fileinput('clear');
bootstrap-fileinput is released under the BSD 3-Clause License. See the bundled LICENSE.md
for details.