Permalink
Browse files

Applying patch from 'hashmich' to make jQueryEngine not override the …

…success callback. This allows you to provide a success callback and still get the html insertion when used with the update key.

Tests updated.
Fixes #1158
  • Loading branch information...
1 parent 5e26d28 commit 5c27abd35fc5a541176f0d9fa4fba014ac2a4886 @markstory markstory committed Oct 2, 2010
@@ -256,14 +256,13 @@ function request($url, $options = array()) {
$options['url'] = $url;
if (isset($options['update'])) {
$wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true;
- if ($wrapCallbacks) {
- $success = $this->jQueryObject . '("' . $options['update'] . '").html(data);';
- } else {
- $success = sprintf(
- 'function (data, textStatus) {%s("%s").html(data);}',
- $this->jQueryObject,
- $options['update']
- );
+ $success = '';
+ if(isset($options['success']) AND !empty($options['success'])) {
+ $success .= $options['success'];
+ }
+ $success .= $this->jQueryObject . '("' . $options['update'] . '").html(data);';
+ if (!$wrapCallbacks) {
+ $success = 'function (data, textStatus) {' . $success . '}';
}
$options['dataType'] = 'html';
$options['success'] = $success;
@@ -184,7 +184,7 @@ function testRequest() {
'method' => 'post',
'wrapCallbacks' => false
));
- $expected = '$.ajax({dataType:"html", success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
+ $expected = '$.ajax({dataType:"html", success:function (data, textStatus) {doFoo$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($result, $expected);
$result = $this->Jquery->request('/people/edit/1', array(
@@ -195,7 +195,7 @@ function testRequest() {
'data' => '$("#someId").serialize()',
'wrapCallbacks' => false
));
- $expected = '$.ajax({data:$("#someId").serialize(), dataType:"html", success:function (data, textStatus) {$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
+ $expected = '$.ajax({data:$("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($result, $expected);
$result = $this->Jquery->request('/people/edit/1', array(
@@ -225,7 +225,7 @@ function testRequestWithAlternateJqueryObject() {
'data' => '$j("#someId").serialize()',
'wrapCallbacks' => false
));
- $expected = '$j.ajax({data:$j("#someId").serialize(), dataType:"html", success:function (data, textStatus) {$j("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
+ $expected = '$j.ajax({data:$j("#someId").serialize(), dataType:"html", success:function (data, textStatus) {doFoo$j("#updated").html(data);}, type:"post", url:"\\/people\\/edit\\/1"});';
$this->assertEqual($result, $expected);
}

0 comments on commit 5c27abd

Please sign in to comment.