devel_krumo_path.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. (function ($) {
  2. /**
  3. * Attaches double-click behavior to toggle full path of Krumo elements.
  4. */
  5. Drupal.behaviors.devel = {
  6. attach: function (context, settings) {
  7. // Add hint to footnote
  8. $('.krumo-footnote .krumo-call').once().before('<img style="vertical-align: middle;" title="Click to expand. Double-click to show path." src="' + settings.basePath + 'misc/help.png"/>');
  9. var krumo_name = [];
  10. var krumo_type = [];
  11. function krumo_traverse(el) {
  12. krumo_name.push($(el).html());
  13. krumo_type.push($(el).siblings('em').html().match(/\w*/)[0]);
  14. if ($(el).closest('.krumo-nest').length > 0) {
  15. krumo_traverse($(el).closest('.krumo-nest').prev().find('.krumo-name'));
  16. }
  17. }
  18. $('.krumo-child > div:first-child', context).dblclick(
  19. function(e) {
  20. if ($(this).find('> .krumo-php-path').length > 0) {
  21. // Remove path if shown.
  22. $(this).find('> .krumo-php-path').remove();
  23. }
  24. else {
  25. // Get elements.
  26. krumo_traverse($(this).find('> a.krumo-name'));
  27. // Create path.
  28. var krumo_path_string = '';
  29. for (var i = krumo_name.length - 1; i >= 0; --i) {
  30. // Start element.
  31. if ((krumo_name.length - 1) == i)
  32. krumo_path_string += '$' + krumo_name[i];
  33. if (typeof krumo_name[(i-1)] !== 'undefined') {
  34. if (krumo_type[i] == 'Array') {
  35. krumo_path_string += "[";
  36. if (!/^\d*$/.test(krumo_name[(i-1)]))
  37. krumo_path_string += "'";
  38. krumo_path_string += krumo_name[(i-1)];
  39. if (!/^\d*$/.test(krumo_name[(i-1)]))
  40. krumo_path_string += "'";
  41. krumo_path_string += "]";
  42. }
  43. if (krumo_type[i] == 'Object')
  44. krumo_path_string += '->' + krumo_name[(i-1)];
  45. }
  46. }
  47. $(this).append('<div class="krumo-php-path" style="font-family: Courier, monospace; font-weight: bold;">' + krumo_path_string + '</div>');
  48. // Reset arrays.
  49. krumo_name = [];
  50. krumo_type = [];
  51. }
  52. }
  53. );
  54. }
  55. };
  56. })(jQuery);