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

Improve Omnibox #292

Merged
merged 3 commits into from
Mar 12, 2024
Merged
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
33 changes: 21 additions & 12 deletions feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1617,21 +1617,30 @@ public function frontend_boost_form( $args ) {
}

public function friends_search_autocomplete( $results, $q ) {
$url = preg_match( '#^(?:https?:\/\/)?(?:w{3}\.)?[\w-]+(?:\.[\w-]+)+((?:\/[^\s\/]*)*)#i', $q, $m );
$url_with_path = isset( $m[1] ) && $m[1];
$url = preg_match( '#^(https?:\/\/)?(?:w{3}\.)?[\w-]+(?:\.[\w-]+)+((?:\/[^\s\/]*)*)#i', $q, $m );
$url_with_path = isset( $m[2] ) && $m[2];

if ( ( $url && ! $url_with_path ) || preg_match( '/^@?' . self::ACTIVITYPUB_USERNAME_REGEXP . '$/i', $q ) ) {
$result = '<a href="' . esc_url( admin_url( 'admin.php?page=add-friend&url=' . urlencode( $q ) ) ) . '" class="has-icon-left">';
$result .= '<span class="ab-icon dashicons dashicons-users"></span>';
$result .= 'Follow ';
$result .= ' <small>';
$result .= esc_html( $q );
$result .= '</small></a>';
$results[] = $result;
$already_added = false;
foreach ( $results as $result ) {
if ( strpos( $result, $q ) !== false ) {
$already_added = true;
}
}

if ( ! $already_added ) {
if ( ( $url && ! $url_with_path ) || preg_match( '/^@?' . self::ACTIVITYPUB_USERNAME_REGEXP . '$/i', $q ) ) {
$result = '<a href="' . esc_url( add_query_arg( 'url', $m[1] ? $q : 'https://' . $q, admin_url( 'admin.php?page=add-friend' ) ) ) . '" class="has-icon-left">';
$result .= '<span class="ab-icon dashicons dashicons-businessperson"><span class="dashicons dashicons-plus"></span></span>';
$result .= 'Follow ';
$result .= ' <small>';
$result .= esc_html( $q );
$result .= '</small></a>';
$results[] = $result;
}
}

if ( $url_with_path ) {
$result = '<a href="' . esc_url( home_url( '/friends/type/status/?boost=' . urlencode( $q ) ) ) . '" class="has-icon-left">';
$result = '<a href="' . esc_url( add_query_arg( 'boost', $q, home_url( '/friends/type/status/' ) ) ) . '" class="has-icon-left">';
$result .= '<span class="ab-icon dashicons dashicons-controls-repeat"></span>';
$result .= 'Boost ';
$result .= ' <small>';
Expand All @@ -1641,7 +1650,7 @@ public function friends_search_autocomplete( $results, $q ) {
}

if ( $url_with_path ) {
$result = '<a href="' . esc_url( home_url( '/friends/type/status/?in_reply_to=' . urlencode( $q ) ) ) . '" class="has-icon-left">';
$result = '<a href="' . esc_url( add_query_arg( 'in_reply_to', $q, home_url( '/friends/type/status/' ) ) ) . '" class="has-icon-left">';
$result .= '<span class="ab-icon dashicons dashicons-admin-comments"></span>';
$result .= 'Reply to ';
$result .= ' <small>';
Expand Down
2 changes: 1 addition & 1 deletion friends.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion friends.css.map

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@
return;
}

searchResultFocused = ( results.length + searchResultFocused ) % results.length;

const el = results.get( searchResultFocused );
if ( el ) {
el.focus();
} else {
searchResultFocused = results.length;
}
return false;
}
Expand Down Expand Up @@ -81,6 +85,36 @@
},
} );
} );

$document.on( 'keydown', function ( e ) {
const searchDialog = $( '.search-dialog' );
if ( searchDialog.length ) {
if (
(e.metaKey && 75 === e.keyCode ) // cmd-k.
|| ( e.ctrlKey && 75 === e.keyCode ) // ctrl-p.
) {
// move all the childnodes of section.navbar-section search into the .search-dialog:
searchDialog.append( $( '.navbar-section.search' ).children() );

// create a new dialog
if ( searchDialog.is(':visible') ) {
searchDialog.hide();
$( '.navbar-section.search' ).append( searchDialog.children() );
} else {
searchDialog.show();
}

$( 'input#master-search' ).focus();
return false;
}

if ( 27 === e.keyCode ) {
searchDialog.hide();
$( '.navbar-section.search' ).append( $( '.search-dialog' ).children() );
}
}
} );

$document.on(
'click',
'a.friends-auth-link, button.comments.friends-auth-link',
Expand Down
36 changes: 36 additions & 0 deletions friends.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ h2#page-title a.dashicons {
}
}

::backdrop {
background-color: rgba(0, 0, 0, 0.75);
}

.friends-page {
background-color: $body-bg;
color: $body-font-color;
Expand Down Expand Up @@ -193,13 +197,36 @@ h2#page-title a.dashicons {
.menu-item:hover small.label-secondary {
display: inline-block;
}


.has-icon-left .ab-icon {
line-height: 1.2;
margin-right: .2em;

.dashicons.dashicons-plus {
color: #32c170;
font-size: .5em;
margin-left: -1.5em;
margin-top: -2.1em;
}
}
}

