index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. $(function() {
  2. $('#sidebar').on('click', 'a', function(e) {
  3. if (e.currentTarget.className.indexOf('deltree') !== -1) {
  4. e.preventDefault();
  5. if (confirm('Are you sure you want to delete this whole tree and all it\'s keys?')) {
  6. $.ajax({
  7. type: "POST",
  8. url: this.href,
  9. data: 'post=1',
  10. success: function(url) {
  11. top.location.href = top.location.pathname+url;
  12. }
  13. });
  14. }
  15. } else {
  16. if (e.currentTarget.href.indexOf('/?') == -1) {
  17. return;
  18. }
  19. e.preventDefault();
  20. var href;
  21. if ((e.currentTarget.href.indexOf('?') == -1) ||
  22. (e.currentTarget.href.indexOf('?') == (e.currentTarget.href.length - 1))) {
  23. href = 'overview.php';
  24. } else {
  25. href = e.currentTarget.href.substr(e.currentTarget.href.indexOf('?') + 1);
  26. if (href.indexOf('&') != -1) {
  27. href = href.replace('&', '.php?');
  28. } else {
  29. href += '.php';
  30. }
  31. }
  32. if (href.indexOf('flush.php') == 0) {
  33. if (confirm('Are you sure you want to delete this key and all it\'s values?')) {
  34. $.ajax({
  35. type: "POST",
  36. url: href,
  37. data: 'post=1',
  38. success: function() {
  39. window.location.reload();
  40. }
  41. });
  42. }
  43. } else {
  44. $('#iframe').attr('src', href);
  45. }
  46. $('li.current').removeClass('current');
  47. $(this).parent().addClass('current');
  48. }
  49. });
  50. $('#server').change(function(e) {
  51. if (location.href.indexOf('?') == -1) {
  52. location.href = location.href+'?s='+e.target.value;
  53. } else if (location.href.indexOf('&s=') == -1) {
  54. location.href = location.href+'&s='+e.target.value;
  55. } else {
  56. location.href = location.href.replace(/s=[0-9]*/, 's='+e.target.value);
  57. }
  58. });
  59. $('#database').change(function(e) {
  60. if (location.href.indexOf('?') == -1) {
  61. location.href = location.href+'?d='+e.target.value;
  62. } else if (location.href.indexOf('&d=') == -1) {
  63. location.href = location.href+'&d='+e.target.value;
  64. } else {
  65. location.href = location.href.replace(/d=[0-9]*/, 'd='+e.target.value);
  66. }
  67. });
  68. $('li.current').parents('li.folder').removeClass('collapsed');
  69. $('#sidebar').on('click', 'li.folder', function(e) {
  70. var t = $(this);
  71. if ((e.pageY >= t.offset().top) &&
  72. (e.pageY <= t.offset().top + t.children('div').height())) {
  73. e.stopPropagation();
  74. t.toggleClass('collapsed');
  75. }
  76. });
  77. $('#btn_server_filter').click(function() {
  78. var filter = $('#server_filter').val();
  79. location.href = top.location.pathname + '?overview&s=' + $('#server').val() + '&d=' + ($('#database').val() || '') + '&filter=' + filter;
  80. });
  81. $('#server_filter').keydown(function(e){
  82. if (e.keyCode == 13) {
  83. $('#btn_server_filter').click();
  84. }
  85. });
  86. $('#filter').focus(function() {
  87. if ($(this).hasClass('info')) {
  88. $(this).removeClass('info').val('');
  89. }
  90. }).keyup(function() {
  91. var val = $(this).val();
  92. $('li:not(.folder)').each(function(i, el) {
  93. var key = $('a', el).get(0);
  94. var key = unescape(key.href.substr(key.href.indexOf('key=') + 4));
  95. if (key.indexOf(val) == -1) {
  96. $(el).addClass('hidden');
  97. } else {
  98. $(el).removeClass('hidden');
  99. }
  100. });
  101. $('li.folder').each(function(i, el) {
  102. if ($('li:not(.hidden, .folder)', el).length == 0) {
  103. $(el).addClass('hidden');
  104. } else {
  105. $(el).removeClass('hidden');
  106. }
  107. });
  108. });
  109. var isResizing = false;
  110. var lastDownX = 0;
  111. var lastWidth = 0;
  112. var resizeSidebar = function(w) {
  113. $('#sidebar').css('width', w);
  114. $('#keys').css('width', w);
  115. $('#resize').css('left', w + 10);
  116. $('#resize-layover').css('left', w + 15);
  117. $('#frame').css('left', w + 15);
  118. };
  119. if (parseInt($.cookie('sidebar')) > 0) {
  120. resizeSidebar(parseInt($.cookie('sidebar')));
  121. }
  122. $('#resize').on('mousedown', function (e) {
  123. isResizing = true;
  124. lastDownX = e.clientX;
  125. lastWidth = $('#sidebar').width();
  126. $('#resize-layover').css('z-index', 1000);
  127. e.preventDefault();
  128. });
  129. $(document).on('mousemove', function (e) {
  130. if (!isResizing) {
  131. return;
  132. }
  133. var w = lastWidth - (lastDownX - e.clientX);
  134. if (w < 250 ) {
  135. w = 250;
  136. } else if (w > 1000) {
  137. w = 1000;
  138. }
  139. resizeSidebar(w);
  140. $.cookie('sidebar', w);
  141. }).on('mouseup', function (e) {
  142. isResizing = false;
  143. $('#resize-layover').css('z-index', 0);
  144. });
  145. });