-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNavHandler.php
More file actions
executable file
·148 lines (133 loc) · 3.5 KB
/
NavHandler.php
File metadata and controls
executable file
·148 lines (133 loc) · 3.5 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
class NavHandler extends Base
{
const Solo = 'solo';
private $ActiveSection;
private $Launched;
private $ContentPanel;
private $Token;
private $CreationFunction;
//For Animations
private $Animate;
private $PrevIndex;
private $Group;
static $Section, $Width, $Height;
function __construct($contentPanel, $creationFunction, $group = null, $tokenName = 'section')
{
$this->ContentPanel = $contentPanel;
$this->Token = $tokenName;
$this->CreationFunction = $creationFunction;
$this->Group = $group;
if($this->Token)
{
$token = URL::GetToken($this->Token);
if($token)
{
if($group && $group instanceof Group)
$group->SelectedValue = $token;
$this->LaunchSection($token);
}
}
}
/**
* Tells NavHandler to launch a particular section.
*
* @param string $section
* @param bool|NavHandler::Solo $reCreate
* - true: forces recreation of a section
* - false: uses a previous instance if any exist
* - NavHandler: simply adds the object to the ContentPanel specified WITHOUT keeping track of it. This is useful
* for things like windows.
* @return Base
*/
function LaunchSection($section = null, $reCreate = false)
{
if ($section instanceof Group)
{
$section = $section->SelectedValue;
}
if (!$reCreate && $this->ActiveSection == $section)
{
return null;
}
$parent = $this->ContentPanel;
if ($this->Launched[$section] == null || $reCreate)
{
self::$Section = $section;
self::$Width = $parent->Width;
self::$Height = $parent->Height;
if ($reCreate !== self::Solo && isset($this->Launched[$section]))
{
$this->Launched[$section]->Leave();
}
$object = $this->CreationFunction->Exec();
if ($object)
{
if ($reCreate !== self::Solo)
{
$this->Launched[$section] = $object;
}
$this->ContentPanel->Controls->Add($object);
}
else
{
$this->ActiveSection = $section;
return null;
}
}
if ($this->Token)
{
URL::SetToken($this->Token, $section);
}
if (isset($this->Animate) && isset($this->Group))
{
$selectedPosition = $this->Group->SelectedPosition;
}
if ($reCreate !== self::Solo)
{
if (isset($this->Animate) && $this->PrevIndex !== null)
{
$animateLeft = false;
if (isset($this->Group))
{
$animateLeft = $selectedPosition > $this->PrevIndex;
}
$activePanel = $this->Launched[$section];
$properties = $this->Animate == System::Horizontal?array('Left', 'Width'):array('Top', 'Height');
$magnitude = $activePanel->{$properties[1]};
$animateProp = $properties[0];
$activePanel->$animateProp = $animateLeft?$magnitude:(-1 * $magnitude);
Animate::$animateProp($activePanel, 0, 500);
if($this->ActiveSection != null)
{
$activePanel = $this->Launched[$this->ActiveSection];
$to = $animateLeft?(-1 * $magnitude):$magnitude;
Animate::$animateProp($activePanel, $to, 500);
}
}
elseif($this->ActiveSection != null)
{
$this->Launched[$this->ActiveSection]->Visible = false;
}
if (isset($this->Animate))
{
$this->PrevIndex = $selectedPosition;
}
$this->ActiveSection = $section;
$this->Launched[$section]->Visible = true;
}
}
function SetAnimate($animate)
{
$this->Animate = $animate;
}
function GetContentPanel()
{
return $this->ContentPanel;
}
function GetActiveSection()
{
return $this->ActiveSection;
}
}
?>