Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faux LiveChat Target existing window if available #18960

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public function register_actions() {
add_action( 'admin_footer', array( $this, 'add_fab_icon' ) );

add_action( 'admin_enqueue_scripts', array( $this, 'add_fab_styles' ) );

add_action( 'admin_enqueue_scripts', array( $this, 'add_fab_scripts' ) );
}

/**
Expand Down Expand Up @@ -109,4 +111,19 @@ public function add_fab_icon() {
public function add_fab_styles() {
wp_enqueue_style( 'a8c-faux-inline-help', plugins_url( 'inline-help.css', __FILE__ ), array(), JETPACK__VERSION );
}

/**
* Enqueues FAB JS scripts.
*
* @return void
*/
public function add_fab_scripts() {
getdave marked this conversation as resolved.
Show resolved Hide resolved
wp_enqueue_script(
'a8c-faux-inline-help',
plugins_url( 'inline-help.js', __FILE__ ),
array(),
JETPACK__VERSION,
true
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
?>

<div class="a8c-faux-inline-help">
<a class="a8c-faux-inline-help__button" href="<?php echo esc_url( $args['href'] ); ?>" target="_blank" rel="noopener noreferrer" title="<?php echo esc_attr__( 'Help', 'jetpack' ); ?>">
<a data-faux-inline-help class="a8c-faux-inline-help__button" href="<?php echo esc_url( $args['href'] ); ?>" target="WPComInlineHelp" rel="noopener noreferrer" title="<?php echo esc_attr__( 'Help', 'jetpack' ); ?>">
<?php echo wp_kses( $args['icon'], $args['svg_allowed'] ); ?>
</a>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
( function () {
var windowObjectReference = null;
function init() {
document.querySelector( '[data-faux-inline-help]' ).addEventListener( 'click', function ( e ) {
getdave marked this conversation as resolved.
Show resolved Hide resolved
e.preventDefault();

if ( windowObjectReference === null || windowObjectReference.closed ) {
windowObjectReference = window.open( e.target.href, e.target.target );
} else {
windowObjectReference.focus();
}
} );
}

if ( document.readyState === 'loading' ) {
document.addEventListener( 'DOMContentLoaded', init );
} else {
init();
}
getdave marked this conversation as resolved.
Show resolved Hide resolved
} )();