Changeset 2282
- Timestamp:
- 09/21/05 08:11:51 (3 years ago)
- Files:
-
- spinoffs/scriptaculous/CHANGELOG (modified) (1 diff)
- spinoffs/scriptaculous/src/controls.js (modified) (5 diffs)
- spinoffs/scriptaculous/test/unit/ajax_inplaceeditor_test.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinoffs/scriptaculous/CHANGELOG
r2280 r2282 1 1 *SVN* 2 3 * Fixed a bug with Safari and the InPlaceEditor with form submission. Add support for interpreting simple <br>s into linebreaks. [Jon Tirsen] 2 4 3 5 * New Control.Slider() for horizontal and vertical sliders [Marty Haught] spinoffs/scriptaculous/src/controls.js
r2216 r2282 459 459 return Form.serialize(form); 460 460 }, 461 handleLineBreaks: true, 461 462 loadingText: 'Loading...', 462 463 savingClassName: 'inplaceeditor-saving', … … 511 512 this.element.parentNode.insertBefore(this.form, this.element); 512 513 Field.focus(this.editField); 514 // stop the event to avoid a page refresh in Safari 515 if (arguments.length > 1) { 516 Event.stop(arguments[0]); 517 } 513 518 }, 514 519 getForm: function() { … … 537 542 return form; 538 543 }, 544 hasHTMLLineBreaks: function(string) { 545 if (!this.options.handleLineBreaks) return false; 546 return string.match(/<br/i) || string.match(/<p>/i); 547 }, 548 convertHTMLLineBreaks: function(string) { 549 return string.replace(/<br>/gi, "\n").replace(/<br\/>/gi, "\n").replace(/<\/p>/gi, "\n").replace(/<p>/gi, ""); 550 }, 539 551 createEditField: function(form) { 540 if (this.options.rows == 1 ) {552 if (this.options.rows == 1 && !this.hasHTMLLineBreaks(this.getText())) { 541 553 this.options.textarea = false; 542 554 var textField = document.createElement("input"); … … 554 566 var textArea = document.createElement("textarea"); 555 567 textArea.name = "value"; 556 textArea.value = this. getText();568 textArea.value = this.convertHTMLLineBreaks(this.getText()); 557 569 textArea.rows = this.options.rows; 558 570 textArea.cols = this.options.cols || 40; … … 610 622 ); 611 623 this.onLoading(); 624 // stop the event to avoid a page refresh in Safari 625 if (arguments.length > 1) { 626 Event.stop(arguments[0]); 627 } 612 628 return false; 613 629 }, spinoffs/scriptaculous/test/unit/ajax_inplaceeditor_test.html
r2063 r2282 22 22 <a id="tobeeditedEditControl" href="#">edit</a> 23 23 24 <div id="tobeeditedMultiLine">First line<br/>Second line<br/>Third line</div> 24 25 25 26 <!-- Tests follow --> … … 32 33 inPlaceEditor = new Ajax.InPlaceEditor($('tobeedited'), '_ajax_inplaceeditor_result.html', { 33 34 externalControl: $('tobeeditedEditControl'), 35 ajaxOptions: {method: 'get'} //override so we can use a static for the result 36 }); 37 inPlaceEditorMultiLine = new Ajax.InPlaceEditor($('tobeeditedMultiLine'), '_ajax_inplaceeditor_result.html', { 34 38 ajaxOptions: {method: 'get'} //override so we can use a static for the result 35 39 }); … … 167 171 Event.simulateMouse(document.forms[0].childNodes[2],'click'); 168 172 assertVisible($('tobeeditedEditControl')); 173 }}, 174 175 testHasLineBreaksDetectsHTMLLineBreaks: function() { with(this) { 176 assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<br/>Line 2")); 177 assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<br>Line 2")); 178 assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("<p>Line 1</p>Line 2")); 179 assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<BR/>Line 2")); 180 assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("Line 1<BR>Line 2")); 181 assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("<P>Line 1</P>Line 2")); 182 assert(inPlaceEditorMultiLine.hasHTMLLineBreaks("<P>Line 1<P>Line 2")); 183 assert(!inPlaceEditorMultiLine.hasHTMLLineBreaks("One line")); 184 }}, 185 186 testConvertsHTMLLineBreaksIntoNewLines: function() { with(this) { 187 assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<br/>Line 2")); 188 assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<br>Line 2")); 189 // <p> not supported (too hard) 190 //assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("<p>Line 1</p>Line 2")); 191 assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<BR/>Line 2")); 192 assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("Line 1<BR>Line 2")); 193 // <p> not supported (too hard) 194 //assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("<P>Line 1</P>Line 2")); 195 // unclosed <P>s not supported yet 196 //assertEqual("Line 1\nLine 2", inPlaceEditorMultiLine.convertHTMLLineBreaks("<P>Line 1<P>Line 2")); 197 // <p> not supported (too hard) 198 //assertEqual("Line 1\nLine 2\nLine 3\nLine 4", inPlaceEditorMultiLine.convertHTMLLineBreaks("<P>Line 1</P>Line 2<br>Line 3<p>Line 4</P>")); 199 assertEqual("One line", inPlaceEditorMultiLine.convertHTMLLineBreaks("One line")); 200 }}, 201 202 testConvertsParagraphsAndBRsIntoLineBreaks: function() { with(this) { 203 inPlaceEditorMultiLine.enterEditMode(); 204 assertEqual("TEXTAREA", document.forms[0].firstChild.tagName); 205 assertEqual("First line\nSecond line\nThird line", document.forms[0].firstChild.value) 206 // doesn't automatically determine size yet 207 //assertEqual(3, document.forms[0].firstChild.rows); 169 208 }} 170 209