Skip to content

Commit fede1e7

Browse files
committed
Merge branch 'InPlaceEditor.originalValue' into official
2 parents 299f8b9 + 054a10f commit fede1e7

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/controls.js

+5
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,11 @@ Ajax.InPlaceEditor = Class.create({
726726
this.element.style.backgroundColor = this._originalBackground;
727727
this.element.show();
728728
},
729+
originalValue: function() {
730+
// return deHTMLified value-before-edit, available
731+
// during "callback" and before.
732+
return (this._oldInnerHTML || this.element.innerHTML).unescapeHTML();
733+
},
729734
triggerCallback: function(cbName, arg) {
730735
if ('function' == typeof this.options[cbName]) {
731736
this.options[cbName](this, arg);

test/functional/ajax_inplaceeditor_test.html

+5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ <h1>script.aculo.us Demo</h1>
1919

2020
<h1 id="tobeedited">To be edited</h1>
2121
<script>
22+
$('tobeedited').widg =
2223
new Ajax.InPlaceEditor($('tobeedited'), '_ajax_inplaceeditor_result.html', {
2324
ajaxOptions: {method: 'get'} //override so we can use a static for the result
2425
});
2526
</script>
27+
<p>
28+
originalValue: <b id="tbe_orig">(displayed here by button)</b>
29+
<button onClick="$('tbe_orig').innerHTML = $('tobeedited').widg.originalValue().escapeHTML()"> Update </button>
30+
</p>
2631

2732
<h1 id="tobeeditedblur">To be edited w/ blur</h1>
2833
<script>

test/unit/ajax_inplaceeditor_test.html

+24
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,30 @@ <h1 id="tobeedited">To be edited</h1>
374374
});
375375
}},
376376

377+
testOriginalValueAvailable: function() { with(this) {
378+
var seen = {}; // results go here
379+
$('newtbe').update('Old text &amp; before edit'); // start with known text (htmlified here)
380+
var ipe = new Ajax.InPlaceEditor('newtbe', '_ajax_inplaceeditor_result2.html', {
381+
callback: function(form, newval, thirdarg) {
382+
seen['new'] = newval;
383+
seen['old'] = ipe.originalValue();
384+
seen['thirdarg'] = thirdarg;
385+
return 'foo=bar';
386+
}
387+
});
388+
assertEqual("Old text & before edit", ipe.originalValue(), 'Original text before click');
389+
Event.simulateMouse('newtbe', 'click');
390+
ipe._controls.editor.value = "Text & typed in" // set <input type=text> contents
391+
Event.simulateKey('newtbe', 'keydown', { keyCode: Event.KEY_RETURN });
392+
wait(200, function() {
393+
assertEqual("Text & typed in", seen['new'], 'New text for server');
394+
assertEqual("Old text & before edit", seen['old'], 'Original text');
395+
assertEqual("New to be edited - edited\n", $('newtbe').innerHTML, 'Text from server');
396+
assertNull(seen['thirdarg'], 'There is no third arg, yet'); // maybe pass original value or ipe?
397+
ipe.dispose();
398+
});
399+
}},
400+
377401
testCallbackFunctionReturnTypes: function() { with(this) {
378402
var params = [];
379403
var responder = {

0 commit comments

Comments
 (0)