-
Notifications
You must be signed in to change notification settings - Fork 27
/
Document.as
231 lines (199 loc) · 6.42 KB
/
Document.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* ,----,
* ,/ .`|
* ,---, .--.--. ,` .' :,-.----. ,---, ,---,
* ' .' \ / / '. ; ; /\ / \ ,`--.' | .' .' `\
* / ; '. | : /`. /.'___,/ ,' ; : \ | : :,---.' \
* : : \ ; | |--` | : | | | .\ : : | '| | .`\ |
* : | /\ \| : ;_ ; |.'; ; . : |: | | : |: : | ' |
* | : ' ;. :\ \ `.`----' | | | | \ : ' ' ;| ' ' ; :
* | | ;/ \ \`----. \ ' : ; | : . / | | |' | ; . |
* ' : | \ \ ,'__ \ \ | | | ' ; | | \ ' : ;| | : | '
* | | ' '--' / /`--' / ' : | | | ;\ \| | '' : | / ;
* | : : '--'. / ; |.' : ' | \.'' : || | '` ,/
* | | ,' `--'---' '---' : : :-' ; |.' ; : .'
* `--'' | |.' '---' | ,.' 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.display.Sprite;
import flash.external.ExternalInterface;
import framework.cache.Cache;
import framework.net.Assets;
import framework.display.Base;
import flash.display.DisplayObjectContainer;
import flash.display.DisplayObject;
import framework.display.ElementBase;
public class Document extends Base
{
public var anchors:Array = []; // {name:"name", offsetLeft:0, offsetParent:"parent", offsetTop:0, x:0, y:0}
public var cookie:Object = {};
public var images:Array = []; // {border:false, complete:true, width:0, height:0, lowsrc:"", name:"", src:""}
public var embeds:Array = []; // { name:"", width:0, height:0, hidden:false, pluginspage:"", src:"", type:"", units:"" }
public var forms:Array = [];
public var layers:Array = [];
public var links:Array = []; // {hash:"", host:"", hostname:"", href:"", innerText:"", offsetLeft:0, offsetParent:0, offsetTop:0, pathname:"", port:0, protocol:"", search:"", target:"", text:"", x:0, y:0 }
public var styleSheets:Array = []
public var lastModified:Date;
public var parser:Parser;
public var referrer:String;
public var window:Window;
public var cache:Cache;
public var assets:Assets;
//
public var selectedForm:Form;
private var _documentElement:Node;
private var _fgColor:Object;
private var _title:String;
public function get documentElement():Object
{
return _documentElement;
}
public function get domain():String
{
return window.location.toString();
}
public function get fgColor():Object
{
return _fgColor;
}
public function set fgColor(value:Object):void
{
if (value !== _fgColor)
{
_fgColor = value;
window.location.refresh()
}
}
public function get title():String
{
return _title;
}
public function set title(value:String):void
{
if (value !== _title)
{
_title = value;
ExternalInterface.call("document.title="+_title)
}
}
public function get url():Object
{
return window.location.href;
}
public function Document( window:Window )
{
this.window = window;
parser = new Parser( window.navigator.tags );
cache = new Cache( this );
assets = new Assets( cache );
super();
graphics.clear();
}
public function close():void
{
window.close()
}
public function getElementById( id:String ):Element
{
var result:Element;
function loop( target:Sprite ) : void {
var length:int = target.numChildren;
for(var i:uint=0; i < length; i++) {
var child:* = target.getChildAt(i);
if( child is DisplayObjectContainer ) {
var check:DisplayObject = child.getChildByName( id );
if( check != null ) {
result = check as Element;
}else{
loop( child );
}
}
}
}
loop( window );
return result;
}
public function getElementsByClassName( name:String ):Array
{
var results:Array = new Array();
function loop( target:DisplayObjectContainer ) : void {
if( target is ElementBase )
target = (target as ElementBase).rawChildren;
for( var i:uint=0; i < target.numChildren; i++) {
var child:* = target.getChildAt(i);
if( child is Node ){
var classes:String = ( child as Node ).innerXML.@["class"].toString();
if( classes ) {
for each( var clazz:String in classes.split(" ") ) {
if( clazz == name ) {
results.push( child )
}
}
}
}
if( child is DisplayObjectContainer ) {
loop( child );
}
}
}
loop( window );
return results;
}
public function getElementsByTagName( name:String ):Array
{
var results:Array = new Array();
function loop( target:DisplayObjectContainer ) : void {
if( target is ElementBase )
target = (target as ElementBase).rawChildren;
for( var i:uint=0; i < target.numChildren; i++) {
var child:* = target.getChildAt(i);
if( child is Node ){
var nodeName:String = ( child as Node ).innerXML.localName();
if( nodeName == name ) {
results.push( child );
}
}
if( child is DisplayObjectContainer ) {
loop( child );
}
}
}
loop( window );
return results;
}
public function hasFeature( feature:String, domVersion:String=null ) : Boolean
{
return this.hasOwnProperty(feature)
}
//createDocumentFragment()
public function createElement( name:String ) : Node
{
return null
}
/*
public function createTextNode( name:String ) : TextNode
{
return null
}
*/
public function write( content:String ):void
{
}
public function writeln( content:String ):void
{
write( content );
}
}
}