Commit df7356e0 authored by allan's avatar allan

add search functionality

parent c08a2568
Pipeline #1486 passed with stage
in 1 second
......@@ -15,6 +15,10 @@ $questions = get_posts( array(
'suppress_filters' => true,
) );
?>
<div class="searchbox">
<div class="searchbox-label"><?php echo pll__('Find our what you want to know on the GDPR') ?></div>
<input type="text" id="searchText" class="input" placeholder="<?php echo pll__('Enter your term...') ?>">
</div>
<ul class="filters button-group filters-button-group">
<?php
foreach ($audiences as $audience) {
......@@ -31,6 +35,8 @@ $questions = get_posts( array(
<button class="expand-all button expand"><?php echo pll__('expand all') ?></button>
<button class="collapse-all button collapse" style="display: none;"><?php echo pll__('collapse all') ?></button>
</div>
<div class="no-results" style="display: none;"><?php _e( 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', 'intergalactic' ); ?></div>
<ul class="questions accordions">
<?php
......@@ -44,7 +50,7 @@ $questions = get_posts( array(
}
?>
<li id="<?php echo $question->ID ?>" class="accordion <?php echo implode(' ', $cat_class) ?>">
<h4 class="accordion-header toggle" data-action="toggle"><?php echo $question->post_title ?></h4>
<h4 class="accordion-header toggle title" data-action="toggle"><div><?php echo $question->post_title ?></div></h4>
<div class="accordion-body">
<div class="acordion-content"><?php echo $question->post_content ?></div>
</div>
......
......@@ -109,6 +109,8 @@ function intergalactic_scripts() {
wp_enqueue_style( 'gdpr-style', get_template_directory_uri() . '/gdpr.css', array(), '0.0.1' );
wp_enqueue_script( 'searcher-script', get_template_directory_uri() . '/js/searcher.js', array( 'jquery' ), '20182205', true );
wp_enqueue_script( 'gdpr-script', get_template_directory_uri() . '/js/gdpr.js', array( 'jquery' ), '20181905', true );
......@@ -178,6 +180,9 @@ add_action( 'admin_print_styles-appearance_page_custom-header', 'intergalactic_a
*/
pll_register_string('expand-all', 'expand all', $group, $multiline); // register 'expand all' button text
pll_register_string('collapse-all', 'collapse all', $group, $multiline); // register 'collapse all' button text
pll_register_string('search-box-title', 'Find our what you want to know on the GDPR', $group, $multiline); // register search box title text
pll_register_string('search-box-placeholder', 'Enter your term...', $group, $multiline); // register search box placeholder text
pll_register_string('filter-label', 'Filter', $group, $multiline); // register Filter label text
/**
* Implement the Custom Header feature.
......
.site-description {display: none;}
ul.accordions {
list-style: none;
margin: 0;
......
......@@ -60,5 +60,29 @@
$('.expand').show();
}
});
// Question search
$('.accordions').searcher({
itemSelector: '.accordion',
textSelector: 'div',
inputSelector: '#searchText',
highlight: "<span class='highlight'>$1</span>",
toggle: function(item, containsText) {
if (containsText) $(item).slideDown();
else $(item).slideUp();
}
});
// show no results
$('#searchText').on('keyup', function() {
setTimeout(function() {
var count = $('.accordion:visible');
if (count.length == 0) {
$('.no-results').slideDown();
} else {
$('.no-results').slideUp();
}
}, 500);
});
});
})(jQuery);
/*! jQuery Searcher Plugin - v0.3.0 - 2016-01-29
* https://github.com/lloiser/jquery-searcher/
* Copyright (c) 2016 Lukas Beranek; Licensed MIT
*/
(function(){"use strict";function a(a){function b(b,c){this.element=b,this.options=a.extend({},f,c),this._create()}function c(a){return a.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1")}var d="searcher",e="plugin_"+d,f={itemSelector:"tbody > tr",textSelector:"td",inputSelector:"",caseSensitive:!1,toggle:function(b,c){a(b).toggle(c)}};b.prototype={dispose:function(){this._$input.unbind("."+d);var a=this.options,b=a.toggle||f.toggle;this._$element.find(a.itemSelector).each(function(){b(this,!0)})},filter:function(b){this._lastValue=b;var d=this.options,e=d.textSelector,g=d.toggle||f.toggle,h="gm"+(d.caseSensitive?"":"i"),i=new RegExp("("+c(b)+")",h);this._$element.find(d.itemSelector).each(function(){var b=a(this),c=e?b.find(e):b,d=!1;c=c.each(function(){return d=d||!!a(this).text().match(i),!d}),g(this,d)})},_create:function(){var b=this.options;this._$element=a(this.element),this._fn=a.proxy(this._onValueChange,this);var c="input."+d+" change."+d+" keyup."+d;this._$input=a(b.inputSelector).bind(c,this._fn),this._lastValue=null;var e=b.toggle||f.toggle;this._$element.find(b.itemSelector).each(function(){e(this,!0)})},_onValueChange:function(){var a=this._$input.val();a!==this._lastValue&&this.filter(a)}},a.fn[d]=function(c){var d=Array.prototype.slice.call(arguments,1);return this.each(function(){var f=a.data(this,e),g=typeof c;"string"===g&&f?(f[c].apply(f,d),"dispose"===c&&a.removeData(this,e)):"object"===g&&(f?a.extend(f.options,c):a.data(this,e,new b(this,c)))})}}"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a:a(jQuery)}).call(this);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment