U
Une Bévue
i have a simplified Hash like that :
function Hash(){
var _hash=new Array(),_keys=new Array(),_length=0;
this.length=function(){return _length;};
this.add=function(k,v){if(typeof(_hash[k])==='undefined'){_keys.push(k);
_length++;}_hash[k]=v;};
this.valueOf=function(k){return _hash[k];};
this.keyAt=function(i){return _keys;};
}
with two subclasses of it:
function Properties(){}
Properties.prototype=new Hash();
Properties.prototype.cssText=function(){
var s = '';
for(var i=0;i<this.length();i++){s+=this.keyAt(i)+':
'+this.valueOf(this.keyAt(i))+';';}
return s;
};
function Selectors(){}
Selectors.prototype=new Hash();
Selectors.prototype.rule=function(selector){return selector+
'
{'+this.valueOf(selector).cssText()+'}';};
Selectors.prototype.rules=function(){
var s = '',tab=' ';
for(var i=0;i<this.length();i++){s+=this.keyAt(i)+
'
{\n'+tab+this.valueOf(this.keyAt(i)).cssText()+'\n}\n';}
return s;
}
when i test the Properties instanciation :
var props1=new Properties();
props1.add('background-color','#eee');
props1.add('color','#333');
props1.cssText() // gives : background-color: #eee;color: #333; // OK
var props2=new Properties();
props2.add('background-color','#6aca6a');
props2.add('color','#f60');
props2.cssText() // donne : background-color: #6aca6a;color: #f60; // OK
then i put those Properties in a Selectors Hash that way :
var sels=new Selectors();
sels.add('div#menu dl dt',props1);
sels.add('div#menu dl dt:hover',props2);
the problems arrose here :
sels.rule('div#menu dl dt')// gives :
#6aca6a;color: #f60;}// WRONG
sels.rule('div#menu dl dt:hover')// gives :
div#menu dl dt:hover {background-color: #6aca6a;color: #f60;}// OK BY
CHANCE...
and also :
sels.rules()// gives :
div#menu dl dt {
background-color: #6aca6a;color: #f60;
}
div#menu dl dt:hover {
background-color: #6aca6a;color: #f60;
}
then i do have the two right selectors but it seems the last instance of
Properties did overcome the first one ???
any light ???
function Hash(){
var _hash=new Array(),_keys=new Array(),_length=0;
this.length=function(){return _length;};
this.add=function(k,v){if(typeof(_hash[k])==='undefined'){_keys.push(k);
_length++;}_hash[k]=v;};
this.valueOf=function(k){return _hash[k];};
this.keyAt=function(i){return _keys;};
}
with two subclasses of it:
function Properties(){}
Properties.prototype=new Hash();
Properties.prototype.cssText=function(){
var s = '';
for(var i=0;i<this.length();i++){s+=this.keyAt(i)+':
'+this.valueOf(this.keyAt(i))+';';}
return s;
};
function Selectors(){}
Selectors.prototype=new Hash();
Selectors.prototype.rule=function(selector){return selector+
'
{'+this.valueOf(selector).cssText()+'}';};
Selectors.prototype.rules=function(){
var s = '',tab=' ';
for(var i=0;i<this.length();i++){s+=this.keyAt(i)+
'
{\n'+tab+this.valueOf(this.keyAt(i)).cssText()+'\n}\n';}
return s;
}
when i test the Properties instanciation :
var props1=new Properties();
props1.add('background-color','#eee');
props1.add('color','#333');
props1.cssText() // gives : background-color: #eee;color: #333; // OK
var props2=new Properties();
props2.add('background-color','#6aca6a');
props2.add('color','#f60');
props2.cssText() // donne : background-color: #6aca6a;color: #f60; // OK
then i put those Properties in a Selectors Hash that way :
var sels=new Selectors();
sels.add('div#menu dl dt',props1);
sels.add('div#menu dl dt:hover',props2);
the problems arrose here :
sels.rule('div#menu dl dt')// gives :
#6aca6a;color: #f60;}// WRONG
sels.rule('div#menu dl dt:hover')// gives :
div#menu dl dt:hover {background-color: #6aca6a;color: #f60;}// OK BY
CHANCE...
and also :
sels.rules()// gives :
div#menu dl dt {
background-color: #6aca6a;color: #f60;
}
div#menu dl dt:hover {
background-color: #6aca6a;color: #f60;
}
then i do have the two right selectors but it seems the last instance of
Properties did overcome the first one ???
any light ???