From 095f93ebb2b38dca9e87e0185f0f51f6da03de12 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 22 Nov 2011 23:28:22 -0500 Subject: [PATCH] Added tests for append and prepend methods of dom module --- README.md | 0 combine.php | 4 ++-- kis-all.js | 0 kis-min.js | 0 src/modules/DOM.js | 18 ++++++++++++++++-- tests/tests/dom.js | 28 ++++++++++++++++++++++++++++ 6 files changed, 46 insertions(+), 4 deletions(-) mode change 100644 => 100755 README.md mode change 100644 => 100755 kis-all.js mode change 100644 => 100755 kis-min.js diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/combine.php b/combine.php index f77589b..16d5366 100755 --- a/combine.php +++ b/combine.php @@ -52,14 +52,14 @@ foreach($files as $f) file_put_contents("kis-custom.js", $new_file); //Get a much-minified version from Google's closure compiler -$ch = curl_init('http://closure-compiler.appspot.com/compile'); +/*$ch = curl_init('http://closure-compiler.appspot.com/compile'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, 'output_info=compiled_code&output_format=text&compilation_level=SIMPLE_OPTIMIZATIONS&js_code=' . urlencode($new_file)); $output = curl_exec($ch); curl_close($ch); -file_put_contents("kis-custom-min.js", $output); +file_put_contents("kis-custom-min.js", $output);*/ //Display the output on-screen too diff --git a/kis-all.js b/kis-all.js old mode 100644 new mode 100755 diff --git a/kis-min.js b/kis-min.js old mode 100644 new mode 100755 diff --git a/src/modules/DOM.js b/src/modules/DOM.js index c6c05d1..f410b52 100644 --- a/src/modules/DOM.js +++ b/src/modules/DOM.js @@ -313,7 +313,14 @@ */ append: function(htm) { - this.el.insertAdjacentHTML('beforeend', htm); + if(typeof document.insertAdjacentHTML !== "undefined") + { + this.el.insertAdjacentHTML('beforeend', htm); + } + else + { + this.el.innerHTML += htm; + } }, /** * Adds to the innerHTML of the selected element, before the current children @@ -325,7 +332,14 @@ */ prepend: function(htm) { - this.el.insertAdjacentHTML('afterbegin', htm); + if(typeof document.insertAdjacentHTML !== "undefined") + { + this.el.insertAdjacentHTML('afterbegin', htm); + } + else + { + this.el.innerHTML = htm + this.el.innerHTML; + } }, /** * Sets or gets the innerHTML propery of the element(s) passed diff --git a/tests/tests/dom.js b/tests/tests/dom.js index 15a5025..9fadea8 100644 --- a/tests/tests/dom.js +++ b/tests/tests/dom.js @@ -89,4 +89,32 @@ equal($_('#r14').dom.html(test_html).toLowerCase(), test_html, "Sets html"); }); + test("append", function(){ + + expect(1); + + //Remove the text from this element…so we can add to it + $_("#r14").dom.html(""); + + var html = ""; + + $_("#r14 ul").dom.append('
  • This is a test item
  • '); + + equal($('#r14').innerHTML, html, "Append adds a child to the end of the selected element"); + }); + + test("prepend", function(){ + + expect(1); + + var html = ''; + + $_("#r14 ul").dom.prepend('
  • Test2
  • '); + + equal($('#r14').innerHTML, html, "Prepend adds a child to the beginning of the selected element"); + + //Clean up the html + $_("#r14").dom.html(""); + }); + }()); \ No newline at end of file