Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ata methods and PJAX issues when used together
  • Loading branch information
derekisbusy authored and samdark committed Oct 19, 2015
1 parent d5d40aa commit 17e2255
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Yii Framework 2 Change Log
-----------------------

- Bug #6351: Find MySQL FK constraints from `information_schema` tables instead of `SHOW CREATE TABLE` to improve reliability (nineinchnick)
- Bug #6363, #8301, #8582, #9566: Fixed data methods and PJAX issues when used together (derekisbusy)
- Bug #8723: Fixed `yii\helpers\VarDumper::export()` unable to export circle referenced objects with `Closure` (klimov-paul)
- Bug #9108: Negative number resulted in no formatting when using `Formatter::asSize()` or `Formatter::asShortSize` (nxnx, cebe)
- Bug #9288: Fixed `FileHelper::createDirectory` directory creation to be concurrency friendly (dynasource)
Expand Down
51 changes: 45 additions & 6 deletions framework/assets/yii.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,51 @@ yii = (function ($) {
*
* @param $e the jQuery representation of the element
*/
handleAction: function ($e) {
handleAction: function ($e, event) {
var method = $e.data('method'),
$form = $e.closest('form'),
action = $e.attr('href'),
params = $e.data('params');
params = $e.data('params'),
pjax = $e.data('pjax'),
pjaxPushState = !!$e.data('pjax-push-state'),
pjaxReplaceState = !!$e.data('pjax-replace-state'),
pjaxTimeout = $e.data('pjax-timeout'),
pjaxScrollTo = $e.data('pjax-scrollto'),
pjaxContainer,
pjaxOptions = {};

if (pjax !== undefined && $.support.pjax) {
if ($e.data('pjax-container')) {
pjaxContainer = $e.data('pjax-container');
} else {
pjaxContainer = $e.closest('[data-pjax-container=""]');
}
// default to body if pjax container not found
if (!pjaxContainer.length) {
pjaxContainer = $('body');
}
pjaxOptions = {
container: pjaxContainer,
push: pjaxPushState,
replace: pjaxReplaceState,
scrollTo: pjaxScrollTo,
timeout: pjaxTimeout
}
}

if (method === undefined) {
if (action && action != '#') {
window.location = action;
if (pjax !== undefined && $.support.pjax) {
$.pjax.click(event, pjaxOptions);
} else {
window.location = action;
}
} else if ($e.is(':submit') && $form.length) {
if (pjax !== undefined && $.support.pjax) {
$form.on('submit',function(e){
$.pjax.submit(e, pjaxOptions);
})
}
$form.trigger('submit');
}
return;
Expand Down Expand Up @@ -202,7 +237,11 @@ yii = (function ($) {
oldAction = $form.attr('action');
$form.attr('action', action);
}

if (pjax !== undefined && $.support.pjax) {
$form.on('submit',function(e){
$.pjax.submit(e, pjaxOptions);
})
}
$form.trigger('submit');
$.when($form.data('yiiSubmitFinalizePromise')).then(
function () {
Expand Down Expand Up @@ -291,10 +330,10 @@ yii = (function ($) {

if (message !== undefined) {
pub.confirm(message, function () {
pub.handleAction($this);
pub.handleAction($this, event);
});
} else {
pub.handleAction($this);
pub.handleAction($this, event);
}
event.stopImmediatePropagation();
return false;
Expand Down
8 changes: 7 additions & 1 deletion framework/widgets/Pjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ public function init()
echo Html::tag('title', Html::encode($view->title));
}
} else {
echo Html::beginTag('div', $this->options);
echo Html::beginTag('div', array_merge([
'data-pjax-container' => '',
'data-pjax-push-state' => $this->enablePushState,
'data-pjax-replace-state' => $this->enableReplaceState,
'data-pjax-timeout' => $this->timeout,
'data-pjax-scrollto' => $this->scrollTo,
], $this->options));
}
}

Expand Down

0 comments on commit 17e2255

Please sign in to comment.