From dab9f72d58429318cd1838299086a2edc67bcec0 Mon Sep 17 00:00:00 2001 From: Eskild Hustvedt Date: Thu, 13 Dec 2012 19:04:17 +0100 Subject: [PATCH 1/2] Added debug.idnode for generating IDs for nodes Can be used to help identify elementents that are being referred to in debugging messages. --- src/lib/debug.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib/debug.js b/src/lib/debug.js index 90a364f..7946fa2 100644 --- a/src/lib/debug.js +++ b/src/lib/debug.js @@ -94,6 +94,25 @@ goog.scope(function() { } }; + /** + * Helper that returns an identifying string for an HTML element + * @param {element} node + */ + debug.idnode = function (node) { + // data-sizes is as specific as we can get (id gets stripped) + var identifier = node.getAttribute('data-sizes'); + if (goog.isString(identifier)) { + return node+' (data-sizes='+identifier+')'; + } + // classes identify it better than nothing + identifier = node.getAttribute('class'); + if (goog.isString(identifier)) { + return node+' (class='+identifier+')'; + } + // Can't identify it, just return + return node; + }; + /** * Assert helper * @param {boolean} assertion From f794632442e0dae3c881439139e4ca09c3096659 Mon Sep 17 00:00:00 2001 From: Eskild Hustvedt Date: Thu, 13 Dec 2012 19:05:21 +0100 Subject: [PATCH 2/2] Use idnode to identify nodes in debugging messages --- src/layout/block.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/layout/block.js b/src/layout/block.js index 5a4ae7d..8c7e3ff 100644 --- a/src/layout/block.js +++ b/src/layout/block.js @@ -62,7 +62,7 @@ goog.scope(function() { // This is a very defensive move, since a display: none item that // is made visible when in a specific column or grid can really mess up a // layout - debug.warn('Zero-height block ignored'); + debug.warn('Zero-height block ignored: ' + debug.idnode(node)); this.ignore = true; return; @@ -588,7 +588,7 @@ goog.scope(function() { Block.sanitizeNode = function(node, baseLineHeight) { // Should never get text & comment nodes if (node.nodeType !== 1) { - debug.error('Text node sent to sanitize: ' + node); + debug.error('Text node sent to sanitize: ' + debug.idnode(node)); return node; } @@ -702,7 +702,7 @@ goog.scope(function() { if (metrics.outerH % baseLineHeight) { // Shit, looks like even with the normalization, we're still out of // sync. Use padding bottom to fix it up - debug.info('Forcing padding due to mismatch: ' + node); + debug.info('Forcing padding due to mismatch: ' + debug.idnode(node)); metrics.paddingBottom += baseLineHeight - metrics.outerH % baseLineHeight;