-
Notifications
You must be signed in to change notification settings - Fork 27
/
History.as
139 lines (117 loc) · 3.94 KB
/
History.as
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
/* ,----,
* ,/ .`|
* ,---, .--.--. ,` .' :,-.----. ,---, ,---,
* ' .' \ / / '. ; ; /\ / \ ,`--.' | .' .' `\
* / ; '. | : /`. /.'___,/ ,' ; : \ | : :,---.' \
* : : \ ; | |--` | : | | | .\ : : | '| | .`\ |
* : | /\ \| : ;_ ; |.'; ; . : |: | | : |: : | ' |
* | : ' ;. :\ \ `.`----' | | | | \ : ' ' ;| ' ' ; :
* | | ;/ \ \`----. \ ' : ; | : . / | | |' | ; . |
* ' : | \ \ ,'__ \ \ | | | ' ; | | \ ' : ;| | : | '
* | | ' '--' / /`--' / ' : | | | ;\ \| | '' : | / ;
* | : : '--'. / ; |.' : ' | \.'' : || | '` ,/
* | | ,' `--'---' '---' : : :-' ; |.' ; : .'
* `--'' | |.' '---' | ,.' Tyler
* ActionScript tested rapid iterative dev `---' Copyright2010'---' Larson
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* http://www.gnu.org/licenses
*/
package framework.view.htmlwrapper
{
import flash.events.Event;
public class History
{
public static var HISTORY_UPDATED:String = "historyUpdated";
private var _document:Document
private var _history:Array = [];
private var _currentIndex:uint = 0;
private var _current:String;
private var _next:String;
private var _previous:String;
public function History( document:Document )
{
super();
_document = document;
_document.window.addEventListener( Location.LOCATION_CHANGE, locationChange )
}
public function back():void
{
go( -1 );
}
public function forward():void
{
go( 1 );
}
public function go( location:* ):void
{
if( location is String )
{
_history.push( new HistoryItem( location ) );
_currentIndex = _currentIndex + 1;
_current = location;
}else{
_currentIndex = _currentIndex + int( location );
_current = _history[ _currentIndex ].href;
}
if( length >= _currentIndex )
_history.splice( _currentIndex + 1, length-_currentIndex+1);
if( _currentIndex > 1 )
_previous = _history[ _currentIndex - 1 ].href;
else
_previous = null;
if( _currentIndex <= length )
_next = _history[ _currentIndex + 1 ].href;
else
_next = null;
_document.window.dispatchEvent( new Event( History.HISTORY_UPDATED ) )
}
//---------------------------------------
// GETTER / SETTERS
//---------------------------------------
public function get current():String
{
return _current;
}
public function get next():String
{
return _next;
}
public function get previous():String
{
return _previous;
}
public function get length():uint
{
return _history.length;
}
private function locationChange( event:Event ):void
{
var location:String = _document.window.location.href;
_history.push( new HistoryItem( location ) );
_currentIndex = _history.length - 1;
if(_currentIndex > 1 )
_previous = _history[ _currentIndex - 1 ].href;
else
_previous = null;
_current = location;
}
}
}
class HistoryItem
{
public var href:String;
public function HistoryItem( _href:String )
{
super();
href = _href
}
}