/**
* File attachment wrapper.
*
* @author Htmlstream
* @version 1.0
*
*/
;(function ($) {
'use strict';
$.HSCore.components.HSFileAttachment = {
/**
*
*
* @var Object _baseConfig
*/
_baseConfig: {
input: '
\
Drop files here or Browse your device
\
Maximum file size 10mb
\
',
box: '',
item: '\
\
{{fi-name}}
\
{{fi-size2}}
\
{{fi-image}}
\
{{fi-progressBar}}
\
\
',
itemAppend: '\
\
{{fi-name}}
\
{{fi-size2}}
\
{{fi-image}}
\
{{fi-progressBar}}
\
{{fi-icon}}
\
\
\
',
progressBar: '',
selectors: {
list: '.js-result-list',
item: '.js-result-list__item',
progressBar: '.u-progress-bar-v1',
remove: '.js-result-list-item-remove'
}
},
/**
*
*
* @var jQuery pageCollection
*/
pageCollection: $(),
/**
* Initialization of File attachment wrapper.
*
* @param String selector (optional)
* @param Object config (optional)
*
* @return jQuery pageCollection - collection of initialized items.
*/
init: function (selector, config) {
this.collection = selector && $(selector).length ? $(selector) : $();
if (!$(selector).length) return;
this.config = config && $.isPlainObject(config) ?
$.extend({}, this._baseConfig, config) : this._baseConfig;
this.config.itemSelector = selector;
this.initFileAttachment();
return this.pageCollection;
},
initFileAttachment: function () {
//Variables
var $self = this,
config = $self.config,
collection = $self.pageCollection;
//Actions
this.collection.each(function (i, el) {
//Variables
var $this = $(el);
$this.filer({
changeInput: config.input,
showThumbs: true,
templates: {
box: config.box,
item: config.item,
itemAppend: config.itemAppend,
progressBar: config.progressBar,
_selectors: config.selectors,
itemAppendToEnd: false,
removeConfirmation: true
},
dragDrop: {},
uploadFile: {
url: '../../../assets/include/php/file-upload/upload.php',
data: {},
type: 'POST',
enctype: 'multipart/form-data',
beforeSend: function () {
},
success: function (data, el) {
var parent = el.find(".u-progress-bar-v1").parent();
el.find(".u-progress-bar-v1").fadeOut("slow", function () {
$(" Success
").hide().appendTo(parent).fadeIn("slow");
});
},
error: function (el) {
var parent = el.find(".u-progress-bar-v1").parent();
el.find(".u-progress-bar-v1").fadeOut("slow", function () {
$(" Error
").hide().appendTo(parent).fadeIn("slow");
});
}
}
});
//Actions
collection = collection.add($this);
});
}
};
})(jQuery);