I noticed the Custom search paths only displays as a select dropdown. Is there any way to allow the user to choose the Selector Type(ex. Radio buttons) for the Custom Search Paths and the "Label Text"?

Or maybe Custom Search Paths can be combined with "Content" fieldset.

Not sure if this is possible but here you go

Example Search Form
================
Search input

Label text - Customize your search
radio - Search this site
checkbox - Departments
checkbox - Questions
checkbox - Events

radio - Custom search path
radio - Custom search path
radio - Custom search path

================

I was mainly hoping that a user could click into the search field then see a list of options drop down similar to the sites below
Example www.themeforest.net - click into their search field.
http://tympanus.net/Tutorials/UIElements/SearchBox/

Once it has dropped down the user could check the content types he/she wants to search or the external sites he/she wants to search on.

What do you think would be the best way to handle this?

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jdanthinne’s picture

Status: Active » Needs work

Hi,

The first part (adding a label, and choosing a selector type) should be easy. I'm just waiting for the issue #916344: How to reference selected taxonomy term in custom search path? to be fixed (major reworking of custom paths), so I can add more options.

The second part (themeforest-like) is a very very nice idea, but is more a theming/css/js thing, but I'll think about it.

rhymeswithcamera’s picture

+1 subscribing

jdanthinne’s picture

Status: Needs work » Needs review

I've just upload a new DEV version (should be available tomorrow), with settings for selector type and label text.
Please review.

gmclelland’s picture

So far everything is working correctly for me. I am seeing the selector type and using the checkboxes.

jdanthinne’s picture

Status: Needs review » Needs work

Great. When other current bugs are gone, I'll have a look at the "themeforest"-like thing.

gmclelland’s picture

Well I figured out the Themeforest like search. I ended up not using the code from http://tympanus.net/Tutorials/UIElements/SearchBox/. It had a usability problem of the search options disappearing when you mouseout.

If interested, here is the code I used to fade in the search options when the search input is clicked. When you click outside the search input it will make the search options disappear. It works great, but falls short in that it doesn't work with the keyboard. I probably need to spend some more time on keyboard accessibility and abstraction. This works with the stock drupal jquery.

Of course you need to add your own CSS to hide and position the search options.

Drupal.behaviors.cmftaoAddSearchBoxClass = function (context) {
var $searchTitle = $('#block-custom_search_blocks-1>div.block-title');
var $searchInput = $('#edit-custom-search-blocks-form-1');
var $searchOptions = $('#block-custom_search_blocks-1 div.custom-search-types');
var $searchPaths = $('#block-custom_search_blocks-1 div#edit-custom-search-paths-wrapper');
 

/* Hide the block title */
$searchTitle.remove();

/* Hide the Search Options */
$searchOptions.hide().click(function(e){
e.stopPropagation();
});

/* Hide the Search Paths */
$searchPaths.hide().click(function(e){
e.stopPropagation();
});

/* Open the Search Options and Search Paths */
$searchInput.click(function(e){
    e.stopPropagation();
    $searchOptions.fadeIn('normal');
    $searchPaths.fadeIn('normal');
    $(this).addClass('opened');
    
});

/* Hide the search options when focus outside */
/* http://rob-bell.net/2009/02/handling-clicks-outside-a-specified-area-in-jquery/ */

$(document).click(function(){
$searchPaths.hide();
$searchOptions.hide();
$searchInput.removeClass('opened');
});

/* End of behavior */
};
Everett Zufelt’s picture

Is there a demo of this applied somewhere? I am curious if it will work for screen-reader users. IMO, if this doesn't work for keyboard only users it is a regression and not an enhancement.

gmclelland’s picture

Unfortunately, there is no demo. It is running locally. It works in IE6+, Firefox, Chrome, Safari, Opera. It should now be keyboard accessible.

I just posted this code to help someone who might be trying to do the same thing.

Drupal.behaviors.cmftaoSearchBoxDropdown = function (context) {
var $searchTitle = $('#block-custom_search_blocks-1>div.block-title');
var $searchInput = $('#edit-custom-search-blocks-form-1');
var $searchOptions = $('#block-custom_search_blocks-1 div.custom-search-types');
var $searchPaths = $('#block-custom_search_blocks-1 div#edit-custom-search-paths-wrapper');
 

/* Hide the block title */
$searchTitle.remove();

/* Add a close Search Options link */
$searchOptions.append('<a class="closeSearchOptions" href="#">Close</a>');
$searchOptions.find('a.closeSearchOptions').click(function(e){
e.preventDefault(); /* prevent browser default */
$searchOptions.hide();
$searchPaths.hide();
});

/* Hide the Search Options */
$searchOptions.hide().click(function(e){
e.stopPropagation();
});

/* Hide the Search Paths */
$searchPaths.hide().click(function(e){
e.stopPropagation();
});

/* Open the Search Options and Search Paths */
$searchInput.bind('click focus',(function(e){
    e.stopPropagation();
    $searchOptions.fadeIn('normal');
    $searchPaths.fadeIn('normal');
    $(this).addClass('opened');

    
}));

/* Hide the search options when focus outside */
/* http://rob-bell.net/2009/02/handling-clicks-outside-a-specified-area-in-jquery/ */

$(document).bind('click focus',function(){
$searchPaths.hide();
$searchOptions.hide();
$searchInput.removeClass('opened');
});

/* End of behavior */
};
rhymeswithcamera’s picture

