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);">' + PMA_getImage('b_edit.png') + ' ' + PMA_messages
['strEdit'] + '</a>';
8 saveLink
= '<a href="#" class="saveLink">' + PMA_getImage('b_save.png') + ' ' + PMA_messages
['strSave'] + '</a> ';
9 cancelLink
= '<a href="#" class="cancelLink">' + PMA_getImage('b_close.png') + ' ' + PMA_messages
['strCancel'] + '</a> ';
11 /* Variable editing */
13 $('table.data tbody tr td:nth-child(2)').hover(
15 // Only add edit element if it is the global value, not session value and not when the element is being edited
16 if ($(this).parent().children('th').length
> 0 && ! $(this).hasClass('edit')) {
17 $(this).prepend(editLink
);
21 $(this).find('a.editLink').remove();
26 // Filter options are invisible for disabled js users
27 $('fieldset#tableFilter').css('display','');
29 $('#filterText').keyup(function(e
) {
30 if ($(this).val().length
== 0) {
33 textFilter
= new RegExp("(^| )"+$(this).val().replace(/_
/g
,' '),'i');
38 if (location
.hash
.substr(1).split('=')[0] == 'filter') {
39 var name
= location
.hash
.substr(1).split('=')[1];
40 // Only allow variable names
41 if (! name
.match(/[^0-9a-zA-Z_]+/)) {
42 $('#filterText').attr('value',name
).trigger('keyup');
46 /* Table width limiting */
47 $('table.data').after($tmpDiv
=$('<span>'+testString
+'</span>'));
48 charWidth
= $tmpDiv
.width() / testString
.length
;
51 $(window
).resize(limitTableWidth
);
54 /* This function chops of long variable values to keep the table from overflowing horizontally
55 * It does so by taking a test string and calculating an average font width and removing 'excess width / average font width'
56 * chars, so it is not very accurate.
58 function limitTableWidth() {
64 $('table.data').after($tmpTable
= $('<table id="testTable" style="width:100%;"><tr><td>' + testString
+ '</td></tr></table>'));
65 maxTableWidth
= $('#testTable').width();
67 charDiff
= ($('table.data').width() - maxTableWidth
) / charWidth
;
69 if ($('body').innerWidth() < $('table.data').width() + 10 || $('body').innerWidth() > $('table.data').width() + 20) {
72 $('table.data tbody tr td:nth-child(2)').each(function() {
73 maxChars
= Math
.max($(this).text().length
, maxChars
);
76 // Do not resize smaller if there's only 50 chars displayed already
77 if (charDiff
> 0 && maxChars
< 50) { return; }
79 $('table.data tbody tr td:nth-child(2)').each(function() {
80 if ((charDiff
> 0 && $(this).text().length
> maxChars
- charDiff
) || (charDiff
< 0 && $(this).find('abbr.cutoff').length
> 0)) {
81 if ($(this).find('abbr.cutoff').length
> 0) {
82 fulltext
= $(this).find('abbr.cutoff').attr('title');
84 fulltext
= $(this).text();
85 // Do not cut off elements with html in it and hope they are not too long
86 if (fulltext
.length
!= $(this).html().length
) { return 0; }
89 if (fulltext
.length
< maxChars
- charDiff
) {
90 $(this).html(fulltext
);
92 $(this).html('<abbr class="cutoff" title="' + fulltext
+ '">' + fulltext
.substr(0, maxChars
- charDiff
- 3) + '...</abbr>');
99 /* Filters the rows by the user given regexp */
100 function filterVariables() {
101 var mark_next
= false, firstCell
;
104 $('table.filteredData tbody tr').each(function() {
105 firstCell
= $(this).children(':first');
107 if (mark_next
|| textFilter
== null || textFilter
.exec(firstCell
.text())) {
108 // If current global value is different from session value (=has class diffSession), then display that one too
109 mark_next
= $(this).hasClass('diffSession') && ! mark_next
;
112 $(this).css('display','');
114 $(this).addClass('odd');
115 $(this).removeClass('even');
117 $(this).addClass('even');
118 $(this).removeClass('odd');
121 $(this).css('display','none');
127 /* Called by inline js. Allows the user to edit a server variable */
128 function editVariable(link
)
130 var varName
= $(link
).parent().parent().find('th:first').first().text().replace(/ /g
,'_');
131 var mySaveLink
= $(saveLink
);
132 var myCancelLink
= $(cancelLink
);
133 var $cell
= $(link
).parent();
135 $cell
.addClass('edit');
137 $cell
.find('a.editLink').remove();
139 mySaveLink
.click(function() {
140 $.get('server_variables.php?' + url_query
, {
144 varValue
: $cell
.find('input').attr('value')
147 $cell
.html(data
.variable
);
149 PMA_ajaxShowMessage(data
.error
, false);
150 $cell
.html($cell
.find('span.oldContent').html());
152 $cell
.removeClass('edit');
158 myCancelLink
.click(function() {
159 $cell
.html($cell
.find('span.oldContent').html());
160 $cell
.removeClass('edit');
164 $.get('server_variables.php?' + url_query
, {
169 // hide original content
170 $cell
.html('<span class="oldContent" style="display:none;">' + $cell
.html() + '</span>');
171 // put edit field and save/cancel link
172 $cell
.prepend('<table class="serverVariableEditTable" border="0"><tr><td></td><td style="width:100%;">' +
173 '<input type="text" id="variableEditArea" value="' + data
+ '" /></td></tr</table>');
174 $cell
.find('table td:first').append(mySaveLink
);
175 $cell
.find('table td:first').append(' ');
176 $cell
.find('table td:first').append(myCancelLink
);
178 // Keyboard shortcuts to the rescue
179 $('input#variableEditArea').focus();
180 $('input#variableEditArea').keydown(function(event
) {
182 if(event
.keyCode
== 13) mySaveLink
.trigger('click');
184 if(event
.keyCode
== 27) myCancelLink
.trigger('click');