News:

Wondering if this will always be free?  See why free is better.

Main Menu

Add context to simple (quick) search

Started by pctwo, September 07, 2006, 01:59:25 AM

Previous topic - Next topic

pctwo

with 1.1RC3, we can now search in a topic using the simple (quick) search.  However, the user may not realize that when he's in a board, he's searching only the board if he uses the simple search, and when he's in a topic, he's searching only that topic.  This little change (which I haven't packaged into a nice mod b/c I haven't learned how to -- newbie alert!!) will show the user what context he's searching in and allows him to change it using a <select>.  So when he's at top level, there's no option.  When he's in a board, he can search the board or all.  When he's in a topic, he can search the topic, the board, or all.  Visual mockup (I can't post attachment)


____________ (search)   [ all         ]
                        [ this board  ]
                        [ this topic  ]


File:
Themes/name/index.template.php

Find:

   // Output any remaining HTML headers. (from mods, maybe?)
   echo $context['html_headers'], '

Add after


<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function search_context_change()
{
ctx =  document.quick_search.search_context.value;
if (ctx=="topic") {
if (document.quick_search.board_) document.quick_search.board_.name="dontuse";
document.quick_search.topic_.name = "topic";
} else
if (ctx=="board") {
if (document.quick_search.topic_) document.quick_search.topic_.name="donotuse";
document.quick_search.board_.name = "brd["+document.quick_search.board_.value+"]";
} else {
if (document.quick_search.board_) document.quick_search.board_.name="dontuse";
if (document.quick_search.topic_) document.quick_search.topic_.name="donotuse";
}
}
// ]]></script>



find:


<form action="', $scripturl, '?action=search2" method="post"


change to (add name="quick_search")

<form name="quick_search" action="', $scripturl, '?action=search2" method="post"

replace block


// Search within current topic?
if (!empty($context['current_topic']))
echo '
<input type="hidden" name="topic" value="', $context['current_topic'], '" />';

// If we're on a certain board, limit it to this board ;).
elseif (!empty($context['current_board']))
echo '
<input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';


replace with


if (!empty($context['current_board']) || !empty($context['current_topic']))
{
echo '
<select onchange="javascript:search_context_change();" name="search_context">
<option value="all">', $txt['search_context_all'], '</option>';

$hidden_inputs = '';

if (!empty($context['current_board']))
{
echo '
<option value="board" ',
empty($context['current_topic'])
? 'selected="selected"' : '', '>', $txt['search_context_board'], '</option>';
$hidden_inputs .= '
<input type="hidden" id="board_" name="' .
(empty($context['current_topic']) ? 'brd[' . $context['current_board'] . ']' : 'dontuse') .
'" value="' . $context['current_board'] . '" />';
}
if (!empty($context['current_topic']))
{
echo '
<option value="topic" selected="selected">', $txt['search_context_topic'], '</option>';
$hidden_inputs .= '
<input type="hidden" id="topic_" name="topic" value="' . $context['current_topic'] . '" />';
}
echo '
</select>', $hidden_inputs;
}


almost over!  now add to themes/name/languages/index.(lang).php


$txt['search_context_board'] = 'this board';
$txt['search_context_topic'] = 'this topic';
$txt['search_context_all'] = 'all';


hope that's useful :)

Bigguy

This seems real cool. I can try to package it for you if you. Not tonight cause its late but if your interested PM me. :)

Bigguy

I have started the package and now am in the testing phaze. I will do more tomorrow as there are some errors.

pctwo

oops, I messed up something in the original post.  I had id="quick_search" when it should've been name="quick_search".  I've tested this on Opera 9, IE 6, and Firefox 1.5.  I guess if you really want to be safe you should have both name and id :)

JayBachatero

This is a nice Tip.  I was just about to suggest for you to package it up.  If you are interested take a look at Package SDK, anyone?.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Bigguy

Have you fixed your first post. ??? I will start over. I want to do it.

EDIT: unless you would like to try pctwo. ???

pctwo

#6
I'll learn how one of these days, but til then, please do it.  I'm more likely to mess something up :)

thanks, Bigguy.  And by all means give yourself credit, like "___ mod by Bigguy, based on a tip by pctwo"

edit: yes my first post should now be correct

Bigguy

I'll get on it today for you. If all goes well it might be done by tonight. (I hope) ;)

Bigguy

Having some major problems with this part of the one edit:

<!-- // --><![CDATA[

I don't think This can be in the middle of the code.

JayBachatero

You can't.  Try using the board mod format instead of the .xml.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Bigguy

Ok, I'll give that a shot.  Thanks Jay.

pctwo

Quote from: Bigguy on September 09, 2006, 07:46:10 PM
Having some major problems with this part of the one edit:

<!-- // --><![CDATA[

I don't think This can be in the middle of the code.

I just copied that syntax without knowing what it does really.  what DOES it do?

Traditionally, you're supposed to wrap the entire script with <!-- --> so you don't confuse really old browsers, but that's hardly necessary nowadays.

Dannii

If your javascript has < > or & you need to put it in <![CDATA[ ]]> tags so that it is valid x(ht)ml. Javascript however won't understand that, so you need to comment it out with // tags first.
I'm not certain why the (x)html comments are needed to comment out the // though..

If you wrap the whole script in (x)html comments then moddern browsers might not run the script at all.
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Bigguy

Well, making a .mod file is a bit harder I think then making a .xml file. I keep getting a modification parse error, but I'm still trying. :)

Bigguy

Ok, I have not given up just got a bit busy. I will start on this again later tonight. :)

Bigguy

That one edit is still screwing me up is there another way to right that.

pctwo

#16
I think you can forget the cdata stuff

<script language="JavaScript" type="text/javascript"><!--

--></script>



php seems ok with it and it passes w3c validation.

I'm sorry you're having so much trouble.  I think it's harder to package this little mod up than to write it :(

P.S: I think we should change

$txt['search_context_all'] = 'all';

to

$txt['search_context_all'] = 'entire forum';

to make it clearer.

Bigguy

Ok, I'll give that a try. I have had it packaged and installed but I keep getting parse errors and I don't think I am packing that cdata stuff right so I will try it without it.

Assistance

Quotewith 1.1RC3, we can now search in a topic using the simple (quick) search.  However, the user may not realize that when he's in a board, he's searching only the board if he uses the simple search, and when he's in a topic, he's searching only that topic.

some admins may not know that aswell  :-[
~playing poker~

GaMerZ


Advertisement: