Skip to content
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
161 changes: 24 additions & 137 deletions web/app/plugins/mitlib-multisearch-widget/class-multisearch-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,124 +32,58 @@ public function __construct() {
* @link https://developer.wordpress.org/reference/classes/wp_widget/
*/
public function widget( $args, $instance ) {
// Identify which templates are needed based on instance variable.
$all_template = 'templates/tab-all-eds.php';
$books_template = 'templates/tab-books-eds.php';
$articles_template = 'templates/tab-articles-eds.php';
$articles_tab_name = 'Journals + articles';
$more_template = 'templates/tab-more-eds.php';
if ( 'alma' == $instance['targets'] ) {
$all_template = 'templates/tab-all-alma.php';
$books_template = 'templates/tab-books-alma.php';
$articles_template = 'templates/tab-articles-alma.php';
$articles_tab_name = 'Articles + chapters';
$more_template = 'templates/tab-more-alma.php';
}
// Strip initial arguments.
$args = null;

// By default, we use the v2 template (suitable for v2 page layouts).
$all_template = 'templates/tab-all-use-v2.php';
if ( 'use' == $instance['targets'] ) {
Comment on lines +38 to 40

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling legacy settings would be a legitimate concern if this code was part of a plugin that was being shipped to external consumers. Under those conditions, I absolutely agree that handling outdated values during a transition would be essential.

This codebase, however, is meant only for our public website - which no longer has any widgets configured for these settings.

// Alternatively, we use the v1 template (for old page layouts).
$all_template = 'templates/tab-all-use.php';
}
if ( 'use-v2' == $instance['targets'] ) {
$all_template = 'templates/tab-all-use-v2.php';
}
// Strip initial arguments.
$args = null;

// Register / enqueue javascript.
// First we add the responsive tabs plugin.
wp_register_script(
'responsivetabs-js',
plugin_dir_url( __FILE__ ) . 'libs/jquery.responsiveTabs.min.js',
array( 'jquery' ),
'1.6.1',
false
);
// Second, we add this plugin's javascript.
wp_register_script(
'multisearch-js',
plugin_dir_url( __FILE__ ) . 'mitlib-multisearch-widget.js',
array( 'responsivetabs-js' ),
'1.4.1',
array(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pages containing these widgets will have jQuery available, as the themes we use all have declared jQuery as a dependency. I'm not convinced that explicitly naming it as a dependency in this way is necessary, but I'm open to doing so if you'd like. Doing this doesn't break anything in my local, so there could be value is making it explicit.

Looking at the javascript that still remains in this plugin, I'm probably more interested in refactoring it so that we no longer rely on jQuery at all in this plugin - the selection rules that we're using seem like something that vanilla javascript is now capable of handling - but I don't want to expand the scope of this cleanup work to that extent right now.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'm fine with NOT declaring jQuery as dependency here since it's included on our themes.

+1 to refactoring jQuery out of this in the future... selection in vanilla is very similar nowadays and even the benefits of jQuery (animations/transitions) isn't that challenging to do with JS/CSS anymore. No need to worry about that now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is quite a bit of javascript maintenance still do around this codebase, so it probably makes sense to ensure that we have that included on any platform roadmap that we come up with.

'1.8.0',
false
);
// Finally, we enquey only this plugin's javascript (which brings everything else in).
wp_enqueue_script( 'multisearch-js' );

// Register / enqueue styles.
wp_register_style( 'responsivetabs-css', plugin_dir_url( __FILE__ ) . 'libs/responsive-tabs.css', '', '1.6.1' );
wp_register_style(
'multisearch-tabs',
plugin_dir_url( __FILE__ ) . 'mitlib-multisearch-widget.css',
array( 'responsivetabs-css' ),
'1.3.0'
array(),
'1.8.0'
);
wp_enqueue_style( 'multisearch-tabs' );

if ( $instance['targets'] != 'use-v2' ) {
// Determine whether to enable NLS based on widget settings and the user's cookie.
$nls_enabled = $this->readCookie( $instance['nls_default'] );

$nls_link_toggle = $this->setToggleValue( $nls_enabled );

$nls_included = $instance['nls_included'];

if ( 'use' == $instance['targets'] ) {
// Render markup.
echo '<noscript><p>It appears that your browser does not support javascript.</p>';
include( 'templates/form_nojs.html' );
include 'templates/form_nojs.html';
echo '</noscript>';
echo '<div id="multisearch" class="' . esc_attr( $this->widgetClasses( $instance ) ) . ' nojs">';
echo '<h2 id="searchtabsheader" class="sr">Search the MIT libraries</h2>';

};

// Render the search tabs only when "Unified Search" option is not selected
if ( $instance['targets'] != 'use' && $instance['targets'] != 'use-v2' ) {

echo '<ul id="search_tabs_nav" aria-labelledby="searchtabsheader">
<li><a id="tab-all" href="#search-all"><span>All</span></a></li>
<li><a id="tab-books" href="#search-books"><span>Books + media</span></a></li>
<li><a id="tab-articles" href="#search-articles"><span>'
. esc_html( $articles_tab_name )
. '</span></a></li>
<li><a id="tab-more" href="#search-more"><span>More...</span></a></li>
</ul>';

// Render the individual tab panes
echo '<div id="search-all" aria-labelledby="tab-all">';
include( $all_template );
echo '</div>';
echo '<div id="search-books" aria-labelledby="tab-books">';
include( $books_template );
echo '</div>';
echo '<div id="search-articles" aria-labelledby="tab-articles">';
include( $articles_template );
echo '</div>';
echo '<div id="search-more" aria-labelledby="tab-more">';
include( $more_template );
echo '</div>';

};

if ( $instance['targets'] == 'use' ) {

// Determine whether to enable NLS based on widget settings and the user's cookie.
$nls_enabled = $this->readCookie( $instance['nls_default'] );

$nls_link_toggle = $this->setToggleValue( $nls_enabled );

$nls_included = $instance['nls_included'];

echo '<div id="search-all" class="r-tabs-panel r-tabs-state-active use" aria-labelledby="tab-all">';
include( $all_template );
echo '</div>';

};

if ( $instance['targets'] == 'use-v2' ) {

// Determine whether to enable NLS based on widget settings and the user's cookie.
$nls_enabled = $this->readCookie( $instance['nls_default'] );

$nls_link_toggle = $this->setToggleValue( $nls_enabled );

$nls_included = $instance['nls_included'];

include( $all_template );

include $all_template;

if ( 'use' == $instance['targets'] ) {
echo '</div>'; // This closes the div#search-all.
};

if ( $instance['banner_text'] ) {
Expand All @@ -170,8 +104,8 @@ public function widget( $args, $instance ) {
echo '</div>';
}

if ( $instance['targets'] != 'use-v2' ) {
echo '</div>';
if ( 'use' == $instance['targets'] ) {
echo '</div>'; // This closes the div#multisearch.
};
}

Expand All @@ -186,11 +120,7 @@ public function form( $instance ) {
$banner_text = $instance['banner_text'];
$targets = $instance['targets'];
if ( '' == $instance['targets'] ) {
$targets = 'eds';
}
$bento_url = $instance['bento_url'];
if ( '' == $instance['bento_url'] ) {
$bento_url = 'https://lib.mit.edu/';
$targets = 'use-v2';
}
$nls_default = $instance['nls_default'];
if ( '' == $instance['nls_default'] ) {
Expand All @@ -211,36 +141,6 @@ class="widefat"
</p>
<p>Which set of search targets should be shown?</p>
<ul>
<li>
<label>
<input
type="radio"
name="<?php echo esc_attr( $this->get_field_name( 'targets' ) ); ?>"
value="eds"
<?php
if ( 'eds' == $targets ) {
echo "checked='checked'";
}
?>
>
EDS and Barton
</label>
</li>
<li>
<label>
<input
type="radio"
name="<?php echo esc_attr( $this->get_field_name( 'targets' ) ); ?>"
value="alma"
<?php
if ( 'alma' == $targets ) {
echo "checked='checked'";
}
?>
>
Alma and Primo
</label>
</li>
<li>
<label>
<input
Expand Down Expand Up @@ -272,18 +172,6 @@ class="widefat"
</label>
</li>
</ul>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'bento_url' ) ); ?>">
<?php esc_attr_e( 'Bento URL' ); ?> (formatted like "https://lib.mit.edu/")
</label>
<input
class="widefat"
id="<?php echo esc_attr( $this->get_field_id( 'bento_url' ) ); ?>"
type="text"
name="<?php echo esc_attr( $this->get_field_name( 'bento_url' ) ); ?>"
value="<?php echo esc_html( $bento_url ); ?>">
</p>
<h3>Natural language search</h3>
<p>
Should the natural language option be shown?<br>
<label>
Expand Down Expand Up @@ -348,7 +236,6 @@ public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['banner_text'] = $new_instance['banner_text'];
$instance['targets'] = $new_instance['targets'];
$instance['bento_url'] = $new_instance['bento_url'];
$instance['nls_default'] = $new_instance['nls_default'];
$instance['nls_included'] = $new_instance['nls_included'];
return $instance;
Expand Down

This file was deleted.

34 changes: 0 additions & 34 deletions web/app/plugins/mitlib-multisearch-widget/libs/responsive-tabs.css

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
/* These styles were in libs/responsive-tabs.css. */
.r-tabs .r-tabs-nav {
margin: 0;
padding: 0;
}

.r-tabs .r-tabs-tab {
display: inline-block;
margin: 0;
list-style: none;
}

.r-tabs .r-tabs-panel {
padding: 15px;
display: none;
}

.r-tabs .r-tabs-accordion-title {
display: none;
}

.r-tabs .r-tabs-panel.r-tabs-state-active {
display: block;
}

/* Accordion responsive breakpoint */
@media only screen and (max-width: 768px) {
.r-tabs .r-tabs-nav {
display: none;
}

.r-tabs .r-tabs-accordion-title {
display: block;
}
}

/* These styles were always part of this file. */
#multisearch.nojs {
display: none;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ function preventSearch(textField,button) {
$( button ).prop('disabled', true);
e.preventDefault();
}

});

}


Expand All @@ -28,35 +26,10 @@ jQuery( document ).ready(function() {
// If javascript is present, we disable the nojs class.
$tabs.removeClass("nojs");

// Check if this is the USE form and does not need tabs.
if ( $('#search-all').hasClass("use") ) {
// add r-tabs class to force styling of the form to be consistent with the other tabs.
$tabs.addClass("r-tabs");
} else {
// Call Responsive Tabs plugin.
$tabs.responsiveTabs({
rotate: false,
startCollapsed: false,
collapsible: false,
setHash: true
});

$( '#search_tabs_nav a' ).click( function(e) {
$( '#search_tabs_nav a' ).removeAttr( "aria-expanded" );
$( '#search_tabs_nav a .current' ).remove();
$(this).attr( "aria-expanded", "true" ).prepend( "<span class='sr current'>Current: </span>" );
});
}
// add r-tabs class to force styling of the form to be consistent with the other tabs.
$tabs.addClass("r-tabs");

// prevent submission until text field is not empty
preventSearch( '#searchinput-bento', '.search-bento .button-search');

preventSearch( '#searchinput-bookslocal', 'form#booksearch .button-search');

preventSearch( '#searchinput-article', 'form#edssearch .button-search');

preventSearch( '#searchinput-site', '.search-site .button-search');


});

Loading