forked from w3canvas/ascanvas
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CSSProperties.as
116 lines (103 loc) · 3.5 KB
/
CSSProperties.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
/*
CanvasDOM by Jumis, Inc
FIXME: This is just an ".attributes" implementation with sprinkles
Unless otherwise noted:
All source code is hereby released into public domain.
http://creativecommons.org/publicdomain/zero/1.0/
http://creativecommons.org/licenses/publicdomain/
Lead development by Charles Pritchard
Influenced by
The World Wide Web Consortium ( http://www.w3.org/TR/DOM-Level-3-Events/idl-definitions.html )
Wikipedia ( http://en.wikipedia.org/wiki/DOM_Events )
*/
package com.w3canvas.ascanvas {
// CSSStyleDeclaration
// These throw DOMException on Error
// FIXME: ExpandoMutableEvents: DOMAttrModified / propertychange
dynamic public class CSS2Properties extends Expando {
private var root = null;
public function CSS2Properties(attr = null, parent=null) {
super(attr);
if(parent) root = parent;
trait = super.trait;
}
// HTMLBlockElement
private var element;
public function get width() { return trait.width; };
public function set width(width:*):void{
if(isNaN(width=parseInt(width))) return;
trait.width = width;
if(root) root.resize();
};
public function get height() { return trait.height; };
public function set height(height:*):void{
if(isNaN(height=parseInt(height))) return;
trait.height = height;
if(root) root.resize();
};
public function get top() { return trait.top; };
public function set top(top:*):void{
if(isNaN(top=parseInt(top))) return;
trait.top = top;
if(root) root.move();
};
public function get left() { return trait.left; };
public function set left(left:*):void{
if(isNaN(left=parseInt(left))) { if(left) throw new Error("no: "+left); else return; }
trait.left = left;
if(root) root.move();
};
public function get zIndex() { return trait.zIndex; };
public function set zIndex(zIndex:*):void{
if(isNaN(zIndex=parseInt(zIndex))) return;
trait.zIndex = zIndex;
if(root) root.move();
};
private const parseCss = new RegExp('([^{])\s*\{\s*([^}])\s*}','g');
public function set cssText(css) {
var cssArr = css.split(parseCss);
var x,i; var y; var k,v; for(i in cssArr) {
y = cssArr[i];
while(true) {
x = y.indexOf(':');
if(-1<x) {
k = cssArr[i].substr(0,x);
v = cssArr[i].substr(x+1);
x = k.indexOf('-');
while(-1<x) {
k = k.substr(0,x)+k.substr(++x,1).toUpperCase()+k.substr(x+1);
x = k.indexOf('-');
}
x = v.indexOf(';');
if(-1<x) { y = v.substr(x+1); v = v.substr(0,x); }
while(v.substr(0,1)==' ')
v = v.substr(1);
trait[k]=v;
if(x<0) break;
} }
}
// trait = new CSS2Properties(cssArr,root);
};
public function get cssText() { return ''; };
public function toString() {
var s=''; for(i in trait) if(i != 'cssText') s+=i+': '+trait[i]+';'; return s;
}
}
// Doesn't merge-in yet.
dynamic public class CSSStyleDeclaration extends CSS2Properties {
// private var root = null;
public function getPropertyValue(a) { return trait[a]; };
public function setProperty(a,b,priority='') { trait[a] = b; };
public function removeProperty(a) { delete trait[a]; };
public function getPropertyPriority(a) { return ''; };
override public function get length() { return trait.length; };
public function get parentRule() { return null; };
public function CSSStyleDeclaration(css = null, parent=null) {
super(css,parent);
if(parent != null) root = parent;
if(css == null) cssText = '';
if(typeof(css) == 'object') { trait = css; }
else if (typeof(css) == 'string') cssText = css;
}
}
}