File size: 1,190 Bytes
bc20498 |
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 |
let styfn = {};
styfn.appendFromJson = function( json ){
let style = this;
for( let i = 0; i < json.length; i++ ){
let context = json[ i ];
let selector = context.selector;
let props = context.style || context.css;
let names = Object.keys( props );
style.selector( selector ); // apply selector
for( let j = 0; j < names.length; j++ ){
let name = names[j];
let value = props[ name ];
style.css( name, value ); // apply property
}
}
return style;
};
// accessible cy.style() function
styfn.fromJson = function( json ){
let style = this;
style.resetToDefault();
style.appendFromJson( json );
return style;
};
// get json from cy.style() api
styfn.json = function(){
let json = [];
for( let i = this.defaultLength; i < this.length; i++ ){
let cxt = this[ i ];
let selector = cxt.selector;
let props = cxt.properties;
let css = {};
for( let j = 0; j < props.length; j++ ){
let prop = props[ j ];
css[ prop.name ] = prop.strValue;
}
json.push( {
selector: !selector ? 'core' : selector.toString(),
style: css
} );
}
return json;
};
export default styfn;
|