-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed slot, added no-follow toggle
- Loading branch information
Showing
3 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
import { ToggleControl } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
class NoFollowToggle extends Component { | ||
isChecked() { | ||
const { rel } = this.props.attributes; | ||
|
||
if ( ! rel ) { | ||
return false; | ||
} | ||
|
||
return rel.split( ' ' ).includes( 'nofollow' ); | ||
} | ||
|
||
toggle() { | ||
const { setLinkAttributes, attributes } = this.props; | ||
|
||
const rel = attributes.rel; | ||
|
||
if ( this.isChecked() ) { | ||
if ( ! rel ) { | ||
return; | ||
} | ||
|
||
const newRel = rel.split( ' ' ).filter( ( relItem ) => { | ||
return relItem !== 'nofollow'; | ||
} ).join( ' ' ); | ||
|
||
setLinkAttributes( { | ||
...attributes, | ||
rel: newRel, | ||
} ); | ||
return; | ||
} | ||
|
||
if ( ! rel ) { | ||
setLinkAttributes( { | ||
...attributes, | ||
rel: 'nofollow', | ||
} ); | ||
} else { | ||
setLinkAttributes( { | ||
...attributes, | ||
rel: [ rel, 'nofollow' ].join( ' ' ), | ||
} ); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<ToggleControl | ||
label={ __( 'No Follow' ) } | ||
checked={ this.isChecked() } | ||
onChange={ this.toggle.bind( this ) } | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default NoFollowToggle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters