Added tests for append and prepend methods of dom module

This commit is contained in:
Timothy Warren 2011-11-22 23:28:22 -05:00
parent e635925a6d
commit 095f93ebb2
6 changed files with 46 additions and 4 deletions

0
README.md Normal file → Executable file
View File

View File

@ -52,14 +52,14 @@ foreach($files as $f)
file_put_contents("kis-custom.js", $new_file); file_put_contents("kis-custom.js", $new_file);
//Get a much-minified version from Google's closure compiler //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_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 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)); 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); $output = curl_exec($ch);
curl_close($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 //Display the output on-screen too

0
kis-all.js Normal file → Executable file
View File

0
kis-min.js vendored Normal file → Executable file
View File

View File

@ -313,7 +313,14 @@
*/ */
append: function(htm) 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 * Adds to the innerHTML of the selected element, before the current children
@ -325,7 +332,14 @@
*/ */
prepend: function(htm) 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 * Sets or gets the innerHTML propery of the element(s) passed

View File

@ -89,4 +89,32 @@
equal($_('#r14').dom.html(test_html).toLowerCase(), test_html, "Sets html"); 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("<ul><li>Test</li></ul>");
var html = "<ul><li>Test</li><li>This is a test item</li></ul>";
$_("#r14 ul").dom.append('<li>This is a test item</li>');
equal($('#r14').innerHTML, html, "Append adds a child to the end of the selected element");
});
test("prepend", function(){
expect(1);
var html = '<ul><li>Test2</li><li>Test</li><li>This is a test item</li></ul>';
$_("#r14 ul").dom.prepend('<li>Test2</li>');
equal($('#r14').innerHTML, html, "Prepend adds a child to the beginning of the selected element");
//Clean up the html
$_("#r14").dom.html("");
});
}()); }());