-
Notifications
You must be signed in to change notification settings - Fork 3
/
EChosen.php
78 lines (69 loc) · 1.92 KB
/
EChosen.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* EChosen class file.
*
* @author Andrius Marcinkevicius <[email protected]>
* @copyright Copyright © 2011 Andrius Marcinkevicius
* @license Licensed under MIT license. http://ifdattic.com/MIT-license.txt
* @version 1.5.1
*/
/**
* EChosen makes select boxes much more user-friendly.
*
* @author Andrius Marcinkevicius <[email protected]>
*/
class EChosen extends CWidget
{
/**
* @var string apply chosen plugin to these elements.
*/
public $target = '.chzn-select';
/**
* @var boolean use jQuery plugin, otherwise use Prototype plugin.
*/
public $useJQuery = true;
/**
* @var boolean include un-minified plugin then debuging.
*/
public $debug = false;
/**
* @var array native Chosen plugin options.
*/
public $options = array();
/**
* @var int script registration position.
*/
public $scriptPosition = CClientScript::POS_END;
/**
* Apply Chosen plugin to select boxes.
*/
public function run()
{
// Publish extension assets
$assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . '/assets' );
// Register extension assets
$cs = Yii::app()->getClientScript();
$cs->registerCssFile( $assets . '/chosen.css' );
// Get extension for JavaScript file
$ext = '.min.js';
if( $this->debug )
$ext = '.js';
// Use jQuery plugin version
if( $this->useJQuery )
{
// Register jQuery scripts
$options = CJavaScript::encode( $this->options );
$cs->registerScriptFile( $assets . '/chosen.jquery' . $ext,
$this->scriptPosition );
$cs->registerScript( __CLASS__.'#'.$this->id,
"$( '{$this->target}' ).chosen({$options});", CClientScript::POS_READY );
}
// Use Prototype plugin version
else
{
// Register Prototype scripts
$cs->registerScriptFile( $assets . '/chosen.proto' . $ext,
$this->scriptPosition );
}
}
}