Translated using Weblate.
[phpmyadmin.git] / js / navigation.js
blob21e05b8e218e4e0e42fefba37926f3534beb25f3
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * function used in or for navigation frame
4  */
6 /**
7  * init
8  */
9 var today = new Date();
10 var expires = new Date(today.getTime() + (56 * 86400000));
11 var pma_navi_width;
12 var pma_saveframesize_timeout = null;
14 /**
15  * opens/closes (hides/shows) tree elements
16  *
17  * @param   string  id          id of the element in the DOM
18  * @param   boolean only_open   do not close/hide element
19  */
20 function toggle(id, only_open)
22     var el = document.getElementById('subel' + id);
23     if (! el) {
24         return false;
25     }
27     var img = document.getElementById('el' + id + 'Img');
29     if (el.style.display == 'none' || only_open) {
30         el.style.display = '';
31         if (img) {
32             var newimg = PMA_getImage('b_minus.png');
33             img.className = newimg.attr('class');
34             img.src = newimg.attr('src');
35             img.alt = '-';
36         }
37     } else {
38         el.style.display = 'none';
39         if (img) {
40             var newimg = PMA_getImage('b_plus.png');
41             img.className = newimg.attr('class');
42             img.src = newimg.attr('src');
43             img.alt = '+';
44         }
45     }
46     return true;
49 function PMA_callFunctionDelayed(myfunction, delay)
51     if (typeof pma_saveframesize_timeout == "number") {
52          window.clearTimeout(pma_saveframesize_timeout);
53         pma_saveframesize_timeout = null;
54     }
57 /**
58  * saves current navigation frame width in a cookie
59  * usally called on resize of the navigation frame
60  */
61 function PMA_saveFrameSizeReal()
63     if (parent.text_dir == 'ltr') {
64         pma_navi_width = parseInt(parent.document.getElementById('mainFrameset').cols)
65     } else {
66         pma_navi_width = parent.document.getElementById('mainFrameset').cols.match(/\d+$/)
67     }
68     if ((pma_navi_width > 0) && (pma_navi_width != PMA_getCookie('pma_navi_width'))) {
69         PMA_setCookie('pma_navi_width', pma_navi_width, expires);
70     }
73 /**
74  * calls PMA_saveFrameSizeReal with delay
75  */
76 function PMA_saveFrameSize()
78     //alert(typeof(pma_saveframesize_timeout) + ' : ' + pma_saveframesize_timeout);
80     if (typeof pma_saveframesize_timeout == "number") {
81         window.clearTimeout(pma_saveframesize_timeout);
82         pma_saveframesize_timeout = null;
83     }
85     pma_saveframesize_timeout = window.setTimeout(PMA_saveFrameSizeReal, 2000);
88 /**
89  * sets navigation frame width to the value stored in the cookie
90  * usally called on document load
91  */
92 function PMA_setFrameSize()
94     pma_navi_width = PMA_getCookie('pma_navi_width');
95     //alert('from cookie: ' + typeof(pma_navi_width) + ' : ' + pma_navi_width);
96     if (pma_navi_width != null && parent.document != document) {
97         if (parent.text_dir == 'ltr') {
98             parent.document.getElementById('mainFrameset').cols = pma_navi_width + ',*';
99         } else {
100             parent.document.getElementById('mainFrameset').cols = '*,' + pma_navi_width;
101         }
102         //alert('framesize set');
103     }
107  * retrieves a named value from cookie
109  * @param   string  name    name of the value to retrieve
110  * @return  string  value   value for the given name from cookie
111  */
112 function PMA_getCookie(name)
114     var start = document.cookie.indexOf(name + "=");
115     var len = start + name.length + 1;
116     if ((!start) && (name != document.cookie.substring(0, name.length))) {
117         return null;
118     }
119     if (start == -1) {
120         return null;
121     }
122     var end = document.cookie.indexOf(";", len);
123     if (end == -1) {
124         end = document.cookie.length;
125     }
126     return unescape(document.cookie.substring(len,end));
130  * stores a named value into cookie
132  * @param   string  name    name of value
133  * @param   string  value   value to be stored
134  * @param   Date    expires expire time
135  * @param   string  path
136  * @param   string  domain
137  * @param   boolean secure
138  */
139 function PMA_setCookie(name, value, expires, path, domain, secure)
141     document.cookie = name + "=" + escape(value) +
142         ( (expires) ? ";expires=" + expires.toGMTString() : "") +
143         ( (path)    ? ";path=" + path : "") +
144         ( (domain)  ? ";domain=" + domain : "") +
145         ( (secure)  ? ";secure" : "");
149  * hide all LI elements with second A tag which doesn`t contain requested value
151  * @param   string  value    requested value
153  */
154 function fast_filter(value)
156     lowercase_value = value.toLowerCase();
157     $("#subel0 a[class!='tableicon']").each(function(idx,elem){
158         $elem = $(elem);
159         // .indexOf is case sensitive so convert to lowercase to compare
160         if (value && $elem.html().toLowerCase().indexOf(lowercase_value) == -1) {
161             $elem.parent().hide();
162         } else {
163             $elem.parents('li').show();
164         }
165     });
169  * Clears fast filter.
170  */
171 function clear_fast_filter()
173     var $elm = $('#fast_filter');
174     $elm.val('');
175     fast_filter('');
179  * Reloads the recent tables list.
180  */
181 function PMA_reloadRecentTable()
183     $.get('navigation.php', {
184             'token': window.parent.token,
185             'server': window.parent.server,
186             'ajax_request': true,
187             'recent_table': true},
188         function (data) {
189             if (data.success == true) {
190                 $('#recentTable').html(data.options);
191             }
192         });
195 /* Performed on load */
196 $(document).ready(function(){
197     /* Display filter */
198     $('#NavFilter').css('display', 'inline');
199     var txt = $('#fast_filter').val();
201     $('#fast_filter.gray').live('focus', function() {
202         $(this).removeClass('gray');
203         clear_fast_filter();
204     });
206     $('#fast_filter:not(.gray)').live('focusout', function() {
207         var $input = $(this);
208         if ($input.val() == '') {
209             $input
210                 .addClass('gray')
211                 .val(txt);
212         }
213     });
215     $('#clear_fast_filter').click(function() {
216         clear_fast_filter();
217         $('#fast_filter').focus();
218     });
220     $('#fast_filter').keyup(function(evt) {
221         fast_filter($(this).val());
222     });
224     /* Jump to recent table */
225     $('#recentTable').change(function() {
226         if (this.value != '') {
227             var arr = jQuery.parseJSON(this.value);
228             window.parent.setDb(arr['db']);
229             window.parent.setTable(arr['table']);
230             window.parent.refreshMain($('#LeftDefaultTabTable')[0].value);
231         }
232     });
234     /* Create table */
235     $('#newtable a.ajax').click(function(event){
236         event.preventDefault();
237         /*Getting the url */
238         var url = $('#newtable a').attr("href");
239         if (url.substring(0, 15) == "tbl_create.php?") {
240              url = url.substring(15);
241         }
242         url = url +"&num_fields=&ajax_request=true";
243         /*Creating a div on the frame_content frame */
244         var div = parent.frame_content.$('<div id="create_table_dialog"></div>');
245         var target = "tbl_create.php";
247         /*
248          * Calling to the createTableDialog function
249          * (needs to be done in the context of frame_content in order
250          *  for the qtip tooltips to work)
251          * */
252         parent.frame_content.PMA_createTableDialog(div , url , target);
253     });//end of create new table
254 });//end of document get ready