Skip to content

Commit

Permalink
fixed some issues with css module, added tests to spec to verify
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcher committed Feb 10, 2010
1 parent 0c7976e commit 7f43bbf
Show file tree
Hide file tree
Showing 12 changed files with 2,887 additions and 1,866 deletions.
1 change: 1 addition & 0 deletions bin/jquery-1.4.1-test.js
Expand Up @@ -29,6 +29,7 @@ Envjs({

//allow jquery to run ajax
isLocal = false;
jQuery.ajaxSetup({async : false});


var unsafeStop = stop,
Expand Down
8 changes: 7 additions & 1 deletion bin/test-jquery.sh
Expand Up @@ -47,7 +47,13 @@ case "$VERSION" in
cd -
fi
echo 'running jquery 1.4.1 tests'
java -Xmx512M -jar rhino/js.jar -opt -1 bin/jquery-1.4.1-test.js
if [ $DEBUG -eq 1 ]; then
echo 'enabling rhino debugger'
java -cp rhino/js.jar org.mozilla.javascript.tools.debugger.Main bin/jquery-1.4.1-test.js
else
echo 'running with rhino'
java -jar rhino/js.jar -opt -1 bin/jquery-1.4.1-test.js
fi
echo 'completed jquery 1.4.1 tests'
;;
esac
Expand Down
9 changes: 6 additions & 3 deletions build.xml
Expand Up @@ -540,10 +540,11 @@
<fileset dir="${SRC_DIR}" includes="css/__global__.js" />
<fileset dir="${SRC_DIR}" includes="common/intro.js" />
<fileset dir="${SRC_DIR}" includes="common/__extend__.js" />
<fileset dir="${SRC_DIR}" includes="common/__toArray__.js" />
<fileset dir="${SRC_DIR}" includes="common/__setArray__.js" />
<fileset dir="${SRC_DIR}" includes="css/properties.js" />
<fileset dir="${SRC_DIR}" includes="css/rule.js" />
<fileset dir="${SRC_DIR}" includes="css/stylesheet.js" />
<fileset dir="${SRC_DIR}" includes="css/htmlelement.js" />
<fileset dir="${SRC_DIR}" includes="common/outro.js" />
</concat>
<echo message="Finished Building ${CSS_DIST}"/>
Expand Down Expand Up @@ -628,8 +629,9 @@
<fileset dir="${DIST_DIR}" includes="event.js" />
<fileset dir="${DIST_DIR}" includes="timer.js" />
<fileset dir="${DIST_DIR}" includes="html.js" />
<fileset dir="${DIST_DIR}" includes="xhr.js" />
<fileset dir="${DIST_DIR}" includes="css.js" />
<fileset dir="${DIST_DIR}" includes="parser.js" />
<fileset dir="${DIST_DIR}" includes="xhr.js" />
<fileset dir="${DIST_DIR}" includes="window.js" />
</concat>
<echo message="${ENV_DIST} built." />
Expand All @@ -649,8 +651,9 @@
<fileset dir="${DIST_DIR}" includes="event.js" />
<fileset dir="${DIST_DIR}" includes="timer.js" />
<fileset dir="${DIST_DIR}" includes="html.js" />
<fileset dir="${DIST_DIR}" includes="xhr.js" />
<fileset dir="${DIST_DIR}" includes="css.js" />
<fileset dir="${DIST_DIR}" includes="parser.js" />
<fileset dir="${DIST_DIR}" includes="xhr.js" />
<fileset dir="${DIST_DIR}" includes="window.js" />
</concat>
<echo message="${ENV_RHINO} built." />
Expand Down
101 changes: 71 additions & 30 deletions dist/css.js
Expand Up @@ -33,22 +33,34 @@ function __extend__(a,b) {
a[i] = b[i];
} return a;
};
/**
* @author john resig
*/
//from jQuery
function __setArray__( target, array ) {
// Resetting the length to 0, then using the native Array push
// is a super-fast way to populate an object with array-like properties
target.length = 0;
Array.prototype.push.apply( target, array );
};
/*
* CSS2Properties - DOM Level 2 CSS
*/
CSS2Properties = function(element){
//this.onSetCallback = options.onSet?options.onSet:(function(){});
this.styleIndex = __supportedStyles__();
this.nameMap = {};
this.__previous__ = {};
this.__element__ = element;
this.styleIndex = __supportedStyles__();//non-standard
this.type = element.tagName;//non-standard
__setArray__(this,[]);
__cssTextToStyles__(this, element.getAttribute('style')||'');
};
__extend__(CSS2Properties.prototype, {
get cssText(){
var css = '';
for(var i=0;i<this.length;i++){
css+=this[i]+":"+this.getPropertyValue(this[i])+';'
var css = '',
i;
for(i=0;i<this.length;i++){
css+=this[i]+": "+this.getPropertyValue(this[i])+';';
if(i+1<this.length)
css+=" ";
}
return css;
},
Expand All @@ -62,11 +74,14 @@ __extend__(CSS2Properties.prototype, {

},
getPropertyValue : function(name){
var index;
if(name in this.styleIndex){
//$info(name +' in style index');
return this[name];
}else if(name in this.nameMap){
return this[__toCamelCase__(name)];
}else{
index = Array.prototype.indexOf.apply(this, name)
if(index > -1)
return this[index];
}
//$info(name +' not found');
return null;
Expand All @@ -76,40 +91,36 @@ __extend__(CSS2Properties.prototype, {
},
removeProperty: function(name){
this.styleIndex[name] = null;
name = __toDashed__(name);
var index = Array.prototype.indexOf.apply(this, [name]);
if(index > -1){
Array.prototype.splice.apply(this, [1,index]);
}
},
setProperty: function(name, value){
setProperty: function(name, value, priority){
//$info('setting css property '+name+' : '+value);
name = __toCamelCase__(name);
if(name in this.styleIndex){
if(name in this.styleIndex && value !== undefined){
//$info('setting camel case css property ');
if (value!==undefined){
this.styleIndex[name] = value;
}
if(name!==__toDashed__(name)){
//$info('setting dashed name css property ');
name = __toDashed__(name);
this[name] = value;
if(!(name in this.nameMap)){
Array.prototype.push.apply(this, [name]);
this.nameMap[name] = this.length;
}

this.styleIndex[name] = value;
//$info('setting dashed name css property ');
name = __toDashed__(name);
if( Array.prototype.indexOf.apply(this, [name]) === -1 ){
Array.prototype.push.apply(this,[name]);
}
}
//$info('finished setting css property '+name+' : '+value);
},
toString:function(){
if (this.length >0){
return "{\n\t"+Array.prototype.join.apply(this,[';\n\t'])+"}\n";
}else{
return '';
}
return '[object CSS2Properties]';
}
});



var __cssTextToStyles__ = function(css2props, cssText){

//console.log('__cssTextToStyles__ %s %s', css2props, cssText);
//var styleArray=[];
var style, styles = cssText.split(';');
for ( var i = 0; i < styles.length; i++ ) {
Expand Down Expand Up @@ -201,7 +212,7 @@ var __supportedStyles__ = function(){
fontStyle: null,
fontVariant: null,
fontWeight: null,
height: '1px',
height: '',
left: null,
letterSpacing: null,
lineHeight: null,
Expand Down Expand Up @@ -307,7 +318,7 @@ for(var style in __supportedStyles__()){
//display will be set to a tagName specific value if ""
CSS2Properties.prototype.__defineGetter__(name, function(){
var val = this.styleIndex[name];
val = val?val:__displayMap__[this.__element__.tagName];
val = val?val:__displayMap__[this.type];
//$log(" css2properties.get " + name + "="+val+" for("+this.__element__.tagName+")");
return val;
});
Expand Down Expand Up @@ -416,6 +427,36 @@ CSSStyleSheet = function(options){



/**
* @author envjs team
*/
$css2properties = [{}];

__extend__(HTMLElement.prototype, {
get style(){
if ( !this.css2uuid ) {
this.css2uuid = $css2properties.length;
$css2properties[this.css2uuid] = new CSS2Properties(this);
}
return $css2properties[this.css2uuid];
},
setAttribute: function (name, value) {
Element.prototype.setAttribute.apply(this,[name, value]);
if (name === "style") {
__updateCss2Props__(this, value);
}
}
});

var __updateCss2Props__ = function(elem, values){
//console.log('__updateCss2Props__ %s %s', elem, values);
if ( !elem.css2uuid ) {
elem.css2uuid = $css2properties.length;
$css2properties[elem.css2uuid] = new CSS2Properties(elem);
}
__cssTextToStyles__($css2properties[elem.css2uuid], values);
};

/**
* @author john resig & the envjs team
* @uri http://www.envjs.com/
Expand Down

0 comments on commit 7f43bbf

Please sign in to comment.