• awesome plugin! just one request … there is a way to view the results at the top and not at the bottom … I put the fixed widget at the bottom of the body and it shows me the results in the foooter … I would like to show them at the top. ..it’s possible? thank you very much

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    So, as I understand, you are talking about ajax search results box.
    In this case yes, it is possible. Please use following code snippet

    add_action( 'wp_enqueue_scripts', 'aws_wp_enqueue_scripts', 999 );
    function aws_wp_enqueue_scripts() {
        
        $script = '
            function getResultsBlockHeight( resultsBlock ) {
                   var $resultsBlock = jQuery( resultsBlock );
                    var resultsHeight = $resultsBlock.height();
    
                    if ( resultsHeight === 0 ) {
                        var copied_elem = $resultsBlock.clone()
                            .attr("id", false)
                            .css({visibility:"hidden", display:"block",
                                position:"absolute"});
                        jQuery("body").append(copied_elem);
                        resultsHeight = copied_elem.height();
                        copied_elem.remove();
                    }
    
                    return resultsHeight;
            }
            
        
            function aws_results_layout( styles, options ) {
            
                    var offset = options.form.offset();
                    var bodyOffset = jQuery(\'body\').offset();
                    var bodyPosition = jQuery(\'body\').css(\'position\');
                    var bodyHeight = jQuery(document).height();
                    var resultsHeight = options.resultsBlock.height();
                    
                    
                    if ( bodyPosition === \'relative\' || bodyPosition === \'absolute\' || bodyPosition === \'fixed\' ) {
                        styles.top = offset.top + jQuery( options.form).innerHeight() - bodyOffset.top;
                        styles.left = offset.left - bodyOffset.left;
                    } else {
                        styles.top = offset.top + jQuery( options.form).innerHeight();
                        styles.left = offset.left;
                    }
                    
                    resultsHeight = getResultsBlockHeight( options.resultsBlock );
                    styles.top = styles.top - resultsHeight - jQuery(options.form).innerHeight();
                    
                    
                return styles;
            }
            AwsHooks.add_filter( "aws_results_layout", aws_results_layout );
        ';
    
        wp_add_inline_script( 'aws-script', $script);
        wp_add_inline_script( 'aws-pro-script', $script);
    
    }

    You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.

    Regards

    Thread Starter vogliadibuono

    (@vogliadibuono)

    wow! perfect! what if i want it to do it only on mobile? or only on a specific search widget(for example using the CSS ID)? thank you very much for your patience and professionalism

    • This reply was modified 3 years, 10 months ago by vogliadibuono.
    Plugin Author ILLID

    (@mihail-barinov)

    Well to you it only on mobile you can add following line in the beginning of aws_wp_enqueue_scripts function.

    if ( ! wp_is_mobile()  ) {
        return;
    }

    For winget you can add after

    var resultsHeight = options.resultsBlock.height();

    following code

    if ( ! jQuery( options.form).closest("WIDGET_SELECTOR").length > 0 ) {
                        return styles;
                    }

    change WIDGET_SELECTOR to proper winget selector.

    Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘shows results to the top’ is closed to new replies.