1 <?php
2 /**
3 * @copyright Copyright © 2amigOS! Consulting Group 2013-
4 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
5 * @package foundation.components
6 * @version 1.0.0
7 */
8 namespace foundation\widgets;
9
10 use foundation\helpers\ArrayHelper;
11 use foundation\helpers\Nav;
12 use foundation\enum\Enum;
13
14 /**
15 * Magellan renders the Magellan Foundation 4 plugin. Magellan is a style agnostic plugin that lets you style a sticky
16 * navigation that denotes where you are on the page.
17 *
18 * @see http://foundation.zurb.com/docs/components/clearing.html
19 *
20 * @author Antonio Ramirez <amigo.cobos@gmail.com>
21 * @package foundation\widgets
22 */
23 class Magellan extends base\Widget
24 {
25 /**
26 * @var array the navigation items. They have the following syntax:
27 *
28 * <pre>
29 * 'items' => array(
30 * array('id' => 'anchor on page', 'label' => 'item label')
31 * )
32 * </pre>
33 */
34 public $items = array();
35
36
37 /**
38 * Widget's initialization widget
39 */
40 public function init()
41 {
42 $this->assets = array(
43 'js' => YII_DEBUG ? 'foundation/foundation.magellan.js' : 'foundation.min.js'
44 );
45 $this->htmlOptions['data-magellan-expedition'] = Enum::NAV_FIXED;
46 parent::init();
47 }
48
49 /**
50 * Renders the widget
51 */
52 public function run()
53 {
54 echo $this->renderMagellan();
55 }
56
57 /**
58 * Renders magellan
59 * @return string the resulting tag
60 */
61 public function renderMagellan()
62 {
63 $list = array();
64 foreach ($this->items as $item) {
65 $listItem['url'] = '#' . $item['id'];
66 $listItem['label'] = $item['label'];
67 $listItem['itemOptions'] = array('data-magellan-arrival' => $item['id']);
68 $list[] = $listItem;
69 }
70
71 return \CHtml::tag('div', $this->htmlOptions, Nav::sub($list));
72 }
73 }