[haXe] Another haxeJs newbie question
Franco Ponticelli
franco.ponticelli at gmail.com
Tue Dec 4 09:35:46 CET 2007
I've tested your code and it works for me (FF and IE) ... I've just made
some oreder ...
import js.Dom;
class Example {
public static function main() {
var sheets = js.Lib.document.styleSheets;
if(sheets!=null)for(i in 0...sheets.length) {
var sheet = sheets[i];
var rules : Array<Dynamic> = untyped sheet.cssRules != null ?
sheet.cssRules : sheet.rules;
for(j in 0...rules.length) {
var rule = rules[j];
if(rule.selectorText == ".menuItem") {
rule.style.color = "#FFFFFF";
rule.style.backgroundColor = "#FF0000";
rule.style.fontSize = "0.8em";
rule.style.padding = "4px";
}
}
}
}
}
On Dec 3, 2007 10:36 PM, Axel Huizinga <axel at 3drachen.de> wrote:
> Franco Ponticelli schrieb:
>
> > I've not tested it but I suspect that the stylesheets field is
> > mispelled ... I think the correct name is styleSheets. If it is so you
> > have to change its definition in the haxe/js/Dom.hx file.
> >
> > About your second question you will have to implement your solution.
> > The JS API in haXe is quite essential. I suggest you to take a look at
> > how big libraries deal with that problem and implement your solution
> > in haXe.
> >
> > Franco.
> >
> > On Dec 3, 2007 6:21 PM, Axel Huizinga <axel at 3drachen.de
> > <mailto:axel at 3drachen.de>> wrote:
> >
> > Hi,
> > first I wonder why
> >
> > var a:HtmlCollection<StyleSheet> =
> js.Lib.document.stylesheets;
> > trace(a);
> >
> > reports null though I have one external stylesheet linked to my html
> > document.
> >
> Ok changing to styleSheets solved the first.
> But I still have some trouble to implement the rules access.
> Started with mozilla compatible syntax:
>
> var a:HtmlCollection<StyleSheet> = js.Lib.document.styleSheets;
> trace(a);
> if(a!=null)for(i in 0...a.length)
> {
> trace(a[i]);
> for(j in 0...a[i].cssRules.length)
> {
> trace(a[i].cssRules[j].selectorText);
> //a[i].rules[j].style.color = 'red';
> if(a[i].cssRules[j].selectorText == '.menuItem'){
> a[i].cssRules[j].style.color = "#FFFFFF";
> a[i].cssRules[j].style.backgroundColor = "#FF0000";
> a[i].cssRules[j].style.fontSize = config.get('font-size');
> a[i].cssRules[j].style.padding = config.get('padding');
> var props:Array<String> =
> Reflect.fields(a[i].cssRules[j].style);
> trace(props.toString());
> }
> }
> }
>
> works partially. The padding and fontSize is applied but the
> color/backgroundColor not!
> trace of the style fields reports: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14
>
> Any more hints?
>
> Axel
>
> > And then I'd like to change stylesheet rules via javascript.
> > Is there a way to do this with haxe?
> >
> > Cordially,
> > Axel
> >
> > --
> > haXe - an open source web programming language
> > http://haxe.org
> >
> >
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.motion-twin.com/pipermail/haxe/attachments/20071204/89b2d2d6/attachment.htm
More information about the Haxe
mailing list