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 revisionPrevious revision
tips:default_text_search [2010-11-13 00:17] – make sure the default text isn't searched 137.71.23.54tips:default_text_search [2013-09-18 22:05] (current) – Update to use placeholder attribute Klap-in
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.1289603820.txt.gz · Last modified: 2010-11-13 00:17 by 137.71.23.54

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki