Translation update done using Pootle.
[phpmyadmin/madhuracj.git] / js / navigation.js
blobe4d7a207b1c32fd16ae9fded6787131c3cf167f5
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             img.className = 'icon ic_b_minus';
33             img.alt = '-';
34         }
35     } else {
36         el.style.display = 'none';
37         if (img) {
38             img.className = 'icon ic_b_plus';
39             img.alt = '+';
40         }
41     }
42     return true;
45 function PMA_callFunctionDelayed(myfunction, delay)
47     if (typeof pma_saveframesize_timeout == "number") {
48          window.clearTimeout(pma_saveframesize_timeout);
49         pma_saveframesize_timeout = null;
50     }
53 /**
54  * saves current navigation frame width in a cookie
55  * usally called on resize of the navigation frame
56  */
57 function PMA_saveFrameSizeReal()
59     if (parent.text_dir == 'ltr') {
60         pma_navi_width = parseInt(parent.document.getElementById('mainFrameset').cols)
61     } else {
62         pma_navi_width = parent.document.getElementById('mainFrameset').cols.match(/\d+$/)
63     }
64     if ((pma_navi_width > 0) && (pma_navi_width != PMA_getCookie('pma_navi_width'))) {
65         PMA_setCookie('pma_navi_width', pma_navi_width, expires);
66     }
69 /**
70  * calls PMA_saveFrameSizeReal with delay
71  */
72 function PMA_saveFrameSize()
74     //alert(typeof(pma_saveframesize_timeout) + ' : ' + pma_saveframesize_timeout);
76     if (typeof pma_saveframesize_timeout == "number") {
77         window.clearTimeout(pma_saveframesize_timeout);
78         pma_saveframesize_timeout = null;
79     }
81     pma_saveframesize_timeout = window.setTimeout(PMA_saveFrameSizeReal, 2000);
84 /**
85  * sets navigation frame width to the value stored in the cookie
86  * usally called on document load
87  */
88 function PMA_setFrameSize()
90     pma_navi_width = PMA_getCookie('pma_navi_width');
91     //alert('from cookie: ' + typeof(pma_navi_width) + ' : ' + pma_navi_width);
92     if (pma_navi_width != null && parent.document != document) {
93         if (parent.text_dir == 'ltr') {
94             parent.document.getElementById('mainFrameset').cols = pma_navi_width + ',*';
95         } else {
96             parent.document.getElementById('mainFrameset').cols = '*,' + pma_navi_width;
97         }
98         //alert('framesize set');
99     }
103  * retrieves a named value from cookie
105  * @param   string  name    name of the value to retrieve
106  * @return  string  value   value for the given name from cookie
107  */
108 function PMA_getCookie(name)
110     var start = document.cookie.indexOf(name + "=");
111     var len = start + name.length + 1;
112     if ((!start) && (name != document.cookie.substring(0, name.length))) {
113         return null;
114     }
115     if (start == -1) {
116         return null;
117     }
118     var end = document.cookie.indexOf(";", len);
119     if (end == -1) {
120         end = document.cookie.length;
121     }
122     return unescape(document.cookie.substring(len,end));
126  * stores a named value into cookie
128  * @param   string  name    name of value
129  * @param   string  value   value to be stored
130  * @param   Date    expires expire time
131  * @param   string  path
132  * @param   string  domain
133  * @param   boolean secure
134  */
135 function PMA_setCookie(name, value, expires, path, domain, secure)
137     document.cookie = name + "=" + escape(value) +
138         ( (expires) ? ";expires=" + expires.toGMTString() : "") +
139         ( (path)    ? ";path=" + path : "") +
140         ( (domain)  ? ";domain=" + domain : "") +
141         ( (secure)  ? ";secure" : "");
145  * hide all LI elements with second A tag which doesn`t contain requested value
147  * @param   string  value    requested value
149  */
150 function fast_filter(value)
152     lowercase_value = value.toLowerCase();
153     $("#subel0 a[class!='tableicon']").each(function(idx,elem){
154         $elem = $(elem);
155         // .indexOf is case sensitive so convert to lowercase to compare
156         if (value && $elem.html().toLowerCase().indexOf(lowercase_value) == -1) {
157             $elem.parent().hide();
158         } else {
159             $elem.parent().show();
160         }
161     });
165  * Clears fast filter.
166  */
167 function clear_fast_filter()
169     var elm = $('#NavFilter input');
170     elm.val('');
171     fast_filter('');
172     elm.focus();
176  * Reloads the recent tables list.
177  */
178 function PMA_reloadRecentTable()
180     $.get('navigation.php', {
181             'token': window.parent.token,
182             'server': window.parent.server,
183             'ajax_request': true,
184             'recent_table': true},
185         function (data) {
186             if (data.success == true) {
187                 $('#recentTable').html(data.options);
188             }
189         });
192 /* Performed on load */
193 $(document).ready(function(){
194     /* Display filter */
195     $('#NavFilter').css('display', 'inline');
196     $('input[id="fast_filter"]').focus(function() {
197         if($(this).attr("value") === "filter tables by name") {
198             clear_fast_filter();
199         }
200     });
201     $('#clear_fast_filter').click(clear_fast_filter);
202     $('#fast_filter').focus(function (evt) {evt.target.select();});
203     $('#fast_filter').keyup(function (evt) {fast_filter(evt.target.value);});
205     /* Jump to recent table */
206     $('#recentTable').change(function() {
207         if (this.value != '') {
208             var arr = jQuery.parseJSON(this.value);
209             window.parent.setDb(arr['db']);
210             window.parent.setTable(arr['table']);
211             window.parent.refreshMain($('#LeftDefaultTabTable')[0].value);
212         }
213     });
215     /* Create table */
216     $('#newtable a.ajax').click(function(event){
217         event.preventDefault();
218         /*Getting the url */
219         var url = $('#newtable a').attr("href");
220         if (url.substring(0, 15) == "tbl_create.php?") {
221              url = url.substring(15);
222         }
223         url = url +"&num_fields=&ajax_request=true";
224         /*Creating a div on the frame_content frame */
225         var div = parent.frame_content.$('<div id="create_table_dialog"></div>');
226         var target = "tbl_create.php";
228         /*Calling to the createTableDialog function*/
229         PMA_createTableDialog(div , url , target);
230     });//end of create new table
231 });//end of document get ready