Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 35 additions & 27 deletions src/comp/tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,35 +263,43 @@ export default class Tabs extends React.Component {

tabLabelOnClick() {
let $target = $( event.target );
if ( !$target.is( "a" ) ) {
while ( !$target.is( "tab-label" ) ) { $target = $target.parent(); }
const $a = $target.find( "a" ),
href = $a.attr( "href" );
href.startsWith( "#" ) && $a[0].click();
} else {
const style = styles.get( this.state.id ),
idx = $target.attr( "id" ),
value = $target.attr( "value" ),
name = $target.text(),
$prev = $( "tab-label[active=true]" );

$( "tab-label[active=true]" )
.attr( "active", false ).css({ ...style.label })
.find( "tab-border" ).css({ ...style.border });

$target.parent().attr( "active", true )
.css({ ...style.label, ...style.label_active })
.find( "tab-border" ).css({ ...style.border, ...style.border_active });

$( "tab-group[active=true]" )
.attr( "active", false )
.velocity({ opacity: 0 }, { complete: target => {
$(target).css({ ...style.group });
$($( "tab-group" )[idx]).attr( "active", true ).css({ ...style.group, ...style.group_active })
}});

this.props.onChange && this.props.onChange( $prev, event );
//点击的是最外层的 label,需要触发 a 的点击
if($target.is("tab-label")) {
const $a = $target.find( "a" );
$a[0] && $a[0].click();
return;
}

//点击的是 a 中的子项(这里如果 dom 结构发生改变的话会有问题)
if(!$target.is('a')) { $target = $target.parent(); }

//处理 a 的情况
const href = $target.attr('href');
if(!href.startsWith( "#" )) { return; }

const style = styles.get( this.state.id ),
idx = $target.attr( "id" ),
value = $target.attr( "value" ),
name = $target.text(),
$prev = $( "tab-label[active=true]" );

$( "tab-label[active=true]" )
.attr( "active", false ).css({ ...style.label })
.find( "tab-border" ).css({ ...style.border });

$target.parent().attr( "active", true )
.css({ ...style.label, ...style.label_active })
.find( "tab-border" ).css({ ...style.border, ...style.border_active });

$( "tab-group[active=true]" )
.attr( "active", false )
.velocity({ opacity: 0 }, { complete: target => {
$(target).css({ ...style.group });
$($( "tab-group" )[idx]).attr( "active", true ).css({ ...style.group, ...style.group_active })
}});

this.props.onChange && this.props.onChange( $prev, $target );
}

render() {
Expand Down
11 changes: 5 additions & 6 deletions src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function vernotify() {

/**
* First load call remote simpread data structure( usage storage.Sync() )
*
*
* @param {bool} is first load
*/
function firstLoad( first ) {
Expand Down Expand Up @@ -138,7 +138,7 @@ function mainRender( idx ) {

/**
* Tabs render
*
*
* @param {string} header background color
*/
function tabsRender( color ) {
Expand Down Expand Up @@ -169,10 +169,9 @@ function tabsRender( color ) {
<section><Unrdist list={ storage.unrdist.map( item => { return { ...item }} ) } /></section>
<section><About option={ storage.option } /></section>
</Tabs>,
tabsOnChange = ( $prev, event ) => {
let $target = $( event.target );
while ( !$target.is( "tab-label" ) ) { $target = $target.parent(); }
const idx = $target.find( "a" ).attr( "id" );
tabsOnChange = ( $prev, $target ) => {
//这里已经找到 target,所以直接传过来
const idx = $target.attr( "id" );
mainRender( idx );
conf.tabsItem.forEach( ( item, index ) => item.active = idx == index ? true : false );
},
Expand Down