commitall
This commit is contained in:
@ -0,0 +1,167 @@
|
||||
/*!
|
||||
* bsCustomFileInput v1.3.4 (https://github.com/Johann-S/bs-custom-file-input)
|
||||
* Copyright 2018 - 2020 Johann-S <johann.servoire@gmail.com>
|
||||
* Licensed under MIT (https://github.com/Johann-S/bs-custom-file-input/blob/master/LICENSE)
|
||||
*/
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.bsCustomFileInput = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
var Selector = {
|
||||
CUSTOMFILE: '.custom-file input[type="file"]',
|
||||
CUSTOMFILELABEL: '.custom-file-label',
|
||||
FORM: 'form',
|
||||
INPUT: 'input'
|
||||
};
|
||||
|
||||
var textNodeType = 3;
|
||||
|
||||
var getDefaultText = function getDefaultText(input) {
|
||||
var defaultText = '';
|
||||
var label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL);
|
||||
|
||||
if (label) {
|
||||
defaultText = label.textContent;
|
||||
}
|
||||
|
||||
return defaultText;
|
||||
};
|
||||
|
||||
var findFirstChildNode = function findFirstChildNode(element) {
|
||||
if (element.childNodes.length > 0) {
|
||||
var childNodes = [].slice.call(element.childNodes);
|
||||
|
||||
for (var i = 0; i < childNodes.length; i++) {
|
||||
var node = childNodes[i];
|
||||
|
||||
if (node.nodeType !== textNodeType) {
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
|
||||
var restoreDefaultText = function restoreDefaultText(input) {
|
||||
var defaultText = input.bsCustomFileInput.defaultText;
|
||||
var label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL);
|
||||
|
||||
if (label) {
|
||||
var element = findFirstChildNode(label);
|
||||
element.textContent = defaultText;
|
||||
}
|
||||
};
|
||||
|
||||
var fileApi = !!window.File;
|
||||
var FAKE_PATH = 'fakepath';
|
||||
var FAKE_PATH_SEPARATOR = '\\';
|
||||
|
||||
var getSelectedFiles = function getSelectedFiles(input) {
|
||||
if (input.hasAttribute('multiple') && fileApi) {
|
||||
return [].slice.call(input.files).map(function (file) {
|
||||
return file.name;
|
||||
}).join(', ');
|
||||
}
|
||||
|
||||
if (input.value.indexOf(FAKE_PATH) !== -1) {
|
||||
var splittedValue = input.value.split(FAKE_PATH_SEPARATOR);
|
||||
return splittedValue[splittedValue.length - 1];
|
||||
}
|
||||
|
||||
return input.value;
|
||||
};
|
||||
|
||||
function handleInputChange() {
|
||||
var label = this.parentNode.querySelector(Selector.CUSTOMFILELABEL);
|
||||
|
||||
if (label) {
|
||||
var element = findFirstChildNode(label);
|
||||
var inputValue = getSelectedFiles(this);
|
||||
|
||||
if (inputValue.length) {
|
||||
element.textContent = inputValue;
|
||||
} else {
|
||||
restoreDefaultText(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleFormReset() {
|
||||
var customFileList = [].slice.call(this.querySelectorAll(Selector.INPUT)).filter(function (input) {
|
||||
return !!input.bsCustomFileInput;
|
||||
});
|
||||
|
||||
for (var i = 0, len = customFileList.length; i < len; i++) {
|
||||
restoreDefaultText(customFileList[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var customProperty = 'bsCustomFileInput';
|
||||
var Event = {
|
||||
FORMRESET: 'reset',
|
||||
INPUTCHANGE: 'change'
|
||||
};
|
||||
var bsCustomFileInput = {
|
||||
init: function init(inputSelector, formSelector) {
|
||||
if (inputSelector === void 0) {
|
||||
inputSelector = Selector.CUSTOMFILE;
|
||||
}
|
||||
|
||||
if (formSelector === void 0) {
|
||||
formSelector = Selector.FORM;
|
||||
}
|
||||
|
||||
var customFileInputList = [].slice.call(document.querySelectorAll(inputSelector));
|
||||
var formList = [].slice.call(document.querySelectorAll(formSelector));
|
||||
|
||||
for (var i = 0, len = customFileInputList.length; i < len; i++) {
|
||||
var input = customFileInputList[i];
|
||||
Object.defineProperty(input, customProperty, {
|
||||
value: {
|
||||
defaultText: getDefaultText(input)
|
||||
},
|
||||
writable: true
|
||||
});
|
||||
handleInputChange.call(input);
|
||||
input.addEventListener(Event.INPUTCHANGE, handleInputChange);
|
||||
}
|
||||
|
||||
for (var _i = 0, _len = formList.length; _i < _len; _i++) {
|
||||
formList[_i].addEventListener(Event.FORMRESET, handleFormReset);
|
||||
|
||||
Object.defineProperty(formList[_i], customProperty, {
|
||||
value: true,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
},
|
||||
destroy: function destroy() {
|
||||
var formList = [].slice.call(document.querySelectorAll(Selector.FORM)).filter(function (form) {
|
||||
return !!form.bsCustomFileInput;
|
||||
});
|
||||
var customFileInputList = [].slice.call(document.querySelectorAll(Selector.INPUT)).filter(function (input) {
|
||||
return !!input.bsCustomFileInput;
|
||||
});
|
||||
|
||||
for (var i = 0, len = customFileInputList.length; i < len; i++) {
|
||||
var input = customFileInputList[i];
|
||||
restoreDefaultText(input);
|
||||
input[customProperty] = undefined;
|
||||
input.removeEventListener(Event.INPUTCHANGE, handleInputChange);
|
||||
}
|
||||
|
||||
for (var _i2 = 0, _len2 = formList.length; _i2 < _len2; _i2++) {
|
||||
formList[_i2].removeEventListener(Event.FORMRESET, handleFormReset);
|
||||
|
||||
formList[_i2][customProperty] = undefined;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return bsCustomFileInput;
|
||||
|
||||
})));
|
||||
//# sourceMappingURL=bs-custom-file-input.js.map
|
File diff suppressed because one or more lines are too long
7
account/theme/pages/plugins/bs-custom-file-input/bs-custom-file-input.min.js
vendored
Normal file
7
account/theme/pages/plugins/bs-custom-file-input/bs-custom-file-input.min.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/*!
|
||||
* bsCustomFileInput v1.3.4 (https://github.com/Johann-S/bs-custom-file-input)
|
||||
* Copyright 2018 - 2020 Johann-S <johann.servoire@gmail.com>
|
||||
* Licensed under MIT (https://github.com/Johann-S/bs-custom-file-input/blob/master/LICENSE)
|
||||
*/
|
||||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).bsCustomFileInput=t()}(this,function(){"use strict";var s={CUSTOMFILE:'.custom-file input[type="file"]',CUSTOMFILELABEL:".custom-file-label",FORM:"form",INPUT:"input"},l=function(e){if(0<e.childNodes.length)for(var t=[].slice.call(e.childNodes),n=0;n<t.length;n++){var l=t[n];if(3!==l.nodeType)return l}return e},u=function(e){var t=e.bsCustomFileInput.defaultText,n=e.parentNode.querySelector(s.CUSTOMFILELABEL);n&&(l(n).textContent=t)},n=!!window.File,r=function(e){if(e.hasAttribute("multiple")&&n)return[].slice.call(e.files).map(function(e){return e.name}).join(", ");if(-1===e.value.indexOf("fakepath"))return e.value;var t=e.value.split("\\");return t[t.length-1]};function d(){var e=this.parentNode.querySelector(s.CUSTOMFILELABEL);if(e){var t=l(e),n=r(this);n.length?t.textContent=n:u(this)}}function v(){for(var e=[].slice.call(this.querySelectorAll(s.INPUT)).filter(function(e){return!!e.bsCustomFileInput}),t=0,n=e.length;t<n;t++)u(e[t])}var p="bsCustomFileInput",m="reset",h="change";return{init:function(e,t){void 0===e&&(e=s.CUSTOMFILE),void 0===t&&(t=s.FORM);for(var n,l,r=[].slice.call(document.querySelectorAll(e)),i=[].slice.call(document.querySelectorAll(t)),o=0,u=r.length;o<u;o++){var c=r[o];Object.defineProperty(c,p,{value:{defaultText:(n=void 0,n="",(l=c.parentNode.querySelector(s.CUSTOMFILELABEL))&&(n=l.textContent),n)},writable:!0}),d.call(c),c.addEventListener(h,d)}for(var f=0,a=i.length;f<a;f++)i[f].addEventListener(m,v),Object.defineProperty(i[f],p,{value:!0,writable:!0})},destroy:function(){for(var e=[].slice.call(document.querySelectorAll(s.FORM)).filter(function(e){return!!e.bsCustomFileInput}),t=[].slice.call(document.querySelectorAll(s.INPUT)).filter(function(e){return!!e.bsCustomFileInput}),n=0,l=t.length;n<l;n++){var r=t[n];u(r),r[p]=void 0,r.removeEventListener(h,d)}for(var i=0,o=e.length;i<o;i++)e[i].removeEventListener(m,v),e[i][p]=void 0}}});
|
||||
//# sourceMappingURL=bs-custom-file-input.min.js.map
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user