-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelect2Asset.php
63 lines (56 loc) · 1.25 KB
/
Select2Asset.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* @link
* @copyright Copyright (c) 2016 Venu Narukulla
* @license http://www.yiiframework.com/license/
*/
namespace indicalabs\select2;
/**
* @author Venu Narukulla. Venu <[email protected]>
* @since 2.0
*/
class Select2Asset extends \yii\web\AssetBundle
{
/**
* @var string Plugin language
*/
public $language;
public $sourcePath = '@npm/select2/dist';
public $js = [
'js/select2.full.min.js',
// 'js/select2.min.js',
];
public $css = [
'css/select2.min.css',
];
public $depends = [
'yii\web\JqueryAsset',
];
/**
* @inheritdoc
*/
public function registerAssetFiles($view)
{
if ($this->language !== null) {
$this->js[] = 'select2_locale_' . $this->language . '.js';
}
$view->registerJs(<<<JS
function formatResult(item) {
if(!item.id) {
// return `text` for optgroup
return item.text;
}
// return item template
return '<i>' + item.text + '</i>';
};
function formatSelection(repo) {
//repo.selected =true;
// return selection template
//return '<b>' + item.text + '</b>';
return repo.full_name || repo.text;
};
JS
, \yii\web\View::POS_READY);
parent::registerAssetFiles($view);
}
}