diff --git a/devel.module b/devel.module index 2444e1a..9ef5d9d 100644 --- a/devel.module +++ b/devel.module @@ -441,8 +441,12 @@ function devel_set_message($msg, $type = NULL) { // Return boolean. No need for cache here. function has_krumo() { // see README.txt or just download from http://krumo.sourceforge.net/ - @include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'devel') .'/krumo/class.krumo.php'; - return function_exists('krumo') && !drupal_is_cli(); + @include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'devel') . '/krumo/class.krumo.php'; + if (function_exists('krumo') && !drupal_is_cli()) { + drupal_add_js(drupal_get_path('module', 'devel') . '/krumo_path.js'); + return TRUE; + } + return FALSE; } /** diff --git a/krumo_path.js b/krumo_path.js new file mode 100755 index 0000000..fe741e5 --- /dev/null +++ b/krumo_path.js @@ -0,0 +1,106 @@ +(function ($) { + +/** + * Attaches double-click behavior to toggle full path of Krumo elements. + */ +Drupal.behaviors.devel = { + attach: function (context, settings) { + + // Set title tag for each krumo element. + $('.krumo-root div.krumo-element').each( + function(e) { + if ($(this).hasClass('krumo-expand')) + $(this).attr('title','Click to expand. Double click to show path.'); + else + $(this).attr('title','Double click to show path.'); + }); + + // Set title tag after click on element. + $('.krumo-child > div:first-child.krumo-expand', context).live('click', + function(e) { + if ($(this).hasClass('krumo-php-path-open')) + double_click = 'Double click to hide path.'; + else + double_click = 'Double click to show path.'; + + if ($(this).hasClass('krumo-opened')) + $(this).attr('title','Click to collapse. ' + double_click); + else + $(this).attr('title','Click to expand. ' + double_click); + }); + + var krumo_name = []; + var krumo_type = []; + + function krumo_traverse(el) { + krumo_name.push($(el).html()); + krumo_type.push($(el).siblings('em').html().match(/\w*/)[0]); + + if ($(el).closest('.krumo-nest').length > 0) { + krumo_traverse($(el).closest('.krumo-nest').prev().find('.krumo-name')); + } + } + + $('.krumo-child > div:first-child', context).dblclick( + function(e) { + if ($(this).find('> .krumo-php-path').length > 0) { + // Remove path if shown. + $(this).removeClass('krumo-php-path-open').find('> .krumo-php-path').remove(); + + // Set title tag. + if ($(this).hasClass('krumo-opened')) + $(this).attr('title','Click to collapse. Double click to show path.'); + else { + if ($(this).hasClass('krumo-expand')) + $(this).attr('title','Click to expand. Double click to show path.'); + else + $(this).attr('title','Double click to show path.'); + } + } + else { + // Get elements. + krumo_traverse($(this).find('> a.krumo-name')); + + // Create path. + var krumo_path_string = ''; + for (var i = krumo_name.length - 1; i >= 0; --i) { + // Start element. + if ((krumo_name.length - 1) == i) + krumo_path_string += '$' + krumo_name[i]; + + if (typeof krumo_name[(i-1)] !== 'undefined') { + if (krumo_type[i] == 'Array') { + krumo_path_string += "[" + if (!/^\d*$/.test(krumo_name[(i-1)])) + krumo_path_string += "'"; + krumo_path_string += krumo_name[(i-1)]; + if (!/^\d*$/.test(krumo_name[(i-1)])) + krumo_path_string += "'"; + krumo_path_string += "]"; + } + if (krumo_type[i] == 'Object') + krumo_path_string += '->' + krumo_name[(i-1)]; + } + } + $(this).addClass('krumo-php-path-open').append('
' + krumo_path_string + '
'); + + // Set title tag. + if ($(this).hasClass('krumo-opened')) + $(this).attr('title','Click to collapse. Double click to hide path.'); + else { + if ($(this).hasClass('krumo-expand')) + $(this).attr('title','Click to expand. Double click to hide path.'); + else + $(this).attr('title','Double click to hide path.'); + } + + // Reset arrays. + krumo_name = []; + krumo_type = []; + } + } + ); + } +}; + +})(jQuery);