Exemplo n.º 1
0
 */
use yii\widgets\Pjax;
use rhoone\widgets\search\assets\SearchAsset;
use rhoone\widgets\search\result\ContainerWidget;
use rhoone\widgets\search\result\FormWidget;
SearchAsset::register($this);
/* @var $pjaxConfig array */
/* @var $containerConfig array */
/* @var $formConfig array */
/* @var $searchUrlPattern string */
/* @var $this yii\web\View */
$formId = $formConfig['formConfig']['id'];
$keywordsInputId = $formConfig['keywordsFieldConfig']['id'];
$js = <<<EOT
    var pattern = "{$searchUrlPattern}";
    \$(document).bind("pjax:complete", rhoone.search.end);
    \$(document).bind("pjax:timeout", rhoone.search.cancel);
    \$(document).bind("rhoone:search_start", {pattern: pattern}, function(e) {
        \$("#{$keywordsInputId}").attr("value", rhoone.search.keywords);
        \$("#{$formId}").attr("action", e.data.pattern.replace("{{%keywords}}",\$("#{$keywordsInputId}").val()));
        \$("#{$formId}").submit();
    });
EOT;
$this->registerJs($js);
/**
 * If current request is PJAX one, the above content wrapped in `Pjax` only will be returned, the other will be ignored.
 */
$pjax = Pjax::begin($pjaxConfig);
echo ContainerWidget::widget($containerConfig);
echo FormWidget::widget($formConfig);
Pjax::end();
Exemplo n.º 2
0
 public function init()
 {
     if (!is_array($this->pjaxConfig)) {
         $this->pjaxConfig = [];
     }
     if (is_array($this->pjaxConfig)) {
         $this->pjaxConfig = ArrayHelper::merge(static::getPjaxConfig(), $this->pjaxConfig);
     }
     if (!is_array($this->formConfig)) {
         $this->formConfig = [];
     }
     if (!isset($this->formConfig['formConfig']) || !is_array($this->formConfig['formConfig'])) {
         $this->formConfig['formConfig'] = [];
     }
     if (is_array($this->formConfig['formConfig'])) {
         $this->formConfig['formConfig'] = ArrayHelper::merge(FormWidget::getFormConfig(), $this->formConfig['formConfig']);
     }
     if (!isset($this->formConfig['keywordsFieldConfig']) || !is_array($this->formConfig['keywordsFieldConfig'])) {
         $this->formConfig['keywordsFieldConfig'] = [];
     }
     if (is_array($this->formConfig['keywordsFieldConfig'])) {
         $this->formConfig['keywordsFieldConfig'] = ArrayHelper::merge(FormWidget::getKeywordsFieldConfig(), $this->formConfig['keywordsFieldConfig']);
     }
     if (!isset($this->pjaxConfig['formSelector'])) {
         $this->pjaxConfig['formSelector'] = "#" . $this->formConfig['formConfig']['id'];
     }
     if (empty($this->searchUrlPatternAnchor) || !is_string($this->searchUrlPatternAnchor)) {
         $this->searchUrlPatternAnchor = '{{%keywords}}';
     }
     if (empty($this->searchUrlPattern) || !is_string($this->searchUrlPattern)) {
         $this->searchUrlPattern = Url::home() . "s";
     }
     if (strpos($this->searchUrlPattern, $this->searchUrlPatternAnchor) === false) {
         $this->searchUrlPattern .= "?q=" . $this->searchUrlPatternAnchor;
     }
 }