Skip to content

Commit

Permalink
Do not display selector when only one Namespace available
Browse files Browse the repository at this point in the history
  • Loading branch information
gamma committed Sep 8, 2014
1 parent bfe0f88 commit 42f6678
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 13 additions & 7 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ function tpl_searchform($namespaces, $return = false) {
$searchForm = ob_get_contents();
ob_end_clean();

// Default Selct
$namespaceSelect = '<select class="fancysearch_namespace" name="namespace">';
foreach ($namespaces as $element) {
list($ns, $name, $class) = $element;
$namespaceSelect .= '<option class="fancysearch_ns_'.hsc($class).'" value="'.hsc($ns).'"'.($cur_val === $ns ? ' selected="selected"' : '').'>'.$name.'</option>';
}
$namespaceSelect .= '</select>';
// Default Select
if ( count($namespaces) == 1 ) {
// Only one of them. All of them.
list($ns, $name, $class) = $namespaces[0];
$namespaceSelect = '<input name="namespace" value="'.hsc($ns).'" type="hidden"/>';
} else {
$namespaceSelect = '<select class="fancysearch_namespace" name="namespace">';
foreach ($namespaces as $element) {
list($ns, $name, $class) = $element;
$namespaceSelect .= '<option class="fancysearch_ns_'.hsc($class).'" value="'.hsc($ns).'"'.($cur_val === $ns ? ' selected="selected"' : '').'>'.$name.'</option>';
}
$namespaceSelect .= '</select>';
}

// Insert reight at the beginning.
$searchForm = substr_replace($searchForm, $namespaceSelect, strpos($searchForm, '<input'), 0);
Expand Down
3 changes: 3 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ select.fancysearch_namespace option {

#dokuwiki__sitetools form.search #qsearch__in {
width: 36em;
}

#dokuwiki__sitetools form.search select ~ #qsearch__in {
box-sizing: border-box;
padding-left: 50%;
}

0 comments on commit 42f6678

Please sign in to comment.