This is awesome! I want to test it out, but since I'm not a developer, per se, can you tell me what file to copy/paste this code into? Thanks for tackling this!

gmclelland’s picture

In your theme add a javascript file with the code I provided. Make sure your javascript file is referenced in your .info file.
Something like scripts[] = js/cmf_script.js

Then change the variables at the top of the code to match your selectors in your theme. Customize as needed. CSS is needed to control the look and positioning of the dropdown.

rhymeswithcamera’s picture

Got it - and got it working. Now to make it look pretty. He! Thank you!

jdanthinne’s picture

Nice script gmclelland! Got it working with some changes.
But I won't implement it in that way. I'd prefer to make a UI in the settings (perhaps within the "Ordering tree") where people could chose what to include in this fading options block, so taxonomy selectors could also be included as well if needed.

rhymeswithcamera’s picture

I may be a Drupal noob, but that's not my story in Facebook land. If this were Facebook, I'd give comment #12 two thumbs up! Thanks @gmclelland and @jdanthinne!

jdanthinne’s picture

Status: Needs work » Needs review

Here it is!!
I've just committed a new Dev version.
Now you can put form elements in the "popup" region, and this region will only appear when search field is activated.
I've added css and js for basic behaviour (region hided at first, and position is "absolute"), so update your css definitions to match your theme.
Please test deeply (there are many many changes in the module to achieve this), and review.

rhymeswithcamera’s picture

This is great! I will try it out in the next day or two and report back.

gmclelland’s picture

@jdanthinne - So far it looks to be working good with one search field. I haven't tried testing two search fields on the same page.

Is there anyway you could move the close link inside of div.fieldset-content?
You can do this by changing:

Line 107 - custom_search.js
from var popup = $('fieldset.custom_search-popup');
to this var popup = $('fieldset.custom_search-popup div.fieldset-content');

The reason I say this is because I would like the close link to be located in the bottom right of the popup. The only way to do this currently is to set a height and width on the fieldset.custom_search-popup and then absolutely position the close link to the bottom right. The problem with that is, the height of fieldset.custom_search-popup is unknown(it grows in height based on what search options are in it).

By placing the close link inside of the div.fieldset-content, it will naturally fall below(after) all the other elements.

FYI... After making the change, I noticed the popup fades in twice for some reason. I'm still looking into that. The close link is positioned correctly. Maybe it's just my theme?

What's your thoughts? Great job, by the way.

jdanthinne’s picture

FileSize
19.48 KB

Okay, for the double fadeIn, I've changed (and commited to DEV)
if (popup.find('input,select').length) popup.fadeIn().addClass('opened');
to
if (popup.find('input,select').length && !popup.hasClass('opened')) popup.fadeIn().addClass('opened');.

That was happening because the search field has two event listeners 'click' and 'focus' and they both open the popup. With this change, the code checks if it's already open...

And for the change you've made. That doesn't work for me, because there's no div.fieldset-content by default (I'm always using Garland for the tests). But you don't need it, I've tested this css definition for the close link:
a.custom_search-popup-close { position:absolute; right:5px; bottom:3px;}
and it works fine! (see my screenshot)

Please re-test and re-view :-)

gmclelland’s picture

I made the changes you indicated. That fixed the double fade. I changed my css and it worked just as you said.

Hive Five,
-Glenn

jdanthinne’s picture

Status: Needs review » Fixed

Thanks. That was a nice feature idea :-)

rhymeswithcamera’s picture

I have just tested the 02-Nov-2010 DEV release in my test localhost environment. I've run into two new issues. I suspect that I may not have everything configured right yet.

(1) When I do a keyword search - with or without types - I get an "Oops! This link appears to be broken." Looking at the URL, the port number is missing.
Actual: test.localhost/search/apachesolr_search/[keyword]
Expected: test.localhost:8082/search/apachesolr_search/[keyword]

