Commit 6ab97d92 by Qiang Xue

pjax WIP

parent a87e8672
Copyright (c) Chris Wanstrath
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Software), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\widgets; namespace yii\widgets;
use yii\web\AssetBundle; use yii\web\AssetBundle;
/** /**
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
use Yii;
use yii\base\Widget;
use yii\helpers\Json;
/**
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Pjax extends Widget
{
public $links = 'a';
public function init()
{
ob_start();
ob_implicit_flush(false);
echo '<div id="' . $this->getId() . '">';
}
public function run()
{
echo '</div>';
$content = ob_get_clean();
$headers = Yii::$app->getRequest()->getHeaders();
if ($headers->get('X-Pjax') && ($selector = $headers->get('X-PJax-Container')) === '#' . $this->getId()) {
// todo: send the response and terminate the application
} else {
$this->registerClientScript();
return $content;
}
}
/**
* Registers the needed JavaScript.
*/
public function registerClientScript()
{
$view = $this->getView();
PjaxAsset::register($view);
$js = 'jQuery(document).pjax("' . Json::encode($this->links) . '", "#' . $this->getId() . '");';
$view->registerJs($js);
}
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
use yii\web\AssetBundle;
/**
* This asset bundle provides the javascript files required by [[yii\widgets\Pjax]] widget.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class PjaxAsset extends AssetBundle
{
public $sourcePath = '@yii/assets';
public $js = [
'pjax/jquery.pjax.js',
];
public $depends = [
'yii\web\YiiAsset',
];
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment