simp-select 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +3 -0
- package/.browserslistrc +3 -0
- package/.eslintignore +5 -0
- package/.eslintrc +29 -0
- package/README.md +107 -0
- package/dist/const.ts +42 -0
- package/dist/demo/index.html +63 -63
- package/dist/simpleSelect.d.ts +1 -0
- package/dist/simpleSelect.js +1 -1
- package/dist/simpleSelectItem.d.ts +7 -14
- package/dist/style.css +1 -1
- package/package.json +1 -6
- package/src/const/simpleSelection.const.ts +2 -3
- package/src/demo/index.html +263 -0
- package/src/polyfill.js +136 -0
- package/src/simpleSelect.ts +155 -0
- package/src/simpleSelectItem.ts +515 -0
- package/src/simpleSelectItemDOM.ts +623 -0
- package/src/style.css +416 -0
- package/src/utils/simpleSelection.utils.ts +74 -0
- package/src/utils/store.ts +60 -0
- package/tsconfig.json +16 -0
- package/webpack.config.js +74 -0
package/dist/style.css
CHANGED
@@ -1 +1 @@
|
|
1
|
-
:root{--simpS_bg:#fff;--simpS_pad_hor:15px;--simpS_height_top:40px;--simpS_color:#27272a;--simpS_color_light:#eae9e9;--simpS_color_cheked:#d9d7d7;--simpS_color_yes:green;--simpS_color_no:red;--simpS_color_placeholder:#5d5c5c;--simpS_color_dis:#8b8b8b;--simpS_radius:4px;--simpS_f_size:16px;--simpS_f_shadow:0 0 3px 0 var(--simpS_color);--simpS_size_check:20px;--simpS_li_h:36px;--simpS_btn_h:34px;--simpS_btn_bg:#f9f9f9;--simpS_btn_bg_reverse:#eeecec}.SimpleSel{-webkit-box-sizing:border-box;box-sizing:border-box;color:#27272a;color:var(--simpS_color);font-size:16px;font-size:var(--simpS_f_size);position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.SimpleSel--disabled{color:#8b8b8b;color:var(--simpS_color_dis);opacity:.8}.SimpleSel *,.SimpleSel :after,.SimpleSel :before,.SimpleSel__select_init{-webkit-box-sizing:border-box;box-sizing:border-box}.SimpleSel__select_init{height:100%;opacity:0;position:absolute;right:0;top:0;width:100%}.SimpleSel__select_init--native{z-index:5}.SimpleSel__bottom_control,.SimpleSel__control{-webkit-font-smoothing:inherit;-moz-osx-font-smoothing:inherit;-ms-flex-line-pack:center;-webkit-box-align:center;-ms-flex-align:center;-webkit-box-pack:center;-ms-flex-pack:center;align-content:center;align-items:center;-webkit-appearance:none;background-color:#f9f9f9;background-color:var(--simpS_btn_bg);border:none;border-radius:0;color:inherit;cursor:pointer;display:-webkit-box;display:-ms-flexbox;display:flex;font:inherit;height:34px;height:var(--simpS_btn_h);justify-content:center;line-height:normal;margin:0;outline:none;overflow:visible;padding:1px 10px;text-align:center;width:auto}.SimpleSel__bottom_control:hover,.SimpleSel__control:hover{background-color:#eeecec;background-color:var(--simpS_btn_bg_reverse)}.SimpleSel__list_item_icon,.SimpleSel__reset_all__icon,.SimpleSel__select_all__icon{-webkit-box-align:center;-ms-flex-align:center;-webkit-box-pack:center;-ms-flex-pack:center;align-items:center;border:1px solid;border-radius:4px;border-radius:var(--simpS_radius);display:-webkit-box;display:-ms-flexbox;display:flex;height:20px;height:var(--simpS_size_check);justify-content:center;margin-right:7px;position:relative;width:20px;width:var(--simpS_size_check)}.SimpleSel__list_item_icon:before,.SimpleSel__select_all__icon:before{border:solid;border-width:0 2px 2px 0;content:"";display:block;height:11px;height:calc(var(--simpS_size_check)/2 + 1px);left:4px;top:1px;-webkit-transform:rotate(45deg) translate(-17%,-10%);transform:rotate(45deg) translate(-17%,-10%);-webkit-transition:all .25s;transition:all .25s;width:6.66667px;width:calc(var(--simpS_size_check)/3)}.SimpleSel__top{position:relative}.SimpleSel__top_body{-webkit-box-align:center;-ms-flex-align:center;-webkit-box-pack:justify;-ms-flex-pack:justify;align-items:center;background-color:#fff;background-color:var(--simpS_bg);border:2px solid;border-radius:4px;border-radius:var(--simpS_radius);color:currentColor;cursor:pointer;display:-webkit-box;display:-ms-flexbox;display:flex;height:40px;height:var(--simpS_height_top);justify-content:space-between;padding:5px 0 5px 15px;padding:5px 0 5px var(--simpS_pad_hor);position:relative}.SimpleSel--disabled .SimpleSel__top_body{cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.SimpleSel__top_body:focus-visible{-webkit-box-shadow:0 0 3px 0 #27272a;box-shadow:0 0 3px 0 #27272a;-webkit-box-shadow:var(--simpS_f_shadow);box-shadow:var(--simpS_f_shadow)}.SimpleSel__title{-webkit-box-flex:1;-ms-flex:1;flex:1;overflow:hidden;text-align:left;text-overflow:ellipsis;white-space:nowrap}.SimpleSel__icon{-webkit-box-align:center;-ms-flex-align:center;-webkit-box-pack:center;-ms-flex-pack:center;align-items:center;display:-webkit-box;display:-ms-flexbox;display:flex;height:40px;height:var(--simpS_height_top);justify-content:center;position:relative;width:40px;width:var(--simpS_height_top)}.SimpleSel__icon:after{border-bottom:2px solid;border-right:2px solid;content:"";display:inline;height:.5em;left:50%;position:absolute;top:calc(50% - 2px);-webkit-transform:rotate(45deg) translate(-50%,-50%);transform:rotate(45deg) translate(-50%,-50%);-webkit-transform-origin:left top;transform-origin:left top;-webkit-transition:transform .25s,top .25s;transition:transform .25s,top .25s;width:.5em}.SimpleSel--open .SimpleSel__icon:after{top:calc(50% + 2px);-webkit-transform:rotate(225deg) translate(-50%,-50%);transform:rotate(225deg) translate(-50%,-50%)}.SimpleSel--single[data-count-checked-full="0"] .SimpleSel__title,.SimpleSel__list_item--not_value,.SimpleSel__title--placeholder{color:#5d5c5c;color:var(--simpS_color_placeholder)}.SimpleSel__body{background-color:#fff;background-color:var(--simpS_bg);border:1px solid;border-radius:4px;border-radius:var(--simpS_radius);max-height:0;opacity:0;overflow:hidden;overflow-y:auto;position:absolute;-webkit-transition:max-height .25s,opacity .1s;transition:max-height .25s,opacity .1s;width:100%;z-index:3}.SimpleSel:not(.SimpleSel--up) .SimpleSel--multi{margin-top:2px;top:100%}.SimpleSel--up:not(.SimpleSel--float) .SimpleSel__body{bottom:100%;margin-bottom:2px}.SimpleSel--open .SimpleSel__body{max-height:230px;opacity:1}.SimpleSel__search{border-radius:4px;border-radius:var(--simpS_radius);padding:2px 15px;padding:2px var(--simpS_pad_hor);width:100%}.SimpleSel__search--top{display:none;height:100%;left:0;opacity:0;position:absolute;top:0}.SimpleSel--open .SimpleSel__search--top{display:block;opacity:1}.SimpleSel__search--dropdown{border:none;border-bottom:1px solid;border-radius:0;height:34px;height:var(--simpS_btn_h)}.SimpleSel__controls{border-bottom:1px solid;display:-webkit-box;display:-ms-flexbox;display:flex}.SimpleSel__control{-webkit-box-flex:1;-ms-flex:1;flex:1}.SimpleSel__control+.SimpleSel__control{border-left:1px solid}.SimpleSel__select_all__icon{border-color:green;border-color:var(--simpS_color_yes);border-radius:50%;color:#d9d7d7;color:var(--simpS_color_cheked)}.SimpleSel[data-count-checked-full="0"] .SimpleSel__select_all__icon{color:#eae9e9;color:var(--simpS_color_light)}.SimpleSel[data-check-all-multi=yes] .SimpleSel__select_all__icon{color:green;color:var(--simpS_color_yes)}.SimpleSel__reset_all__icon{border-radius:50%;color:red;color:var(--simpS_color_no);position:relative}.SimpleSel__reset_all__icon:after,.SimpleSel__reset_all__icon:before{background-color:currentColor;content:" ";height:60%;left:8px;left:calc(var(--simpS_f_size)/2);position:absolute;width:2px}.SimpleSel__reset_all__icon:before{-webkit-transform:rotate(45deg);transform:rotate(45deg)}.SimpleSel__reset_all__icon:after{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.SimpleSel__bottom_controls{border-top:1px solid;bottom:0;display:-webkit-box;display:-ms-flexbox;display:flex;margin-top:5px;position:sticky}.SimpleSel__bottom_control--hide{display:none}.SimpleSel__bottom_control{-webkit-box-flex:1;-ms-flex:1;flex:1}.SimpleSel__bottom_control--ok{text-transform:uppercase}.SimpleSel__bottom_control+.SimpleSel__bottom_control{border-left:1px solid}.SimpleSel__list{list-style-type:none;margin:0;padding:0}.SimpleSel__group_items:not(:first-child){margin-top:5px}.SimpleSel__group_title{background-color:#eae9e9;background-color:var(--simpS_color_light);display:block;font-size:1.02em;font-weight:700;margin-bottom:2px;padding:6px 10px}.SimpleSel__group{list-style-type:none;margin:0;padding:0}.SimpleSel__list_item{cursor:pointer}.SimpleSel__list_item:not(:last-child){border-bottom:1px solid #eae9e9;border-bottom:1px solid var(--simpS_color_light)}.SimpleSel__list_item--disabled{cursor:default;opacity:.5}.SimpleSel__list_item_body{-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-ms-flexbox;display:flex;min-height:36px;min-height:var(--simpS_li_h);padding:5px 15px;padding:5px var(--simpS_pad_hor)}.SimpleSel__list_item_body:hover{background-color:#eae9e9;background-color:var(--simpS_color_light)}.SimpleSel--single .SimpleSel__list_item--checked{background-color:#d9d7d7;background-color:var(--simpS_color_cheked)}.SimpleSel__list_item:not(.SimpleSel__list_item--checked) .SimpleSel__list_item_icon:before{height:0;opacity:0;width:0}.SimpleSel__close{display:none}.SimpleSel--body_open{overflow:hidden;position:relative}.SimpleSel--float .SimpleSel__body{-webkit-box-orient:vertical;-webkit-box-direction:normal;display:none;-ms-flex-direction:column;flex-direction:column;left:50%;max-height:90%;max-width:90%;overflow:hidden;overflow-y:auto;position:fixed;top:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%)}.SimpleSel--open{z-index:7}.SimpleSel--float .SimpleSel__bottom_control--hide,.SimpleSel--float.SimpleSel--open .SimpleSel__body{display:-webkit-box;display:-ms-flexbox;display:flex}.SimpleSel--float .SimpleSel__list{-webkit-box-flex:1;-ms-flex:1;flex:1}
|
1
|
+
:root{--simpS_bg:#fff;--simpS_pad_hor:15px;--simpS_height_top:40px;--simpS_color:#27272a;--simpS_color_light:#eae9e9;--simpS_color_cheked:#d9d7d7;--simpS_color_yes:green;--simpS_color_no:red;--simpS_color_placeholder:#5d5c5c;--simpS_color_dis:#8b8b8b;--simpS_radius:4px;--simpS_f_size:16px;--simpS_f_shadow:0 0 3px 0 var(--simpS_color);--simpS_size_check:20px;--simpS_li_h:36px;--simpS_btn_h:34px;--simpS_btn_bg:#f9f9f9;--simpS_btn_bg_reverse:#eeecec}.SimpleSel{-webkit-box-sizing:border-box;box-sizing:border-box;color:#27272a;color:var(--simpS_color);font-size:16px;font-size:var(--simpS_f_size);position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.SimpleSel--disabled{color:#8b8b8b;color:var(--simpS_color_dis);opacity:.8}.SimpleSel *,.SimpleSel :after,.SimpleSel :before,.SimpleSel__select_init{-webkit-box-sizing:border-box;box-sizing:border-box}.SimpleSel__select_init{height:100%;opacity:0;position:absolute;right:0;top:0;width:100%}.SimpleSel__select_init--native{z-index:5}.SimpleSel__bottom_control,.SimpleSel__control{-webkit-font-smoothing:inherit;-moz-osx-font-smoothing:inherit;-ms-flex-line-pack:center;-webkit-box-align:center;-ms-flex-align:center;-webkit-box-pack:center;-ms-flex-pack:center;align-content:center;align-items:center;-webkit-appearance:none;background-color:#f9f9f9;background-color:var(--simpS_btn_bg);border:none;border-radius:0;color:inherit;cursor:pointer;display:-webkit-box;display:-ms-flexbox;display:flex;font:inherit;height:34px;height:var(--simpS_btn_h);justify-content:center;line-height:normal;margin:0;outline:none;overflow:visible;padding:1px 10px;text-align:center;width:auto}.SimpleSel__bottom_control:hover,.SimpleSel__control:hover{background-color:#eeecec;background-color:var(--simpS_btn_bg_reverse)}.SimpleSel__list_item_icon,.SimpleSel__reset_all__icon,.SimpleSel__select_all__icon{-webkit-box-align:center;-ms-flex-align:center;-webkit-box-pack:center;-ms-flex-pack:center;align-items:center;border:1px solid;border-radius:4px;border-radius:var(--simpS_radius);display:-webkit-box;display:-ms-flexbox;display:flex;height:20px;height:var(--simpS_size_check);justify-content:center;margin-right:7px;position:relative;width:20px;width:var(--simpS_size_check)}.SimpleSel__list_item_icon:before,.SimpleSel__select_all__icon:before{border:solid;border-width:0 2px 2px 0;content:"";display:block;height:11px;height:calc(var(--simpS_size_check)/2 + 1px);left:4px;top:1px;-webkit-transform:rotate(45deg) translate(-17%,-10%);transform:rotate(45deg) translate(-17%,-10%);-webkit-transition:all .25s;transition:all .25s;width:6.66667px;width:calc(var(--simpS_size_check)/3)}.SimpleSel__top{position:relative}.SimpleSel__top_body{-webkit-box-align:center;-ms-flex-align:center;-webkit-box-pack:justify;-ms-flex-pack:justify;align-items:center;background-color:#fff;background-color:var(--simpS_bg);border:2px solid;border-radius:4px;border-radius:var(--simpS_radius);color:currentColor;cursor:pointer;display:-webkit-box;display:-ms-flexbox;display:flex;height:40px;height:var(--simpS_height_top);justify-content:space-between;padding:5px 0 5px 15px;padding:5px 0 5px var(--simpS_pad_hor);position:relative}.SimpleSel--disabled .SimpleSel__top_body{cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.SimpleSel__top_body:focus-visible{-webkit-box-shadow:0 0 3px 0 #27272a;box-shadow:0 0 3px 0 #27272a;-webkit-box-shadow:var(--simpS_f_shadow);box-shadow:var(--simpS_f_shadow)}.SimpleSel__title{-webkit-box-flex:1;-ms-flex:1;flex:1;overflow:hidden;text-align:left;text-overflow:ellipsis;white-space:nowrap}.SimpleSel__icon{-webkit-box-align:center;-ms-flex-align:center;-webkit-box-pack:center;-ms-flex-pack:center;align-items:center;display:-webkit-box;display:-ms-flexbox;display:flex;height:40px;height:var(--simpS_height_top);justify-content:center;position:relative;width:40px;width:var(--simpS_height_top)}.SimpleSel__icon:after{border-bottom:2px solid;border-right:2px solid;content:"";display:inline;height:.5em;left:50%;position:absolute;top:calc(50% - 2px);-webkit-transform:rotate(45deg) translate(-50%,-50%);transform:rotate(45deg) translate(-50%,-50%);-webkit-transform-origin:left top;transform-origin:left top;-webkit-transition:transform .25s,top .25s;transition:transform .25s,top .25s;width:.5em}.SimpleSel--open .SimpleSel__icon:after{top:calc(50% + 2px);-webkit-transform:rotate(225deg) translate(-50%,-50%);transform:rotate(225deg) translate(-50%,-50%)}.SimpleSel--single[data-count-checked-full="0"] .SimpleSel__title,.SimpleSel__list_item--not_value,.SimpleSel__title--placeholder{color:#5d5c5c;color:var(--simpS_color_placeholder)}.SimpleSel__body{background-color:#fff;background-color:var(--simpS_bg);border:1px solid;border-radius:4px;border-radius:var(--simpS_radius);max-height:0;opacity:0;overflow:hidden;overflow-y:auto;position:absolute;-webkit-transition:max-height .25s,opacity .1s;transition:max-height .25s,opacity .1s;width:100%;z-index:3}.SimpleSel:not(.SimpleSel--up) .SimpleSel--multi{margin-top:2px;top:100%}.SimpleSel--up:not(.SimpleSel--float) .SimpleSel__body{bottom:100%;margin-bottom:2px}.SimpleSel--open .SimpleSel__body{max-height:230px;opacity:1}.SimpleSel__search{border-radius:4px;border-radius:var(--simpS_radius);padding:2px 15px;padding:2px var(--simpS_pad_hor);width:100%}.SimpleSel__search--top{display:none;height:100%;left:0;opacity:0;position:absolute;top:0}.SimpleSel--open .SimpleSel__search--top{display:block;opacity:1}.SimpleSel__search--dropdown{border:none;border-bottom:1px solid;border-radius:0;height:34px;height:var(--simpS_btn_h)}.SimpleSel__controls{border-bottom:1px solid;display:-webkit-box;display:-ms-flexbox;display:flex}.SimpleSel__control{-webkit-box-flex:1;-ms-flex:1;flex:1}.SimpleSel__control+.SimpleSel__control{border-left:1px solid}.SimpleSel__select_all__icon{border-color:green;border-color:var(--simpS_color_yes);border-radius:50%;color:#d9d7d7;color:var(--simpS_color_cheked)}.SimpleSel[data-count-checked-full="0"] .SimpleSel__select_all__icon{color:#eae9e9;color:var(--simpS_color_light)}.SimpleSel[data-check-all-multi=yes] .SimpleSel__select_all__icon{color:green;color:var(--simpS_color_yes)}.SimpleSel__reset_all__icon{border-radius:50%;color:red;color:var(--simpS_color_no);position:relative}.SimpleSel__reset_all__icon:after,.SimpleSel__reset_all__icon:before{background-color:currentColor;content:" ";height:60%;left:8px;left:calc(var(--simpS_f_size)/2);position:absolute;width:2px}.SimpleSel__reset_all__icon:before{-webkit-transform:rotate(45deg);transform:rotate(45deg)}.SimpleSel__reset_all__icon:after{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.SimpleSel__bottom_controls{border-top:1px solid;bottom:0;display:-webkit-box;display:-ms-flexbox;display:flex;margin-top:5px;position:sticky}.SimpleSel__bottom_controls--hide{display:none!important}.SimpleSel__bottom_control--hide{display:none}.SimpleSel__bottom_control{-webkit-box-flex:1;-ms-flex:1;flex:1}.SimpleSel__bottom_control--ok{text-transform:uppercase}.SimpleSel__bottom_control+.SimpleSel__bottom_control{border-left:1px solid}.SimpleSel__list{list-style-type:none;margin:0;padding:0}.SimpleSel__group_items:not(:first-child){margin-top:5px}.SimpleSel__group_title{background-color:#eae9e9;background-color:var(--simpS_color_light);display:block;font-size:1.02em;font-weight:700;margin-bottom:2px;padding:6px 10px}.SimpleSel__group{list-style-type:none;margin:0;padding:0}.SimpleSel__list_item{cursor:pointer}.SimpleSel__list_item:not(:last-child){border-bottom:1px solid #eae9e9;border-bottom:1px solid var(--simpS_color_light)}.SimpleSel__list_item--disabled{cursor:default;opacity:.5}.SimpleSel__list_item_body{-webkit-box-align:center;-ms-flex-align:center;align-items:center;display:-webkit-box;display:-ms-flexbox;display:flex;min-height:36px;min-height:var(--simpS_li_h);padding:5px 15px;padding:5px var(--simpS_pad_hor)}.SimpleSel__list_item_body:hover{background-color:#eae9e9;background-color:var(--simpS_color_light)}.SimpleSel--single .SimpleSel__list_item--checked{background-color:#d9d7d7;background-color:var(--simpS_color_cheked)}.SimpleSel__list_item:not(.SimpleSel__list_item--checked) .SimpleSel__list_item_icon:before{height:0;opacity:0;width:0}.SimpleSel__close{display:none}.SimpleSel--body_open{overflow:hidden;position:relative}.SimpleSel--float .SimpleSel__body{-webkit-box-orient:vertical;-webkit-box-direction:normal;display:none;-ms-flex-direction:column;flex-direction:column;left:50%;max-height:90%;max-width:90%;overflow:hidden;overflow-y:auto;position:fixed;top:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%)}.SimpleSel--open{z-index:7}.SimpleSel--float .SimpleSel__bottom_control--hide,.SimpleSel--float.SimpleSel--open .SimpleSel__body{display:-webkit-box;display:-ms-flexbox;display:flex}.SimpleSel--float .SimpleSel__list{-webkit-box-flex:1;-ms-flex:1;flex:1}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "simp-select",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.6",
|
4
4
|
"description": "simp-select - this plugin replaces the select",
|
5
5
|
"main": "dist/simpleSelect.js",
|
6
6
|
"types": "dist/simpleSelect.d.ts",
|
@@ -10,11 +10,6 @@
|
|
10
10
|
"dev": "webpack --env development --watch",
|
11
11
|
"build": "webpack --env production"
|
12
12
|
},
|
13
|
-
"files": [
|
14
|
-
"dist",
|
15
|
-
"src/const",
|
16
|
-
"src/types"
|
17
|
-
],
|
18
13
|
"repository": {
|
19
14
|
"type": "git",
|
20
15
|
"url": "https://github.com/yura-brd/SimpSelect"
|
@@ -8,15 +8,14 @@ export const simpleSelectLocale: ISimpleSelectLocale = {
|
|
8
8
|
all: 'all',
|
9
9
|
ok: 'Ok',
|
10
10
|
cansel: 'Cansel',
|
11
|
-
|
12
11
|
selectAll: 'Select all',
|
13
12
|
resetAll: 'Reset all',
|
14
13
|
};
|
15
14
|
export const simpleSelectionOptions: ISimpleSelectOptions = {
|
16
|
-
isSearch:
|
15
|
+
isSearch: false,
|
17
16
|
isSearchInDropdown: false,
|
18
17
|
|
19
|
-
countShowSelected:
|
18
|
+
countShowSelected: 3,
|
20
19
|
isConfirmInMulti: false,
|
21
20
|
isConfirmInMultiOkClickOutside: false,
|
22
21
|
|
@@ -0,0 +1,263 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport"
|
6
|
+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
7
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
8
|
+
<title>Document</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="../style.css" />
|
11
|
+
|
12
|
+
<script src="../simpleSelect.js"></script>
|
13
|
+
|
14
|
+
</head>
|
15
|
+
|
16
|
+
<style>
|
17
|
+
|
18
|
+
#app {
|
19
|
+
/* temp*/
|
20
|
+
width: 250px;
|
21
|
+
margin: 0 auto;
|
22
|
+
}
|
23
|
+
|
24
|
+
#app {
|
25
|
+
margin-bottom: 30px;
|
26
|
+
border-bottom: 1px solid;
|
27
|
+
text-align: center;
|
28
|
+
padding-bottom: 10px;
|
29
|
+
}
|
30
|
+
|
31
|
+
.items {
|
32
|
+
display: flex;
|
33
|
+
flex-wrap: wrap;
|
34
|
+
justify-content: center;
|
35
|
+
gap: 10px;
|
36
|
+
margin: 20px auto;
|
37
|
+
max-width: 600px;
|
38
|
+
}
|
39
|
+
.item {
|
40
|
+
width: 250px;
|
41
|
+
}
|
42
|
+
</style>
|
43
|
+
<body>
|
44
|
+
<div id="app"></div>
|
45
|
+
|
46
|
+
<div class="items">
|
47
|
+
<div class="item">
|
48
|
+
<select id="select_first"
|
49
|
+
disabled
|
50
|
+
multiple>
|
51
|
+
<option value="a1">a 1</option>
|
52
|
+
<option value="a2">a 2</option>
|
53
|
+
<option value="a3">a 3</option>
|
54
|
+
<option value="a4">a 4</option>
|
55
|
+
<option value="a5">a 5</option>
|
56
|
+
</select>
|
57
|
+
</div>
|
58
|
+
<div class="item">
|
59
|
+
<select multiple
|
60
|
+
data-simple-placeholder="custom placeholder"
|
61
|
+
data-simple-is-confirm="false"
|
62
|
+
data-simple-count-shows-selected="3">
|
63
|
+
<option value="a1"
|
64
|
+
data-simple-html-before="<span>|before| </span>"
|
65
|
+
data-simple-html-after="<span> |after|</div>"
|
66
|
+
>b 1</option>
|
67
|
+
<option value="a22" disabled="disabled">b 2 dis</option>
|
68
|
+
<option value="a3">b 3</option>
|
69
|
+
<option value="a4">b 4</option>
|
70
|
+
<option value="a5">b 5</option>
|
71
|
+
</select>
|
72
|
+
</div>
|
73
|
+
<div class="item" >
|
74
|
+
<select id="select_second"
|
75
|
+
data-simple-is-confirm="false"
|
76
|
+
|
77
|
+
data-simple-reset-all="false"
|
78
|
+
data-simple-select-all="true"
|
79
|
+
data-simple-item-html-before="<span>before</span>"
|
80
|
+
multiple data-simple-debounce-time="1000">
|
81
|
+
<optgroup label="Группа 1">
|
82
|
+
<option value="1.1">multiple Опция 1.1</option>
|
83
|
+
</optgroup>
|
84
|
+
<optgroup label="Группа 2">
|
85
|
+
<option value="2.1">multiple Опция 2.1</option>
|
86
|
+
<option value="2.2">multiple Опция 2.2</option>
|
87
|
+
</optgroup>
|
88
|
+
<optgroup label="Группа 3" disabled>
|
89
|
+
<option value="3.1">multiple Опция 3.1</option>
|
90
|
+
<option value="3.2">multiple Опция 3.2</option>
|
91
|
+
<option value="3.3">multiple Опция 3.3</option>
|
92
|
+
</optgroup>
|
93
|
+
</select>
|
94
|
+
</div>
|
95
|
+
|
96
|
+
<div class="item">
|
97
|
+
<select
|
98
|
+
|
99
|
+
data-simple-select-search-dropdown="true"
|
100
|
+
data-simple-show-checkbox="true"
|
101
|
+
class="color_red"
|
102
|
+
data-simple-add-classes="class1"
|
103
|
+
|
104
|
+
data-simple-select-search="false"
|
105
|
+
>
|
106
|
+
<optgroup label="Группа 1">
|
107
|
+
<option value="1">Опция 1.1</option>
|
108
|
+
</optgroup>
|
109
|
+
<optgroup label="Группа 2">
|
110
|
+
<option value="1">Опция 2.1</option>
|
111
|
+
<option value="1">Опция 2.2</option>
|
112
|
+
</optgroup>
|
113
|
+
<optgroup label="Группа 3" disabled>
|
114
|
+
<option value="1">Опция 3.1</option>
|
115
|
+
<option value="1">Опция 3.2</option>
|
116
|
+
<option value="1">Опция 3.3</option>
|
117
|
+
</optgroup>
|
118
|
+
</select>
|
119
|
+
</div>
|
120
|
+
|
121
|
+
<div class="item">
|
122
|
+
<select
|
123
|
+
data-simple-add-classes="class1 class2"
|
124
|
+
data-simple-item-html-before="<div>before</div>"
|
125
|
+
data-simple-item-html-after="<div>after</div>"
|
126
|
+
data-simple-select-search-dropdown="true"
|
127
|
+
data-simple-up="true"
|
128
|
+
>
|
129
|
+
<option>Опция 5.1</option>
|
130
|
+
<option>Опция 5.2</option>
|
131
|
+
</select>
|
132
|
+
</div>
|
133
|
+
|
134
|
+
|
135
|
+
<!--
|
136
|
+
|
137
|
+
<select
|
138
|
+
data-simple-select-search
|
139
|
+
data-simple-select-search-dropdown
|
140
|
+
data-simple-count-shows-selected="3"
|
141
|
+
data-simple-is-confirm="true" // only multiselect
|
142
|
+
data-simple-debounce-time="1000" // only multiselect
|
143
|
+
data-simple-placeholder="text"
|
144
|
+
data-simple-reset-all="true" // only multiselect
|
145
|
+
data-simple-select-all="true" // only multiselect
|
146
|
+
!data-simple-show-checkbox="true" // only not multiselect
|
147
|
+
|
148
|
+
!data-simple-item-html-before="<div>before</div>"
|
149
|
+
!data-simple-item-html-after="<div>after</div>"
|
150
|
+
!data-simple-add-classes="class1 class2"
|
151
|
+
|
152
|
+
data-simple-float-width="1000"
|
153
|
+
data-simple-up="true"
|
154
|
+
|
155
|
+
></select>
|
156
|
+
-->
|
157
|
+
<!--
|
158
|
+
<div class="wrapper">
|
159
|
+
<select></select>
|
160
|
+
<div class="wrapper__top">
|
161
|
+
<div class="wrapper__top_body"></div>
|
162
|
+
*? <div class="wrapper__search"></div>
|
163
|
+
</div>
|
164
|
+
* <div class="wrapper__body">
|
165
|
+
? <div class="wrapper__search"></div>
|
166
|
+
? <div class="wrapper__setting"></div>
|
167
|
+
<div class="wrapper__list_items">
|
168
|
+
тут или список или группа списков
|
169
|
+
</div>
|
170
|
+
? <div class="wrapper__setting_bottom"></div>
|
171
|
+
</div>
|
172
|
+
</div>
|
173
|
+
-->
|
174
|
+
</div>
|
175
|
+
|
176
|
+
<script>
|
177
|
+
|
178
|
+
const sel = new SimpleSelect('select', {
|
179
|
+
// callbackOpen: (item) => {
|
180
|
+
// console.log('open', item);
|
181
|
+
// },
|
182
|
+
// callbackClose: (item) => {
|
183
|
+
// console.log('close', item);
|
184
|
+
// },
|
185
|
+
// callbackDestroy: (item) => {
|
186
|
+
// console.log('callbackDestroy', item);
|
187
|
+
// },
|
188
|
+
// // detectNative: () => {
|
189
|
+
// // return false;
|
190
|
+
// // },
|
191
|
+
// callbackChangeSelect: (e, that) => {
|
192
|
+
// console.group();
|
193
|
+
// console.log(e);
|
194
|
+
// console.log(that);
|
195
|
+
// console.groupEnd();
|
196
|
+
// },
|
197
|
+
|
198
|
+
// isUp: true,
|
199
|
+
// sepChars: ',',
|
200
|
+
// // changeBodyLi: (liBody:HTMLDivElement, option: HTMLOptionElement) => {
|
201
|
+
// return liBody
|
202
|
+
// }
|
203
|
+
// debounceTime: 2000
|
204
|
+
})
|
205
|
+
// @ts-ignore
|
206
|
+
// window['sel'] = sel;
|
207
|
+
//
|
208
|
+
// setTimeout(() => {
|
209
|
+
// console.log('first', sel.getSelectFirst());
|
210
|
+
//
|
211
|
+
// const second = document.getElementById('select_second');
|
212
|
+
//
|
213
|
+
// const id = second.getAttribute('data-simple-select-init');
|
214
|
+
//
|
215
|
+
// console.log('by id', sel.getSelectById(id));
|
216
|
+
// }, 1500)
|
217
|
+
//
|
218
|
+
// const app = document.querySelector('#app')
|
219
|
+
// const select = document.createElement('select');
|
220
|
+
// select.innerHTML = '<option value="1">1</option><option value="2">2</option>'
|
221
|
+
// app.innerHTML = `
|
222
|
+
// <div>
|
223
|
+
// <select class="addSelect">
|
224
|
+
// <option selected>new option 0</option>
|
225
|
+
// <option value='1'>new option</option>
|
226
|
+
// <option value='2'>new option2</option>
|
227
|
+
// <option value='3'>new option3</option>
|
228
|
+
// <select>
|
229
|
+
// </div>
|
230
|
+
// `
|
231
|
+
// app.append(select);
|
232
|
+
// const sel3 = new SimpleSelect(select)
|
233
|
+
// window['sel3'] = sel3;
|
234
|
+
//
|
235
|
+
// setTimeout(() => {
|
236
|
+
// const sel2 = new SimpleSelect('.addSelect', {
|
237
|
+
// locale: {
|
238
|
+
// noSearch: 'Не найдено: ',
|
239
|
+
// searchText: 'Поиск',
|
240
|
+
// title: 'Выбрать',
|
241
|
+
// selected: 'Выбрано:',
|
242
|
+
// all: 'все',
|
243
|
+
// cansel: 'Отмена',
|
244
|
+
// ok: 'OK',
|
245
|
+
// resetAll: 'reset all',
|
246
|
+
// selectAll: 'select all'
|
247
|
+
// }
|
248
|
+
// })
|
249
|
+
// window['sel2'] = sel2;
|
250
|
+
// }, 500)
|
251
|
+
|
252
|
+
// setupCounter(document.querySelector<HTMLButtonElement>('#counter')!)
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
</script>
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
</body>
|
263
|
+
</html>
|
package/src/polyfill.js
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
if (!Array.from) {
|
2
|
+
Array.from = (function () {
|
3
|
+
var toStr = Object.prototype.toString;
|
4
|
+
var isCallable = function (fn) {
|
5
|
+
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
|
6
|
+
};
|
7
|
+
var toInteger = function (value) {
|
8
|
+
var number = Number(value);
|
9
|
+
if (isNaN(number)) { return 0; }
|
10
|
+
if (number === 0 || !isFinite(number)) { return number; }
|
11
|
+
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
|
12
|
+
};
|
13
|
+
var maxSafeInteger = Math.pow(2, 53) - 1;
|
14
|
+
var toLength = function (value) {
|
15
|
+
var len = toInteger(value);
|
16
|
+
return Math.min(Math.max(len, 0), maxSafeInteger);
|
17
|
+
};
|
18
|
+
|
19
|
+
return function from(arrayLike/*, mapFn, thisArg */) {
|
20
|
+
var C = this;
|
21
|
+
|
22
|
+
var items = Object(arrayLike);
|
23
|
+
|
24
|
+
if (arrayLike == null) {
|
25
|
+
throw new TypeError('Array.from requires an array-like object - not null or undefined');
|
26
|
+
}
|
27
|
+
|
28
|
+
var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
|
29
|
+
var T;
|
30
|
+
if (typeof mapFn !== 'undefined') {
|
31
|
+
if (!isCallable(mapFn)) {
|
32
|
+
throw new TypeError('Array.from: when provided, the second argument must be a function');
|
33
|
+
}
|
34
|
+
|
35
|
+
if (arguments.length > 2) {
|
36
|
+
T = arguments[2];
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
var len = toLength(items.length);
|
41
|
+
|
42
|
+
|
43
|
+
var A = isCallable(C) ? Object(new C(len)) : new Array(len);
|
44
|
+
|
45
|
+
var k = 0;
|
46
|
+
var kValue;
|
47
|
+
while (k < len) {
|
48
|
+
kValue = items[k];
|
49
|
+
if (mapFn) {
|
50
|
+
A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
|
51
|
+
} else {
|
52
|
+
A[k] = kValue;
|
53
|
+
}
|
54
|
+
k += 1;
|
55
|
+
}
|
56
|
+
A.length = len;
|
57
|
+
return A;
|
58
|
+
};
|
59
|
+
}());
|
60
|
+
}
|
61
|
+
|
62
|
+
if (!Array.prototype.forEach) {
|
63
|
+
Array.prototype.forEach = function (callback, thisArg) {
|
64
|
+
var T, k;
|
65
|
+
|
66
|
+
if (this == null) {
|
67
|
+
throw new TypeError(" this is null or not defined");
|
68
|
+
}
|
69
|
+
|
70
|
+
var O = Object(this);
|
71
|
+
|
72
|
+
var len = O.length >>> 0;
|
73
|
+
|
74
|
+
if (typeof callback !== "function") {
|
75
|
+
throw new TypeError(callback + " is not a function");
|
76
|
+
}
|
77
|
+
|
78
|
+
if (arguments.length > 1) {
|
79
|
+
T = thisArg;
|
80
|
+
}
|
81
|
+
|
82
|
+
k = 0;
|
83
|
+
|
84
|
+
while (k < len) {
|
85
|
+
var kValue;
|
86
|
+
|
87
|
+
if (k in O) {
|
88
|
+
kValue = O[k];
|
89
|
+
|
90
|
+
callback.call(T, kValue, k, O);
|
91
|
+
}
|
92
|
+
k++;
|
93
|
+
}
|
94
|
+
};
|
95
|
+
}
|
96
|
+
|
97
|
+
if (typeof window !== 'undefined' && window.NodeList && !NodeList.prototype.forEach) {
|
98
|
+
NodeList.prototype.forEach = function (callback, thisArg) {
|
99
|
+
thisArg = thisArg || window;
|
100
|
+
for (var i = 0; i < this.length; i++) {
|
101
|
+
callback.call(thisArg, this[i], i, this);
|
102
|
+
}
|
103
|
+
};
|
104
|
+
}
|
105
|
+
|
106
|
+
if (!Element.prototype.matches) {
|
107
|
+
Element.prototype.matches = Element.prototype.msMatchesSelector ||
|
108
|
+
Element.prototype.webkitMatchesSelector;
|
109
|
+
}
|
110
|
+
|
111
|
+
if (!Element.prototype.closest) {
|
112
|
+
Element.prototype.closest = function(s) {
|
113
|
+
var el = this;
|
114
|
+
|
115
|
+
do {
|
116
|
+
if (Element.prototype.matches.call(el, s)) return el;
|
117
|
+
el = el.parentElement || el.parentNode;
|
118
|
+
} while (el !== null && el.nodeType === 1);
|
119
|
+
return null;
|
120
|
+
};
|
121
|
+
}
|
122
|
+
|
123
|
+
(function () {
|
124
|
+
if ( typeof window.CustomEvent === "function" ) return false; //If not IE
|
125
|
+
|
126
|
+
function CustomEvent ( event, params ) {
|
127
|
+
params = params || { bubbles: false, cancelable: false, detail: undefined };
|
128
|
+
var evt = document.createEvent( 'CustomEvent' );
|
129
|
+
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
|
130
|
+
return evt;
|
131
|
+
}
|
132
|
+
|
133
|
+
CustomEvent.prototype = window.Event.prototype;
|
134
|
+
|
135
|
+
window.CustomEvent = CustomEvent;
|
136
|
+
})();
|
@@ -0,0 +1,155 @@
|
|
1
|
+
import { ISimpleSelectOptions, ISimpleSelectProps } from './types/simpleSelect.types';
|
2
|
+
import { selectorType } from './types/item.types';
|
3
|
+
import './polyfill.js';
|
4
|
+
|
5
|
+
import {
|
6
|
+
nameMark, nameSelect, simpleSelectionOptions,
|
7
|
+
} from './const/simpleSelection.const';
|
8
|
+
import { createDataAttr, toCamelCase } from './utils/simpleSelection.utils';
|
9
|
+
import { SimpleSelectItem } from './simpleSelectItem';
|
10
|
+
import './style.css';
|
11
|
+
|
12
|
+
export default class SimpleSelect {
|
13
|
+
callCount = Date.now();
|
14
|
+
|
15
|
+
countInit = 0;
|
16
|
+
|
17
|
+
// $selects: HTMLSelectElement[] = [];
|
18
|
+
$selects: SimpleSelectItem[] = [];
|
19
|
+
|
20
|
+
options!: ISimpleSelectOptions;
|
21
|
+
|
22
|
+
nameMarkTransform = toCamelCase(nameMark);
|
23
|
+
|
24
|
+
dataNameMark = createDataAttr(nameMark);
|
25
|
+
|
26
|
+
isNative!: boolean;
|
27
|
+
|
28
|
+
constructor(selector: selectorType, options?: ISimpleSelectProps) {
|
29
|
+
if (!selector) {
|
30
|
+
selector = 'select';
|
31
|
+
}
|
32
|
+
// this.$selects = Array.from(document.querySelectorAll(selector));
|
33
|
+
|
34
|
+
this.options = {
|
35
|
+
...simpleSelectionOptions,
|
36
|
+
...options,
|
37
|
+
};
|
38
|
+
|
39
|
+
if (typeof selector === 'string') {
|
40
|
+
this.init(Array.from(document.querySelectorAll(selector)));
|
41
|
+
} else if (selector instanceof HTMLSelectElement) {
|
42
|
+
this.init([selector]);
|
43
|
+
} else if (selector instanceof NodeList) {
|
44
|
+
this.init(Array.from(selector));
|
45
|
+
} else if (Array.isArray(selector)) {
|
46
|
+
this.init(selector);
|
47
|
+
} else {
|
48
|
+
console.warn('Wrong selector: ', selector);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
detectMobile() {
|
53
|
+
if (this.options.detectNative) {
|
54
|
+
this.isNative = this.options.detectNative();
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
58
|
+
// @ts-ignore
|
59
|
+
const ua = navigator.userAgent || navigator.vendor || window.opera;
|
60
|
+
|
61
|
+
let res = false;
|
62
|
+
// Checks for iOs, Android, Blackberry, Opera Mini, and Windows mobile devices
|
63
|
+
for (let i = 0; i < this.options.nativeOnDevice.length; i++) {
|
64
|
+
if (ua.toString().toLowerCase().indexOf(this.options.nativeOnDevice[i].toLowerCase()) > 0) {
|
65
|
+
if (this.options.nativeOnDevice[i]) {
|
66
|
+
res = true;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
this.isNative = res;
|
71
|
+
}
|
72
|
+
|
73
|
+
private init(selects: HTMLSelectElement[]) {
|
74
|
+
this.detectMobile();
|
75
|
+
selects.forEach(($select) => {
|
76
|
+
this.build($select);
|
77
|
+
});
|
78
|
+
}
|
79
|
+
|
80
|
+
createMethods(select: SimpleSelectItem) {
|
81
|
+
const self = this;
|
82
|
+
return {
|
83
|
+
getInstance: () => select.getSelect(),
|
84
|
+
reload() {
|
85
|
+
self.rebuild(select);
|
86
|
+
},
|
87
|
+
update() {
|
88
|
+
select.updateHTML();
|
89
|
+
},
|
90
|
+
detach() {
|
91
|
+
self.detach(select);
|
92
|
+
},
|
93
|
+
};
|
94
|
+
}
|
95
|
+
|
96
|
+
setMethods(select: SimpleSelectItem) {
|
97
|
+
// @ts-ignore
|
98
|
+
select.$select[nameSelect] = this.createMethods(select);
|
99
|
+
}
|
100
|
+
|
101
|
+
setMethodsClear(select: SimpleSelectItem) {
|
102
|
+
// @ts-ignore
|
103
|
+
delete select.$select[nameSelect];
|
104
|
+
}
|
105
|
+
|
106
|
+
private build(select: HTMLSelectElement) {
|
107
|
+
const isProcessed = this.nameMarkTransform in select.dataset;
|
108
|
+
if (isProcessed) {
|
109
|
+
console.warn('This element has already been initialized', select);
|
110
|
+
return;
|
111
|
+
}
|
112
|
+
|
113
|
+
this.countInit += 1;
|
114
|
+
const id = `${this.callCount}-${this.countInit}`;
|
115
|
+
select.setAttribute(this.dataNameMark, id);
|
116
|
+
// this.$selects.push(select);
|
117
|
+
|
118
|
+
const newSelect = new SimpleSelectItem(select, this.options, {
|
119
|
+
id, isNative: this.isNative,
|
120
|
+
});
|
121
|
+
this.$selects.push(newSelect);
|
122
|
+
this.setMethods(newSelect);
|
123
|
+
}
|
124
|
+
|
125
|
+
private detach(itemSelect: SimpleSelectItem) {
|
126
|
+
itemSelect.detachItem();
|
127
|
+
|
128
|
+
itemSelect.$select.removeAttribute(this.dataNameMark);
|
129
|
+
this.setMethodsClear(itemSelect);
|
130
|
+
this.$selects = this.$selects.filter((item) => item !== itemSelect);
|
131
|
+
}
|
132
|
+
|
133
|
+
public rebuild(selectsItems: SimpleSelectItem) {
|
134
|
+
const select = selectsItems.$select;
|
135
|
+
this.detach(selectsItems);
|
136
|
+
this.build(select);
|
137
|
+
}
|
138
|
+
|
139
|
+
public getSelects() {
|
140
|
+
return this.$selects;
|
141
|
+
}
|
142
|
+
|
143
|
+
public getSelectFirst() {
|
144
|
+
// return this.$selects[0];
|
145
|
+
return this.createMethods(this.$selects[0]);
|
146
|
+
}
|
147
|
+
|
148
|
+
public getSelectById(id:string) {
|
149
|
+
const search = this.$selects.filter((item) => item.id === id)[0];
|
150
|
+
if (!search) {
|
151
|
+
return null;
|
152
|
+
}
|
153
|
+
return this.createMethods(search);
|
154
|
+
}
|
155
|
+
}
|