-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3426 from WordImpress/issue/2602v2
feat(admin-form): copy form shortcode to clipboard via button #2602
- Loading branch information
Showing
11 changed files
with
1,362 additions
and
936 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,5 @@ | |
@import 'chosen'; | ||
@import 'importer'; | ||
@import 'export'; | ||
@import 'goals'; | ||
@import 'goals'; | ||
@import 'tooltip'; |
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,30 @@ | ||
$give-shortcode-space: 20px; | ||
$give-shortcode-space-half: $give-shortcode-space * 0.5; | ||
$hintPrefix: "give-shortcode-tooltip--"; | ||
$hintFontSize: 12px; | ||
$hintFontFamily: inherit; | ||
$hintVerticalPadding: $give-shortcode-space-half; | ||
$hintHorizontalPadding: $give-shortcode-space-half; | ||
$hintSizeSmall: $give-shortcode-space * 4; | ||
$hintSizeMedium: $give-shortcode-space * 7; | ||
$hintSizeLarge: $give-shortcode-space *14; | ||
$hintDefaultColor: #141414; | ||
$hintTransitionDuration: 0; | ||
|
||
@import "~hint.css/src/hint.scss"; | ||
|
||
.give-shortcode-tooltip { | ||
font-weight: normal; | ||
cursor: help; | ||
|
||
&:after { | ||
box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 ); | ||
text-shadow: none; | ||
} | ||
|
||
& .dashicons { | ||
font-size: 16px; | ||
vertical-align: middle; | ||
margin-right: 2px; | ||
} | ||
} |
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
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,60 @@ | ||
class GiveButton { | ||
constructor( element ) { | ||
this.root = element; | ||
this.buttonText = this.root.textContent.trim(); | ||
this.iconPosition = 'before'; | ||
|
||
const icon = this.root.querySelector( '.dashicons' ); | ||
|
||
if ( icon ) { | ||
this.iconClassName = icon.className; | ||
} | ||
} | ||
|
||
enable() { | ||
this.root.disabled = false; | ||
} | ||
|
||
disable() { | ||
this.root.disabled = true; | ||
} | ||
|
||
setBusyState() { | ||
const busyIcon = '<span class="dashicons dashicons-marker"></span>'; | ||
this.root.innerHTML = `${busyIcon} ${this.buttonText}`; | ||
this.disable(); | ||
} | ||
|
||
removeBusyState() { | ||
this.enable(); | ||
|
||
if ( this.iconClassName ) { | ||
this.updateIcon( this.iconClassName ); | ||
} | ||
} | ||
|
||
updateIcon( className, position = 'before' ) { | ||
const icon = `<span class="${className}"></span>`; | ||
|
||
if ( 'after' === position ) { | ||
this.root.innerHTML = `${this.buttonText} ${icon}`; | ||
} else { | ||
this.root.innerHTML = `${icon} ${this.buttonText}`; | ||
} | ||
|
||
this.iconClassName = className; | ||
this.iconPosition = position; | ||
} | ||
|
||
updateButtonText( text ) { | ||
this.buttonText = text; | ||
|
||
if ( this.iconClassName ) { | ||
this.updateIcon( this.iconClassName, this.iconPosition ); | ||
} else { | ||
this.root.textContent = text; | ||
} | ||
} | ||
} | ||
|
||
export default GiveButton; |
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,43 @@ | ||
import GiveButton from './button'; | ||
import ClipboardJS from 'clipboard'; | ||
|
||
class GiveShortcodeButton extends GiveButton { | ||
constructor( element ) { | ||
super( element ); | ||
this.shortcode = this.root.dataset.giveShortcode; | ||
this.clipboard = new ClipboardJS( this.root, { | ||
text: function( trigger ) { | ||
return trigger.dataset.giveShortcode; | ||
} | ||
}); | ||
this.reset = this.reset.bind( this ); | ||
} | ||
|
||
init() { | ||
this.registerEventHandlers(); | ||
} | ||
|
||
registerEventHandlers() { | ||
this.clipboard.on( 'success', () => this.handleSuccessClick() ); | ||
this.clipboard.on( 'error', () => this.handleErrorClick() ); | ||
} | ||
|
||
handleSuccessClick( event ) { | ||
this.updateIcon( 'dashicons dashicons-yes' ); | ||
this.root.setAttribute( 'aria-label', give_vars.copied ); | ||
this.root.addEventListener( 'mouseout', this.reset ); | ||
} | ||
|
||
handleErrorClick( event ) { | ||
this.updateIcon( 'dashicons dashicons-warning' ); | ||
this.root.setAttribute( 'aria-label', 'Shortcode could not be copied.' ); | ||
} | ||
|
||
reset( event ) { | ||
this.updateIcon( 'dashicons dashicons-admin-page' ); | ||
this.root.setAttribute( 'aria-label', this.shortcode ); | ||
this.root.removeEventListener( 'mouseout', this.reset ); | ||
} | ||
} | ||
|
||
export {GiveShortcodeButton}; |
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
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
Oops, something went wrong.