1: <?php
2: /**
3: * TbAffix class file.
4: * @author Christoffer Niska <[email protected]>
5: * @copyright Copyright © Christoffer Niska 2013-
6: * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
7: * @package bootstrap.widgets
8: */
9:
10: Yii::import('bootstrap.behaviors.TbWidget');
11:
12: /**
13: * Bootstrap affix widget.
14: * @see http://twitter.github.com/bootstrap/javascript.html#affix
15: */
16: class TbAffix extends CWidget
17: {
18: /**
19: * @var string the HTML tag for the container.
20: */
21: public $tagName = 'div';
22: /**
23: * @var mixed pixels to offset from screen when calculating position of scroll.
24: */
25: public $offset;
26: /**
27: * @var array the HTML attributes for the container.
28: */
29: public $htmlOptions = array();
30:
31: /**
32: * Initializes the widget.
33: */
34: public function init()
35: {
36: $this->attachBehavior('TbWidget', new TbWidget);
37: $this->copyId();
38: $this->htmlOptions['data-spy'] = 'affix';
39: if (isset($this->offset)) {
40: if (is_string($this->offset)) {
41: $this->offset = array('top', $this->offset);
42: }
43:
44: if (is_array($this->offset) && count($this->offset) === 2) {
45: list($position, $offset) = $this->offset;
46: $this->htmlOptions['data-offset-' . $position] = $offset;
47: }
48: }
49: echo TbHtml::openTag($this->tagName, $this->htmlOptions);
50: }
51:
52: /**
53: * Runs the widget.
54: */
55: public function run()
56: {
57: echo CHtml::closeTag($this->tagName);
58: }
59: }