Workaround for Chrome problem on db search
[phpmyadmin-themes.git] / js / db_search.js
blob41ea5e66e900ad5226f0ce40bdb3bb44ac204c73
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * @fileoverview    JavaScript functions used on Database Search page
4  * @name            Database Search
5  *
6  * @requires    jQuery
7  * @requires    js/functions.js
8  */
10 /**
11  * AJAX script for the Database Search page.
12  *
13  * Actions ajaxified here:
14  * Retrieve result of SQL query
15  */
17 $(document).ready(function() {
19     /**
20      * Set a parameter for all Ajax queries made on this page.  Don't let the
21      * web server serve cached pages
22      */
23     $.ajaxSetup({
24         cache: 'false'
25     });
27     /**
28      * Prepare a div containing a link, otherwise it's incorrectly displayed 
29      * after a couple of clicks
30      */
31     $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
32     .insertAfter('#db_search_form')
33     // don't show it until we have results on-screen
34     .hide();
36    $('#togglesearchformlink')
37        .html(PMA_messages['strShowSearchCriteria'])
38        .bind('click', function() {
39             var $link = $(this);
40             $('#db_search_form').slideToggle();
41             if ($link.text() == PMA_messages['strHideSearchCriteria']) {
42                 $link.text(PMA_messages['strShowSearchCriteria']);
43             } else {
44                 $link.text(PMA_messages['strHideSearchCriteria']);
45             }
46             // avoid default click action
47             return false;
48        });
49     /**
50      * Ajax Event handler for retrieving the result of an SQL Query
51      * (see $GLOBALS['cfg']['AjaxEnable'])
52      *
53      * @uses    PMA_ajaxShowMessage()
54      */
55     $("#db_search_form.ajax").live('submit', function(event) {
56         event.preventDefault();
58         PMA_ajaxShowMessage(PMA_messages['strSearching']);
59         // jQuery object to reuse
60         $form = $(this);
61         
62         // add this hidden field just once 
63         if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
64             $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
65         }
67         $.post($form.attr('action'), $form.serialize() + "&submit_search=" + $("#buttonGo").val(),  function(response) {
68             if (typeof response == 'string') {
69                 // found results
70                 $("#searchresults").html(response);
71                 $("#sqlqueryresults").trigger('appendAnchor');
72                 $('#db_search_form')
73                     // workaround for Chrome problem (bug #3168569)
74                     .slideToggle()
75                     .hide();
76                 $('#togglesearchformlink')
77                     // always start with the Show message
78                     .text(PMA_messages['strShowSearchCriteria'])
79                 $('#togglesearchformdiv')
80                     // now it's time to show the div containing the link 
81                     .show();
82             } else {
83                 // error message (zero rows)
84                 $("#sqlqueryresults").html(response['message']);
85             }            
86         })
87     })
88 }, 'top.frame_content'); // end $(document).ready()