2 var textFilter = null, odd_row = false;
3 var testString = 'abcdefghijklmnopqrstuvwxyz0123456789,ABCEFGHIJKLMOPQRSTUVWXYZ';
4 var $tmpDiv, charWidth;
7 editLink = '<a href="#" class="editLink" onclick="return editVariable(this);"><img class="icon ic_b_edit" src="themes/dot.gif" alt=""> '+PMA_messages['strEdit']+'</a>';
8 saveLink = '<a href="#" class="saveLink"><img class="icon ic_b_save" src="themes/dot.gif" alt=""> '+PMA_messages['strSave']+'</a> ';
9 cancelLink = '<a href="#" class="cancelLink"><img class="icon ic_b_close" src="themes/dot.gif" alt=""> '+PMA_messages['strCancel']+'</a> ';
15 /* Variable editing */
17 $('table.data tbody tr td:nth-child(2)').hover(
19 // Only add edit element if it is the global value, not session value and not when the element is being edited
20 if ($(this).parent().children('th').length > 0 && ! $(this).hasClass('edit')) {
21 $(this).prepend(editLink);
25 $(this).find('a.editLink').remove();
30 // Filter options are invisible for disabled js users
31 $('fieldset#tableFilter').css('display','');
33 $('#filterText').keyup(function(e) {
34 if ($(this).val().length == 0) {
37 textFilter = new RegExp("(^| )"+$(this).val().replace(/_/g,' '),'i');
42 if (location.hash.substr(1).split('=')[0] == 'filter') {
43 var name = location.hash.substr(1).split('=')[1];
44 // Only allow variable names
45 if (! name.match(/[^0-9a-zA-Z_]+/)) {
46 $('#filterText').attr('value',name).trigger('keyup');
50 /* Table width limiting */
51 $('table.data').after($tmpDiv=$('<span>'+testString+'</span>'));
52 charWidth = $tmpDiv.width() / testString.length;
55 $(window).resize(limitTableWidth);
58 /* This function chops of long variable values to keep the table from overflowing horizontally
59 * It does so by taking a test string and calculating an average font width and removing 'excess width / average font width'
60 * chars, so it is not very accurate.
62 function limitTableWidth() {
68 $('table.data').after($tmpTable = $('<table id="testTable" style="width:100%;"><tr><td>' + testString + '</td></tr></table>'));
69 maxTableWidth = $('#testTable').width();
71 charDiff = ($('table.data').width() - maxTableWidth) / charWidth;
73 if ($('body').innerWidth() < $('table.data').width() + 10 || $('body').innerWidth() > $('table.data').width() + 20) {
76 $('table.data tbody tr td:nth-child(2)').each(function() {
77 maxChars = Math.max($(this).text().length, maxChars);
80 // Do not resize smaller if there's only 50 chars displayed already
81 if (charDiff > 0 && maxChars < 50) { return; }
83 $('table.data tbody tr td:nth-child(2)').each(function() {
84 if ((charDiff > 0 && $(this).text().length > maxChars - charDiff) || (charDiff < 0 && $(this).find('abbr.cutoff').length > 0)) {
85 if ($(this).find('abbr.cutoff').length > 0) {
86 fulltext = $(this).find('abbr.cutoff').attr('title');
88 fulltext = $(this).text();
89 // Do not cut off elements with html in it and hope they are not too long
90 if (fulltext.length != $(this).html().length) { return 0; }
93 if (fulltext.length < maxChars - charDiff) {
94 $(this).html(fulltext);
96 $(this).html('<abbr class="cutoff" title="' + fulltext + '">' + fulltext.substr(0, maxChars - charDiff - 3) + '...</abbr>');
103 /* Filters the rows by the user given regexp */
104 function filterVariables() {
105 var mark_next = false, firstCell;
108 $('table.filteredData tbody tr').each(function() {
109 firstCell = $(this).children(':first');
111 if (mark_next || textFilter == null || textFilter.exec(firstCell.text())) {
112 // If current global value is different from session value (=has class diffSession), then display that one too
113 mark_next = $(this).hasClass('diffSession') && ! mark_next;
116 $(this).css('display','');
118 $(this).addClass('odd');
119 $(this).removeClass('even');
121 $(this).addClass('even');
122 $(this).removeClass('odd');
125 $(this).css('display','none');
131 /* Called by inline js. Allows the user to edit a server variable */
132 function editVariable(link)
134 var varName = $(link).parent().parent().find('th:first').first().text().replace(/ /g,'_');
135 var mySaveLink = $(saveLink);
136 var myCancelLink = $(cancelLink);
137 var $cell = $(link).parent();
139 $cell.addClass('edit');
141 $cell.find('a.editLink').remove();
143 mySaveLink.click(function() {
144 $.get('server_variables.php?' + url_query, {
148 varValue: $cell.find('input').attr('value')
151 $cell.html(data.variable);
153 PMA_ajaxShowMessage(data.error);
154 $cell.html($cell.find('span.oldContent').html());
156 $cell.removeClass('edit');
162 myCancelLink.click(function() {
163 $cell.html($cell.find('span.oldContent').html());
164 $cell.removeClass('edit');
168 $.get('server_variables.php?' + url_query, {
173 // hide original content
174 $cell.html('<span class="oldContent" style="display:none;">' + $cell.html() + '</span>');
175 // put edit field and save/cancel link
176 $cell.prepend('<table class="serverVariableEditTable" border="0"><tr><td></td><td style="width:100%;">' +
177 '<input type="text" id="variableEditArea" value="' + data + '" /></td></tr</table>');
178 $cell.find('table td:first').append(mySaveLink);
179 $cell.find('table td:first').append(' ');
180 $cell.find('table td:first').append(myCancelLink);
182 // Keyboard shortcuts to the rescue
183 $('input#variableEditArea').focus();
184 $('input#variableEditArea').keydown(function(event) {
186 if(event.keyCode == 13) mySaveLink.trigger('click');
188 if(event.keyCode == 27) myCancelLink.trigger('click');