DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:default_text_search

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tips:default_text_search [2010-11-13 00:17]
137.71.23.54 make sure the default text isn't searched
tips:default_text_search [2013-09-18 22:05] (current)
Klap-in Update to use placeholder attribute
Line 1: Line 1:
 ====== Adding default text for the search box ====== ====== Adding default text for the search box ======
  
-Just copy/paste this into your local ''./conf/userscript.js'' file.+Just copy and paste this into your local ''[dokuwiki]/conf/userscript.js'' file.
  
 <code javascript> <code javascript>
-var default_text Enter Keywords to search wiki";+/** 
 + * Add a placeholder text into the input field of the wiki search 
 + */ 
 +jQuery(function () { 
 +    var defaulttext_searchinput 'Enter Keywords to search wiki';
  
-function DefaultSearch_blur() +    var $searchinput jQuery('#qsearch__in'); 
-+    if ($searchinput.length && !$searchinput.attr('placeholder')) { 
-        var search_input document.getElementById('qsearch__in'); +        $searchinput.attr('placeholder', defaulttext_searchinput)
-        if (search_input !== null && search_input.value == ""+    } 
-                search_input.value = default_text+}); 
-}+</code>
  
-function DefaultSearch_focus() 
-{ 
-        var search_input = document.getElementById('qsearch__in'); 
-        if (search_input !== null && search_input.value == default_text) 
-                search_input.value = ""; 
-} 
- 
-function CheckSearch() 
-{ 
-        var search_input = document.getElementById('qsearch__in'); 
-        if (search_input !== null && search_input.value == default_text) 
-                search_input.value = ""; 
-} 
- 
-function installDefaultSearch() 
-{ 
-        var search_input = document.getElementById('qsearch__in'); 
-        var search_form  = document.getElementById('dw__search'); 
-        if(search_input !== null) { 
-                addEvent(search_input, 'focus', DefaultSearch_focus); 
-                addEvent(search_input, 'blur',  DefaultSearch_blur); 
-                search_input.value = default_text; 
-        } 
-        if (search_form !== null) { 
-                addEvent(search_form, 'click', CheckSearch); 
-        } 
- 
- 
-} 
- 
-addInitEvent(installDefaultSearch); 
-</code> 
  
 ===== More info ===== ===== More info =====
  
 Can be found in the [[:devel:javascript]] pages. Can be found in the [[:devel:javascript]] pages.
- 
tips/default_text_search.txt · Last modified: 2013-09-18 22:05 by Klap-in