Skip to content

Commit

Permalink
Refactor Control class to update control option variables and element…
Browse files Browse the repository at this point in the history
… references
  • Loading branch information
zhw2590582 committed Oct 21, 2024
1 parent cc13b9c commit dcd6e08
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 35 deletions.
22 changes: 6 additions & 16 deletions docs/uncompiled/artplayer/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/uncompiled/artplayer/index.js.map

Large diffs are not rendered by default.

24 changes: 6 additions & 18 deletions packages/artplayer/src/control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import {
append,
addClass,
isMobile,
getStyle,
hasClass,
removeClass,
errorHandle,
inverseClass,
Expand Down Expand Up @@ -230,7 +228,7 @@ export default class Control extends Component {
}

selector(option, $ref, events) {
const { hover, proxy } = this.art.events;
const { proxy } = this.art.events;

addClass($ref, 'art-control-selector');
const $value = createElement('div');
Expand Down Expand Up @@ -266,25 +264,15 @@ export default class Control extends Component {
});
}

const resize = () => {
const refWidth = getStyle($ref, 'width');
const listWidth = getStyle($list, 'width');
const left = refWidth / 2 - listWidth / 2;
$list.style.left = `${left}px`;
};

hover($ref, resize);

const event = proxy($list, 'click', async (event) => {
const path = event.composedPath() || [];
const $item = path.find((item) => hasClass(item, 'art-selector-item'));
if (!$item) return;
const find = option.selector[$item.dataset.index];
this.check(find);
const item = option.selector.find(
(item) => item.$control_item === path.find(($item) => item.$control_item === $item),
);
this.check(item);
if (option.onSelect) {
$value.innerHTML = await option.onSelect.call(this.art, find, $item, event);
$value.innerHTML = await option.onSelect.call(this.art, item, item.$control_item, event);
}
resize();
});

events.push(event);
Expand Down
2 changes: 2 additions & 0 deletions packages/artplayer/src/style/selector.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.art-control-selector {
position: relative;
display: flex;
justify-content: center;

.art-selector-list {
display: flex;
Expand Down

0 comments on commit dcd6e08

Please sign in to comment.