Skip to content

Commit

Permalink
Maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
taufik-nurrohman committed Mar 6, 2022
1 parent f4a048e commit 5a60437
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 41 deletions.
6 changes: 5 additions & 1 deletion .github/source/index.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ $name: 'option-picker';

.#{$name} {
&,
& * {
&::before,
&::after,
*,
*::before,
*::after {
box-sizing: border-box;
font: inherit;
}
Expand Down
4 changes: 2 additions & 2 deletions .github/source/index.html.pug
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ block style
| text-align: left;
| vertical-align: top;
| }
| body > p:first-child {
| [role='alert'] {
| background: #ffa;
| border: 1px dashed;
| margin-top: 0;
Expand All @@ -78,7 +78,7 @@ block style
| }

block content
p Do you like this project? Please support my #[a(href='https://github.com/mecha-cms') Mecha CMS] project too. Thank you!
p(role='alert') Do you like this project? Please support my #[a(href='https://github.com/mecha-cms') Mecha CMS] project too. Thank you!
header
h1= title
p Just a generic custom #[code <select>] element with accessibility in mind.
Expand Down
8 changes: 5 additions & 3 deletions .github/source/index.js.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {D, W, getAttribute, getChildren, getClasses, getHTML, getName, getParent, getStyle, getText, hasAttribute, hasClass, letAttribute, letClass, letElement, letText, setAttribute, setChildLast, setClass, setData, setElement, setHTML, setStyle, setStyles, setText, toggleClass} from '@taufik-nurrohman/document';
import {D, W, getAttribute, getChildren, getClasses, getHTML, getName, getParent, getStyle, getText, hasAttribute, hasClass, letAttribute, letClass, letElement, letText, setAttribute, setChildLast, setClass, setData, setElement, setHTML, setNext, setStyle, setStyles, setText, toggleClass} from '@taufik-nurrohman/document';
import {debounce, delay} from '@taufik-nurrohman/tick';
import {fromStates, fromValue} from '@taufik-nurrohman/from';
import {getOffset, getRect, getScroll, getSize, setScroll} from '@taufik-nurrohman/rect';
Expand Down Expand Up @@ -225,7 +225,7 @@ function OP(source, state = {}) {
}

setChildLast(selectBoxFake, selectBoxFakeInput || selectBoxFakeLabel);
getParent(selectBox).insertBefore(selectBoxFake, selectBox.nextSibling);
setNext(selectBox, selectBoxFake);

function doBlur() {
letClass(selectBoxFake, classNameM + 'focus');
Expand Down Expand Up @@ -437,10 +437,12 @@ function OP(source, state = {}) {
}

function onSelectBoxFakeInputValueFocus() {
let value = getText(this),
let t = this,
value = getText(t),
selectBoxOption,
selectBoxFakeOption;
selectBoxOptionIndex = -1; // `<input>` does not have `selectedIndex` property!
selectElementContents(t);
for (let i = 0, j = toCount(selectBoxOptions); i < j; ++i) {
selectBoxOption = selectBoxOptions[i];
selectBoxFakeOption = selectBoxFakeOptions[i];
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Contribute
Release Notes
-------------

### 1.3.2
### 1.3.3

- Added ability to convert `<input>` element with `list` attribute.
- Fixed the custom select box insertion node that does not consider the text node.
Expand Down
6 changes: 5 additions & 1 deletion index.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
}

.option-picker,
.option-picker * {
.option-picker::before,
.option-picker::after,
.option-picker *,
.option-picker *::before,
.option-picker *::after {
box-sizing: border-box;
font: inherit;
}
Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta content="#000" name="theme-color">
<meta content="width=device-width" name="viewport">
<meta content="Just a generic custom `&lt;select&gt;` element with accessibility in mind." name="description">
<title>Option Picker 1.3.2</title>
<title>Option Picker 1.3.3</title>
<link href="index.min.css" rel="stylesheet">
<style>
* {
Expand Down Expand Up @@ -59,7 +59,7 @@
text-align: left;
vertical-align: top;
}
body > p:first-child {
[role='alert'] {
background: #ffa;
border: 1px dashed;
margin-top: 0;
Expand All @@ -74,9 +74,9 @@
</style>
</head>
<body>
<p>Do you like this project? Please support my <a href="https://github.com/mecha-cms">Mecha CMS</a> project too. Thank you!</p>
<p role="alert">Do you like this project? Please support my <a href="https://github.com/mecha-cms">Mecha CMS</a> project too. Thank you!</p>
<header>
<h1>Option Picker 1.3.2</h1>
<h1>Option Picker 1.3.3</h1>
<p>Just a generic custom <code>&lt;select&gt;</code> element with accessibility in mind.</p>
<hr>
</header>
Expand Down
46 changes: 28 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@
}
return "" + x;
};
var D = document;
var W = window;
var B = D.body;
var R = D.documentElement;
var D$1 = document;
var W$1 = window;
var getAttribute = function getAttribute(node, attribute, parseValue) {
if (parseValue === void 0) {
parseValue = true;
Expand All @@ -206,6 +204,9 @@
var getName = function getName(node) {
return toCaseLower(node && node.nodeName || "") || null;
};
var getNext = function getNext(node, anyNode) {
return node['next' + (anyNode ? "" : 'Element') + 'Sibling'] || null;
};
var getParent = function getParent(node, query) {
if (query) {
return node.closest(query) || null;
Expand All @@ -216,7 +217,7 @@
if (parseValue === void 0) {
parseValue = true;
}
var value = W.getComputedStyle(node).getPropertyValue(style);
var value = W$1.getComputedStyle(node).getPropertyValue(style);
if (parseValue) {
value = toValue(value);
}
Expand Down Expand Up @@ -246,9 +247,6 @@
var hasState = function hasState(node, state) {
return state in node;
};
var isWindow = function isWindow(node) {
return node === W;
};
var letAttribute = function letAttribute(node, attribute) {
return node.removeAttribute(attribute), node;
};
Expand Down Expand Up @@ -312,7 +310,7 @@
return setAttribute(node, 'data-' + datum, value);
};
var setElement = function setElement(node, content, attributes) {
node = isString(node) ? D.createElement(node) : node;
node = isString(node) ? D$1.createElement(node) : node;
if (isObject(content)) {
attributes = content;
content = false;
Expand All @@ -335,6 +333,9 @@
var state = 'innerHTML';
return hasState(node, state) && (node[state] = trim ? content.trim() : content), node;
};
var setNext = function setNext(current, node) {
return getParent(current).insertBefore(node, getNext(current, true)), node;
};
var setStyle = function setStyle(node, style, value) {
if (isNumber(value)) {
value += 'px';
Expand Down Expand Up @@ -386,6 +387,13 @@
}, time);
};
};
var D = document;
var W = window;
var B = D.body;
var R = D.documentElement;
var isWindow = function isWindow(node) {
return node === W;
};
var getOffset = function getOffset(node) {
return [node.offsetLeft, node.offsetTop];
};
Expand Down Expand Up @@ -509,9 +517,9 @@
const ZERO_WIDTH_SPACE = '\u200c';

function selectElementContents(node) {
let range = D.createRange();
let range = D$1.createRange();
range.selectNodeContents(node);
let selection = W.getSelection();
let selection = W$1.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
Expand Down Expand Up @@ -635,7 +643,7 @@
selectBoxMultiple = selectBox.multiple,
selectBoxOptionIndex = 0,
selectBoxOptions = selectBox.options,
selectBoxParent = state.parent || D,
selectBoxParent = state.parent || D$1,
selectBoxSize = selectBox.size,
selectBoxTitle = selectBox.title,
selectBoxValue = getValue(),
Expand Down Expand Up @@ -670,7 +678,7 @@
setChildLast(selectBoxFakeInput, selectBoxFakeInputPlaceholder);
}
setChildLast(selectBoxFake, selectBoxFakeInput || selectBoxFakeLabel);
getParent(selectBox).insertBefore(selectBoxFake, selectBox.nextSibling);
setNext(selectBox, selectBoxFake);

function doBlur() {
letClass(selectBoxFake, classNameM + 'focus');
Expand Down Expand Up @@ -880,10 +888,12 @@
}

function onSelectBoxFakeInputValueFocus() {
let value = getText(this),
let t = this,
value = getText(t),
selectBoxOption,
selectBoxFakeOption;
selectBoxOptionIndex = -1; // `<input>` does not have `selectedIndex` property!
selectElementContents(t);
for (let i = 0, j = toCount(selectBoxOptions); i < j; ++i) {
selectBoxOption = selectBoxOptions[i];
selectBoxFakeOption = selectBoxFakeOptions[i];
Expand Down Expand Up @@ -1030,7 +1040,7 @@
function setSelectBoxFakeOptionsPosition(selectBoxFake, useEvent) {
if (!selectBoxSize) {
let [left, top, width, height] = getRect(selectBoxFake),
heightWindow = getSize(W)[1],
heightWindow = getSize(W$1)[1],
heightMax = heightWindow - top - height;
setStyles(selectBoxFakeDropDown, {
'bottom': "",
Expand Down Expand Up @@ -1071,7 +1081,7 @@
}
fire('fit', getLot());
}
onEvents(['resize', 'scroll'], W, onSelectBoxWindow);
onEvents(['resize', 'scroll'], W$1, onSelectBoxWindow);
onEvent('click', selectBoxParent, onSelectBoxParentClick);
onEvent('focus', selectBox, onSelectBoxFocus);
onEvent('click', selectBoxFake, onSelectBoxFakeClick);
Expand Down Expand Up @@ -1114,7 +1124,7 @@
return $; // Already ejected
}
delete source[name];
offEvents(['resize', 'scroll'], W, onSelectBoxWindow);
offEvents(['resize', 'scroll'], W$1, onSelectBoxWindow);
offEvent('click', selectBoxParent, onSelectBoxParentClick);
offEvent('focus', selectBox, onSelectBoxFocus);
letClass(selectBox, classNameE + 'source');
Expand Down Expand Up @@ -1154,6 +1164,6 @@
'parent': null,
'size': 5
};
OP.version = '1.3.2';
OP.version = '1.3.3';
return OP;
});
2 changes: 1 addition & 1 deletion index.min.css

Large diffs are not rendered by default.

0 comments on commit 5a60437

Please sign in to comment.