Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bscheshirwork/yii2-jquery-pjax-asset

Asset for the origin https://github.com/defunkt/jquery-pjax instead of https://github.com/yiisoft/jquery-pjax
https://github.com/bscheshirwork/yii2-jquery-pjax-asset

Last synced: about 1 month ago
JSON representation

Asset for the origin https://github.com/defunkt/jquery-pjax instead of https://github.com/yiisoft/jquery-pjax

Awesome Lists containing this project

README

        

# Asset for origin defunkt/jquery-pjax

This asset propose use original [defunkt/jquery-pjax](https://github.com/defunkt/jquery-pjax) instead
fork [yii2 build in yiisoft/jquery-pjax](https://github.com/yiisoft/jquery-pjax)

## Installation

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

add

```
"bscheshirwork/yii2-jquery-pjax-asset": "@dev"
```

to the require section of your `composer.json` file.

## Usage

@see [defunkt/jquery-pjax readme](https://github.com/defunkt/jquery-pjax) for common usage

### Use directly

First: add assets to you page;
```php

```
Second: we can use `$.pjax` directly in JS block

for document notation
```php
registerJs(new JsExpression(<< tag and non-disabled by comment tag)
$('script').each(function () {
if (!this.src) {
$.each($(this).html().match(/jQuery\('.+'\).yiiGridView\(.+\)/g) || [], function (index, value) {
$.globalEval(value)
})
}
})
})
JS
), \yii\web\View::POS_READY);
?>
```

for concrete tag
```php
registerJs(new JsExpression(<< tag and non-disabled by comment tag)
$('script').each(function () {
if (!this.src) {
$.each($(this).html().match(/jQuery\('.+'\).yiiGridView\(.+\)/g) || [], function (index, value) {
$.globalEval(value)
})
}
})
})
JS
), \yii\web\View::POS_READY);
?>
```

>Note: we can re-init your js widgets like a `yiiGridView`

>Note: we can check sender inside `pjax:beforeSend` event listener if you wish use nested pjax blocks
```js
$('.model-index').on('ready pjax:beforeSend', function (event) {
console.log(event.target)
//...
event.preventDefault()
})
```

### Use as part of a your own widget

add `bscheshirwork\y2jpa\PjaxAsset::register($this);` to `run()` method of your widget

use your widget `id` as tag for build `$('#id').pjax('#id a', '#id', {fragment: '#id'})`expression

on server side we can croup content use `ob_start()`/`ob_end_clean()` mechanism in `widget::begin()`/`widget::end()`

### Tips

For debug reason we can log a global events with `fragment`
The 90% reasons of page reload is a missing `fragment` selector in answer body

```js
$(document).bind('ajaxStart', function(){
console.log('ajaxStart');
}).bind('ajaxSend', function(event, jqXHR, s){
console.log('ajaxSend' + ' ' + s.fragment);
}).bind('ajaxSuccess', function(event, jqXHR, s, success){
console.log('ajaxSuccess' + ' ' + s.fragment);
}).bind('ajaxError', function(event, jqXHR, s, error){
console.log('ajaxError' + ' ' + s.fragment);
}).bind('ajaxComplete', function(event, jqXHR, s){
console.log('ajaxComplete' + ' ' + s.fragment);
}).bind('ajaxStop', function(){
console.log('ajaxStop');
});

$(document).on('pjax:start', function (event, xhr, options) {
console.log('pjax:start' + ' ' + options.fragment);
}).on('pjax:complete', function (event, xhr, textStatus, options) {
console.log('pjax:complete' + ' ' + options.fragment);
}).on('pjax:end', function (event, xhr, options) {
console.log('pjax:end' + ' ' + xhr.status + ' ' + options.fragment);
});

```