button,
input {
min-height: auto;
}

.d-none {
display: none;
}

dialog {
border: 0;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
}


header.navbar section.navbar-section.author {
flex: 3;
}
Expand Down Expand Up @@ -335,6 +362,13 @@ h2#page-title a.dashicons {
}
}
}
.friends-sidebar-customize {
margin-left: 1.5rem;
color: #999;
font-size: .4rem;
line-height: .6rem;
display: block;
}
}

#friends-sidebar .friends-nav {
Expand Down Expand Up @@ -368,6 +402,8 @@ h2#page-title a.dashicons {
padding: .5em;
margin-top: 1em;
margin-bottom: 1em;
max-height: 6em;
overflow-y: auto;
figcaption {
float: right;
a:any-link {
Expand Down
22 changes: 21 additions & 1 deletion includes/class-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,26 @@ public function ajax_load_next_page() {
*/
public function ajax_autocomplete() {
$q = wp_unslash( $_POST['q'] );
$results = apply_filters( 'friends_search_autocomplete', array(), $q );
$results = array();

if ( false ) {
$result = '<a href="' . esc_url( add_query_arg( 'name', $q, admin_url( 'admin.php?page=add-friend' ) ) ) . '" class="has-icon-left">';
$result .= '<span class="ab-icon dashicons dashicons-businessperson"><span class="ab-icon dashicons dashicons-plus"></span></span>';
$result .= 'Add friend';
$result .= ' <small>';
$result .= esc_html( $q );
$result .= '</small></a>';
$results[] = $result;
}
$results = apply_filters( 'friends_search_autocomplete', $results, $q );

$result = '<a href="' . esc_url( add_query_arg( 's', $q, home_url( '/friends/' ) ) ) . '" class="has-icon-left">';
$result .= '<span class="ab-icon dashicons dashicons-search"></span>';
$result .= 'Search for ';
$result .= ' <small>';
$result .= esc_html( $q );
$result .= '</small></a>';
$results[] = $result;

wp_send_json_success( '<li class="menu-item">' . implode( '</li><li class="menu-item">', $results ) . '</li>' );
}
Expand All @@ -616,6 +635,7 @@ public function autocomplete_user_search( $results, $q ) {

foreach ( $users->get_results() as $friend ) {
$result = '<a href="' . esc_url( $friend->get_local_friends_page_url() ) . '" class="has-icon-left">';
$result .= '<span class="ab-icon dashicons dashicons-businessperson"></span>';
$result .= str_ireplace( $q, '<mark>' . $q . '</mark>', $friend->display_name );
$result .= ' <small>';
$result .= str_ireplace( $q, '<mark>' . $q . '</mark>', $friend->user_login );
Expand Down
13 changes: 9 additions & 4 deletions templates/frontend/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<div id="friends-sidebar" class="off-canvas-sidebar">
<div class="friends-brand">
<a class="friends-logo" href="<?php echo esc_url( home_url( '/friends/' ) ); ?>"><h2><?php esc_html_e( 'Friends', 'friends' ); ?></h2></a>

<a class="friends-sidebar-customize" href="https://akirk.blog/wp-admin/customize.php?autofocus[section]=sidebar-widgets-friends-sidebar&url=<?php echo esc_attr( urlencode( home_url( '/friends/' ) ) ); ?>"><?php esc_html_e( 'customize sidebar', 'friends' ); ?></a>
</div>
<div class="friends-nav accordion-container">
<?php dynamic_sidebar( 'friends-sidebar' ); ?>
Expand Down Expand Up @@ -60,12 +62,16 @@
?>

</section>
<?php if ( ! is_singular() ) : ?>
<section class="navbar-section">

<dialog class="search-dialog">
</dialog>


<section class="navbar-section search<?php echo esc_attr( is_singular() ? ' d-hide' : '' ); ?>">
<form class="input-group input-inline form-autocomplete" action="<?php echo esc_url( home_url( '/friends/' ) ); ?>">
<div class="form-autocomplete-input form-input">
<div class="has-icon-right">
<input class="form-input" type="text" tabindex="2" name="s" placeholder="<?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_attr_e( 'Search' ); ?>" value="<?php echo esc_attr( $search ); ?>" id="master-search" autocomplete="off"/>
<input class="form-input" type="text" tabindex="2" name="s" placeholder="<?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_attr_e( 'Search or paste URL' ); ?>" value="<?php echo esc_attr( $search ); ?>" id="master-search" autocomplete="off"/>
<i class="form-icon"></i>
</div>
</div>
Expand All @@ -74,7 +80,6 @@
<button class="btn btn-primary input-group-btn"><?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Search' ); ?></button>
</form>
</section>
<?php endif; ?>
</header>
<?php
do_action( 'friends_after_header', $args );
7 changes: 7 additions & 0 deletions templates/frontend/main-feed-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
$title = _x( 'Audio feed', 'Post format', 'friends' );
break;
}
if ( isset( $_GET['s'] ) ) {
$title = sprintf(
// translators: %s is a search term.
__( 'Search for "%s"', 'friends' ),
esc_html( $_GET['s'] )
);
}

if ( $args['friends']->frontend->reaction ) {
echo esc_html(
Expand Down
Loading