2007-01-18 22:24:27 +00:00
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" lang = "en" >
< head >
< title > Prototype Unit test file< / title >
< meta http-equiv = "content-type" content = "text/html; charset=utf-8" / >
< script src = "../../dist/prototype.js" type = "text/javascript" > < / script >
< script src = "../lib/unittest.js" type = "text/javascript" > < / script >
< link rel = "stylesheet" href = "../test.css" type = "text/css" / >
< style type = "text/css" media = "screen" >
/* < ![CDATA[ */
#testcss1 { font-size:11px; color: #f00; }
#testcss2 { font-size:12px; color: #0f0; display: none; }
#style_test_1 { cursor: pointer; font-size:12px;}
div.style-test { margin-left: 1px }
2007-06-10 12:58:32 +00:00
#style_test_dimensions_container {
position: absolute;
top: 0;
left: 500px;
width: 20px;
height: 30px;
margin: 10px;
padding: 10px;
border: 3px solid red;
}
2007-01-18 22:24:27 +00:00
#not_floating_style { float: none }
#floating_style { float: left }
#op2 { opacity:0.5;filter:alpha(opacity=50)progid:DXImageTransform.Microsoft.Blur(strength=10);}
#scroll_test_1 {
margin: 10px;
padding: 10px;
position: relative;
}
#scroll_test_2 {
position: absolute;
left: 10px;
top: 10px;
}
#dimensions-visible,
#dimensions-display-none,
#dimensions-visible-pos-rel,
#dimensions-display-none-pos-rel,
#dimensions-visible-pos-abs,
#dimensions-display-none-pos-abs {
font-size: 10px;
height: 10em;
width: 20em;
}
#dimensions-visible-pos-abs,
#dimensions-display-none-pos-abs {
position: absolute;
top: 15px;
left: 15px;
}
#dimensions-visible-pos-rel,
#dimensions-display-none-pos-rel {
position: relative;
top: 15px;
left: 15px;
}
#dimensions-display-none, #imensions-display-none-pos-rel, #dimensions-display-none-pos-abs {
display: none;
}
#dimensions-table, #dimensions-tbody, #dimensions-tr, #dimensions-td {
font-size: 10px;
margin: 0;
padding: 0;
border: 0;
border-spacing: 0;
height: 10em;
width: 20em;
}
2007-06-06 14:30:01 +00:00
#notInlineAbsoluted { position: absolute; }
2007-01-18 22:24:27 +00:00
/* for scroll test on really big screens */
body {
height: 40000px;
}
/* ]]> */
< / style >
< / head >
< body >
< h1 > Prototype Unit test file< / h1 >
< p >
Test of functions in dom.js
< / p >
<!-- Log output -->
< div id = "scroll_test_1" >
< p id = "scroll_test_2" > Scroll test< / p >
< / div >
< div id = "testlog" > < / div >
< div id = "test-visible" > visible< / div >
< div id = "test-hidden" style = "display:none;" > hidden< / div >
< div id = "test-toggle-visible" > visible< / div >
< div id = "test-toggle-hidden" style = "display:none;" > hidden< / div >
< div id = "test-hide-visible" > visible< / div >
< div id = "test-hide-hidden" style = "display:none;" > hidden< / div >
< div id = "test-show-visible" > visible< / div >
< div id = "test-show-hidden" style = "display:none;" > hidden< / div >
< div id = "removable-container" > < div id = "removable" > < / div > < / div >
< div >
< table >
< tbody id = "table" >
< tr >
< td > Data< / td >
< / tr >
< tr >
< td id = "a_cell" > First Row< / td >
< / tr >
< tr id = "second_row" >
< td > Second Row< / td >
< / tr >
< / tbody >
< / table >
< / div >
< div id = "table-container-to-replace" >
< table >
< tbody id = "table-to-replace" >
< tr >
< td > Data< / td >
< / tr >
< tr >
< td id = "a_cell-to-replace" > First Row< / td >
< / tr >
< tr id = "second_row-to-replace" >
< td > Second Row< / td >
< / tr >
< / tbody >
< / table >
< / div >
< p class = "test" > Test paragraph outside of container< / p >
< div id = "container" >
< p class = "test" id = "intended" > Test paragraph 1 inside of container< / p >
< p class = "test" > Test paragraph 2 inside of container< / p >
< p class = "test" > Test paragraph 3 inside of container< / p >
< p class = "test" > Test paragraph 4 inside of container< / p >
< / div >
< div id = "testdiv" > to be updated< / div >
< div id = "testdiv-replace-container-1" > < div id = "testdiv-replace-1" > < / div > < / div >
< div id = "testdiv-replace-container-2" > < div id = "testdiv-replace-2" > < / div > < / div >
< div id = "testdiv-replace-container-3" > < div id = "testdiv-replace-3" > < / div > < / div >
< div id = "testdiv-replace-container-4" > < div id = "testdiv-replace-4" > < / div > < / div >
< div id = "testdiv-replace-container-5" > < div id = "testdiv-replace-5" > < / div > < / div >
2007-07-24 18:52:17 +00:00
< div id = "testdiv-replace-container-element" > < div id = "testdiv-replace-element" > < / div > < / div >
< div id = "testdiv-replace-container-toelement" > < div id = "testdiv-replace-toelement" > < / div > < / div >
< div id = "testdiv-replace-container-tohtml" > < div id = "testdiv-replace-tohtml" > < / div > < / div >
< div id = "testtable-replace-container" > < table id = "testtable-replace" > < / table > < / div >
< table id = "testrow-replace-container" > < tr id = "testrow-replace" > < / tr > < / table >
< select id = "testoption-replace-container" > < option id = "testoption-replace" > < / option > < option > stays< / option > < / select >
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
< div id = "testform-replace-container" > < p > some text< / p > < form id = "testform-replace" > < input id = "testinput-replace" type = "text" / > < / form > < p > some text< / p > < / div >
2007-01-18 22:24:27 +00:00
< div id = "element_with_visible_overflow" style = "overflow:visible" > V< / div >
< div id = "element_with_hidden_overflow" style = "overflow:hidden" > H< / div >
< div id = "element_with_scroll_overflow" style = "overflow:scroll" > S< / div >
< div id = "element_extend_test" > < / div >
2007-03-11 22:40:24 +00:00
< div id = "element_reextend_test" > < div id = "discard_1" > < / div > < / div >
2007-01-18 22:24:27 +00:00
< div id = "test_whitespace" > < span > < / span >
< div > < div > < / div > < / div > < span > < / span >
< / div >
< div id = "nav_tests_isolator" >
< div id = "nav_test_first_sibling" > < / div >
< div > < / div >
< p id = "nav_test_p" class = "test" > < / p >
< span id = "nav_test_prev_sibling" > < / span >
< ul id = "navigation_test" style = "display: none" >
< li class = "first" > < em > A< / em > < / li >
< li > < em class = "dim" > B< / em > < / li >
< li id = "navigation_test_c" >
< em > C< / em >
< ul >
< li > < em class = "dim" > E< / em > < / li >
< li id = "navigation_test_f" > < em > F< / em > < / li >
< / ul >
< / li >
< li class = "last" > < em > D< / em > < / li >
< / ul >
< div id = "navigation_test_next_sibling" >
<!-- -->
< / div >
< p > < / p >
< / div >
< div id = "class_names" >
< p class = "A" > < / p >
< ul class = "A B" id = "class_names_ul" >
< li class = "C" > < / li >
< li class = "A C" > < / li >
2007-06-17 22:26:46 +00:00
< li class = "1" > < / li >
2007-01-18 22:24:27 +00:00
< / ul >
< div class = "B C D" > < / div >
2007-06-17 22:26:46 +00:00
< div id = "unextended" > < / div >
2007-01-18 22:24:27 +00:00
< / div >
< div id = "style_test_1" style = "display:none;" > < / div >
< div id = "style_test_2" class = "style-test" style = "font-size:11px;" > < / div >
< div id = "style_test_3" > blah< / div >
2007-10-22 13:14:56 +00:00
< span id = "style_test_4" > blah< / span >
< span id = "style_test_5" > blah< / span >
2007-01-18 22:24:27 +00:00
2007-06-10 12:58:32 +00:00
< div id = "style_test_dimensions_container" >
2007-08-10 14:19:30 +00:00
< div id = "style_test_dimensions" style = "background:#ddd;padding:1px;margin:1px;border:1px solid #00f" > < div style = "height:5px;background:#eee;width:5px;padding:2px;margin:2px;border:2px solid #0f0" > < / div >
2007-06-10 12:58:32 +00:00
< / div >
< / div >
2007-01-18 22:24:27 +00:00
2007-07-24 18:14:36 +00:00
< div id = "test_csstext_1" > test_csstext_1< / div >
< div id = "test_csstext_2" > test_csstext_2< / div >
< div id = "test_csstext_3" style = "border: 1px solid red" > test_csstext_3< / div >
< div id = "test_csstext_4" style = "font-size: 20px" > test_csstext_4< / div >
< div id = "test_csstext_5" > test_csstext_5< / div >
2007-01-18 22:24:27 +00:00
< div id = "custom_attributes" >
< div foo = "1" bar = "2" > < / div >
< div foo = "2" > < / div >
< / div >
2007-07-24 17:31:23 +00:00
< div id = "cloned_element_attributes_issue" foo = "original" > < / div >
< a id = "attributes_with_issues_1" href = "test.html" accesskey = "L" tabindex = "50" title = "a link" onclick = "alert('hello world');" > < / a >
2007-01-18 22:24:27 +00:00
< a id = "attributes_with_issues_2" href = "" accesskey = "" tabindex = "" title = "" > < / a >
< a id = "attributes_with_issues_3" > < / a >
2007-03-08 22:43:18 +00:00
< form id = "attributes_with_issues_form" method = "post" action = "blah" >
< input type = "checkbox" id = "attributes_with_issues_checked" name = "a" checked = "checked" / >
< input type = "checkbox" id = "attributes_with_issues_disabled" name = "b" checked = "checked" disabled = "disabled" / >
< input type = "text" id = "attributes_with_issues_readonly" name = "c" readonly = "readonly" value = "blech" / >
2007-04-28 02:23:26 +00:00
< input type = "date" id = "attributes_with_issues_type" value = "blech" / >
2007-03-08 22:43:18 +00:00
< select id = "attributes_with_issues_multiple" name = "e" multiple = "multiple" >
< option > blech< / option >
< option > blah< / option >
< / select >
< / form >
2007-01-18 22:24:27 +00:00
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
<!-- writeAttributes -->
< p id = "write_attribute_para" > < / a >
< a id = "write_attribute_link" href = "test.html" > < / a >
< form action = "/dev/null" id = "write_attribute_form" method = "get" accept-charset = "utf-8" >
< label id = "write_attribute_label" > < / label >
< input type = "checkbox" name = "write_attribute_checkbox" value = "" id = "write_attribute_checkbox" >
< input type = "checkbox" checked = "checked" name = "write_attribute_checked_checkbox" value = "" id = "write_attribute_checked_checkbox" >
< input type = "text" name = "write_attribute_input" value = "" id = "write_attribute_input" >
< select id = "write_attribute_select" >
< option > Cat< / option >
< option > Dog< / option >
< / select >
< / form >
< table id = "write_attribute_table" >
< tr > < td id = "write_attribute_td" > A< / td > < td > B< / td > < / tr >
< tr > < td > C< / td > < / tr >
< tr > < td > D< / td > < td > E< / td > < td > F< / td > < / tr >
< / table >
2007-01-18 22:24:27 +00:00
< div id = "dom_attribute_precedence" >
2007-03-08 22:43:18 +00:00
< form action = "blech" method = "post" >
2007-01-18 22:24:27 +00:00
< input type = "submit" id = "update" / >
< / form >
< / div >
< div id = "not_floating_none" > NFN< / div >
< div id = "not_floating_inline" style = "float:none" > NFI< / div >
< div id = "not_floating_style" > NFS< / div >
< div id = "floating_inline" style = "float:left" > FI< / div >
< div id = "floating_style" > FS< / div >
<!-- Test Element opacity functions -->
< img id = "op1" alt = "op2" src = "fixtures/logo.gif" style = "opacity:0.5;filter:alpha(opacity=50)" / >
< img id = "op2" alt = "op2" src = "fixtures/logo.gif" / >
< img id = "op3" alt = "op3" src = "fixtures/logo.gif" / >
< img id = "op4-ie" alt = "op3" src = "fixtures/logo.gif" style = "filter:alpha(opacity=30)" / >
< div id = "dimensions-visible" > < / div >
< div id = "dimensions-display-none" > < / div >
< div id = "dimensions-visible-pos-rel" > < / div >
< div id = "dimensions-display-none-pos-rel" > < / div >
< div id = "dimensions-visible-pos-abs" > < / div >
< div id = "dimensions-display-none-pos-abs" > < / div >
< table border = "0" cellspacing = "0" cellpadding = "0" id = "dimensions-table" >
< tbody id = "dimensions-tbody" >
< tr id = "dimensions-tr" >
< td id = "dimensions-td" > Data< / td >
< / tr >
< / tbody >
< / table >
2007-03-27 18:04:59 +00:00
< div id = "dimensions-nester" style = "width: 500px;" >
< div id = "dimensions-nestee" style = "display: none" > This is a nested DIV. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.< / div >
< / div >
2007-01-18 22:24:27 +00:00
< p id = "test-empty" > < / p >
< p id = "test-empty-but-contains-whitespace" >
< / p >
< p id = "test-full" > content< / p >
2007-11-01 15:11:52 +00:00
< div id = "ancestor" >
< div id = "child" >
< div id = "grand-child" >
< div id = "great-grand-child" > < / div >
< / div > < / div > <!-- intentional formatting; don't change this line -->
< div id = "sibling" > < div id = "grand-sibling" > < / div > < / div >
< / div >
2007-01-18 22:24:27 +00:00
< div id = "not-in-the-family" > < / div >
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
< div id = "insertions-container" > < div id = "insertions-main" > < p > some content.< / p > < / div > < / div >
< div id = "insertions-node-container" > < div id = "insertions-node-main" > < p > some content.< / p > < / div > < / div >
< div id = "element-insertions-container" > < div id = "element-insertions-main" > < p > some content.< / p > < / div > < / div >
2007-06-02 15:08:50 +00:00
< div id = "element-insertions-multiple-container" > < div id = "element-insertions-multiple-main" > < p > some content.< / p > < / div > < / div >
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
< table id = "table_for_insertions" > < / table >
< table id = "table_for_row_insertions" > < tr id = "row_1" > < / tr > < / table >
< form method = "post" action = "blah" >
< select id = "select_for_update" name = "select_for_update" >
< option > option 1< / option >
< option > option 2< / option >
< / select >
< select id = "select_for_insert_bottom" name = "select_for_insert_bottom" >
< option > option 1< / option >
< option > option 2< / option >
< / select >
< select id = "select_for_insert_top" name = "select_for_insert_top" >
< option > option 1< / option >
< option > option 2< / option >
< / select >
< / form >
< div id = "wrap-container" > < p id = "wrap" > < / p > < / div >
<!-- Positioning methods bench -->
< div id = "body_absolute" style = "position: absolute; top: 10px; left: 10px" >
< div id = "absolute_absolute" style = "position: absolute; top: 10px; left:10px" > < / div >
< div id = "absolute_relative" style = "position: relative; top: 10px; left:10px" >
2007-08-10 14:19:30 +00:00
< div style = "height:10px;font-size:2px" > test< span id = "inline" > test< / span > < / div >
< div id = "absolute_relative_undefined" > XYZ< / div >
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
< / div >
< / div >
2007-06-06 14:30:01 +00:00
< div id = "notInlineAbsoluted" > < / div >
< div id = "inlineAbsoluted" style = "position: absolute" > < / div >
2007-06-17 22:26:46 +00:00
< div id = "unextended" > < / div >
2007-07-24 17:41:27 +00:00
< div id = "identification" >
< div id = "predefined_id" > < / div >
< div > < / div >
< div > < / div >
< div > < / div >
< div id = "anonymous_element_3" > < / div >
< / div >
2007-06-17 22:26:46 +00:00
2007-01-18 22:24:27 +00:00
<!-- Tests follow -->
< script type = "text/javascript" language = "javascript" charset = "utf-8" >
// < ![CDATA[
2007-04-03 22:21:58 +00:00
var testVar = 'to be updated', testVar2 = '';
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
var getInnerHTML = function(id) {
return $(id).innerHTML.toString().toLowerCase().gsub(/[\r\n\t]/, '');
};
2007-07-24 18:52:17 +00:00
var createParagraph = function(text) {
var p = document.createElement('p');
p.appendChild(document.createTextNode(text));
return p;
}
2007-04-24 05:23:41 +00:00
Element.addMethods({
hashBrowns: function(element) { return 'hash browns'; }
});
2007-01-27 19:45:34 +00:00
Element.addMethods("LI", {
pancakes: function(element) { return "pancakes"; }
});
Element.addMethods("DIV", {
waffles: function(element) { return "waffles"; }
});
Element.addMethods($w("li div"), {
orangeJuice: function(element) { return "orange juice"; }
});
2007-01-18 22:24:27 +00:00
new Test.Unit.Runner({
testDollarFunction: function() { with(this) {
assertUndefined($());
assertNull(document.getElementById('noWayThisIDExists'));
assertNull($('noWayThisIDExists'));
assertIdentical(document.getElementById('testdiv'), $('testdiv'));
assertEnumEqual([ $('testdiv'), $('container') ], $('testdiv', 'container'));
assertEnumEqual([ $('testdiv'), undefined, $('container') ],
$('testdiv', 'noWayThisIDExists', 'container'));
var elt = $('testdiv');
assertIdentical(elt, $(elt));
assertRespondsTo('hide', elt);
2007-01-27 19:45:34 +00:00
assertRespondsTo('childOf', elt);
2007-01-18 22:24:27 +00:00
}},
testGetElementsByClassName: function() {with(this) {
2007-06-17 22:26:46 +00:00
var div = $('class_names'), list = $('class_names_ul');
2007-01-18 22:24:27 +00:00
assertElementsMatch(document.getElementsByClassName('A'), 'p.A', 'ul#class_names_ul.A', 'li.A.C');
2007-06-17 22:26:46 +00:00
if (Prototype.Browser.IE)
assertUndefined(document.getElementById('unextended').show);
assertElementsMatch(div.getElementsByClassName('B'), 'ul#class_names_ul.A.B', 'div.B.C.D');
assertElementsMatch(div.getElementsByClassName('D C B'), 'div.B.C.D');
2007-06-19 20:59:14 +00:00
assertElementsMatch(div.getElementsByClassName(' D\nC\tB '), 'div.B.C.D');
assertElementsMatch(div.getElementsByClassName($w('D C B')));
assertElementsMatch(list.getElementsByClassName('A'), 'li.A.C');
assertElementsMatch(list.getElementsByClassName(' A '), 'li.A.C');
assertElementsMatch(list.getElementsByClassName('C A'), 'li.A.C');
assertElementsMatch(list.getElementsByClassName("C\nA "), 'li.A.C');
2007-06-17 22:26:46 +00:00
assertElementsMatch(list.getElementsByClassName('B'));
assertElementsMatch(list.getElementsByClassName('1'), 'li.1');
assertElementsMatch(list.getElementsByClassName([1]), 'li.1');
assertElementsMatch(list.getElementsByClassName(['1 junk']));
assertElementsMatch(list.getElementsByClassName(''));
assertElementsMatch(list.getElementsByClassName(' '));
assertElementsMatch(list.getElementsByClassName(['']));
assertElementsMatch(list.getElementsByClassName([' ', '']));
assertElementsMatch(list.getElementsByClassName({}));
2007-06-17 22:29:44 +00:00
2007-06-17 22:26:46 +00:00
// those lookups shouldn't have extended all nodes in document
if (Prototype.Browser.IE) assertUndefined(document.getElementById('unextended')['show']);
2007-01-18 22:24:27 +00:00
}},
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
testElementInsertWithHTML: function() {with(this) {
2007-06-02 15:08:50 +00:00
Element.insert('insertions-main', {before:'< p > < em > before< / em > text< / p > < p > more testing< / p > '});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('insertions-container').startsWith('< p > < em > before< / em > text< / p > < p > more testing< / p > '));
2007-06-02 15:08:50 +00:00
Element.insert('insertions-main', {after:'< p > < em > after< / em > text< / p > < p > more testing< / p > '});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('insertions-container').endsWith('< p > < em > after< / em > text< / p > < p > more testing< / p > '));
2007-06-02 15:08:50 +00:00
Element.insert('insertions-main', {top:'< p > < em > top< / em > text.< / p > < p > more testing< / p > '});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('insertions-main').startsWith('< p > < em > top< / em > text.< / p > < p > more testing< / p > '));
2007-06-02 15:08:50 +00:00
Element.insert('insertions-main', {bottom:'< p > < em > bottom< / em > text.< / p > < p > more testing< / p > '});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('insertions-main').endsWith('< p > < em > bottom< / em > text.< / p > < p > more testing< / p > '));
}},
testElementInsertWithDOMNode: function() {with(this) {
2007-06-02 15:08:50 +00:00
Element.insert('insertions-node-main', {before: createParagraph('node before')});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('insertions-node-container').startsWith('< p > node before< / p > '));
2007-06-02 15:08:50 +00:00
Element.insert('insertions-node-main', {after: createParagraph('node after')});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('insertions-node-container').endsWith('< p > node after< / p > '));
2007-06-02 15:08:50 +00:00
Element.insert('insertions-node-main', {top:createParagraph('node top')});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('insertions-node-main').startsWith('< p > node top< / p > '));
2007-06-02 15:08:50 +00:00
Element.insert('insertions-node-main', {bottom:createParagraph('node bottom')});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('insertions-node-main').endsWith('< p > node bottom< / p > '));
assertEqual($('insertions-node-main'), $('insertions-node-main').insert(document.createElement('p')));
}},
2007-01-18 22:24:27 +00:00
2007-07-24 18:52:17 +00:00
testElementInsertWithToElementMethod: function() {with(this) {
Element.insert('insertions-node-main', {toElement: createParagraph.curry('toElement') });
assert(getInnerHTML('insertions-node-main').endsWith('< p > toelement< / p > '));
Element.insert('insertions-node-main', {bottom: {toElement: createParagraph.curry('bottom toElement') }});
assert(getInnerHTML('insertions-node-main').endsWith('< p > bottom toelement< / p > '));
}},
testElementInsertWithToHTMLMethod: function() {with(this) {
Element.insert('insertions-node-main', {toHTML: function() { return '< p > toHTML< / p > '} });
assert(getInnerHTML('insertions-node-main').endsWith('< p > tohtml< / p > '));
Element.insert('insertions-node-main', {bottom: {toHTML: function() { return '< p > bottom toHTML< / p > '} }});
assert(getInnerHTML('insertions-node-main').endsWith('< p > bottom tohtml< / p > '));
}},
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
testElementInsertWithNonString: function() {with(this) {
2007-06-02 15:08:50 +00:00
Element.insert('insertions-main', {bottom:3});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('insertions-main').endsWith('3'));
}},
testElementInsertInTables: function() {with(this) {
2007-06-02 15:08:50 +00:00
Element.insert('second_row', {after:'< tr id = "third_row" > < td > Third Row< / td > < / tr > '});
2007-01-27 19:45:34 +00:00
assert($('second_row').descendantOf('table'));
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
2007-06-02 15:08:50 +00:00
$('a_cell').insert({top:'hello world'});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert($('a_cell').innerHTML.startsWith('hello world'));
2007-06-02 15:08:50 +00:00
$('a_cell').insert({after:'< td > hi planet< / td > '});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assertEqual('hi planet', $('a_cell').next().innerHTML);
$('table_for_insertions').insert('< tr > < td > a cell!< / td > < / tr > ');
assert($('table_for_insertions').innerHTML.gsub('\r\n', '').toLowerCase().include('< tr > < td > a cell!< / td > < / tr > '));
2007-06-02 15:08:50 +00:00
$('row_1').insert({after:'< tr > < / tr > < tr > < / tr > < tr > < td > last< / td > < / tr > '});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assertEqual('last', $A($('table_for_row_insertions').getElementsByTagName('tr')).last().lastChild.innerHTML);
}},
testElementInsertInSelect: function() {with(this) {
var selectTop = $('select_for_insert_top'), selectBottom = $('select_for_insert_bottom');
selectBottom.insert('< option value = "33" > option 33< / option > < option selected = "selected" > option 45< / option > ');
assertEqual('option 45', selectBottom.getValue());
2007-06-02 15:08:50 +00:00
selectTop.insert({top:'< option value = "A" > option A< / option > < option value = "B" selected = "selected" > option B< / option > '});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assertEqual(4, selectTop.options.length);
}},
testElementMethodInsert: function() {with(this) {
2007-06-02 15:08:50 +00:00
$('element-insertions-main').insert({before:'some text before'});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('element-insertions-container').startsWith('some text before'));
2007-06-02 15:08:50 +00:00
$('element-insertions-main').insert({after:'some text after'});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('element-insertions-container').endsWith('some text after'));
2007-06-02 15:08:50 +00:00
$('element-insertions-main').insert({top:'some text top'});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('element-insertions-main').startsWith('some text top'));
2007-06-02 15:08:50 +00:00
$('element-insertions-main').insert({bottom:'some text bottom'});
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('element-insertions-main').endsWith('some text bottom'));
$('element-insertions-main').insert('some more text at the bottom');
assert(getInnerHTML('element-insertions-main').endsWith('some more text at the bottom'));
2007-05-12 19:12:04 +00:00
2007-06-02 15:08:50 +00:00
$('element-insertions-main').insert({TOP:'some text uppercase top'});
2007-05-12 19:12:04 +00:00
assert(getInnerHTML('element-insertions-main').startsWith('some text uppercase top'));
2007-06-02 15:08:50 +00:00
$('element-insertions-multiple-main').insert({
top:'1', bottom:2, before: new Element('p').update('3'), after:'4'
});
assert(getInnerHTML('element-insertions-multiple-main').startsWith('1'));
assert(getInnerHTML('element-insertions-multiple-main').endsWith('2'));
assert(getInnerHTML('element-insertions-multiple-container').startsWith('< p > 3< / p > '));
2007-06-02 16:00:47 +00:00
assert(getInnerHTML('element-insertions-multiple-container').endsWith('4'));
$('element-insertions-main').update('test');
$('element-insertions-main').insert(null);
$('element-insertions-main').insert({bottom:null});
assertEqual('test', getInnerHTML('element-insertions-main'));
$('element-insertions-main').insert(1337);
assertEqual('test1337', getInnerHTML('element-insertions-main'));
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
}},
testInsertionBackwardsCompatibility: function() {with(this) {
new Insertion.Before('element-insertions-main', 'some backward-compatibility testing before');
assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing before'));
new Insertion.After('element-insertions-main', 'some backward-compatibility testing after');
assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing after'));
new Insertion.Top('element-insertions-main', 'some backward-compatibility testing top');
assert(getInnerHTML('element-insertions-main').startsWith('some backward-compatibility testing top'));
new Insertion.Bottom('element-insertions-main', 'some backward-compatibility testing bottom');
assert(getInnerHTML('element-insertions-main').endsWith('some backward-compatibility testing bottom'));
}},
testElementWrap: function() {with(this) {
var element = $('wrap'), parent = document.createElement('div');
2007-07-24 19:08:55 +00:00
element.wrap();
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('wrap-container').startsWith('< div > < p ' ) ) ;
2007-07-24 19:08:55 +00:00
element.wrap('div');
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('wrap-container').startsWith('< div > < div > < p ' ) ) ;
2007-08-10 14:19:30 +00:00
2007-07-24 19:08:55 +00:00
element.wrap(parent);
2007-08-10 14:19:30 +00:00
assert(Object.isFunction(parent.setStyle));
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assert(getInnerHTML('wrap-container').startsWith('< div > < div > < div > < p ' ) ) ;
2007-07-24 19:08:55 +00:00
element.wrap('div', {className: 'wrapper'});
assert(element.up().hasClassName('wrapper'));
element.wrap({className: 'other-wrapper'});
assert(element.up().hasClassName('other-wrapper'));
element.wrap(new Element('div'), {className: 'yet-other-wrapper'});
assert(element.up().hasClassName('yet-other-wrapper'));
var orphan = new Element('p'), div = new Element('div');
orphan.wrap(div);
assertEqual(orphan.parentNode, div);
2007-01-18 22:24:27 +00:00
}},
2007-10-11 06:11:26 +00:00
testElementWrapReturnsWrapper: function() {with(this) {
var element = new Element("div");
var wrapper = element.wrap("div");
assertNotEqual(element, wrapper);
assertEqual(element.up(), wrapper);
}},
2007-01-18 22:24:27 +00:00
testElementVisible: function(){with(this) {
2007-03-11 10:59:06 +00:00
assertNotEqual('none', $('test-visible').style.display);
assertEqual('none', $('test-hidden').style.display);
2007-01-18 22:24:27 +00:00
}},
testElementToggle: function(){with(this) {
2007-03-11 10:59:06 +00:00
$('test-toggle-visible').toggle();
assert(!$('test-toggle-visible').visible());
$('test-toggle-visible').toggle();
assert($('test-toggle-visible').visible());
$('test-toggle-hidden').toggle();
assert($('test-toggle-hidden').visible());
$('test-toggle-hidden').toggle();
assert(!$('test-toggle-hidden').visible());
2007-01-18 22:24:27 +00:00
}},
testElementShow: function(){with(this) {
2007-03-11 10:59:06 +00:00
$('test-show-visible').show();
assert($('test-show-visible').visible());
$('test-show-hidden').show();
assert($('test-show-hidden').visible());
2007-01-18 22:24:27 +00:00
}},
testElementHide: function(){with(this) {
2007-03-11 10:59:06 +00:00
$('test-hide-visible').hide();
assert(!$('test-hide-visible').visible());
$('test-hide-hidden').hide();
assert(!$('test-hide-hidden').visible());
2007-01-18 22:24:27 +00:00
}},
testElementRemove: function(){with(this) {
2007-03-11 10:59:06 +00:00
$('removable').remove();
assert($('removable-container').empty());
2007-01-18 22:24:27 +00:00
}},
testElementUpdate: function() {with(this) {
$('testdiv').update('hello from div!');
assertEqual('hello from div!', $('testdiv').innerHTML);
Element.update('testdiv', 'another hello from div!');
assertEqual('another hello from div!', $('testdiv').innerHTML);
Element.update('testdiv', 123);
2007-10-22 11:30:52 +00:00
assertEqual('123', $('testdiv').innerHTML);
2007-01-18 22:24:27 +00:00
Element.update('testdiv');
2007-10-22 11:30:52 +00:00
assertEqual('', $('testdiv').innerHTML);
Element.update('testdiv', ' ');
assert(!$('testdiv').innerHTML.empty());
2007-01-18 22:24:27 +00:00
}},
testElementUpdateWithScript: function() {with(this) {
2007-04-03 22:21:58 +00:00
$('testdiv').update('hello from div!< script > \ n t e s t V a r = " h e l l o ! " ; \ n < / ' + ' s c r i p t > ' ) ;
2007-01-18 22:24:27 +00:00
assertEqual('hello from div!',$('testdiv').innerHTML);
wait(100,function(){
assertEqual('hello!',testVar);
Element.update('testdiv','another hello from div!\n< script > t e s t V a r = " a n o t h e r h e l l o ! " < / ' + ' s c r i p t > \ n h e r e i t g o e s ' ) ;
// note: IE normalizes whitespace (like line breaks) to single spaces, thus the match test
assertMatch(/^another hello from div!\s+here it goes$/,$('testdiv').innerHTML);
wait(100,function(){
assertEqual('another hello!',testVar);
2007-04-03 22:21:58 +00:00
Element.update('testdiv','a\n< script > t e s t V a r = " a " \ n t e s t V a r = " b " < / ' + ' s c r i p t > ' ) ;
wait(100,function(){
assertEqual('b', testVar);
Element.update('testdiv',
'x< script > t e s t V a r 2 = " a " < / ' + ' s c r i p t > \ n b l a h \ n ' +
'x< script > t e s t V a r 2 = " b " < / ' + ' s c r i p t > ' ) ;
wait(100,function(){
assertEqual('b', testVar2);
});
});
2007-01-18 22:24:27 +00:00
});
});
}},
testElementUpdateInTableRow: function() {with(this) {
$('second_row').update('< td id = "i_am_a_td" > test< / td > ');
assertEqual('test',$('i_am_a_td').innerHTML);
Element.update('second_row','< td id = "i_am_a_td" > another < span > test< / span > < / td > ');
assertEqual('another < span > test< / span > ',$('i_am_a_td').innerHTML.toLowerCase());
}},
testElementUpdateInTableCell: function() {with(this) {
Element.update('a_cell','another < span > test< / span > ');
assertEqual('another < span > test< / span > ',$('a_cell').innerHTML.toLowerCase());
}},
testElementUpdateInTable: function() {with(this) {
Element.update('table','< tr > < td > boo!< / td > < / tr > ');
assertMatch(/^< tr > \s*< td > boo!< \/td>< \/tr>$/,$('table').innerHTML.toLowerCase());
}},
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
testElementUpdateInSelect: function() {with(this) {
var select = $('select_for_update');
select.update('< option value = "3" > option 3< / option > < option selected = "selected" > option 4< / option > ');
assertEqual('option 4', select.getValue());
}},
2007-07-24 18:52:17 +00:00
testElementUpdateWithDOMNode: function() {with(this) {
$('testdiv').update(new Element('div').insert('bla'));
assertEqual('< div > bla< / div > ', getInnerHTML('testdiv'));
}},
testElementUpdateWithToElementMethod: function() {with(this) {
$('testdiv').update({toElement: createParagraph.curry('foo')});
assertEqual('< p > foo< / p > ', getInnerHTML('testdiv'));
}},
testElementUpdateWithToHTMLMethod: function() {with(this) {
$('testdiv').update({toHTML: function() { return 'hello world' }});
assertEqual('hello world', getInnerHTML('testdiv'));
}},
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
2007-01-18 22:24:27 +00:00
testElementReplace: function() {with(this) {
$('testdiv-replace-1').replace('hello from div!');
assertEqual('hello from div!', $('testdiv-replace-container-1').innerHTML);
$('testdiv-replace-2').replace(123);
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assertEqual('123', $('testdiv-replace-container-2').innerHTML);
2007-01-18 22:24:27 +00:00
$('testdiv-replace-3').replace();
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
assertEqual('', $('testdiv-replace-container-3').innerHTML);
2007-07-24 18:52:17 +00:00
$('testrow-replace').replace('< tr > < td > hello< / td > < / tr > ');
assert(getInnerHTML('testrow-replace-container').include('< tr > < td > hello< / td > < / tr > '));
$('testoption-replace').replace('< option > hello< / option > ');
assert($('testoption-replace-container').innerHTML.include('hello'));
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
$('testinput-replace').replace('< p > hello world< / p > ');
2007-07-24 18:52:17 +00:00
assertEqual('< p > hello world< / p > ', getInnerHTML('testform-replace'));
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
$('testform-replace').replace('< form > < / form > ');
2007-07-24 18:52:17 +00:00
assertEqual('< p > some text< / p > < form > < / form > < p > some text< / p > ', getInnerHTML('testform-replace-container'));
2007-01-18 22:24:27 +00:00
}},
testElementReplaceWithScript: function() {with(this) {
$('testdiv-replace-4').replace('hello from div!< script > t e s t V a r R e p l a c e = " h e l l o ! " < / ' + ' s c r i p t > ' ) ;
assertEqual('hello from div!', $('testdiv-replace-container-4').innerHTML);
wait(100,function(){
assertEqual('hello!',testVarReplace);
$('testdiv-replace-5').replace('another hello from div!\n< script > t e s t V a r R e p l a c e = " a n o t h e r h e l l o ! " < / ' + ' s c r i p t > \ n h e r e i t g o e s ' ) ;
// note: IE normalizes whitespace (like line breaks) to single spaces, thus the match test
assertMatch(/^another hello from div!\s+here it goes$/,$('testdiv-replace-container-5').innerHTML);
wait(100,function(){
assertEqual('another hello!',testVarReplace);
});
});
}},
2007-07-24 18:52:17 +00:00
testElementReplaceWithDOMNode: function() {with(this) {
$('testdiv-replace-element').replace(createParagraph('hello'));
assertEqual('< p > hello< / p > ', getInnerHTML('testdiv-replace-container-element'));
}},
testElementReplaceWithToElementMethod: function() {with(this) {
$('testdiv-replace-toelement').replace({toElement: createParagraph.curry('hello')});
assertEqual('< p > hello< / p > ', getInnerHTML('testdiv-replace-container-toelement'));
}},
testElementReplaceWithToHTMLMethod: function() {with(this) {
$('testdiv-replace-tohtml').replace({toHTML: function() { return 'hello' }});
assertEqual('hello', getInnerHTML('testdiv-replace-container-tohtml'));
}},
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
2007-07-13 08:36:14 +00:00
testElementSelectorMethod: function() {with(this) {
['getElementsBySelector','select'].each(function(method){
var testSelector = $('container')[method]('p.test');
assertEqual(testSelector.length, 4);
assertEqual(testSelector[0], $('intended'));
assertEqual(testSelector[0], $$('#container p.test')[0]);
});
}},
testElementAdjacent: function() {with(this) {
var elements = $('intended').adjacent('p');
assertEqual(elements.length, 3);
elements.each(function(element){
assert(element != $('intended'));
});
2007-01-18 22:24:27 +00:00
}},
2007-07-24 17:41:27 +00:00
testElementIdentify: function() {with(this) {
var parent = $('identification');
assertEqual(parent.down().identify(), 'predefined_id');
assertEqual(parent.down(1).identify(), 'anonymous_element_1');
assertEqual(parent.down(2).identify(), 'anonymous_element_2');
assertEqual(parent.down(3).identify(), 'anonymous_element_4');
}},
2007-01-18 22:24:27 +00:00
testElementClassNameMethod: function() {with(this) {
var testClassNames = $('container').getElementsByClassName('test');
var testSelector = $('container').getElementsBySelector('p.test');
assertEqual(testClassNames[0], $('intended'));
assertEqual(testClassNames.length, 4);
assertEqual(testSelector[3], testClassNames[3]);
assertEqual(testClassNames.length, testSelector.length);
}},
testElementAncestors: function() {with(this) {
var ancestors = $('navigation_test_f').ancestors();
assertElementsMatch(ancestors, 'ul', 'li', 'ul#navigation_test',
'div#nav_tests_isolator', 'body', 'html');
assertElementsMatch(ancestors.last().ancestors());
2007-03-11 10:59:06 +00:00
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '< div > < / div > '.times(3);
assert(typeof $(dummy.childNodes[0]).ancestors()[0]['setStyle'] == 'function');
2007-01-18 22:24:27 +00:00
}},
testElementDescendants: function() {with(this) {
assertElementsMatch($('navigation_test').descendants(),
'li', 'em', 'li', 'em.dim', 'li', 'em', 'ul', 'li',
'em.dim', 'li#navigation_test_f', 'em', 'li', 'em');
assertElementsMatch($('navigation_test_f').descendants(), 'em');
2007-03-11 10:59:06 +00:00
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '< div > < / div > '.times(3);
assert(typeof dummy.descendants()[0].setStyle == 'function');
2007-01-18 22:24:27 +00:00
}},
2007-04-24 06:06:44 +00:00
testElementFirstDescendant: function() {with(this) {
assertElementMatches($('navigation_test').firstDescendant(), 'li.first');
assertNull($('navigation_test_next_sibling').firstDescendant());
}},
2007-04-24 06:17:59 +00:00
testElementChildElements: function() {with(this) {
assertElementsMatch($('navigation_test').childElements(),
2007-01-18 22:24:27 +00:00
'li.first', 'li', 'li#navigation_test_c', 'li.last');
assertNotEqual(0, $('navigation_test_next_sibling').childNodes.length);
2007-04-24 06:17:59 +00:00
assertEnumEqual([], $('navigation_test_next_sibling').childElements());
2007-03-11 10:59:06 +00:00
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '< div > < / div > '.times(3);
2007-04-24 06:17:59 +00:00
assert(typeof dummy.childElements()[0].setStyle == 'function');
2007-01-18 22:24:27 +00:00
}},
2007-04-24 06:17:59 +00:00
testElementImmediateDescendants: function() {with(this) {
assertIdentical(Element.Methods.childElements, Element.Methods.immediateDescendants);
}},
2007-01-18 22:24:27 +00:00
testElementPreviousSiblings: function() {with(this) {
assertElementsMatch($('navigation_test').previousSiblings(),
'span#nav_test_prev_sibling', 'p.test', 'div', 'div#nav_test_first_sibling');
assertElementsMatch($('navigation_test_f').previousSiblings(), 'li');
2007-03-11 10:59:06 +00:00
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '< div > < / div > '.times(3);
assert(typeof $(dummy.childNodes[1]).previousSiblings()[0].setStyle == 'function');
2007-01-18 22:24:27 +00:00
}},
testElementNextSiblings: function() {with(this) {
assertElementsMatch($('navigation_test').nextSiblings(),
'div#navigation_test_next_sibling', 'p');
assertElementsMatch($('navigation_test_f').nextSiblings());
2007-03-11 10:59:06 +00:00
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '< div > < / div > '.times(3);
assert(typeof $(dummy.childNodes[0]).nextSiblings()[0].setStyle == 'function');
2007-01-18 22:24:27 +00:00
}},
testElementSiblings: function() {with(this) {
assertElementsMatch($('navigation_test').siblings(),
'div#nav_test_first_sibling', 'div', 'p.test',
'span#nav_test_prev_sibling', 'div#navigation_test_next_sibling', 'p');
2007-03-11 10:59:06 +00:00
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '< div > < / div > '.times(3);
assert(typeof $(dummy.childNodes[0]).siblings()[0].setStyle == 'function');
2007-01-18 22:24:27 +00:00
}},
testElementUp: function() {with(this) {
var element = $('navigation_test_f');
assertElementMatches(element.up(), 'ul');
assertElementMatches(element.up(0), 'ul');
assertElementMatches(element.up(1), 'li');
assertElementMatches(element.up(2), 'ul#navigation_test');
assertElementsMatch(element.up('li').siblings(), 'li.first', 'li', 'li.last');
assertElementMatches(element.up('ul', 1), 'ul#navigation_test');
assertEqual(undefined, element.up('garbage'));
assertEqual(undefined, element.up(6));
2007-03-11 10:59:06 +00:00
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '< div > < / div > '.times(3);
assert(typeof $(dummy.childNodes[0]).up().setStyle == 'function');
2007-01-18 22:24:27 +00:00
}},
testElementDown: function() {with(this) {
var element = $('navigation_test');
assertElementMatches(element.down(), 'li.first');
assertElementMatches(element.down(0), 'li.first');
assertElementMatches(element.down(1), 'em');
assertElementMatches(element.down('li', 5), 'li.last');
assertElementMatches(element.down('ul').down('li', 1), 'li#navigation_test_f');
2007-03-11 10:59:06 +00:00
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '< div > < / div > '.times(3);
assert(typeof dummy.down().setStyle == 'function');
2007-01-18 22:24:27 +00:00
}},
testElementPrevious: function() {with(this) {
var element = $('navigation_test').down('li.last');
assertElementMatches(element.previous(), 'li#navigation_test_c');
assertElementMatches(element.previous(1), 'li');
assertElementMatches(element.previous('.first'), 'li.first');
assertEqual(undefined, element.previous(3));
assertEqual(undefined, $('navigation_test').down().previous());
2007-03-11 10:59:06 +00:00
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '< div > < / div > '.times(3);
assert(typeof $(dummy.childNodes[1]).previous().setStyle == 'function');
2007-01-18 22:24:27 +00:00
}},
testElementNext: function() {with(this) {
var element = $('navigation_test').down('li.first');
assertElementMatches(element.next(), 'li');
assertElementMatches(element.next(1), 'li#navigation_test_c');
assertElementMatches(element.next(2), 'li.last');
assertElementMatches(element.next('.last'), 'li.last');
assertEqual(undefined, element.next(3));
assertEqual(undefined, element.next(2).next());
2007-03-11 10:59:06 +00:00
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '< div > < / div > '.times(3);
assert(typeof $(dummy.childNodes[0]).next().setStyle == 'function');
2007-01-18 22:24:27 +00:00
}},
testElementInspect: function() {with(this) {
assertEqual('< ul id = "navigation_test" > ', $('navigation_test').inspect());
assertEqual('< li class = "first" > ', $('navigation_test').down().inspect());
assertEqual('< em > ', $('navigation_test').down(1).inspect());
}},
testElementMakeClipping: function() {with(this) {
var chained = Element.extend(document.createElement('DIV'));
assertEqual(chained, chained.makeClipping());
assertEqual(chained, chained.makeClipping());
assertEqual(chained, chained.makeClipping().makeClipping());
assertEqual(chained, chained.undoClipping());
assertEqual(chained, chained.undoClipping());
assertEqual(chained, chained.undoClipping().makeClipping());
['hidden','visible','scroll'].each( function(overflowValue) {
var element = $('element_with_'+overflowValue+'_overflow');
assertEqual(overflowValue, element.getStyle('overflow'));
element.makeClipping();
assertEqual('hidden', element.getStyle('overflow'));
element.undoClipping();
assertEqual(overflowValue, element.getStyle('overflow'));
});
}},
testElementExtend: function() {with(this) {
var element = $('element_extend_test');
assertRespondsTo('show', element);
var XHTML_TAGS = $w(
'a abbr acronym address applet area '+
'b bdo big blockquote br button caption '+
'cite code col colgroup dd del dfn div dl dt '+
'em fieldset form h1 h2 h3 h4 h5 h6 hr '+
'i iframe img input ins kbd label legend li '+
'map object ol optgroup option p param pre q samp '+
'script select small span strong style sub sup '+
'table tbody td textarea tfoot th thead tr tt ul var');
XHTML_TAGS.each(function(tag) {
var element = document.createElement(tag);
assertEqual(element, Element.extend(element));
assertRespondsTo('show', element);
});
[null,'','a','aa'].each(function(content) {
var textnode = document.createTextNode(content);
assertEqual(textnode, Element.extend(textnode));
assert(typeof textnode['show'] == 'undefined');
});
}},
2007-03-11 22:40:24 +00:00
testElementExtendReextendsDiscardedNodes: function() {with(this) {
assertRespondsTo('show', $('discard_1'));
$('element_reextend_test').innerHTML += '< div id = "discard_2" > < / div > ';
assertRespondsTo('show', $('discard_1'));
}},
2007-01-18 22:24:27 +00:00
testElementCleanWhitespace: function() {with(this) {
Element.cleanWhitespace("test_whitespace");
assertEqual(3, $("test_whitespace").childNodes.length);
assertEqual(1, $("test_whitespace").firstChild.nodeType);
assertEqual('SPAN', $("test_whitespace").firstChild.tagName);
assertEqual(1, $("test_whitespace").firstChild.nextSibling.nodeType);
assertEqual('DIV', $("test_whitespace").firstChild.nextSibling.tagName);
assertEqual(1, $("test_whitespace").firstChild.nextSibling.nextSibling.nodeType);
assertEqual('SPAN', $("test_whitespace").firstChild.nextSibling.nextSibling.tagName);
var element = document.createElement('DIV');
element.appendChild(document.createTextNode(''));
element.appendChild(document.createTextNode(''));
assertEqual(2, element.childNodes.length);
Element.cleanWhitespace(element);
assertEqual(0, element.childNodes.length);
}},
testElementEmpty: function() {with(this) {
assert($('test-empty').empty());
assert($('test-empty-but-contains-whitespace').empty());
assert(!$('test-full').empty());
}},
testDescendantOf: function() {with(this) {
assert($('child').descendantOf('ancestor'));
assert($('child').descendantOf($('ancestor')));
2007-11-01 15:11:52 +00:00
assert(!$('ancestor').descendantOf($('child')));
assert($('great-grand-child').descendantOf('ancestor'), 'great-grand-child < ancestor ' ) ;
assert($('grand-child').descendantOf('ancestor'), 'grand-child < ancestor ' ) ;
assert($('great-grand-child').descendantOf('grand-child'), 'great-grand-child < grand-child ' ) ;
assert($('grand-child').descendantOf('child'), 'grand-child < child ' ) ;
assert($('great-grand-child').descendantOf('child'), 'great-grand-child < child ' ) ;
window.debug = true;
assert($('sibling').descendantOf('ancestor'), 'sibling < ancestor ' ) ;
assert($('grand-sibling').descendantOf('sibling'), 'grand-sibling < sibling ' ) ;
assert($('grand-sibling').descendantOf('ancestor'), 'grand-sibling < ancestor ' ) ;
assert($('grand-sibling').descendantOf(document.body), 'grand-sibling < body ' ) ;
window.debug = false;
assert(!$('great-grand-child').descendantOf('great-grand-child'), 'great-grand-child < great-grand-child ' ) ;
assert(!$('great-grand-child').descendantOf('sibling'), 'great-grand-child < sibling ' ) ;
assert(!$('sibling').descendantOf('child'), 'sibling < child ' ) ;
assert(!$('great-grand-child').descendantOf('not-in-the-family'), 'great-grand-child < not-in-the-family ' ) ;
assert(!$('child').descendantOf('not-in-the-family'), 'child < not-in-the-family ' ) ;
2007-01-18 22:24:27 +00:00
}},
testChildOf: function() {with(this) {
assert($('child').childOf('ancestor'));
assert($('child').childOf($('ancestor')));
assert($('great-grand-child').childOf('ancestor'));
assert(!$('great-grand-child').childOf('not-in-the-family'));
assertIdentical(Element.Methods.childOf, Element.Methods.descendantOf);
}},
testElementSetStyle: function() { with(this) {
Element.setStyle('style_test_3',{ 'left': '2px' });
assertEqual('2px', $('style_test_3').style.left);
Element.setStyle('style_test_3',{ marginTop: '1px' });
assertEqual('1px', $('style_test_3').style.marginTop);
2007-07-24 18:14:36 +00:00
$('style_test_3').setStyle({ marginTop: '2px', left: '-1px' });
2007-01-18 22:24:27 +00:00
assertEqual('-1px', $('style_test_3').style.left);
assertEqual('2px', $('style_test_3').style.marginTop);
assertEqual('none', $('style_test_3').getStyle('float'));
$('style_test_3').setStyle({ 'float': 'left' });
assertEqual('left', $('style_test_3').getStyle('float'));
$('style_test_3').setStyle({ cssFloat: 'none' });
assertEqual('none', $('style_test_3').getStyle('float'));
assertEqual(1, $('style_test_3').getStyle('opacity'));
$('style_test_3').setStyle({ opacity: 0.5 });
assertEqual(0.5, $('style_test_3').getStyle('opacity'));
$('style_test_3').setStyle({ opacity: '' });
assertEqual(1, $('style_test_3').getStyle('opacity'));
2007-01-19 18:01:43 +00:00
$('style_test_3').setStyle({ opacity: 0 });
assertEqual(0, $('style_test_3').getStyle('opacity'));
2007-07-24 18:14:36 +00:00
$('test_csstext_1').setStyle('font-size: 15px');
assertEqual('15px', $('test_csstext_1').getStyle('font-size'));
$('test_csstext_2').setStyle({height: '40px'});
$('test_csstext_2').setStyle('font-size: 15px');
assertEqual('15px', $('test_csstext_2').getStyle('font-size'));
assertEqual('40px', $('test_csstext_2').getStyle('height'));
$('test_csstext_3').setStyle('font-size: 15px');
assertEqual('15px', $('test_csstext_3').getStyle('font-size'));
assertEqual('1px', $('test_csstext_3').getStyle('border-top-width'));
$('test_csstext_4').setStyle('font-size: 15px');
assertEqual('15px', $('test_csstext_4').getStyle('font-size'));
$('test_csstext_4').setStyle('float: right; font-size: 10px');
assertEqual('right', $('test_csstext_4').getStyle('float'));
assertEqual('10px', $('test_csstext_4').getStyle('font-size'));
$('test_csstext_5').setStyle('float: left; opacity: .5; font-size: 10px');
assertEqual(parseFloat('0.5'), parseFloat($('test_csstext_5').getStyle('opacity')));
}},
2007-01-18 22:24:27 +00:00
2007-03-02 12:36:09 +00:00
testElementSetStyleCamelized: function() { with(this) {
2007-03-04 22:55:08 +00:00
assertNotEqual('30px', $('style_test_3').style.marginTop);
2007-03-02 12:36:09 +00:00
$('style_test_3').setStyle({ marginTop: '30px'}, true);
assertEqual('30px', $('style_test_3').style.marginTop);
}},
2007-02-23 01:19:18 +00:00
testElementSetOpacity: function() { with(this) {
[0,0.1,0.5,0.999].each(function(opacity){
$('style_test_3').setOpacity(opacity);
// b/c of rounding issues on IE special case
assert($('style_test_3').getStyle('opacity').toString().startsWith(opacity));
});
assertEqual(0,
$('style_test_3').setOpacity(0.0000001).getStyle('opacity'));
// for Firefox, we don't set to 1, because of flickering
assert(
$('style_test_3').setOpacity(0.9999999).getStyle('opacity') > 0.999
);
2007-10-22 13:14:56 +00:00
if (Prototype.Browser.IE) {
assert($('style_test_4').setOpacity(0.5).currentStyle.hasLayout);
assert(2, $('style_test_5').setOpacity(0.5).getStyle('zoom'));
assert(0.5, new Element('div').setOpacity(0.5).getOpacity());
assert(2, new Element('div').setOpacity(0.5).setStyle('zoom: 2;').getStyle('zoom'));
assert(2, new Element('div').setStyle('zoom: 2;').setOpacity(0.5).getStyle('zoom'));
}
2007-02-23 01:19:18 +00:00
}},
2007-01-18 22:24:27 +00:00
testElementGetStyle: function() { with(this) {
assertEqual("none",
$('style_test_1').getStyle('display'));
// not displayed, so "null" ("auto" is tranlated to "null")
assertNull(Element.getStyle('style_test_1','width'));
$('style_test_1').show();
// from id rule
assertEqual("pointer",
Element.getStyle('style_test_1','cursor'));
assertEqual("block",
Element.getStyle('style_test_2','display'));
// we should always get something for width (if displayed)
// firefox and safari automatically send the correct value,
// IE is special-cased to do the same
assertEqual($('style_test_2').offsetWidth+'px', Element.getStyle('style_test_2','width'));
assertEqual("static",Element.getStyle('style_test_1','position'));
// from style
assertEqual("11px",
Element.getStyle('style_test_2','font-size'));
// from class
assertEqual("1px",
Element.getStyle('style_test_2','margin-left'));
['not_floating_none','not_floating_style','not_floating_inline'].each(function(element){
assertEqual('none', $(element).getStyle('float'));
assertEqual('none', $(element).getStyle('cssFloat'));
});
['floating_style','floating_inline'].each(function(element){
assertEqual('left', $(element).getStyle('float'));
assertEqual('left', $(element).getStyle('cssFloat'));
});
assertEqual(0.5, $('op1').getStyle('opacity'));
assertEqual(0.5, $('op2').getStyle('opacity'));
assertEqual(1.0, $('op3').getStyle('opacity'));
$('op1').setStyle({opacity: '0.3'});
$('op2').setStyle({opacity: '0.3'});
$('op3').setStyle({opacity: '0.3'});
assertEqual(0.3, $('op1').getStyle('opacity'));
assertEqual(0.3, $('op2').getStyle('opacity'));
assertEqual(0.3, $('op3').getStyle('opacity'));
2007-02-23 01:19:18 +00:00
$('op3').setStyle({opacity: 0});
assertEqual(0, $('op3').getStyle('opacity'));
2007-01-18 22:24:27 +00:00
if(navigator.appVersion.match(/MSIE/)) {
assertEqual('alpha(opacity=30)', $('op1').getStyle('filter'));
assertEqual('progid:DXImageTransform.Microsoft.Blur(strength=10)alpha(opacity=30)', $('op2').getStyle('filter'));
2007-02-23 01:19:18 +00:00
$('op2').setStyle({opacity:''});
assertEqual('progid:DXImageTransform.Microsoft.Blur(strength=10)', $('op2').getStyle('filter'));
assertEqual('alpha(opacity=0)', $('op3').getStyle('filter'));
2007-01-18 22:24:27 +00:00
assertEqual(0.3, $('op4-ie').getStyle('opacity'));
}
2007-06-10 12:58:32 +00:00
// verify that value is still found when using camelized
2007-01-18 22:24:27 +00:00
// strings (function previously used getPropertyValue()
// which expected non-camelized strings)
assertEqual("12px", $('style_test_1').getStyle('fontSize'));
2007-06-10 12:58:32 +00:00
// getStyle on width/height should return values according to
// the CSS box-model, which doesn't include
2007-08-10 14:19:30 +00:00
// margins, paddings or borders
// TODO: This test fails on IE because there seems to be no way
// to calculate this properly (clientWidth/Height returns 0)
if(!navigator.appVersion.match(/MSIE/)) {
assertEqual("14px", $('style_test_dimensions').getStyle('width'));
assertEqual("17px", $('style_test_dimensions').getStyle('height'));
}
2007-01-18 22:24:27 +00:00
}},
2007-02-27 11:35:21 +00:00
testElementGetOpacity: function() {with(this) {
assertEqual(0.45, $('op1').setOpacity(0.45).getOpacity());
}},
2007-01-18 22:24:27 +00:00
testElementReadAttribute: function() {with(this) {
2007-03-08 22:43:18 +00:00
assertEqual('test.html' , $('attributes_with_issues_1').readAttribute('href'));
2007-01-18 22:24:27 +00:00
assertEqual('L' , $('attributes_with_issues_1').readAttribute('accesskey'));
assertEqual('50' , $('attributes_with_issues_1').readAttribute('tabindex'));
assertEqual('a link' , $('attributes_with_issues_1').readAttribute('title'));
2007-07-24 17:31:23 +00:00
$('cloned_element_attributes_issue').readAttribute('foo')
var clone = $('cloned_element_attributes_issue').cloneNode(true);
clone.writeAttribute('foo', 'cloned');
assertEqual('cloned', clone.readAttribute('foo'));
assertEqual('original', $('cloned_element_attributes_issue').readAttribute('foo'));
2007-01-18 22:24:27 +00:00
['href', 'accesskey', 'accesskey', 'title'].each(function(attr){
2007-03-08 22:43:18 +00:00
assertEqual('' , $('attributes_with_issues_2').readAttribute(attr));
});
['checked','disabled','readonly','multiple'].each(function(attr){
assertEqual(attr, $('attributes_with_issues_'+attr).readAttribute(attr));
2007-01-18 22:24:27 +00:00
});
2007-04-28 02:23:26 +00:00
2007-07-24 17:31:23 +00:00
assertEqual("alert('hello world');", $('attributes_with_issues_1').readAttribute('onclick'));
assertNull($('attributes_with_issues_1').readAttribute('onmouseover'));
2007-04-28 02:23:26 +00:00
assertEqual('date', $('attributes_with_issues_type').readAttribute('type'));
assertEqual('text', $('attributes_with_issues_readonly').readAttribute('type'));
2007-01-18 22:24:27 +00:00
var elements = $('custom_attributes').immediateDescendants();
assertEnumEqual(['1', '2'], elements.invoke('readAttribute', 'foo'));
assertEnumEqual(['2', null], elements.invoke('readAttribute', 'bar'));
}},
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
testElementWriteAttribute: function() {with(this) {
var element = Element.extend(document.body.appendChild(document.createElement('p')));
assertRespondsTo('writeAttribute', element);
assertEqual(element, element.writeAttribute('id', 'write_attribute_test'));
assertEqual('write_attribute_test', element.id);
assertEqual('http://prototypejs.org/', $('write_attribute_link').
writeAttribute({href: 'http://prototypejs.org/', title: 'Home of Prototype'}).href);
assertEqual('Home of Prototype', $('write_attribute_link').title);
var element2 = Element.extend(document.createElement('p'));
element2.writeAttribute('id', 'write_attribute_without_hash');
assertEqual('write_attribute_without_hash', element2.id);
element2.writeAttribute('animal', 'cat');
assertEqual('cat', element2.readAttribute('animal'));
}},
testElementWriteAttributeWithBooleans: function() {with(this) {
var input = $('write_attribute_input'),
select = $('write_attribute_select'),
checkbox = $('write_attribute_checkbox'),
checkedCheckbox = $('write_attribute_checked_checkbox');
assert( input. writeAttribute('readonly'). hasAttribute('readonly'));
assert(!input. writeAttribute('readonly', false). hasAttribute('readonly'));
assert( input. writeAttribute('readonly', true). hasAttribute('readonly'));
assert(!input. writeAttribute('readonly', null). hasAttribute('readonly'));
assert( input. writeAttribute('readonly', 'readonly').hasAttribute('readonly'));
assert( select. writeAttribute('multiple'). hasAttribute('multiple'));
assert( input. writeAttribute('disabled'). hasAttribute('disabled'));
assert( checkbox. writeAttribute('checked'). checked);
assert(!checkedCheckbox.writeAttribute('checked', false). checked);
}},
testElementWriteAttributeWithIssues: function() {with(this) {
var input = $('write_attribute_input').writeAttribute({maxlength: 90, tabindex: 10}),
td = $('write_attribute_td').writeAttribute({valign: 'bottom', colspan: 2, rowspan: 2});
assertEqual(90, input.readAttribute('maxlength'));
assertEqual(10, input.readAttribute('tabindex'));
assertEqual(2, td.readAttribute('colspan'));
assertEqual(2, td.readAttribute('rowspan'));
assertEqual('bottom', td.readAttribute('valign'));
var p = $('write_attribute_para'), label = $('write_attribute_label');
assertEqual('some-class', p. writeAttribute({'class': 'some-class'}). readAttribute('class'));
assertEqual('some-className', p. writeAttribute({className: 'some-className'}).readAttribute('class'));
assertEqual('some-id', label.writeAttribute({'for': 'some-id'}). readAttribute('for'));
assertEqual('some-other-id', label.writeAttribute({htmlFor: 'some-other-id'}). readAttribute('for'));
assert(p.writeAttribute({style: 'width: 5px;'}).readAttribute('style').toLowerCase().include('width'));
}},
testElementWriteAttributeWithCustom: function() {with(this) {
var p = $('write_attribute_para').writeAttribute({name: 'martin', location: 'stockholm', age: 26});
assertEqual('martin', p.readAttribute('name'));
assertEqual('stockholm', p.readAttribute('location'));
assertEqual('26', p.readAttribute('age'));
}},
testNewElement: function() {with(this) {
assert(new Element('h1'));
var XHTML_TAGS = $w(
'a abbr acronym address area '+
'b bdo big blockquote br button caption '+
'cite code col colgroup dd del dfn div dl dt '+
'em fieldset form h1 h2 h3 h4 h5 h6 hr '+
'i iframe img input ins kbd label legend li '+
'map object ol optgroup option p param pre q samp '+
'script select small span strong style sub sup '+
'table tbody td textarea tfoot th thead tr tt ul var');
XHTML_TAGS.each(function(tag, index) {
var id = tag + '_' + index, element = document.body.appendChild(new Element(tag, {id: id}));
assertEqual(tag, element.tagName.toLowerCase());
assertEqual(element, document.body.lastChild);
assertEqual(id, element.id);
});
assertRespondsTo('update', new Element('div'));
Element.addMethods({
cheeseCake: function(){
return 'Cheese cake';
}
});
assertRespondsTo('cheeseCake', new Element('div'));
/* window.ElementOld = function(tagName, attributes) {
if (Prototype.Browser.IE & & attributes & & attributes.name) {
tagName = '< ' + tagName + ' name="' + attributes.name + '">';
delete attributes.name;
}
return Element.extend(document.createElement(tagName)).writeAttribute(attributes || {});
};
benchmark(function(){
XHTML_TAGS.each(function(tagName){new Element(tagName)});
}, 5);
benchmark(function(){
XHTML_TAGS.each(function(tagName){new ElementOld(tagName)});
}, 5); */
assertEqual('foobar', new Element('a', {custom: 'foobar'}).readAttribute('custom'));
var input = document.body.appendChild(new Element('input',
{id: 'my_input_field_id', name: 'my_input_field'}));
assertEqual(input, document.body.lastChild);
assertEqual('my_input_field', $(document.body.lastChild).name);
if (Prototype.Browser.IE)
assertMatch(/name=["']?my_input_field["']?/, $('my_input_field').outerHTML);
}},
2007-01-18 22:24:27 +00:00
testElementGetHeight: function() {with(this) {
2007-04-18 16:30:40 +00:00
assertIdentical(100, $('dimensions-visible').getHeight());
assertIdentical(100, $('dimensions-display-none').getHeight());
2007-01-18 22:24:27 +00:00
}},
testElementGetWidth: function() {with(this) {
2007-04-18 16:30:40 +00:00
assertIdentical(200, $('dimensions-visible').getWidth());
assertIdentical(200, $('dimensions-display-none').getWidth());
2007-01-18 22:24:27 +00:00
}},
testElementGetDimensions: function() {with(this) {
2007-04-18 16:30:40 +00:00
assertIdentical(100, $('dimensions-visible').getDimensions().height);
assertIdentical(200, $('dimensions-visible').getDimensions().width);
assertIdentical(100, $('dimensions-display-none').getDimensions().height);
assertIdentical(200, $('dimensions-display-none').getDimensions().width);
assertIdentical(100, $('dimensions-visible-pos-rel').getDimensions().height);
assertIdentical(200, $('dimensions-visible-pos-rel').getDimensions().width);
assertIdentical(100, $('dimensions-display-none-pos-rel').getDimensions().height);
assertIdentical(200, $('dimensions-display-none-pos-rel').getDimensions().width);
assertIdentical(100, $('dimensions-visible-pos-abs').getDimensions().height);
assertIdentical(200, $('dimensions-visible-pos-abs').getDimensions().width);
assertIdentical(100, $('dimensions-display-none-pos-abs').getDimensions().height);
assertIdentical(200, $('dimensions-display-none-pos-abs').getDimensions().width);
// known failing issue
// assert($('dimensions-nestee').getDimensions().width < = 500, 'check for proper dimensions of hidden child elements');
$('dimensions-td').hide();
assertIdentical(100, $('dimensions-td').getDimensions().height);
assertIdentical(200, $('dimensions-td').getDimensions().width);
$('dimensions-td').show();
$('dimensions-tr').hide();
assertIdentical(100, $('dimensions-tr').getDimensions().height);
assertIdentical(200, $('dimensions-tr').getDimensions().width);
$('dimensions-tr').show();
$('dimensions-table').hide();
assertIdentical(100, $('dimensions-table').getDimensions().height);
assertIdentical(200, $('dimensions-table').getDimensions().width);
2007-01-18 22:24:27 +00:00
}},
testDOMAttributesHavePrecedenceOverExtendedElementMethods: function() {with(this) {
assertNothingRaised(function() { $('dom_attribute_precedence').down('form') });
assertEqual($('dom_attribute_precedence').down('input'), $('dom_attribute_precedence').down('form').update);
}},
testClassNames: function() {with(this) {
assertEnumEqual([], $('class_names').classNames());
assertEnumEqual(['A'], $('class_names').down().classNames());
assertEnumEqual(['A', 'B'], $('class_names_ul').classNames());
}},
testHasClassName: function() {with(this) {
2007-11-05 17:43:56 +00:00
assertIdentical(false, $('class_names').hasClassName('does_not_exist'));
assertIdentical(true, $('class_names').down().hasClassName('A'));
assertIdentical(false, $('class_names').down().hasClassName('does_not_exist'));
assertIdentical(true, $('class_names_ul').hasClassName('A'));
assertIdentical(true, $('class_names_ul').hasClassName('B'));
assertIdentical(false, $('class_names_ul').hasClassName('does_not_exist'));
2007-01-18 22:24:27 +00:00
}},
testAddClassName: function() {with(this) {
$('class_names').addClassName('added_className');
assertEnumEqual(['added_className'], $('class_names').classNames());
$('class_names').addClassName('added_className'); // verify that className cannot be added twice.
assertEnumEqual(['added_className'], $('class_names').classNames());
$('class_names').addClassName('another_added_className');
assertEnumEqual(['added_className', 'another_added_className'], $('class_names').classNames());
}},
testRemoveClassName: function() {with(this) {
$('class_names').removeClassName('added_className');
assertEnumEqual(['another_added_className'], $('class_names').classNames());
$('class_names').removeClassName('added_className'); // verify that removing a non existent className is safe.
assertEnumEqual(['another_added_className'], $('class_names').classNames());
$('class_names').removeClassName('another_added_className');
assertEnumEqual([], $('class_names').classNames());
}},
testToggleClassName: function() {with(this) {
$('class_names').toggleClassName('toggled_className');
assertEnumEqual(['toggled_className'], $('class_names').classNames());
$('class_names').toggleClassName('toggled_className');
assertEnumEqual([], $('class_names').classNames());
$('class_names_ul').toggleClassName('toggled_className');
assertEnumEqual(['A', 'B', 'toggled_className'], $('class_names_ul').classNames());
$('class_names_ul').toggleClassName('toggled_className');
assertEnumEqual(['A', 'B'], $('class_names_ul').classNames());
}},
testElementScrollTo: function() {with(this) {
var elem = $('scroll_test_2');
Element.scrollTo('scroll_test_2');
assertEqual(Position.page(elem)[1], 0);
window.scrollTo(0, 0);
elem.scrollTo();
assertEqual(Position.page(elem)[1], 0);
window.scrollTo(0, 0);
2007-01-27 19:45:34 +00:00
}},
2007-01-18 22:24:27 +00:00
2007-04-24 05:23:41 +00:00
testCustomElementMethods: function() {with(this) {
var elem = $('navigation_test_f');
assertRespondsTo('hashBrowns', elem);
assertEqual('hash browns', elem.hashBrowns());
assertRespondsTo('hashBrowns', Element);
assertEqual('hash browns', Element.hashBrowns(elem));
}},
testSpecificCustomElementMethods: function() {with(this) {
2007-01-27 19:45:34 +00:00
var elem = $('navigation_test_f');
assert(Element.Methods.ByTag[elem.tagName]);
assertRespondsTo('pancakes', elem);
assertEqual("pancakes", elem.pancakes());
var elem2 = $('test-visible');
assert(Element.Methods.ByTag[elem2.tagName]);
assertUndefined(elem2.pancakes);
assertRespondsTo('waffles', elem2);
assertEqual("waffles", elem2.waffles());
assertRespondsTo('orangeJuice', elem);
assertRespondsTo('orangeJuice', elem2);
assertEqual("orange juice", elem.orangeJuice());
assertEqual("orange juice", elem2.orangeJuice());
2007-04-24 05:23:41 +00:00
assert(typeof Element.orangeJuice == 'undefined');
assert(typeof Element.pancakes == 'undefined');
assert(typeof Element.waffles == 'undefined');
2007-04-03 22:21:58 +00:00
}},
testScriptFragment: function() {with(this) {
var element = document.createElement('div');
// tests an issue with Safari 2.0 crashing when the ScriptFragment
// regular expression is using a pipe-based approach for
// matching any character
['\r','\n',' '].each(function(character){
$(element).update("< script > " + c h a r a c t e r . t i m e s ( 1 0 0 0 0 ) + " < / s c r " + " i p t > " ) ;
assertEqual('', element.innerHTML);
});
$(element).update("< script > v a r b l a h = ' " + ' \ \ ' . t i m e s ( 1 0 0 0 0 ) + " ' < / s c r " + " i p t > " ) ;
assertEqual('', element.innerHTML);
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
}},
testPositionedOffset: function() {with(this) {
assertEnumEqual([10,10],
$('body_absolute').positionedOffset());
assertEnumEqual([10,10],
$('absolute_absolute').positionedOffset());
assertEnumEqual([10,10],
$('absolute_relative').positionedOffset());
assertEnumEqual([0,10],
$('absolute_relative_undefined').positionedOffset());
}},
testViewportOffset: function() {with(this) {
assertEnumEqual([10,10],
$('body_absolute').viewportOffset());
assertEnumEqual([20,20],
$('absolute_absolute').viewportOffset());
assertEnumEqual([20,20],
$('absolute_relative').viewportOffset());
assertEnumEqual([20,30],
$('absolute_relative_undefined').viewportOffset());
}},
testOffsetParent: function() {with(this) {
assertEqual('body_absolute', $('absolute_absolute').getOffsetParent().id);
assertEqual('body_absolute', $('absolute_relative').getOffsetParent().id);
assertEqual('absolute_relative', $('inline').getOffsetParent().id);
assertEqual('absolute_relative', $('absolute_relative_undefined').getOffsetParent().id);
2007-06-06 14:30:01 +00:00
}},
testAbsolutize: function() {with(this) {
$('notInlineAbsoluted', 'inlineAbsoluted').each(function(elt) {
if ('_originalLeft' in elt) delete elt._originalLeft;
elt.absolutize();
assertUndefined(elt._originalLeft, 'absolutize() did not detect absolute positioning');
});
2007-08-08 20:42:46 +00:00
}},
testViewportDimensions: function() {with(this) {
2007-10-26 03:10:06 +00:00
preservingBrowserDimensions(function() {
window.resizeTo(800, 600);
var before = document.viewport.getDimensions();
window.resizeBy(50, 50);
var after = document.viewport.getDimensions();
2007-08-08 20:42:46 +00:00
2007-10-26 03:10:06 +00:00
assertEqual(before.width + 50, after.width, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THESE TESTS TO PASS");
assertEqual(before.height + 50, after.height, "NOTE: YOU MUST ALLOW JAVASCRIPT TO RESIZE YOUR WINDOW FOR THESE TESTS TO PASS");
}.bind(this));
2007-08-08 20:42:46 +00:00
}},
testViewportScrollOffsets: function() {with(this) {
2007-10-26 03:10:06 +00:00
preservingBrowserDimensions(function() {
window.scrollTo(0, 0);
assertEqual(0, document.viewport.getScrollOffsets().top);
2007-08-08 20:42:46 +00:00
2007-10-26 03:10:06 +00:00
window.scrollTo(0, 35);
assertEqual(35, document.viewport.getScrollOffsets().top);
2007-08-08 20:42:46 +00:00
2007-10-26 03:10:06 +00:00
window.resizeTo(200, 650);
window.scrollTo(25, 35);
assertEqual(25, document.viewport.getScrollOffsets().left);
2007-08-08 20:42:46 +00:00
2007-10-26 03:10:06 +00:00
window.resizeTo(850, 650);
}.bind(this));
2007-08-17 11:20:56 +00:00
}},
testNodeConstants: function() {with(this) {
assert(window.Node, 'window.Node is unavailable');
var constants = $H({
ELEMENT_NODE: 1,
ATTRIBUTE_NODE: 2,
TEXT_NODE: 3,
CDATA_SECTION_NODE: 4,
ENTITY_REFERENCE_NODE: 5,
ENTITY_NODE: 6,
PROCESSING_INSTRUCTION_NODE: 7,
COMMENT_NODE: 8,
DOCUMENT_NODE: 9,
DOCUMENT_TYPE_NODE: 10,
DOCUMENT_FRAGMENT_NODE: 11,
NOTATION_NODE: 12
});
constants.each(function(pair) {
assertEqual(Node[pair.key], pair.value);
}, this);
2007-04-03 22:21:58 +00:00
}}
2007-01-18 22:24:27 +00:00
}, 'testlog');
2007-10-26 03:10:06 +00:00
function preservingBrowserDimensions(callback) {
var original = document.viewport.getDimensions();
window.resizeTo(640, 480);
var resized = document.viewport.getDimensions();
original.width += 640 - resized.width, original.height += 480 - resized.height;
try {
window.resizeTo(original.width, original.height);
callback();
} finally {
window.resizeTo(original.width, original.height);
}
}
2007-01-18 22:24:27 +00:00
// ]]>
< / script >
< / body >
< / html >