forked from crisu83/yiistrap
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTbAffix.php
59 lines (54 loc) · 1.36 KB
/
TbAffix.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
<?php
/**
* TbAffix class file.
* @author Christoffer Niska <christoffer.niska@gmail.com>
* @copyright Copyright © Christoffer Niska 2013-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package bootstrap.widgets
*/
Yii::import('bootstrap.widgets.TbWidget');
/**
* Bootstrap affix widget.
* @see http://twitter.github.com/bootstrap/javascript.html#affix
*/
class TbAffix extends TbWidget
{
/**
* @var string the HTML tag for the container.
*/
public $tagName = 'div';
/**
* @var mixed pixels to offset from screen when calculating position of scroll.
*/
public $offset;
/**
* @var array the HTML attributes for the container.
*/
public $htmlOptions = array();
/**
* Initializes the widget.
*/
public function init()
{
$this->htmlOptions['data-spy'] = 'affix';
if (isset($this->offset))
{
if (is_string($this->offset))
$this->offset = array('top', $this->offset);
if (is_array($this->offset) && count($this->offset) === 2)
{
list($position, $offset) = $this->offset;
if (in_array($position, TbHtml::$navbarPositions))
$this->options = TbHtml::defaultOption('data-offset-' . $position, $offset, $this->options);
}
}
echo CHtml::openTag($this->tagName, $this->htmlOptions);
}
/**
* Runs the widget.
*/
public function run()
{
echo CHtml::closeTag($this->tagName);
}
}