From f57a59d76720985c98bc57a9b3bb43cd13406583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20La=CC=88nnenma=CC=88ki?= Date: Fri, 18 Nov 2011 14:51:54 +0200 Subject: [PATCH 1/2] console.log to clone jQuery objects before appending them. If the appended element was a child of another element it was removed from that element. This caused console.logging a child element to remove it from the parent. --- spec/jasmine/console_log/console_log.yml | 2 +- spec/jasmine/console_log/console_log_spec.js | 7 +++++++ vendor/assets/javascripts/prolog.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/spec/jasmine/console_log/console_log.yml b/spec/jasmine/console_log/console_log.yml index 7a2453e..0ceafe5 100644 --- a/spec/jasmine/console_log/console_log.yml +++ b/spec/jasmine/console_log/console_log.yml @@ -1,5 +1,5 @@ - src_files: + - spec/javascripts/support/jquery-1.6.2.min.js - spec/jasmine/console_log/console_log.js spec_files: diff --git a/spec/jasmine/console_log/console_log_spec.js b/spec/jasmine/console_log/console_log_spec.js index 471396c..90b4a26 100644 --- a/spec/jasmine/console_log/console_log_spec.js +++ b/spec/jasmine/console_log/console_log_spec.js @@ -3,5 +3,12 @@ describe('console.log', function() { console.log("hello"); expect(success).toEqual(1); }); + + it("wont eat my precious jqueries", function() { + var d = $('
b
'); + expect(d.find('#inner').length).toBe(1); + console.log(d.find('#inner')); + expect(d.find('#inner').length).toBe(1); + }); }); diff --git a/vendor/assets/javascripts/prolog.js b/vendor/assets/javascripts/prolog.js index 2fd358b..8fe9b77 100644 --- a/vendor/assets/javascripts/prolog.js +++ b/vendor/assets/javascripts/prolog.js @@ -5,7 +5,7 @@ log: function(data) { var dump, useJsDump; if (typeof jQuery !== 'undefined' && data instanceof jQuery) { - return JHW.log(style_html($("
").append(data).html(), { + return JHW.log(style_html($("
").append(data.clone()).html(), { indent_size: 2 })); } else { -- 2.45.2 From 115e2eff8b16449363a7e552ce60d9804eb273f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20La=CC=88nnenma=CC=88ki?= Date: Mon, 21 Nov 2011 08:14:57 +0200 Subject: [PATCH 2/2] Clone elements before appending them to the temporary div that is used for logging. --- spec/jasmine/console_log/console_log_spec.js | 6 +++--- vendor/assets/coffeescripts/prolog.coffee | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/jasmine/console_log/console_log_spec.js b/spec/jasmine/console_log/console_log_spec.js index 90b4a26..b31345b 100644 --- a/spec/jasmine/console_log/console_log_spec.js +++ b/spec/jasmine/console_log/console_log_spec.js @@ -6,9 +6,9 @@ describe('console.log', function() { it("wont eat my precious jqueries", function() { var d = $('
b
'); - expect(d.find('#inner').length).toBe(1); - console.log(d.find('#inner')); - expect(d.find('#inner').length).toBe(1); + expect(d.find('#inner').length).toBe(1); + console.log(d.find('#inner')); + expect(d.find('#inner').length).toBe(1); }); }); diff --git a/vendor/assets/coffeescripts/prolog.coffee b/vendor/assets/coffeescripts/prolog.coffee index 75479c9..09fbcf7 100644 --- a/vendor/assets/coffeescripts/prolog.coffee +++ b/vendor/assets/coffeescripts/prolog.coffee @@ -2,7 +2,7 @@ if window.JHW window.console = log: (data) -> if typeof(jQuery) != 'undefined' && data instanceof jQuery - JHW.log(style_html($("
").append(data).html(), { indent_size: 2 })) + JHW.log(style_html($("
").append(data.clone()).html(), { indent_size: 2 })) else useJsDump = true -- 2.45.2