Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jirisvoboda committed Jun 4, 2015
1 parent b1c3b56 commit ec2ab0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/ShareIt.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use dlds\shareit\ShareLinksAssets;
use dlds\shareit\ShareItAssets;

class ShareLinks extends \yii\base\Widget {
class ShareIt extends \yii\base\Widget {

/**
* Constants representing each social
Expand All @@ -27,7 +27,7 @@ class ShareLinks extends \yii\base\Widget {
/**
* @var string jQuery selector for sharing links (to bind popup on click there)
*/
public $linkSelector = '.shareit-link';
public $linkClassSelector = 'shareit-link';

/**
* Sharing url template for each network
Expand All @@ -45,15 +45,12 @@ class ShareLinks extends \yii\base\Widget {

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

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

public function run()
{
$js = '$("'.$this->linkSelector.'").yiiShareLinks();';
$this->view->registerJs($js);
echo $this->render($this->viewName);
ShareItAssets::register($this->view);
}

/**
Expand All @@ -68,7 +65,14 @@ public function shareLink($network, $options = [], $text = false, $url = false)

if ($network)
{
return Html::a($text, str_replace('{url}', urlencode($this->url), $network), $options);
Html::addCssClass($options, $this->linkClassSelector);

if (false === $url)
{
$url = $this->url;
}

return Html::a($text, str_replace('{url}', urlencode($url), $network), $options);
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/ShareItAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Yii;
use yii\web\AssetBundle;

class ShareLinksAssets extends AssetBundle
class ShareItAssets extends AssetBundle
{
public $sourcePath = '@shareit/assets';
public $basePath = '@webroot/assets';
Expand Down

0 comments on commit ec2ab0d

Please sign in to comment.