Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jirisvoboda committed Jun 5, 2015
1 parent f22f6e7 commit 1d9ac72
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/ShareIt.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ class ShareIt extends \yii\base\Component {

public function init()
{
$js = '$(".'.$this->linkClassSelector.'").yiiShareLinks();';
$this->view->registerJs($js);
$view = $this->getView();

$this->url = (empty($this->url)) ? Yii::$app->getRequest()->getAbsoluteUrl() : $this->url;
if ($view)
{
$js = '$(".'.$this->linkClassSelector.'").yiiShareLinks();';

ShareItAssets::register($this->view);
$this->getView()->registerJs($js);

ShareItAssets::register($this->view);
}

$this->url = (empty($this->url)) ? Yii::$app->getRequest()->getAbsoluteUrl() : $this->url;
}

/**
Expand All @@ -77,4 +83,18 @@ public function shareLink($network, $options = [], $text = false, $url = false)

return null;
}

/**
* Get current app view
* @return \yii\web\View
*/
protected function getView()
{
if (\Yii::$app && \Yii::$app->controller && \Yii::$app->controller->view)
{
return \Yii::$app->controller->view;
}

return false;
}
}

0 comments on commit 1d9ac72

Please sign in to comment.