(2) My search box appears on all pages. On any non-search-related page, when I click into the search box, the popup does not display. Once I execute a search (and add the port # to the URL - see #1), the search box then works as expected.
Actual: Popup only displays when I'm on a .../search/... page.
Expected: Popup displays anytime I click into the search box on any page.

jdanthinne’s picture

Status: Fixed » Active

Can you download the latest DEV, and run update.php, to be sure…
And then, for (2), does Firebug (Firefox), or WebInspector (Safari/Chrome) throw a javascript error or something?

rhymeswithcamera’s picture

I downloaded the latest DEV, ran update.php (no updates), and ran the same tests in Chrome, Firefox and Safari. No console errors or warnings (that I can tell). I'm still having the same two issues as reported in #20. Regardless of browser, I have to add the port number to all searches, and the popup only shows up on .../search/... pages. Is there something else I should check?

jdanthinne’s picture

Ok, I've found the bug for (1). I was using SERVER_NAME instead of HTTP_HOST. Working fine with the port.
Still investigating for (2). Do you have a test address for me to check? Or a DB dump?

gmclelland’s picture

For what it's worth, my search box is showing and working fine on every page. I'm using the context module for block placement, not the block UI.

jdanthinne’s picture

But is the popup block also showing up on every page?

gmclelland’s picture

Yes, I have a sitewide context setup that say's to show the custom search block on every page.

jdanthinne’s picture

Yeas, but the problem here is not the custom search block itself, but the "contextual" popup block (new feature).
See http://drupal.org/files/issues/popup-close_1.png

gmclelland’s picture

Yes, the popup is showing correctly on every page for me.

jdanthinne’s picture

So, I guess, rhymeswithcamera, perhaps there's some javascript added by something else that goes against the popup behaviour.

rhymeswithcamera’s picture

Thanks for resolving issue 1 (#20). As for the second issue, I investigated a bit more, and it appears that the HTML for the popup is being generated for all pages as it should. In fact, when I inspect the page, the popup elements are all there - just invisible on the non-search pages.

The only HTML difference (that I can see so far) is the opacity setting. On non-search pages, there is a style setting - "opacity: 0" - and I don't see the popup. On search pages, there's no such setting and I see the popup. I've attached screenshots of the HTML output. What is the best way to override the opacity setting?

gmclelland’s picture

Just noticed a problem. When an element is added to the DOM, the behavior gets called again and the close link results in duplicate close links. In my case I noticed it happening when I edit a box with the boxes module. It provides in-page editing of blocks.

The solution is here under behaviors
http://drupal.org/node/205296

I had a similar problem with a Column List Splitter jquery script running again everytime something was added to the DOM.
Here was the code before:

Drupal.behaviors.cmftaoSplitLists = function (context) {
  $('div.menu-block-3 ul.menu').easyListSplitter({colNumber:4});
}; /* End of behavior */

Here is the code after that fixed the problem.

Drupal.behaviors.cmftaoSplitLists = function (context) {
  $('div.menu-block-3 ul.menu:not(cmftaoSplitLists-processed)', context).addClass("cmftaoSplitLists-processed").easyListSplitter({colNumber:4});
}; /* End of behavior */

On line 107 in custom_search.js
I think changing
var popup = $('fieldset.custom_search-popup');

to

var popup = $('fieldset.custom_search-popup:not('custom_search-processed')', context);
popup.click(function(e){
    e.stopPropagation();
  })
popup.addClass("custom_search-processed").append('<a class="custom_search-popup-close" href="#">' + Drupal.t('Close') + '</a>');
$('a.custom_search-popup-close').click(function(e){
    $('fieldset.custom_search-popup.opened').hide().removeClass('opened');
    e.preventDefault();
  });

Hope that helps,
-Glenn

Ela’s picture

This is a very cool new feature :) Thank you for implementing this.
I have just one problem.. the popup seems to display behind my other blocks, so the options hide behind the block below.. :( any tips on how to fix it?

gmclelland’s picture

@Ela - change your css on the options element to a higher z-index

Ela’s picture

@gmclelland ... I'm sorry for my lack of knowledge .. Can you please give me a tip on how to do that?

gmclelland’s picture

In your theme's .css file try adding:

fieldset.custom_search-popup{
z-index:1000;
}
Ela’s picture

Works great! Thank you for the tip! :)

Ela’s picture

... however now the "search" button appears above the Search input ...

gmclelland’s picture

Sorry, but the css styles can vary from theme to theme. Without seeing your site I am unable to help.

jdanthinne’s picture

@rhymeswithcamera : Strange for this opacity thing… Can you try with another theme (Garland), just to see if it's a bug or something to do with your theme?

jdanthinne’s picture

Status: Active » Needs review

@gmclelland : I've fixed the Boxes js bug, without adding additionnal class, but by adding a context:

var popup = $('fieldset.custom_search-popup', context);

Commited to DEV. Please test & review.

gmclelland’s picture

Ok, I couldn't download the new dev yet, but I did make the change you specified in custom_search.js. That fixed the close link from duplicating when I click on the "Edit" link of a box with the Boxes module, however I tried clicking the cog icon and choosing "Edit Skin" on a block with the Skinr module installed and the link still duplicates.

I'm not sure what adding the context parameter does, but I know the javascript on the new drupal.org uses the

var popup = $('fieldset.custom_search-popup:not(.custom_search-processed)', context).addClass("custom_search-processed");

syntax.

I tried adding this to custom_search.js line 107

  var popup = $('fieldset.custom_search-popup:not(.custom_search-processed)', context).addClass("custom_search-processed");

and it fixed the Skinr issue and the Boxes module issue.

Hope that helps,
-Glenn

jdanthinne’s picture

Ok, committed the ':not' fix as well :-)

rhymeswithcamera’s picture

I switched my theme to Garland and the issue disappears, so it must be tied to my theme (which is a custom subtheme based on Fusion Core). I'll continue to tackle on my end. Thanks.

jdanthinne’s picture

Status: Needs review » Closed (fixed)
nicothezulu’s picture

You should take care with fusions overflow css property... it will hide the popup box.