-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f4dc0f
commit f230529
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ nbproject | |
.project | ||
.settings | ||
|
||
# lock file | ||
composer.lock | ||
|
||
# mac deployment helpers | ||
switch | ||
index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "iamwebdesigner/yii2-jquitelight", | ||
"description": "Yii2 Widget for jquitelight highlight plugin", | ||
"license": "Apache 2.0", | ||
"authors": [ | ||
{ | ||
"name": "iamwebdesigner", | ||
"email": "iamawebgeek@gmail.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"bower-asset/jquitelight": "~2.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"iamwebdesigner\\jquitelight\\": "src" | ||
} | ||
}, | ||
"extra": { | ||
"asset-installer-paths": { | ||
"npm-asset-library": "vendor/npm", | ||
"bower-asset-library": "vendor/bower" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace iamwebdesigner\jquitelight; | ||
|
||
use iamwebdesigner\jquitelight\assets\JquitelightAsset; | ||
use yii\base\Exception; | ||
use yii\base\Widget; | ||
use yii\helpers\Html; | ||
use yii\helpers\Json; | ||
|
||
/** | ||
* Class Jquitelight | ||
* @package iamwebdesigner\jquitelight | ||
* @author iamwebdesigner | ||
*/ | ||
class Jquitelight extends Widget | ||
{ | ||
/** | ||
* HTML attributes for rendering container | ||
* @var array | ||
*/ | ||
public $htmlOptions = []; | ||
/** | ||
* The options to be passed for javascript plugin. | ||
* @var array | ||
*/ | ||
public $clientOptions = []; | ||
/** | ||
* Whether to wrap content in a div or not | ||
* if false then jQuery.unwrap method used to get rid of created div | ||
* @var bool | ||
*/ | ||
public $wrapContent = true; | ||
/** | ||
* List of keywords to be highlighted | ||
* can be assoc array as this value if passed for first argument of mark method of js plugin | ||
* @var array | ||
*/ | ||
public $keywords = []; | ||
|
||
/** | ||
* Initialize plugin and open wrapping container | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
if (!$this->htmlOptions['id']) { | ||
$this->htmlOptions['id'] = $this->getId(); | ||
} | ||
if (empty($this->keywords)) { | ||
throw new Exception('No keywords specified for highlighting'); | ||
} | ||
Html::beginTag('div', $this->htmlOptions); | ||
} | ||
|
||
/** | ||
* Register assets and close wrapping container | ||
*/ | ||
public function run() | ||
{ | ||
$this->registerAssets(); | ||
Html::endTag('div'); | ||
} | ||
|
||
/** | ||
* Register scripts | ||
*/ | ||
protected function registerAssets() | ||
{ | ||
$view = $this->getView(); | ||
$id = $this->htmlOptions['id']; | ||
JquitelightAsset::register($view); | ||
$keywords = Json::encode($this->keywords); | ||
$options = Json::encode($this->clientOptions); | ||
$view->registerJs("jQuery('#$id').mark($keywords, $options);", $view::POS_END); | ||
if (!$this->wrapContent) { | ||
$view->registerJs("jQuery('#$id').find(':eq(0)').unwrap();", $view::POS_END); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace iamwebdesigner\jquitelight\assets; | ||
|
||
use yii\web\AssetBundle; | ||
|
||
/** | ||
* Class JquitelightAsset | ||
* @package iamwebdesigner\jquitelight\assets | ||
* @author iamwebdesigner | ||
*/ | ||
class JquitelightAsset extends AssetBundle | ||
{ | ||
public $sourcePath = '@bower/jquitelight'; | ||
public $js = [ | ||
'jquitelight.min.js' | ||
]; | ||
public $depends = [ | ||
'yii\web\JqueryAsset' | ||
]; | ||
} |