diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a4f5a73 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,19 @@ +# Change Log + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +For previous release please refer to this [page](https://github.com/Johann-S/bs-custom-file-input/releases). + + +# 1.1.0 (2018-09-04) + + +### Bug Fixes + +* **core:** make properties private ([b1a5dab](https://github.com/Johann-S/bs-custom-file-input/commit/b1a5dab)) + + +### Features + +* **core:** add typescript definition ([#29](https://github.com/Johann-S/bs-custom-file-input/pull/29)) ([c8e5a01](https://github.com/Johann-S/bs-custom-file-input/commit/c8e5a01)) +* **core:** allow to pass custom selectors ([#25](https://github.com/Johann-S/bs-custom-file-input/issues/25)) ([85db226](https://github.com/Johann-S/bs-custom-file-input/commit/85db226)) diff --git a/dist/bs-custom-file-input.js b/dist/bs-custom-file-input.js index cddee6e..84f1ba6 100644 --- a/dist/bs-custom-file-input.js +++ b/dist/bs-custom-file-input.js @@ -1,5 +1,5 @@ /*! - * BsCustomFileInput v1.0.2 (https://github.com/Johann-S/bs-custom-file-input) + * bsCustomFileInput v1.1.0 (https://github.com/Johann-S/bs-custom-file-input) * Copyright 2018 Johann-S * Licensed under MIT (https://github.com/Johann-S/bs-custom-file-input/blob/master/LICENSE) */ @@ -65,16 +65,28 @@ } var Event = { + FORMRESET: 'reset', INPUTCHANGE: 'change', INPUTFOCUSIN: 'focusin', - INPUTFOCUSOUT: 'focusout', - FORMRESET: 'reset' + INPUTFOCUSOUT: 'focusout' }; var customProperty = 'bsCustomFileInput'; + var customFormSelector = null; + var customInputSelector = null; var bsCustomFileInput = { - init: function init() { - var customFileInputList = [].slice.call(document.querySelectorAll(Selector.CUSTOMFILE)); - var formList = [].slice.call(document.querySelectorAll(Selector.FORM)); + init: function init(inputSelector, formSelector) { + if (inputSelector === void 0) { + inputSelector = Selector.CUSTOMFILE; + } + + if (formSelector === void 0) { + formSelector = Selector.FORM; + } + + customInputSelector = inputSelector; + customFormSelector = formSelector; + var customFileInputList = [].slice.call(document.querySelectorAll(customInputSelector)); + var formList = [].slice.call(document.querySelectorAll(customFormSelector)); for (var i = 0, len = customFileInputList.length; i < len; i++) { var input = customFileInputList[i]; @@ -92,8 +104,8 @@ } }, destroy: function destroy() { - var formList = [].slice.call(document.querySelectorAll(Selector.FORM)); - var customFileInputList = [].slice.call(document.querySelectorAll(Selector.CUSTOMFILE)).filter(function (input) { + var formList = [].slice.call(document.querySelectorAll(customFormSelector)); + var customFileInputList = [].slice.call(document.querySelectorAll(customInputSelector)).filter(function (input) { return !!input.bsCustomFileInput; }); diff --git a/dist/bs-custom-file-input.js.map b/dist/bs-custom-file-input.js.map index 47cd3b0..0da0e5c 100644 --- a/dist/bs-custom-file-input.js.map +++ b/dist/bs-custom-file-input.js.map @@ -1 +1 @@ -{"version":3,"file":"bs-custom-file-input.js","sources":["../src/selector.js","../src/util.js","../src/eventHandlers.js","../src/index.js"],"sourcesContent":["const Selector = {\n CUSTOMFILE: '.custom-file input[type=\"file\"]',\n CUSTOMFILELABEL: '.custom-file-label',\n FORM: 'form',\n}\n\nexport default Selector\n","import Selector from './selector'\n\nconst getDefaultText = (input) => {\n let defaultText = ''\n\n const label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n defaultText = label.innerHTML\n }\n\n return defaultText\n}\n\nconst restoreDefaultText = (input) => {\n const defaultText = input.bsCustomFileInput.defaultText\n const label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n label.innerHTML = defaultText\n }\n}\n\nexport {\n getDefaultText,\n restoreDefaultText,\n}\n","import Selector from './selector'\nimport { restoreDefaultText } from './util'\n\nconst fileApi = !!window.File\n\nconst getSelectedFiles = (input) => {\n if (input.hasAttribute('multiple') && fileApi) {\n const files = [].slice.call(input.files)\n .map((file) => file.name)\n\n return files.join(', ')\n } else {\n return input.value\n }\n}\n\nfunction handleInputChange() {\n const label = this.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n label.innerHTML = getSelectedFiles(this)\n }\n}\n\nfunction handleFormReset() {\n const customFileList = [].slice.call(this.querySelectorAll(Selector.CUSTOMFILE))\n\n for (let i = 0, len = customFileList.length; i < len; i++) {\n restoreDefaultText(customFileList[i])\n }\n}\n\nexport {\n handleInputChange,\n handleFormReset,\n}\n","import { getDefaultText, restoreDefaultText } from './util'\nimport {\n handleFormReset,\n handleInputChange,\n} from './eventHandlers'\nimport Selector from './selector'\n\nconst Event = {\n INPUTCHANGE : 'change',\n INPUTFOCUSIN : 'focusin',\n INPUTFOCUSOUT : 'focusout',\n FORMRESET : 'reset',\n}\n\nconst customProperty = 'bsCustomFileInput'\n\nconst bsCustomFileInput = {\n init() {\n const customFileInputList = [].slice.call(document.querySelectorAll(Selector.CUSTOMFILE))\n const formList = [].slice.call(document.querySelectorAll(Selector.FORM))\n\n for (let i = 0, len = customFileInputList.length; i < len; i++) {\n const input = customFileInputList[i]\n\n Object.defineProperty(input, customProperty, {\n value: {\n defaultText: getDefaultText(input),\n },\n writable: true,\n })\n\n input.addEventListener(Event.INPUTCHANGE, handleInputChange)\n }\n\n for (let i = 0, len = formList.length; i < len; i++) {\n formList[i].addEventListener(Event.FORMRESET, handleFormReset)\n }\n },\n\n destroy() {\n const formList = [].slice.call(document.querySelectorAll(Selector.FORM))\n const customFileInputList = [].slice.call(document.querySelectorAll(Selector.CUSTOMFILE))\n .filter((input) => !!input.bsCustomFileInput)\n\n for (let i = 0, len = customFileInputList.length; i < len; i++) {\n const input = customFileInputList[i]\n\n restoreDefaultText(input)\n input[customProperty] = undefined\n\n input.removeEventListener(Event.INPUTCHANGE, handleInputChange)\n }\n\n for (let i = 0, len = formList.length; i < len; i++) {\n formList[i].removeEventListener(Event.FORMRESET, handleFormReset)\n }\n },\n}\n\nexport default bsCustomFileInput\n"],"names":["Selector","CUSTOMFILE","CUSTOMFILELABEL","FORM","getDefaultText","input","defaultText","label","parentNode","querySelector","innerHTML","restoreDefaultText","bsCustomFileInput","fileApi","window","File","getSelectedFiles","hasAttribute","files","slice","call","map","file","name","join","value","handleInputChange","handleFormReset","customFileList","querySelectorAll","i","len","length","Event","INPUTCHANGE","INPUTFOCUSIN","INPUTFOCUSOUT","FORMRESET","customProperty","init","customFileInputList","document","formList","Object","defineProperty","writable","addEventListener","destroy","filter","undefined","removeEventListener"],"mappings":";;;;;;;;;;;EAAA,IAAMA,QAAQ,GAAG;EACfC,EAAAA,UAAU,EAAE,iCADG;EAEfC,EAAAA,eAAe,EAAE,oBAFF;EAGfC,EAAAA,IAAI,EAAE;EAHS,CAAjB;;ECEA,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACC,KAAD,EAAW;EAChC,MAAIC,WAAW,GAAG,EAAlB;EAEA,MAAMC,KAAK,GAAGF,KAAK,CAACG,UAAN,CAAiBC,aAAjB,CAA+BT,QAAQ,CAACE,eAAxC,CAAd;;EAEA,MAAIK,KAAJ,EAAW;EACTD,IAAAA,WAAW,GAAGC,KAAK,CAACG,SAApB;EACD;;EAED,SAAOJ,WAAP;EACD,CAVD;;EAYA,IAAMK,kBAAkB,GAAG,SAArBA,kBAAqB,CAACN,KAAD,EAAW;EACpC,MAAMC,WAAW,GAAGD,KAAK,CAACO,iBAAN,CAAwBN,WAA5C;EACA,MAAMC,KAAK,GAAGF,KAAK,CAACG,UAAN,CAAiBC,aAAjB,CAA+BT,QAAQ,CAACE,eAAxC,CAAd;;EAEA,MAAIK,KAAJ,EAAW;EACTA,IAAAA,KAAK,CAACG,SAAN,GAAkBJ,WAAlB;EACD;EACF,CAPD;;ECXA,IAAMO,OAAO,GAAG,CAAC,CAACC,MAAM,CAACC,IAAzB;;EAEA,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAmB,CAACX,KAAD,EAAW;EAClC,MAAIA,KAAK,CAACY,YAAN,CAAmB,UAAnB,KAAkCJ,OAAtC,EAA+C;EAC7C,QAAMK,KAAK,GAAG,GAAGC,KAA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AR,EAAWC,GAAG,GAAGS,mBAAmB,CAACR,MAA1C,EAAkDF,CAAC,GAAGC,GAAtD,EAA2DD,CAAC,EAA5D,EAAgE;EAC9D,UAAMzB,KAAK,GAAGmC,mBAAmB,CAACV,CAAD,CAAjC;EAEAnB,MAAAA,kBAAkB,CAACN,KAAD,CAAlB;EACAA,MAAAA,KAAK,CAACiC,cAAD,CAAL,GAAwBW,SAAxB;EAEA5C,MAAAA,KAAK,CAAC6C,mBAAN,CAA0BjB,KAAK,CAACC,WAAhC,EAA6CR,iBAA7C;EACD;;EAED,SAAK,IAAII,GAAC,GAAG,CAAR,EAAWC,KAAG,GAAGW,QAAQ,CAACV,MAA/B,EAAuCF,GAAC,GAAGC,KAA3C,EAAgDD,GAAC,EAAjD,EAAqD;EACnDY,MAAAA,QAAQ,CAACZ,GAAD,CAAR,CAAYoB,mBAAZ,CAAgCjB,KAAK,CAACI,SAAtC,EAAiDV,eAAjD;EACD;EACF;EAxCuB,CAA1B;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"bs-custom-file-input.js","sources":["../src/selector.js","../src/util.js","../src/eventHandlers.js","../src/index.js"],"sourcesContent":["const Selector = {\n CUSTOMFILE: '.custom-file input[type=\"file\"]',\n CUSTOMFILELABEL: '.custom-file-label',\n FORM: 'form',\n}\n\nexport default Selector\n","import Selector from './selector'\n\nconst getDefaultText = (input) => {\n let defaultText = ''\n\n const label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n defaultText = label.innerHTML\n }\n\n return defaultText\n}\n\nconst restoreDefaultText = (input) => {\n const defaultText = input.bsCustomFileInput.defaultText\n const label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n label.innerHTML = defaultText\n }\n}\n\nexport {\n getDefaultText,\n restoreDefaultText,\n}\n","import Selector from './selector'\nimport { restoreDefaultText } from './util'\n\nconst fileApi = !!window.File\n\nconst getSelectedFiles = (input) => {\n if (input.hasAttribute('multiple') && fileApi) {\n const files = [].slice.call(input.files)\n .map((file) => file.name)\n\n return files.join(', ')\n } else {\n return input.value\n }\n}\n\nfunction handleInputChange() {\n const label = this.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n label.innerHTML = getSelectedFiles(this)\n }\n}\n\nfunction handleFormReset() {\n const customFileList = [].slice.call(this.querySelectorAll(Selector.CUSTOMFILE))\n\n for (let i = 0, len = customFileList.length; i < len; i++) {\n restoreDefaultText(customFileList[i])\n }\n}\n\nexport {\n handleInputChange,\n handleFormReset,\n}\n","import { getDefaultText, restoreDefaultText } from './util'\nimport {\n handleFormReset,\n handleInputChange,\n} from './eventHandlers'\nimport Selector from './selector'\n\nconst Event = {\n FORMRESET : 'reset',\n INPUTCHANGE : 'change',\n INPUTFOCUSIN : 'focusin',\n INPUTFOCUSOUT : 'focusout',\n}\n\nconst customProperty = 'bsCustomFileInput'\n\nlet customFormSelector = null\nlet customInputSelector = null\n\nconst bsCustomFileInput = {\n init(inputSelector = Selector.CUSTOMFILE, formSelector = Selector.FORM) {\n customInputSelector = inputSelector\n customFormSelector = formSelector\n\n const customFileInputList = [].slice.call(document.querySelectorAll(customInputSelector))\n const formList = [].slice.call(document.querySelectorAll(customFormSelector))\n\n for (let i = 0, len = customFileInputList.length; i < len; i++) {\n const input = customFileInputList[i]\n\n Object.defineProperty(input, customProperty, {\n value: {\n defaultText: getDefaultText(input),\n },\n writable: true,\n })\n\n input.addEventListener(Event.INPUTCHANGE, handleInputChange)\n }\n\n for (let i = 0, len = formList.length; i < len; i++) {\n formList[i].addEventListener(Event.FORMRESET, handleFormReset)\n }\n },\n\n destroy() {\n const formList = [].slice.call(document.querySelectorAll(customFormSelector))\n const customFileInputList = [].slice.call(document.querySelectorAll(customInputSelector))\n .filter((input) => !!input.bsCustomFileInput)\n\n for (let i = 0, len = customFileInputList.length; i < len; i++) {\n const input = customFileInputList[i]\n\n restoreDefaultText(input)\n input[customProperty] = undefined\n\n input.removeEventListener(Event.INPUTCHANGE, handleInputChange)\n }\n\n for (let i = 0, len = formList.length; i < len; i++) {\n formList[i].removeEventListener(Event.FORMRESET, handleFormReset)\n }\n },\n}\n\nexport default bsCustomFileInput\n"],"names":["Selector","CUSTOMFILE","CUSTOMFILELABEL","FORM","getDefaultText","input","defaultText","label","parentNode","querySelector","innerHTML","restoreDefaultText","bsCustomFileInput","fileApi","window","File","getSelectedFiles","hasAttribute","files","slice","call","map","file","name","join","value","handleInputChange","handleFormReset","customFileList","querySelectorAll","i","len","length","Event","FORMRESET","INPUTCHANGE","INPUTFOCUSIN","INPUTFOCUSOUT","customProperty","customFormSelector","customInputSelector","init","inputSelector","formSelector","customFileInputList","document","formList","Object","defineProperty","writable","addEventListener","destroy","filter","undefined","removeEventListener"],"mappings":";;;;;;;;;;;EAAA,IAAMA,QAAQ,GAAG;EACfC,EAAAA,UAAU,EAAE,iCADG;EAEfC,EAAAA,eAAe,EAAE,oBAFF;EAGfC,EAAAA,IAAI,EAAE;EAHS,CAAjB;;ECEA,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACC,KAAD,EAAW;EAChC,MAAIC,WAAW,GAAG,EAAlB;EAEA,MAAMC,KAAK,GAAGF,KAAK,CAACG,UAAN,CAAiBC,aAAjB,CAA+BT,QAAQ,CAACE,eAAxC,CAAd;;EAEA,MAAIK,KAAJ,EAAW;EACTD,IAAAA,WAAW,GAAGC,KAAK,CAACG,SAApB;EACD;;EAED,SAAOJ,WAAP;EACD,CAVD;;EAYA,IAAMK,kBAAkB,GAAG,SAArBA,kBAAqB,CAACN,KAAD,EAAW;EACpC,MAAMC,WAAW,GAAGD,KAAK,CAACO,iBAAN,CAAwBN,WAA5C;EACA,MAAMC,KAAK,GAAGF,KAAK,CAACG,UAAN,CAAiBC,aAAjB,CAA+BT,QAAQ,CAACE,eAAxC,CAAd;;EAEA,MAAIK,KAAJ,EAAW;EACTA,IAAAA,KAAK,CAACG,SAAN,GAAkBJ,WAAlB;EACD;EACF,CAPD;;ECXA,IAAMO,OAAO,GA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,CAAChB,EAAD,CAAR,CAAYoB,gBAAZ,CAA6BjB,KAAK,CAACC,SAAnC,EAA8CP,eAA9C;EACD;EACF,GAxBuB;EA0BxBwB,EAAAA,OA1BwB,qBA0Bd;EACR,QAAML,QAAQ,GAAG,GAAG3B,KAAH,CAASC,IAAT,CAAcyB,QAAQ,CAAChB,gBAAT,CAA0BU,kBAA1B,CAAd,CAAjB;EACA,QAAMK,mBAAmB,GAAG,GAAGzB,KAAH,CAASC,IAAT,CAAcyB,QAAQ,CAAChB,gBAAT,CAA0BW,mBAA1B,CAAd,EACzBY,MADyB,CAClB,UAAC/C,KAAD;EAAA,aAAW,CAAC,CAACA,KAAK,CAACO,iBAAnB;EAAA,KADkB,CAA5B;;EAGA,SAAK,IAAIkB,CAAC,GAAG,CAAR,EAAWC,GAAG,GAAGa,mBAAmB,CAACZ,MAA1C,EAAkDF,CAAC,GAAGC,GAAtD,EAA2DD,CAAC,EAA5D,EAAgE;EAC9D,UAAMzB,KAAK,GAAGuC,mBAAmB,CAACd,CAAD,CAAjC;EAEAnB,MAAAA,kBAAkB,CAACN,KAAD,CAAlB;EACAA,MAAAA,KAAK,CAACiC,cAAD,CAAL,GAAwBe,SAAxB;EAEAhD,MAAAA,KAAK,CAACiD,mBAAN,CAA0BrB,KAAK,CAACE,WAAhC,EAA6CT,iBAA7C;EACD;;EAED,SAAK,IAAII,GAAC,GAAG,CAAR,EAAWC,KAAG,GAAGe,QAAQ,CAACd,MAA/B,EAAuCF,GAAC,GAAGC,KAA3C,EAAgDD,GAAC,EAAjD,EAAqD;EACnDgB,MAAAA,QAAQ,CAAChB,GAAD,CAAR,CAAYwB,mBAAZ,CAAgCrB,KAAK,CAACC,SAAtC,EAAiDP,eAAjD;EACD;EACF;EA3CuB,CAA1B;;;;;;;;"} \ No newline at end of file diff --git a/dist/bs-custom-file-input.min.js b/dist/bs-custom-file-input.min.js index 2c2aa04..6241302 100644 --- a/dist/bs-custom-file-input.min.js +++ b/dist/bs-custom-file-input.min.js @@ -1,7 +1,7 @@ /*! - * BsCustomFileInput v1.0.2 (https://github.com/Johann-S/bs-custom-file-input) + * bsCustomFileInput v1.1.0 (https://github.com/Johann-S/bs-custom-file-input) * Copyright 2018 Johann-S * 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.bsCustomFileInput=t()}(this,function(){"use strict";var f={CUSTOMFILE:'.custom-file input[type="file"]',CUSTOMFILELABEL:".custom-file-label",FORM:"form"},u=function(e){var t=e.bsCustomFileInput.defaultText,n=e.parentNode.querySelector(f.CUSTOMFILELABEL);n&&(n.innerHTML=t)},t=!!window.File,n=function(e){return e.hasAttribute("multiple")&&t?[].slice.call(e.files).map(function(e){return e.name}).join(", "):e.value};function s(){var e=this.parentNode.querySelector(f.CUSTOMFILELABEL);e&&(e.innerHTML=n(this))}function d(){for(var e=[].slice.call(this.querySelectorAll(f.CUSTOMFILE)),t=0,n=e.length;t {\n let defaultText = ''\n\n const label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n defaultText = label.innerHTML\n }\n\n return defaultText\n}\n\nconst restoreDefaultText = (input) => {\n const defaultText = input.bsCustomFileInput.defaultText\n const label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n label.innerHTML = defaultText\n }\n}\n\nexport {\n getDefaultText,\n restoreDefaultText,\n}\n","import Selector from './selector'\nimport { restoreDefaultText } from './util'\n\nconst fileApi = !!window.File\n\nconst getSelectedFiles = (input) => {\n if (input.hasAttribute('multiple') && fileApi) {\n const files = [].slice.call(input.files)\n .map((file) => file.name)\n\n return files.join(', ')\n } else {\n return input.value\n }\n}\n\nfunction handleInputChange() {\n const label = this.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n label.innerHTML = getSelectedFiles(this)\n }\n}\n\nfunction handleFormReset() {\n const customFileList = [].slice.call(this.querySelectorAll(Selector.CUSTOMFILE))\n\n for (let i = 0, len = customFileList.length; i < len; i++) {\n restoreDefaultText(customFileList[i])\n }\n}\n\nexport {\n handleInputChange,\n handleFormReset,\n}\n","import { getDefaultText, restoreDefaultText } from './util'\nimport {\n handleFormReset,\n handleInputChange,\n} from './eventHandlers'\nimport Selector from './selector'\n\nconst Event = {\n INPUTCHANGE : 'change',\n INPUTFOCUSIN : 'focusin',\n INPUTFOCUSOUT : 'focusout',\n FORMRESET : 'reset',\n}\n\nconst customProperty = 'bsCustomFileInput'\n\nconst bsCustomFileInput = {\n init() {\n const customFileInputList = [].slice.call(document.querySelectorAll(Selector.CUSTOMFILE))\n const formList = [].slice.call(document.querySelectorAll(Selector.FORM))\n\n for (let i = 0, len = customFileInputList.length; i < len; i++) {\n const input = customFileInputList[i]\n\n Object.defineProperty(input, customProperty, {\n value: {\n defaultText: getDefaultText(input),\n },\n writable: true,\n })\n\n input.addEventListener(Event.INPUTCHANGE, handleInputChange)\n }\n\n for (let i = 0, len = formList.length; i < len; i++) {\n formList[i].addEventListener(Event.FORMRESET, handleFormReset)\n }\n },\n\n destroy() {\n const formList = [].slice.call(document.querySelectorAll(Selector.FORM))\n const customFileInputList = [].slice.call(document.querySelectorAll(Selector.CUSTOMFILE))\n .filter((input) => !!input.bsCustomFileInput)\n\n for (let i = 0, len = customFileInputList.length; i < len; i++) {\n const input = customFileInputList[i]\n\n restoreDefaultText(input)\n input[customProperty] = undefined\n\n input.removeEventListener(Event.INPUTCHANGE, handleInputChange)\n }\n\n for (let i = 0, len = formList.length; i < len; i++) {\n formList[i].removeEventListener(Event.FORMRESET, handleFormReset)\n }\n },\n}\n\nexport default bsCustomFileInput\n"],"names":["Selector","CUSTOMFILE","CUSTOMFILELABEL","FORM","restoreDefaultText","input","defaultText","bsCustomFileInput","label","parentNode","querySelector","innerHTML","fileApi","window","File","getSelectedFiles","hasAttribute","slice","call","files","map","file","name","join","value","handleInputChange","this","handleFormReset","customFileList","querySelectorAll","i","len","length","Event","customProperty","init","customFileInputList","document","formList","Object","defineProperty","writable","addEventListener","destroy","filter","undefined","removeEventListener"],"mappings":";;;;;6LAAA,IAAMA,EAAW,CACfC,WAAY,kCACZC,gBAAiB,qBACjBC,KAAM,QCWFC,EAAqB,SAACC,OACpBC,EAAcD,EAAME,kBAAkBD,YACtCE,EAAQH,EAAMI,WAAWC,cAAcV,EAASE,iBAElDM,IACFA,EAAMG,UAAYL,IChBhBM,IAAYC,OAAOC,KAEnBC,EAAmB,SAACV,UACpBA,EAAMW,aAAa,aAAeJ,EACtB,GAAGK,MAAMC,KAAKb,EAAMc,OAC/BC,IAAI,SAACC,UAASA,EAAKC,OAETC,KAAK,MAEXlB,EAAMmB,OAIjB,SAASC,QACDjB,EAAQkB,KAAKjB,WAAWC,cAAcV,EAASE,iBAEjDM,IACFA,EAAMG,UAAYI,EAAiBW,OAIvC,SAASC,YACDC,EAAiB,GAAGX,MAAMC,KAAKQ,KAAKG,iBAAiB7B,EAASC,aAE3D6B,EAAI,EAAGC,EAAMH,EAAeI,OAAQF,EAAIC,EAAKD,IACpD1B,EAAmBwB,EAAeE,ICrBtC,IAAMG,EACY,SADZA,EAIY,QAGZC,EAAiB,0BAEG,CACxBC,wBFfsB9B,EAClBC,EAEEE,EEaE4B,EAAsB,GAAGnB,MAAMC,KAAKmB,SAASR,iBAAiB7B,EAASC,aACvEqC,EAAW,GAAGrB,MAAMC,KAAKmB,SAASR,iBAAiB7B,EAASG,OAEzD2B,EAAI,EAAGC,EAAMK,EAAoBJ,OAAQF,EAAIC,EAAKD,IAAK,KACxDzB,EAAQ+B,EAAoBN,GAElCS,OAAOC,eAAenC,EAAO6B,EAAgB,CAC3CV,MAAO,CACLlB,aFxBcD,EEwBcA,EFvBhCC,OAAAA,OAEEE,EAFFF,EAAc,GAEZE,EAAQH,EAAMI,WAAWC,cAAcV,EAASE,iBAElDM,IACFF,EAAcE,EAAMG,WAGfL,IEiBDmC,UAAU,IAGZpC,EAAMqC,iBAAiBT,EAAmBR,OAGvC,IAAIK,EAAI,EAAGC,EAAMO,EAASN,OAAQF,EAAIC,EAAKD,IAC9CQ,EAASR,GAAGY,iBAAiBT,EAAiBN,IAIlDgB,2BACQL,EAAW,GAAGrB,MAAMC,KAAKmB,SAASR,iBAAiB7B,EAASG,OAC5DiC,EAAsB,GAAGnB,MAAMC,KAAKmB,SAASR,iBAAiB7B,EAASC,aAC1E2C,OAAO,SAACvC,WAAYA,EAAME,oBAEpBuB,EAAI,EAAGC,EAAMK,EAAoBJ,OAAQF,EAAIC,EAAKD,IAAK,KACxDzB,EAAQ+B,EAAoBN,GAElC1B,EAAmBC,GACnBA,EAAM6B,QAAkBW,EAExBxC,EAAMyC,oBAAoBb,EAAmBR,OAG1C,IAAIK,EAAI,EAAGC,EAAMO,EAASN,OAAQF,EAAIC,EAAKD,IAC9CQ,EAASR,GAAGgB,oBAAoBb,EAAiBN"} \ No newline at end of file +{"version":3,"file":"bs-custom-file-input.min.js","sources":["../src/selector.js","../src/util.js","../src/eventHandlers.js","../src/index.js"],"sourcesContent":["const Selector = {\n CUSTOMFILE: '.custom-file input[type=\"file\"]',\n CUSTOMFILELABEL: '.custom-file-label',\n FORM: 'form',\n}\n\nexport default Selector\n","import Selector from './selector'\n\nconst getDefaultText = (input) => {\n let defaultText = ''\n\n const label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n defaultText = label.innerHTML\n }\n\n return defaultText\n}\n\nconst restoreDefaultText = (input) => {\n const defaultText = input.bsCustomFileInput.defaultText\n const label = input.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n label.innerHTML = defaultText\n }\n}\n\nexport {\n getDefaultText,\n restoreDefaultText,\n}\n","import Selector from './selector'\nimport { restoreDefaultText } from './util'\n\nconst fileApi = !!window.File\n\nconst getSelectedFiles = (input) => {\n if (input.hasAttribute('multiple') && fileApi) {\n const files = [].slice.call(input.files)\n .map((file) => file.name)\n\n return files.join(', ')\n } else {\n return input.value\n }\n}\n\nfunction handleInputChange() {\n const label = this.parentNode.querySelector(Selector.CUSTOMFILELABEL)\n\n if (label) {\n label.innerHTML = getSelectedFiles(this)\n }\n}\n\nfunction handleFormReset() {\n const customFileList = [].slice.call(this.querySelectorAll(Selector.CUSTOMFILE))\n\n for (let i = 0, len = customFileList.length; i < len; i++) {\n restoreDefaultText(customFileList[i])\n }\n}\n\nexport {\n handleInputChange,\n handleFormReset,\n}\n","import { getDefaultText, restoreDefaultText } from './util'\nimport {\n handleFormReset,\n handleInputChange,\n} from './eventHandlers'\nimport Selector from './selector'\n\nconst Event = {\n FORMRESET : 'reset',\n INPUTCHANGE : 'change',\n INPUTFOCUSIN : 'focusin',\n INPUTFOCUSOUT : 'focusout',\n}\n\nconst customProperty = 'bsCustomFileInput'\n\nlet customFormSelector = null\nlet customInputSelector = null\n\nconst bsCustomFileInput = {\n init(inputSelector = Selector.CUSTOMFILE, formSelector = Selector.FORM) {\n customInputSelector = inputSelector\n customFormSelector = formSelector\n\n const customFileInputList = [].slice.call(document.querySelectorAll(customInputSelector))\n const formList = [].slice.call(document.querySelectorAll(customFormSelector))\n\n for (let i = 0, len = customFileInputList.length; i < len; i++) {\n const input = customFileInputList[i]\n\n Object.defineProperty(input, customProperty, {\n value: {\n defaultText: getDefaultText(input),\n },\n writable: true,\n })\n\n input.addEventListener(Event.INPUTCHANGE, handleInputChange)\n }\n\n for (let i = 0, len = formList.length; i < len; i++) {\n formList[i].addEventListener(Event.FORMRESET, handleFormReset)\n }\n },\n\n destroy() {\n const formList = [].slice.call(document.querySelectorAll(customFormSelector))\n const customFileInputList = [].slice.call(document.querySelectorAll(customInputSelector))\n .filter((input) => !!input.bsCustomFileInput)\n\n for (let i = 0, len = customFileInputList.length; i < len; i++) {\n const input = customFileInputList[i]\n\n restoreDefaultText(input)\n input[customProperty] = undefined\n\n input.removeEventListener(Event.INPUTCHANGE, handleInputChange)\n }\n\n for (let i = 0, len = formList.length; i < len; i++) {\n formList[i].removeEventListener(Event.FORMRESET, handleFormReset)\n }\n },\n}\n\nexport default bsCustomFileInput\n"],"names":["Selector","CUSTOMFILE","CUSTOMFILELABEL","FORM","restoreDefaultText","input","defaultText","bsCustomFileInput","label","parentNode","querySelector","innerHTML","fileApi","window","File","getSelectedFiles","hasAttribute","slice","call","files","map","file","name","join","value","handleInputChange","this","handleFormReset","customFileList","querySelectorAll","i","len","length","Event","customProperty","customFormSelector","customInputSelector","init","inputSelector","formSelector","customFileInputList","document","formList","Object","defineProperty","writable","addEventListener","destroy","filter","undefined","removeEventListener"],"mappings":";;;;;6LAAA,IAAMA,EAAW,CACfC,WAAY,kCACZC,gBAAiB,qBACjBC,KAAM,QCWFC,EAAqB,SAACC,OACpBC,EAAcD,EAAME,kBAAkBD,YACtCE,EAAQH,EAAMI,WAAWC,cAAcV,EAASE,iBAElDM,IACFA,EAAMG,UAAYL,IChBhBM,IAAYC,OAAOC,KAEnBC,EAAmB,SAACV,UACpBA,EAAMW,aAAa,aAAeJ,EACtB,GAAGK,MAAMC,KAAKb,EAAMc,OAC/BC,IAAI,SAACC,UAASA,EAAKC,OAETC,KAAK,MAEXlB,EAAMmB,OAIjB,SAASC,QACDjB,EAAQkB,KAAKjB,WAAWC,cAAcV,EAASE,iBAEjDM,IACFA,EAAMG,UAAYI,EAAiBW,OAIvC,SAASC,YACDC,EAAiB,GAAGX,MAAMC,KAAKQ,KAAKG,iBAAiB7B,EAASC,aAE3D6B,EAAI,EAAGC,EAAMH,EAAeI,OAAQF,EAAIC,EAAKD,IACpD1B,EAAmBwB,EAAeE,ICrBtC,IAAMG,EACY,QADZA,EAEY,SAKZC,EAAiB,oBAEnBC,EAAqB,KACrBC,EAAsB,WAEA,CACxBC,cAAKC,EAAqCC,YAArCD,IAAAA,EAAgBtC,EAASC,qBAAYsC,IAAAA,EAAevC,EAASG,MAChEiC,EAAsBE,EACtBH,EAAqBI,UFpBDlC,EAClBC,EAEEE,EEmBEgC,EAAsB,GAAGvB,MAAMC,KAAKuB,SAASZ,iBAAiBO,IAC9DM,EAAW,GAAGzB,MAAMC,KAAKuB,SAASZ,iBAAiBM,IAEhDL,EAAI,EAAGC,EAAMS,EAAoBR,OAAQF,EAAIC,EAAKD,IAAK,KACxDzB,EAAQmC,EAAoBV,GAElCa,OAAOC,eAAevC,EAAO6B,EAAgB,CAC3CV,MAAO,CACLlB,aF9BcD,EE8BcA,EF7BhCC,OAAAA,OAEEE,EAFFF,EAAc,GAEZE,EAAQH,EAAMI,WAAWC,cAAcV,EAASE,iBAElDM,IACFF,EAAcE,EAAMG,WAGfL,IEuBDuC,UAAU,IAGZxC,EAAMyC,iBAAiBb,EAAmBR,OAGvC,IAAIK,EAAI,EAAGC,EAAMW,EAASV,OAAQF,EAAIC,EAAKD,IAC9CY,EAASZ,GAAGgB,iBAAiBb,EAAiBN,IAIlDoB,2BACQL,EAAW,GAAGzB,MAAMC,KAAKuB,SAASZ,iBAAiBM,IACnDK,EAAsB,GAAGvB,MAAMC,KAAKuB,SAASZ,iBAAiBO,IACjEY,OAAO,SAAC3C,WAAYA,EAAME,oBAEpBuB,EAAI,EAAGC,EAAMS,EAAoBR,OAAQF,EAAIC,EAAKD,IAAK,KACxDzB,EAAQmC,EAAoBV,GAElC1B,EAAmBC,GACnBA,EAAM6B,QAAkBe,EAExB5C,EAAM6C,oBAAoBjB,EAAmBR,OAG1C,IAAIK,EAAI,EAAGC,EAAMW,EAASV,OAAQF,EAAIC,EAAKD,IAC9CY,EAASZ,GAAGoB,oBAAoBjB,EAAiBN"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d88fec9..00bc5a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bs-custom-file-input", - "version": "1.0.2", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1410aa2..9706b59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bs-custom-file-input", - "version": "1.0.2", + "version": "1.1.0", "description": "A little plugin for Bootstrap 4 custom file input", "author": "Johann-S ", "contributors": [ @@ -27,7 +27,8 @@ }, "files": [ "dist/*.{js,map}", - "bs-custom-file-input.d.ts" + "bs-custom-file-input.d.ts", + "CHANGELOG.md" ], "keywords": [ "bootstrap",