devel_krumo.js 2.6 KB

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