Translated using Weblate (Spanish)
[phpmyadmin.git] / js / navigation.js
blob494b7d0a0460f27decff9dedd7b4d50a111a43eb
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * function used in or for navigation panel
4  *
5  * @package phpMyAdmin-Navigation
6  */
8 /**
9  * updates the tree state in sessionStorage
10  *
11  * @returns void
12  */
13 function navTreeStateUpdate () {
14     // update if session storage is supported
15     if (isStorageSupported('sessionStorage')) {
16         var storage = window.sessionStorage;
17         // try catch necessary here to detect whether
18         // content to be stored exceeds storage capacity
19         try {
20             storage.setItem('navTreePaths', JSON.stringify(traverseNavigationForPaths()));
21             storage.setItem('server', PMA_commonParams.get('server'));
22             storage.setItem('token', PMA_commonParams.get('token'));
23         } catch (error) {
24             // storage capacity exceeded & old navigation tree
25             // state is no more valid, so remove it
26             storage.removeItem('navTreePaths');
27             storage.removeItem('server');
28             storage.removeItem('token');
29         }
30     }
34 /**
35  * updates the filter state in sessionStorage
36  *
37  * @returns void
38  */
39 function navFilterStateUpdate (filterName, filterValue) {
40     if (isStorageSupported('sessionStorage')) {
41         var storage = window.sessionStorage;
42         try {
43             var currentFilter = $.extend({}, JSON.parse(storage.getItem('navTreeSearchFilters')));
44             var filter = {};
45             filter[filterName] = filterValue;
46             currentFilter = $.extend(currentFilter, filter);
47             storage.setItem('navTreeSearchFilters', JSON.stringify(currentFilter));
48         } catch (error) {
49             storage.removeItem('navTreeSearchFilters');
50         }
51     }
55 /**
56  * restores the filter state on navigation reload
57  *
58  * @returns void
59  */
60 function navFilterStateRestore () {
61     if (isStorageSupported('sessionStorage')
62         && typeof window.sessionStorage.navTreeSearchFilters !== 'undefined'
63     ) {
64         var searchClauses = JSON.parse(window.sessionStorage.navTreeSearchFilters);
65         if (Object.keys(searchClauses).length < 1) {
66             return;
67         }
68         // restore database filter if present and not empty
69         if (searchClauses.hasOwnProperty('dbFilter')
70             && searchClauses.dbFilter.length
71         ) {
72             $obj = $('#pma_navigation_tree');
73             if (! $obj.data('fastFilter')) {
74                 $obj.data(
75                     'fastFilter',
76                     new PMA_fastFilter.filter($obj, '')
77                 );
78             }
79             $obj.find('li.fast_filter.db_fast_filter input.searchClause')
80                 .val(searchClauses.dbFilter)
81                 .trigger('keyup');
82         }
83         // find all table filters present in the tree
84         $tableFilters = $('#pma_navigation_tree li.database')
85             .children('div.list_container')
86             .find('li.fast_filter input.searchClause');
87         // restore table filters
88         $tableFilters.each(function () {
89             $obj = $(this).closest('div.list_container');
90             // aPath associated with this filter
91             var filterName = $(this).siblings('input[name=aPath]').val();
92             // if this table's filter has a state stored in storage
93             if (searchClauses.hasOwnProperty(filterName)
94                 && searchClauses[filterName].length
95             ) {
96                 // clear state if item is not visible,
97                 // happens when table filter becomes invisible
98                 // as db filter has already been applied
99                 if (! $obj.is(':visible')) {
100                     navFilterStateUpdate(filterName, '');
101                     return true;
102                 }
103                 if (! $obj.data('fastFilter')) {
104                     $obj.data(
105                         'fastFilter',
106                         new PMA_fastFilter.filter($obj, '')
107                     );
108                 }
109                 $(this).val(searchClauses[filterName])
110                     .trigger('keyup');
111             }
112         });
113     }
117  * Loads child items of a node and executes a given callback
119  * @param isNode
120  * @param $expandElem expander
121  * @param callback    callback function
123  * @returns void
124  */
125 function loadChildNodes (isNode, $expandElem, callback) {
126     var $destination = null;
127     var params = null;
129     if (isNode) {
130         if (!$expandElem.hasClass('expander')) {
131             return;
132         }
133         $destination = $expandElem.closest('li');
134         params = {
135             aPath: $expandElem.find('span.aPath').text(),
136             vPath: $expandElem.find('span.vPath').text(),
137             pos: $expandElem.find('span.pos').text(),
138             pos2_name: $expandElem.find('span.pos2_name').text(),
139             pos2_value: $expandElem.find('span.pos2_value').text(),
140             searchClause: '',
141             searchClause2: ''
142         };
143         if ($expandElem.closest('ul').hasClass('search_results')) {
144             params.searchClause = PMA_fastFilter.getSearchClause();
145             params.searchClause2 = PMA_fastFilter.getSearchClause2($expandElem);
146         }
147     } else {
148         $destination = $('#pma_navigation_tree_content');
149         params = {
150             aPath: $expandElem.attr('aPath'),
151             vPath: $expandElem.attr('vPath'),
152             pos: $expandElem.attr('pos'),
153             pos2_name: '',
154             pos2_value: '',
155             searchClause: '',
156             searchClause2: ''
157         };
158     }
160     var url = $('#pma_navigation').find('a.navigation_url').attr('href');
161     $.get(url, params, function (data) {
162         if (typeof data !== 'undefined' && data.success === true) {
163             $destination.find('div.list_container').remove(); // FIXME: Hack, there shouldn't be a list container there
164             if (isNode) {
165                 $destination.append(data.message);
166                 $expandElem.addClass('loaded');
167             } else {
168                 $destination.html(data.message);
169                 $destination.children()
170                     .first()
171                     .css({
172                         border: '0px',
173                         margin: '0em',
174                         padding : '0em'
175                     })
176                     .slideDown('slow');
177             }
178             if (data._errors) {
179                 var $errors = $(data._errors);
180                 if ($errors.children().length > 0) {
181                     $('#pma_errors').replaceWith(data._errors);
182                 }
183             }
184             if (callback && typeof callback === 'function') {
185                 callback(data);
186             }
187         } else if (data.redirect_flag === '1') {
188             if (window.location.href.indexOf('?') === -1) {
189                 window.location.href += '?session_expired=1';
190             } else {
191                 window.location.href += PMA_commonParams.get('arg_separator') + 'session_expired=1';
192             }
193             window.location.reload();
194         } else {
195             var $throbber = $expandElem.find('img.throbber');
196             $throbber.hide();
197             var $icon = $expandElem.find('img.ic_b_plus');
198             $icon.show();
199             PMA_ajaxShowMessage(data.error, false);
200         }
201     });
205  * Collapses a node in navigation tree.
207  * @param $expandElem expander
209  * @returns void
210  */
211 function collapseTreeNode ($expandElem) {
212     var $children = $expandElem.closest('li').children('div.list_container');
213     var $icon = $expandElem.find('img');
214     if ($expandElem.hasClass('loaded')) {
215         if ($icon.is('.ic_b_minus')) {
216             $icon.removeClass('ic_b_minus').addClass('ic_b_plus');
217             $children.slideUp('fast');
218         }
219     }
220     $expandElem.blur();
221     $children.promise().done(navTreeStateUpdate);
225  * Traverse the navigation tree backwards to generate all the actual
226  * and virtual paths, as well as the positions in the pagination at
227  * various levels, if necessary.
229  * @return Object
230  */
231 function traverseNavigationForPaths () {
232     var params = {
233         pos: $('#pma_navigation_tree').find('div.dbselector select').val()
234     };
235     if ($('#navi_db_select').length) {
236         return params;
237     }
238     var count = 0;
239     $('#pma_navigation_tree').find('a.expander:visible').each(function () {
240         if ($(this).find('img').is('.ic_b_minus') &&
241             $(this).closest('li').find('div.list_container .ic_b_minus').length === 0
242         ) {
243             params['n' + count + '_aPath'] = $(this).find('span.aPath').text();
244             params['n' + count + '_vPath'] = $(this).find('span.vPath').text();
246             var pos2_name = $(this).find('span.pos2_name').text();
247             if (! pos2_name) {
248                 pos2_name = $(this)
249                     .parent()
250                     .parent()
251                     .find('span.pos2_name:last')
252                     .text();
253             }
254             var pos2_value = $(this).find('span.pos2_value').text();
255             if (! pos2_value) {
256                 pos2_value = $(this)
257                     .parent()
258                     .parent()
259                     .find('span.pos2_value:last')
260                     .text();
261             }
263             params['n' + count + '_pos2_name'] = pos2_name;
264             params['n' + count + '_pos2_value'] = pos2_value;
266             params['n' + count + '_pos3_name'] = $(this).find('span.pos3_name').text();
267             params['n' + count + '_pos3_value'] = $(this).find('span.pos3_value').text();
268             count++;
269         }
270     });
271     return params;
275  * Executed on page load
276  */
277 $(function () {
278     if (! $('#pma_navigation').length) {
279         // Don't bother running any code if the navigation is not even on the page
280         return;
281     }
283     // Do not let the page reload on submitting the fast filter
284     $(document).on('submit', '.fast_filter', function (event) {
285         event.preventDefault();
286     });
288     // Fire up the resize handlers
289     new ResizeHandler();
291     /**
292      * opens/closes (hides/shows) tree elements
293      * loads data via ajax
294      */
295     $(document).on('click', '#pma_navigation_tree a.expander', function (event) {
296         event.preventDefault();
297         event.stopImmediatePropagation();
298         var $icon = $(this).find('img');
299         if ($icon.is('.ic_b_plus')) {
300             expandTreeNode($(this));
301         } else {
302             collapseTreeNode($(this));
303         }
304     });
306     /**
307      * Register event handler for click on the reload
308      * navigation icon at the top of the panel
309      */
310     $(document).on('click', '#pma_navigation_reload', function (event) {
311         event.preventDefault();
313         // Find the loading symbol and show it
314         var $icon_throbber_src = $('#pma_navigation').find('.throbber');
315         $icon_throbber_src.show();
316         // TODO Why is a loading symbol both hidden, and invisible?
317         $icon_throbber_src.css('visibility', '');
319         // Callback to be used to hide the loading symbol when done reloading
320         function hideNav () {
321             $icon_throbber_src.hide();
322         }
324         // Reload the navigation
325         PMA_reloadNavigation(hideNav);
326     });
328     $(document).on('change', '#navi_db_select',  function (event) {
329         if (! $(this).val()) {
330             PMA_commonParams.set('db', '');
331             PMA_reloadNavigation();
332         }
333         $(this).closest('form').trigger('submit');
334     });
336     /**
337      * Register event handler for click on the collapse all
338      * navigation icon at the top of the navigation tree
339      */
340     $(document).on('click', '#pma_navigation_collapse', function (event) {
341         event.preventDefault();
342         $('#pma_navigation_tree').find('a.expander').each(function () {
343             var $icon = $(this).find('img');
344             if ($icon.is('.ic_b_minus')) {
345                 $(this).click();
346             }
347         });
348     });
350     /**
351      * Register event handler to toggle
352      * the 'link with main panel' icon on mouseenter.
353      */
354     $(document).on('mouseenter', '#pma_navigation_sync', function (event) {
355         event.preventDefault();
356         var synced = $('#pma_navigation_tree').hasClass('synced');
357         var $img = $('#pma_navigation_sync').children('img');
358         if (synced) {
359             $img.removeClass('ic_s_link').addClass('ic_s_unlink');
360         } else {
361             $img.removeClass('ic_s_unlink').addClass('ic_s_link');
362         }
363     });
365     /**
366      * Register event handler to toggle
367      * the 'link with main panel' icon on mouseout.
368      */
369     $(document).on('mouseout', '#pma_navigation_sync', function (event) {
370         event.preventDefault();
371         var synced = $('#pma_navigation_tree').hasClass('synced');
372         var $img = $('#pma_navigation_sync').children('img');
373         if (synced) {
374             $img.removeClass('ic_s_unlink').addClass('ic_s_link');
375         } else {
376             $img.removeClass('ic_s_link').addClass('ic_s_unlink');
377         }
378     });
380     /**
381      * Register event handler to toggle
382      * the linking with main panel behavior
383      */
384     $(document).on('click', '#pma_navigation_sync', function (event) {
385         event.preventDefault();
386         var synced = $('#pma_navigation_tree').hasClass('synced');
387         var $img = $('#pma_navigation_sync').children('img');
388         if (synced) {
389             $img
390                 .removeClass('ic_s_unlink')
391                 .addClass('ic_s_link')
392                 .attr('alt', PMA_messages.linkWithMain)
393                 .attr('title', PMA_messages.linkWithMain);
394             $('#pma_navigation_tree')
395                 .removeClass('synced')
396                 .find('li.selected')
397                 .removeClass('selected');
398         } else {
399             $img
400                 .removeClass('ic_s_link')
401                 .addClass('ic_s_unlink')
402                 .attr('alt', PMA_messages.unlinkWithMain)
403                 .attr('title', PMA_messages.unlinkWithMain);
404             $('#pma_navigation_tree').addClass('synced');
405             PMA_showCurrentNavigation();
406         }
407     });
409     /**
410      * Bind all "fast filter" events
411      */
412     $(document).on('click', '#pma_navigation_tree li.fast_filter span', PMA_fastFilter.events.clear);
413     $(document).on('focus', '#pma_navigation_tree li.fast_filter input.searchClause', PMA_fastFilter.events.focus);
414     $(document).on('blur', '#pma_navigation_tree li.fast_filter input.searchClause', PMA_fastFilter.events.blur);
415     $(document).on('keyup', '#pma_navigation_tree li.fast_filter input.searchClause', PMA_fastFilter.events.keyup);
417     /**
418      * Ajax handler for pagination
419      */
420     $(document).on('click', '#pma_navigation_tree div.pageselector a.ajax', function (event) {
421         event.preventDefault();
422         PMA_navigationTreePagination($(this));
423     });
425     /**
426      * Node highlighting
427      */
428     $(document).on(
429         'mouseover',
430         '#pma_navigation_tree.highlight li:not(.fast_filter)',
431         function () {
432             if ($('li:visible', this).length === 0) {
433                 $(this).addClass('activePointer');
434             }
435         }
436     );
437     $(document).on(
438         'mouseout',
439         '#pma_navigation_tree.highlight li:not(.fast_filter)',
440         function () {
441             $(this).removeClass('activePointer');
442         }
443     );
445     /** Create a Routine, Trigger or Event */
446     $(document).on('click', 'li.new_procedure a.ajax, li.new_function a.ajax', function (event) {
447         event.preventDefault();
448         var dialog = new RTE.object('routine');
449         dialog.editorDialog(1, $(this));
450     });
451     $(document).on('click', 'li.new_trigger a.ajax', function (event) {
452         event.preventDefault();
453         var dialog = new RTE.object('trigger');
454         dialog.editorDialog(1, $(this));
455     });
456     $(document).on('click', 'li.new_event a.ajax', function (event) {
457         event.preventDefault();
458         var dialog = new RTE.object('event');
459         dialog.editorDialog(1, $(this));
460     });
462     /** Edit Routines, Triggers or Events */
463     $(document).on('click', 'li.procedure > a.ajax, li.function > a.ajax', function (event) {
464         event.preventDefault();
465         var dialog = new RTE.object('routine');
466         dialog.editorDialog(0, $(this));
467     });
468     $(document).on('click', 'li.trigger > a.ajax', function (event) {
469         event.preventDefault();
470         var dialog = new RTE.object('trigger');
471         dialog.editorDialog(0, $(this));
472     });
473     $(document).on('click', 'li.event > a.ajax', function (event) {
474         event.preventDefault();
475         var dialog = new RTE.object('event');
476         dialog.editorDialog(0, $(this));
477     });
479     /** Execute Routines */
480     $(document).on('click', 'li.procedure div a.ajax img,' +
481         ' li.function div a.ajax img', function (event) {
482         event.preventDefault();
483         var dialog = new RTE.object('routine');
484         dialog.executeDialog($(this).parent());
485     });
486     /** Export Triggers and Events */
487     $(document).on('click', 'li.trigger div:eq(1) a.ajax img,' +
488         ' li.event div:eq(1) a.ajax img', function (event) {
489         event.preventDefault();
490         var dialog = new RTE.object();
491         dialog.exportDialog($(this).parent());
492     });
494     /** New index */
495     $(document).on('click', '#pma_navigation_tree li.new_index a.ajax', function (event) {
496         event.preventDefault();
497         var url = $(this).attr('href').substr(
498             $(this).attr('href').indexOf('?') + 1
499         ) + PMA_commonParams.get('arg_separator') + 'ajax_request=true';
500         var title = PMA_messages.strAddIndex;
501         indexEditorDialog(url, title);
502     });
504     /** Edit index */
505     $(document).on('click', 'li.index a.ajax', function (event) {
506         event.preventDefault();
507         var url = $(this).attr('href').substr(
508             $(this).attr('href').indexOf('?') + 1
509         ) + PMA_commonParams.get('arg_separator') + 'ajax_request=true';
510         var title = PMA_messages.strEditIndex;
511         indexEditorDialog(url, title);
512     });
514     /** New view */
515     $(document).on('click', 'li.new_view a.ajax', function (event) {
516         event.preventDefault();
517         PMA_createViewDialog($(this));
518     });
520     /** Hide navigation tree item */
521     $(document).on('click', 'a.hideNavItem.ajax', function (event) {
522         event.preventDefault();
523         var argSep = PMA_commonParams.get('arg_separator');
524         var params = $(this).getPostData();
525         params += argSep + 'ajax_request=true' + argSep + 'server=' + PMA_commonParams.get('server');
526         $.ajax({
527             type: 'POST',
528             data: params,
529             url: $(this).attr('href'),
530             success: function (data) {
531                 if (typeof data !== 'undefined' && data.success === true) {
532                     PMA_reloadNavigation();
533                 } else {
534                     PMA_ajaxShowMessage(data.error);
535                 }
536             }
537         });
538     });
540     /** Display a dialog to choose hidden navigation items to show */
541     $(document).on('click', 'a.showUnhide.ajax', function (event) {
542         event.preventDefault();
543         var $msg = PMA_ajaxShowMessage();
544         var argSep = PMA_commonParams.get('arg_separator');
545         var params = $(this).getPostData();
546         params += argSep + 'ajax_request=true';
547         $.post($(this).attr('href'), params, function (data) {
548             if (typeof data !== 'undefined' && data.success === true) {
549                 PMA_ajaxRemoveMessage($msg);
550                 var buttonOptions = {};
551                 buttonOptions[PMA_messages.strClose] = function () {
552                     $(this).dialog('close');
553                 };
554                 $('<div/>')
555                     .attr('id', 'unhideNavItemDialog')
556                     .append(data.message)
557                     .dialog({
558                         width: 400,
559                         minWidth: 200,
560                         modal: true,
561                         buttons: buttonOptions,
562                         title: PMA_messages.strUnhideNavItem,
563                         close: function () {
564                             $(this).remove();
565                         }
566                     });
567             } else {
568                 PMA_ajaxShowMessage(data.error);
569             }
570         });
571     });
573     /** Show a hidden navigation tree item */
574     $(document).on('click', 'a.unhideNavItem.ajax', function (event) {
575         event.preventDefault();
576         var $tr = $(this).parents('tr');
577         var $msg = PMA_ajaxShowMessage();
578         var argSep = PMA_commonParams.get('arg_separator');
579         var params = $(this).getPostData();
580         params += argSep + 'ajax_request=true' + argSep + 'server=' + PMA_commonParams.get('server');
581         $.ajax({
582             type: 'POST',
583             data: params,
584             url: $(this).attr('href'),
585             success: function (data) {
586                 PMA_ajaxRemoveMessage($msg);
587                 if (typeof data !== 'undefined' && data.success === true) {
588                     $tr.remove();
589                     PMA_reloadNavigation();
590                 } else {
591                     PMA_ajaxShowMessage(data.error);
592                 }
593             }
594         });
595     });
597     // Add/Remove favorite table using Ajax.
598     $(document).on('click', '.favorite_table_anchor', function (event) {
599         event.preventDefault();
600         $self = $(this);
601         var anchor_id = $self.attr('id');
602         if ($self.data('favtargetn') !== null) {
603             if ($('a[data-favtargets="' + $self.data('favtargetn') + '"]').length > 0) {
604                 $('a[data-favtargets="' + $self.data('favtargetn') + '"]').trigger('click');
605                 return;
606             }
607         }
609         $.ajax({
610             url: $self.attr('href'),
611             cache: false,
612             type: 'POST',
613             data: {
614                 favorite_tables: (isStorageSupported('localStorage') && typeof window.localStorage.favorite_tables !== 'undefined')
615                     ? window.localStorage.favorite_tables
616                     : '',
617                 server: PMA_commonParams.get('server'),
618             },
619             success: function (data) {
620                 if (data.changes) {
621                     $('#pma_favorite_list').html(data.list);
622                     $('#' + anchor_id).parent().html(data.anchor);
623                     PMA_tooltip(
624                         $('#' + anchor_id),
625                         'a',
626                         $('#' + anchor_id).attr('title')
627                     );
628                     // Update localStorage.
629                     if (isStorageSupported('localStorage')) {
630                         window.localStorage.favorite_tables = data.favorite_tables;
631                     }
632                 } else {
633                     PMA_ajaxShowMessage(data.message);
634                 }
635             }
636         });
637     });
638     // Check if session storage is supported
639     if (isStorageSupported('sessionStorage')) {
640         var storage = window.sessionStorage;
641         // remove tree from storage if Navi_panel config form is submitted
642         $(document).on('submit', 'form.config-form', function (event) {
643             storage.removeItem('navTreePaths');
644         });
645         // Initialize if no previous state is defined
646         if ($('#pma_navigation_tree_content').length &&
647             typeof storage.navTreePaths === 'undefined'
648         ) {
649             PMA_reloadNavigation();
650         } else if (PMA_commonParams.get('server') === storage.server &&
651             PMA_commonParams.get('token') === storage.token
652         ) {
653             // Reload the tree to the state before page refresh
654             PMA_reloadNavigation(navFilterStateRestore, JSON.parse(storage.navTreePaths));
655         } else {
656             // If the user is different
657             navTreeStateUpdate();
658         }
659     }
663  * Expands a node in navigation tree.
665  * @param $expandElem expander
666  * @param callback    callback function
668  * @returns void
669  */
670 function expandTreeNode ($expandElem, callback) {
671     var $children = $expandElem.closest('li').children('div.list_container');
672     var $icon = $expandElem.find('img');
673     if ($expandElem.hasClass('loaded')) {
674         if ($icon.is('.ic_b_plus')) {
675             $icon.removeClass('ic_b_plus').addClass('ic_b_minus');
676             $children.slideDown('fast');
677         }
678         if (callback && typeof callback === 'function') {
679             callback.call();
680         }
681         $children.promise().done(navTreeStateUpdate);
682     } else {
683         var $throbber = $('#pma_navigation').find('.throbber')
684             .first()
685             .clone()
686             .css({ visibility: 'visible', display: 'block' })
687             .click(false);
688         $icon.hide();
689         $throbber.insertBefore($icon);
691         loadChildNodes(true, $expandElem, function (data) {
692             if (typeof data !== 'undefined' && data.success === true) {
693                 var $destination = $expandElem.closest('li');
694                 $icon.removeClass('ic_b_plus').addClass('ic_b_minus');
695                 $children = $destination.children('div.list_container');
696                 $children.slideDown('fast');
697                 if ($destination.find('ul > li').length === 1) {
698                     $destination.find('ul > li')
699                         .find('a.expander.container')
700                         .click();
701                 }
702                 if (callback && typeof callback === 'function') {
703                     callback.call();
704                 }
705                 PMA_showFullName($destination);
706             } else {
707                 PMA_ajaxShowMessage(data.error, false);
708             }
709             $icon.show();
710             $throbber.remove();
711             $children.promise().done(navTreeStateUpdate);
712         });
713     }
714     $expandElem.blur();
718  * Auto-scrolls the newly chosen database
720  * @param  object   $element    The element to set to view
721  * @param  boolean  $forceToTop Whether to force scroll to top
723  */
724 function scrollToView ($element, $forceToTop) {
725     navFilterStateRestore();
726     var $container = $('#pma_navigation_tree_content');
727     var elemTop = $element.offset().top - $container.offset().top;
728     var textHeight = 20;
729     var scrollPadding = 20; // extra padding from top of bottom when scrolling to view
730     if (elemTop < 0 || $forceToTop) {
731         $container.stop().animate({
732             scrollTop: elemTop + $container.scrollTop() - scrollPadding
733         });
734     } else if (elemTop + textHeight > $container.height()) {
735         $container.stop().animate({
736             scrollTop: elemTop + textHeight - $container.height() + $container.scrollTop() + scrollPadding
737         });
738     }
742  * Expand the navigation and highlight the current database or table/view
744  * @returns void
745  */
746 function PMA_showCurrentNavigation () {
747     var db = PMA_commonParams.get('db');
748     var table = PMA_commonParams.get('table');
749     $('#pma_navigation_tree')
750         .find('li.selected')
751         .removeClass('selected');
752     if (db) {
753         var $dbItem = findLoadedItem(
754             $('#pma_navigation_tree').find('> div'), db, 'database', !table
755         );
756         if ($('#navi_db_select').length &&
757             $('option:selected', $('#navi_db_select')).length
758         ) {
759             if (! PMA_selectCurrentDb()) {
760                 return;
761             }
762             // If loaded database in navigation is not same as current one
763             if ($('#pma_navigation_tree_content').find('span.loaded_db:first').text()
764                 !== $('#navi_db_select').val()
765             ) {
766                 loadChildNodes(false, $('option:selected', $('#navi_db_select')), function (data) {
767                     handleTableOrDb(table, $('#pma_navigation_tree_content'));
768                     var $children = $('#pma_navigation_tree_content').children('div.list_container');
769                     $children.promise().done(navTreeStateUpdate);
770                 });
771             } else {
772                 handleTableOrDb(table, $('#pma_navigation_tree_content'));
773             }
774         } else if ($dbItem) {
775             var $expander = $dbItem.children('div:first').children('a.expander');
776             // if not loaded or loaded but collapsed
777             if (! $expander.hasClass('loaded') ||
778                 $expander.find('img').is('.ic_b_plus')
779             ) {
780                 expandTreeNode($expander, function () {
781                     handleTableOrDb(table, $dbItem);
782                 });
783             } else {
784                 handleTableOrDb(table, $dbItem);
785             }
786         }
787     } else if ($('#navi_db_select').length && $('#navi_db_select').val()) {
788         $('#navi_db_select').val('').hide().trigger('change');
789     }
790     PMA_showFullName($('#pma_navigation_tree'));
792     function handleTableOrDb (table, $dbItem) {
793         if (table) {
794             loadAndHighlightTableOrView($dbItem, table);
795         } else {
796             var $container = $dbItem.children('div.list_container');
797             var $tableContainer = $container.children('ul').children('li.tableContainer');
798             if ($tableContainer.length > 0) {
799                 var $expander = $tableContainer.children('div:first').children('a.expander');
800                 $tableContainer.addClass('selected');
801                 expandTreeNode($expander, function () {
802                     scrollToView($dbItem, true);
803                 });
804             } else {
805                 scrollToView($dbItem, true);
806             }
807         }
808     }
810     function findLoadedItem ($container, name, clazz, doSelect) {
811         var ret = false;
812         $container.children('ul').children('li').each(function () {
813             var $li = $(this);
814             // this is a navigation group, recurse
815             if ($li.is('.navGroup')) {
816                 var $container = $li.children('div.list_container');
817                 var $childRet = findLoadedItem(
818                     $container, name, clazz, doSelect
819                 );
820                 if ($childRet) {
821                     ret = $childRet;
822                     return false;
823                 }
824             } else { // this is a real navigation item
825                 // name and class matches
826                 if (((clazz && $li.is('.' + clazz)) || ! clazz) &&
827                         $li.children('a').text() === name) {
828                     if (doSelect) {
829                         $li.addClass('selected');
830                     }
831                     // taverse up and expand and parent navigation groups
832                     $li.parents('.navGroup').each(function () {
833                         var $cont = $(this).children('div.list_container');
834                         if (! $cont.is(':visible')) {
835                             $(this)
836                                 .children('div:first')
837                                 .children('a.expander')
838                                 .click();
839                         }
840                     });
841                     ret = $li;
842                     return false;
843                 }
844             }
845         });
846         return ret;
847     }
849     function loadAndHighlightTableOrView ($dbItem, itemName) {
850         var $container = $dbItem.children('div.list_container');
851         var $expander;
852         var $whichItem = isItemInContainer($container, itemName, 'li.table, li.view');
853         // If item already there in some container
854         if ($whichItem) {
855             // get the relevant container while may also be a subcontainer
856             var $relatedContainer = $whichItem.closest('li.subContainer').length
857                 ? $whichItem.closest('li.subContainer')
858                 : $dbItem;
859             $whichItem = findLoadedItem(
860                 $relatedContainer.children('div.list_container'),
861                 itemName, null, true
862             );
863             // Show directly
864             showTableOrView($whichItem, $relatedContainer.children('div:first').children('a.expander'));
865         // else if item not there, try loading once
866         } else {
867             var $sub_containers = $dbItem.find('.subContainer');
868             // If there are subContainers i.e. tableContainer or viewContainer
869             if ($sub_containers.length > 0) {
870                 var $containers = [];
871                 $sub_containers.each(function (index) {
872                     $containers[index] = $(this);
873                     $expander = $containers[index]
874                         .children('div:first')
875                         .children('a.expander');
876                     if (! $expander.hasClass('loaded')) {
877                         loadAndShowTableOrView($expander, $containers[index], itemName);
878                     }
879                 });
880             // else if no subContainers
881             } else {
882                 $expander = $dbItem
883                     .children('div:first')
884                     .children('a.expander');
885                 if (! $expander.hasClass('loaded')) {
886                     loadAndShowTableOrView($expander, $dbItem, itemName);
887                 }
888             }
889         }
890     }
892     function loadAndShowTableOrView ($expander, $relatedContainer, itemName) {
893         loadChildNodes(true, $expander, function (data) {
894             var $whichItem = findLoadedItem(
895                 $relatedContainer.children('div.list_container'),
896                 itemName, null, true
897             );
898             if ($whichItem) {
899                 showTableOrView($whichItem, $expander);
900             }
901         });
902     }
904     function showTableOrView ($whichItem, $expander) {
905         expandTreeNode($expander, function (data) {
906             if ($whichItem) {
907                 scrollToView($whichItem, false);
908             }
909         });
910     }
912     function isItemInContainer ($container, name, clazz) {
913         var $whichItem = null;
914         $items = $container.find(clazz);
915         var found = false;
916         $items.each(function () {
917             if ($(this).children('a').text() === name) {
918                 $whichItem = $(this);
919                 return false;
920             }
921         });
922         return $whichItem;
923     }
927  * Disable navigation panel settings
929  * @return void
930  */
931 function PMA_disableNaviSettings () {
932     $('#pma_navigation_settings_icon').addClass('hide');
933     $('#pma_navigation_settings').remove();
937  * Ensure that navigation panel settings is properly setup.
938  * If not, set it up
940  * @return void
941  */
942 function PMA_ensureNaviSettings (selflink) {
943     $('#pma_navigation_settings_icon').removeClass('hide');
945     if (!$('#pma_navigation_settings').length) {
946         var params = {
947             getNaviSettings: true,
948             server: PMA_commonParams.get('server'),
949         };
950         var url = $('#pma_navigation').find('a.navigation_url').attr('href');
951         $.post(url, params, function (data) {
952             if (typeof data !== 'undefined' && data.success) {
953                 $('#pma_navi_settings_container').html(data.message);
954                 setupRestoreField();
955                 setupValidation();
956                 setupConfigTabs();
957                 $('#pma_navigation_settings').find('form').attr('action', selflink);
958             } else {
959                 PMA_ajaxShowMessage(data.error);
960             }
961         });
962     } else {
963         $('#pma_navigation_settings').find('form').attr('action', selflink);
964     }
968  * Reloads the whole navigation tree while preserving its state
970  * @param  function     the callback function
971  * @param  Object       stored navigation paths
973  * @return void
974  */
975 function PMA_reloadNavigation (callback, paths) {
976     var params = {
977         reload: true,
978         no_debug: true,
979         server: PMA_commonParams.get('server'),
980     };
981     paths = paths || traverseNavigationForPaths();
982     $.extend(params, paths);
983     if ($('#navi_db_select').length) {
984         params.db = PMA_commonParams.get('db');
985         requestNaviReload(params);
986         return;
987     }
988     requestNaviReload(params);
990     function requestNaviReload (params) {
991         var url = $('#pma_navigation').find('a.navigation_url').attr('href');
992         $.post(url, params, function (data) {
993             if (typeof data !== 'undefined' && data.success) {
994                 $('#pma_navigation_tree').html(data.message).children('div').show();
995                 if ($('#pma_navigation_tree').hasClass('synced')) {
996                     PMA_selectCurrentDb();
997                     PMA_showCurrentNavigation();
998                 }
999                 // Fire the callback, if any
1000                 if (typeof callback === 'function') {
1001                     callback.call();
1002                 }
1003                 navTreeStateUpdate();
1004             } else {
1005                 PMA_ajaxShowMessage(data.error);
1006             }
1007         });
1008     }
1011 function PMA_selectCurrentDb () {
1012     var $naviDbSelect = $('#navi_db_select');
1014     if (!$naviDbSelect.length) {
1015         return false;
1016     }
1018     if (PMA_commonParams.get('db')) { // db selected
1019         $naviDbSelect.show();
1020     }
1022     $naviDbSelect.val(PMA_commonParams.get('db'));
1023     return $naviDbSelect.val() === PMA_commonParams.get('db');
1027  * Handles any requests to change the page in a branch of a tree
1029  * This can be called from link click or select change event handlers
1031  * @param object $this A jQuery object that points to the element that
1032  * initiated the action of changing the page
1034  * @return void
1035  */
1036 function PMA_navigationTreePagination ($this) {
1037     var $msgbox = PMA_ajaxShowMessage();
1038     var isDbSelector = $this.closest('div.pageselector').is('.dbselector');
1039     var url;
1040     var params;
1041     if ($this[0].tagName === 'A') {
1042         url = $this.attr('href');
1043         params = 'ajax_request=true';
1044     } else { // tagName === 'SELECT'
1045         url = 'navigation.php';
1046         params = $this.closest('form').serialize() + PMA_commonParams.get('arg_separator') + 'ajax_request=true';
1047     }
1048     var searchClause = PMA_fastFilter.getSearchClause();
1049     if (searchClause) {
1050         params += PMA_commonParams.get('arg_separator') + 'searchClause=' + encodeURIComponent(searchClause);
1051     }
1052     if (isDbSelector) {
1053         params += PMA_commonParams.get('arg_separator') + 'full=true';
1054     } else {
1055         var searchClause2 = PMA_fastFilter.getSearchClause2($this);
1056         if (searchClause2) {
1057             params += PMA_commonParams.get('arg_separator') + 'searchClause2=' + encodeURIComponent(searchClause2);
1058         }
1059     }
1060     $.post(url, params, function (data) {
1061         if (typeof data !== 'undefined' && data.success) {
1062             PMA_ajaxRemoveMessage($msgbox);
1063             if (isDbSelector) {
1064                 var val = PMA_fastFilter.getSearchClause();
1065                 $('#pma_navigation_tree')
1066                     .html(data.message)
1067                     .children('div')
1068                     .show();
1069                 if (val) {
1070                     $('#pma_navigation_tree')
1071                         .find('li.fast_filter input.searchClause')
1072                         .val(val);
1073                 }
1074             } else {
1075                 var $parent = $this.closest('div.list_container').parent();
1076                 var val = PMA_fastFilter.getSearchClause2($this);
1077                 $this.closest('div.list_container').html(
1078                     $(data.message).children().show()
1079                 );
1080                 if (val) {
1081                     $parent.find('li.fast_filter input.searchClause').val(val);
1082                 }
1083                 $parent.find('span.pos2_value:first').text(
1084                     $parent.find('span.pos2_value:last').text()
1085                 );
1086                 $parent.find('span.pos3_value:first').text(
1087                     $parent.find('span.pos3_value:last').text()
1088                 );
1089             }
1090         } else {
1091             PMA_ajaxShowMessage(data.error);
1092             PMA_handleRedirectAndReload(data);
1093         }
1094         navTreeStateUpdate();
1095     });
1099  * @var ResizeHandler Custom object that manages the resizing of the navigation
1101  * XXX: Must only be ever instanciated once
1102  * XXX: Inside event handlers the 'this' object is accessed as 'event.data.resize_handler'
1103  */
1104 var ResizeHandler = function () {
1105     /**
1106      * @var int panel_width Used by the collapser to know where to go
1107      *                      back to when uncollapsing the panel
1108      */
1109     this.panel_width = 0;
1110     /**
1111      * @var string left Used to provide support for RTL languages
1112      */
1113     this.left = $('html').attr('dir') === 'ltr' ? 'left' : 'right';
1114     /**
1115      * Adjusts the width of the navigation panel to the specified value
1116      *
1117      * @param int pos Navigation width in pixels
1118      *
1119      * @return void
1120      */
1121     this.setWidth = function (pos) {
1122         if (typeof pos !== 'number') {
1123             pos = 240;
1124         }
1125         var $resizer = $('#pma_navigation_resizer');
1126         var resizer_width = $resizer.width();
1127         var $collapser = $('#pma_navigation_collapser');
1128         var windowWidth = $(window).width();
1129         $('#pma_navigation').width(pos);
1130         $('body').css('margin-' + this.left, pos + 'px');
1131         $('#floating_menubar, #pma_console')
1132             .css('margin-' + this.left, (pos + resizer_width) + 'px');
1133         $resizer.css(this.left, pos + 'px');
1134         if (pos === 0) {
1135             $collapser
1136                 .css(this.left, pos + resizer_width)
1137                 .html(this.getSymbol(pos))
1138                 .prop('title', PMA_messages.strShowPanel);
1139         } else if (windowWidth > 768) {
1140             $collapser
1141                 .css(this.left, pos)
1142                 .html(this.getSymbol(pos))
1143                 .prop('title', PMA_messages.strHidePanel);
1144             $('#pma_navigation_resizer').css({ 'width': '3px' });
1145         } else {
1146             $collapser
1147                 .css(this.left, windowWidth - 22)
1148                 .html(this.getSymbol(100))
1149                 .prop('title', PMA_messages.strHidePanel);
1150             $('#pma_navigation').width(windowWidth);
1151             $('body').css('margin-' + this.left, '0px');
1152             $('#pma_navigation_resizer').css({ 'width': '0px' });
1153         }
1154         setTimeout(function () {
1155             $(window).trigger('resize');
1156         }, 4);
1157     };
1158     /**
1159      * Returns the horizontal position of the mouse,
1160      * relative to the outer side of the navigation panel
1161      *
1162      * @param int pos Navigation width in pixels
1163      *
1164      * @return void
1165      */
1166     this.getPos = function (event) {
1167         var pos = event.pageX;
1168         var windowWidth = $(window).width();
1169         var windowScroll = $(window).scrollLeft();
1170         pos = pos - windowScroll;
1171         if (this.left !== 'left') {
1172             pos = windowWidth - event.pageX;
1173         }
1174         if (pos < 0) {
1175             pos = 0;
1176         } else if (pos + 100 >= windowWidth) {
1177             pos = windowWidth - 100;
1178         } else {
1179             this.panel_width = 0;
1180         }
1181         return pos;
1182     };
1183     /**
1184      * Returns the HTML code for the arrow symbol used in the collapser
1185      *
1186      * @param int width The width of the panel
1187      *
1188      * @return string
1189      */
1190     this.getSymbol = function (width) {
1191         if (this.left === 'left') {
1192             if (width === 0) {
1193                 return '&rarr;';
1194             } else {
1195                 return '&larr;';
1196             }
1197         } else {
1198             if (width === 0) {
1199                 return '&larr;';
1200             } else {
1201                 return '&rarr;';
1202             }
1203         }
1204     };
1205     /**
1206      * Event handler for initiating a resize of the panel
1207      *
1208      * @param object e Event data (contains a reference to resizeHandler)
1209      *
1210      * @return void
1211      */
1212     this.mousedown = function (event) {
1213         event.preventDefault();
1214         $(document)
1215             .on('mousemove', { 'resize_handler': event.data.resize_handler },
1216                 $.throttle(event.data.resize_handler.mousemove, 4))
1217             .on('mouseup', { 'resize_handler': event.data.resize_handler },
1218                 event.data.resize_handler.mouseup);
1219         $('body').css('cursor', 'col-resize');
1220     };
1221     /**
1222      * Event handler for terminating a resize of the panel
1223      *
1224      * @param object e Event data (contains a reference to resizeHandler)
1225      *
1226      * @return void
1227      */
1228     this.mouseup = function (event) {
1229         $('body').css('cursor', '');
1230         configSet('NavigationWidth', event.data.resize_handler.getPos(event));
1231         $('#topmenu').menuResizer('resize');
1232         $(document)
1233             .off('mousemove')
1234             .off('mouseup');
1235     };
1236     /**
1237      * Event handler for updating the panel during a resize operation
1238      *
1239      * @param object e Event data (contains a reference to resizeHandler)
1240      *
1241      * @return void
1242      */
1243     this.mousemove = function (event) {
1244         event.preventDefault();
1245         var pos = event.data.resize_handler.getPos(event);
1246         event.data.resize_handler.setWidth(pos);
1247         if ($('.sticky_columns').length !== 0) {
1248             handleAllStickyColumns();
1249         }
1250     };
1251     /**
1252      * Event handler for collapsing the panel
1253      *
1254      * @param object e Event data (contains a reference to resizeHandler)
1255      *
1256      * @return void
1257      */
1258     this.collapse = function (event) {
1259         event.preventDefault();
1260         var panel_width = event.data.resize_handler.panel_width;
1261         var width = $('#pma_navigation').width();
1262         if (width === 0 && panel_width === 0) {
1263             panel_width = 240;
1264         }
1265         configSet('NavigationWidth', panel_width);
1266         event.data.resize_handler.setWidth(panel_width);
1267         event.data.resize_handler.panel_width = width;
1268     };
1269     /**
1270      * Event handler for resizing the navigation tree height on window resize
1271      *
1272      * @return void
1273      */
1274     this.treeResize = function (event) {
1275         var $nav        = $('#pma_navigation');
1276         var $nav_tree   = $('#pma_navigation_tree');
1277         var $nav_header = $('#pma_navigation_header');
1278         var $nav_tree_content = $('#pma_navigation_tree_content');
1279         $nav_tree.height($nav.height() - $nav_header.height());
1280         if ($nav_tree_content.length > 0) {
1281             $nav_tree_content.height($nav_tree.height() - $nav_tree_content.position().top);
1282         } else {
1283             // TODO: in fast filter search response there is no #pma_navigation_tree_content, needs to be added in php
1284             $nav_tree.css({
1285                 'overflow-y': 'auto'
1286             });
1287         }
1288         // Set content bottom space beacuse of console
1289         $('body').css('margin-bottom', $('#pma_console').height() + 'px');
1290     };
1291     // Hide the pma_navigation initially when loaded on mobile
1292     if ($(window).width() < 768) {
1293         this.setWidth(0);
1294     } else {
1295         this.setWidth(configGet('NavigationWidth', false));
1296         $('#topmenu').menuResizer('resize');
1297     }
1298     // Register the events for the resizer and the collapser
1299     $(document).on('mousedown', '#pma_navigation_resizer', { 'resize_handler': this }, this.mousedown);
1300     $(document).on('click', '#pma_navigation_collapser', { 'resize_handler': this }, this.collapse);
1302     // Add the correct arrow symbol to the collapser
1303     $('#pma_navigation_collapser').html(this.getSymbol($('#pma_navigation').width()));
1304     // Fix navigation tree height
1305     $(window).on('resize', this.treeResize);
1306     // need to call this now and then, browser might decide
1307     // to show/hide horizontal scrollbars depending on page content width
1308     setInterval(this.treeResize, 2000);
1309     this.treeResize();
1310 }; // End of ResizeHandler
1313  * @var object PMA_fastFilter Handles the functionality that allows filtering
1314  *                            of the items in a branch of the navigation tree
1315  */
1316 var PMA_fastFilter = {
1317     /**
1318      * Construct for the asynchronous fast filter functionality
1319      *
1320      * @param object $this        A jQuery object pointing to the list container
1321      *                            which is the nearest parent of the fast filter
1322      * @param string searchClause The query string for the filter
1323      *
1324      * @return new PMA_fastFilter.filter object
1325      */
1326     filter: function ($this, searchClause) {
1327         /**
1328          * @var object $this A jQuery object pointing to the list container
1329          *                   which is the nearest parent of the fast filter
1330          */
1331         this.$this = $this;
1332         /**
1333          * @var bool searchClause The query string for the filter
1334          */
1335         this.searchClause = searchClause;
1336         /**
1337          * @var object $clone A clone of the original contents
1338          *                    of the navigation branch before
1339          *                    the fast filter was applied
1340          */
1341         this.$clone = $this.clone();
1342         /**
1343          * @var object xhr A reference to the ajax request that is currently running
1344          */
1345         this.xhr = null;
1346         /**
1347          * @var int timeout Used to delay the request for asynchronous search
1348          */
1349         this.timeout = null;
1351         var $filterInput = $this.find('li.fast_filter input.searchClause');
1352         if ($filterInput.length !== 0 &&
1353             $filterInput.val() !== '' &&
1354             $filterInput.val() !== $filterInput[0].defaultValue
1355         ) {
1356             this.request();
1357         }
1358     },
1359     /**
1360      * Gets the query string from the database fast filter form
1361      *
1362      * @return string
1363      */
1364     getSearchClause: function () {
1365         var retval = '';
1366         var $input = $('#pma_navigation_tree')
1367             .find('li.fast_filter.db_fast_filter input.searchClause');
1368         if ($input.length && $input.val() !== $input[0].defaultValue) {
1369             retval = $input.val();
1370         }
1371         return retval;
1372     },
1373     /**
1374      * Gets the query string from a second level item's fast filter form
1375      * The retrieval is done by trasversing the navigation tree backwards
1376      *
1377      * @return string
1378      */
1379     getSearchClause2: function ($this) {
1380         var $filterContainer = $this.closest('div.list_container');
1381         var $filterInput = $([]);
1382         if ($filterContainer
1383             .find('li.fast_filter:not(.db_fast_filter) input.searchClause')
1384             .length !== 0) {
1385             $filterInput = $filterContainer
1386                 .find('li.fast_filter:not(.db_fast_filter) input.searchClause');
1387         }
1388         var searchClause2 = '';
1389         if ($filterInput.length !== 0 &&
1390             $filterInput.first().val() !== $filterInput[0].defaultValue
1391         ) {
1392             searchClause2 = $filterInput.val();
1393         }
1394         return searchClause2;
1395     },
1396     /**
1397      * @var hash events A list of functions that are bound to DOM events
1398      *                  at the top of this file
1399      */
1400     events: {
1401         focus: function (event) {
1402             var $obj = $(this).closest('div.list_container');
1403             if (! $obj.data('fastFilter')) {
1404                 $obj.data(
1405                     'fastFilter',
1406                     new PMA_fastFilter.filter($obj, $(this).val())
1407                 );
1408             }
1409             if ($(this).val() === this.defaultValue) {
1410                 $(this).val('');
1411             } else {
1412                 $(this).select();
1413             }
1414         },
1415         blur: function (event) {
1416             if ($(this).val() === '') {
1417                 $(this).val(this.defaultValue);
1418             }
1419             var $obj = $(this).closest('div.list_container');
1420             if ($(this).val() === this.defaultValue && $obj.data('fastFilter')) {
1421                 $obj.data('fastFilter').restore();
1422             }
1423         },
1424         keyup: function (event) {
1425             var $obj = $(this).closest('div.list_container');
1426             var str = '';
1427             if ($(this).val() !== this.defaultValue && $(this).val() !== '') {
1428                 $obj.find('div.pageselector').hide();
1429                 str = $(this).val();
1430             }
1432             /**
1433              * FIXME at the server level a value match is done while on
1434              * the client side it is a regex match. These two should be aligned
1435              */
1437             // regex used for filtering.
1438             var regex;
1439             try {
1440                 regex = new RegExp(str, 'i');
1441             } catch (err) {
1442                 return;
1443             }
1445             // this is the div that houses the items to be filtered by this filter.
1446             var outerContainer;
1447             if ($(this).closest('li.fast_filter').is('.db_fast_filter')) {
1448                 outerContainer = $('#pma_navigation_tree_content');
1449             } else {
1450                 outerContainer = $obj;
1451             }
1453             // filters items that are directly under the div as well as grouped in
1454             // groups. Does not filter child items (i.e. a database search does
1455             // not filter tables)
1456             var item_filter = function ($curr) {
1457                 $curr.children('ul').children('li.navGroup').each(function () {
1458                     $(this).children('div.list_container').each(function () {
1459                         item_filter($(this)); // recursive
1460                     });
1461                 });
1462                 $curr.children('ul').children('li').children('a').not('.container').each(function () {
1463                     if (regex.test($(this).text())) {
1464                         $(this).parent().show().removeClass('hidden');
1465                     } else {
1466                         $(this).parent().hide().addClass('hidden');
1467                     }
1468                 });
1469             };
1470             item_filter(outerContainer);
1472             // hides containers that does not have any visible children
1473             var container_filter = function ($curr) {
1474                 $curr.children('ul').children('li.navGroup').each(function () {
1475                     var $group = $(this);
1476                     $group.children('div.list_container').each(function () {
1477                         container_filter($(this)); // recursive
1478                     });
1479                     $group.show().removeClass('hidden');
1480                     if ($group.children('div.list_container').children('ul')
1481                         .children('li').not('.hidden').length === 0) {
1482                         $group.hide().addClass('hidden');
1483                     }
1484                 });
1485             };
1486             container_filter(outerContainer);
1488             if ($(this).val() !== this.defaultValue && $(this).val() !== '') {
1489                 if (! $obj.data('fastFilter')) {
1490                     $obj.data(
1491                         'fastFilter',
1492                         new PMA_fastFilter.filter($obj, $(this).val())
1493                     );
1494                 } else {
1495                     if (event.keyCode === 13) {
1496                         $obj.data('fastFilter').update($(this).val());
1497                     }
1498                 }
1499             } else if ($obj.data('fastFilter')) {
1500                 $obj.data('fastFilter').restore(true);
1501             }
1502             // update filter state
1503             var filterName;
1504             if ($(this).attr('name') === 'searchClause2') {
1505                 filterName = $(this).siblings('input[name=aPath]').val();
1506             } else {
1507                 filterName = 'dbFilter';
1508             }
1509             navFilterStateUpdate(filterName, $(this).val());
1510         },
1511         clear: function (event) {
1512             event.stopPropagation();
1513             // Clear the input and apply the fast filter with empty input
1514             var filter = $(this).closest('div.list_container').data('fastFilter');
1515             if (filter) {
1516                 filter.restore();
1517             }
1518             var value = $(this).prev()[0].defaultValue;
1519             $(this).prev().val(value).trigger('keyup');
1520         }
1521     }
1524  * Handles a change in the search clause
1526  * @param string searchClause The query string for the filter
1528  * @return void
1529  */
1530 PMA_fastFilter.filter.prototype.update = function (searchClause) {
1531     if (this.searchClause !== searchClause) {
1532         this.searchClause = searchClause;
1533         this.request();
1534     }
1537  * After a delay of 250mS, initiates a request to retrieve search results
1538  * Multiple calls to this function will always abort the previous request
1540  * @return void
1541  */
1542 PMA_fastFilter.filter.prototype.request = function () {
1543     var self = this;
1544     if (self.$this.find('li.fast_filter').find('img.throbber').length === 0) {
1545         self.$this.find('li.fast_filter').append(
1546             $('<div class="throbber"></div>').append(
1547                 $('#pma_navigation_content')
1548                     .find('img.throbber')
1549                     .clone()
1550                     .css({ visibility: 'visible', display: 'block' })
1551             )
1552         );
1553     }
1554     if (self.xhr) {
1555         self.xhr.abort();
1556     }
1557     var url = $('#pma_navigation').find('a.navigation_url').attr('href');
1558     var params = self.$this.find('> ul > li > form.fast_filter').first().serialize();
1560     if (self.$this.find('> ul > li > form.fast_filter:first input[name=searchClause]').length === 0) {
1561         var $input = $('#pma_navigation_tree').find('li.fast_filter.db_fast_filter input.searchClause');
1562         if ($input.length && $input.val() !== $input[0].defaultValue) {
1563             params += PMA_commonParams.get('arg_separator') + 'searchClause=' + encodeURIComponent($input.val());
1564         }
1565     }
1566     self.xhr = $.ajax({
1567         url: url,
1568         type: 'post',
1569         dataType: 'json',
1570         data: params,
1571         complete: function (jqXHR, status) {
1572             if (status !== 'abort') {
1573                 var data = JSON.parse(jqXHR.responseText);
1574                 self.$this.find('li.fast_filter').find('div.throbber').remove();
1575                 if (data && data.results) {
1576                     self.swap.apply(self, [data.message]);
1577                 }
1578             }
1579         }
1580     });
1583  * Replaces the contents of the navigation branch with the search results
1585  * @param string list The search results
1587  * @return void
1588  */
1589 PMA_fastFilter.filter.prototype.swap = function (list) {
1590     this.$this
1591         .html($(list).html())
1592         .children()
1593         .show()
1594         .end()
1595         .find('li.fast_filter input.searchClause')
1596         .val(this.searchClause);
1597     this.$this.data('fastFilter', this);
1600  * Restores the navigation to the original state after the fast filter is cleared
1602  * @param bool focus Whether to also focus the input box of the fast filter
1604  * @return void
1605  */
1606 PMA_fastFilter.filter.prototype.restore = function (focus) {
1607     if (this.$this.children('ul').first().hasClass('search_results')) {
1608         this.$this.html(this.$clone.html()).children().show();
1609         this.$this.data('fastFilter', this);
1610         if (focus) {
1611             this.$this.find('li.fast_filter input.searchClause').focus();
1612         }
1613     }
1614     this.searchClause = '';
1615     this.$this.find('div.pageselector').show();
1616     this.$this.find('div.throbber').remove();
1620  * Show full name when cursor hover and name not shown completely
1622  * @param object $containerELem Container element
1624  * @return void
1625  */
1626 function PMA_showFullName ($containerELem) {
1627     $containerELem.find('.hover_show_full').mouseenter(function () {
1628         /** mouseenter */
1629         var $this = $(this);
1630         var thisOffset = $this.offset();
1631         if ($this.text() === '') {
1632             return;
1633         }
1634         var $parent = $this.parent();
1635         if (($parent.offset().left + $parent.outerWidth())
1636            < (thisOffset.left + $this.outerWidth())) {
1637             var $fullNameLayer = $('#full_name_layer');
1638             if ($fullNameLayer.length === 0) {
1639                 $('body').append('<div id="full_name_layer" class="hide"></div>');
1640                 $('#full_name_layer').mouseleave(function () {
1641                     /** mouseleave */
1642                     $(this).addClass('hide')
1643                         .removeClass('hovering');
1644                 }).mouseenter(function () {
1645                     /** mouseenter */
1646                     $(this).addClass('hovering');
1647                 });
1648                 $fullNameLayer = $('#full_name_layer');
1649             }
1650             $fullNameLayer.removeClass('hide');
1651             $fullNameLayer.css({ left: thisOffset.left, top: thisOffset.top });
1652             $fullNameLayer.html($this.clone());
1653             setTimeout(function () {
1654                 if (! $fullNameLayer.hasClass('hovering')) {
1655                     $fullNameLayer.trigger('mouseleave');
1656                 }
1657             }, 200);
1658         }
1659     });