|
import * as is from '../is'; |
|
import * as util from '../util'; |
|
|
|
let styfn = {}; |
|
|
|
|
|
|
|
styfn.applyBypass = function( eles, name, value, updateTransitions ){ |
|
let self = this; |
|
let props = []; |
|
let isBypass = true; |
|
|
|
|
|
if( name === '*' || name === '**' ){ |
|
|
|
if( value !== undefined ){ |
|
for( let i = 0; i < self.properties.length; i++ ){ |
|
let prop = self.properties[ i ]; |
|
let name = prop.name; |
|
|
|
let parsedProp = this.parse( name, value, true ); |
|
|
|
if( parsedProp ){ |
|
props.push( parsedProp ); |
|
} |
|
} |
|
} |
|
|
|
} else if( is.string( name ) ){ |
|
let parsedProp = this.parse( name, value, true ); |
|
|
|
if( parsedProp ){ |
|
props.push( parsedProp ); |
|
} |
|
} else if( is.plainObject( name ) ){ |
|
let specifiedProps = name; |
|
updateTransitions = value; |
|
|
|
let names = Object.keys( specifiedProps ); |
|
|
|
for( let i = 0; i < names.length; i++ ){ |
|
let name = names[i]; |
|
let value = specifiedProps[ name ]; |
|
|
|
if( value === undefined ){ |
|
value = specifiedProps[ util.dash2camel( name ) ]; |
|
} |
|
|
|
if( value !== undefined ){ |
|
let parsedProp = this.parse( name, value, true ); |
|
|
|
if( parsedProp ){ |
|
props.push( parsedProp ); |
|
} |
|
} |
|
} |
|
} else { |
|
return false; |
|
} |
|
|
|
|
|
if( props.length === 0 ){ return false; } |
|
|
|
|
|
let ret = false; |
|
for( let i = 0; i < eles.length; i++ ){ |
|
let ele = eles[ i ]; |
|
let diffProps = {}; |
|
let diffProp; |
|
|
|
for( let j = 0; j < props.length; j++ ){ |
|
let prop = props[ j ]; |
|
|
|
if( updateTransitions ){ |
|
let prevProp = ele.pstyle( prop.name ); |
|
diffProp = diffProps[ prop.name ] = { prev: prevProp }; |
|
} |
|
|
|
ret = this.applyParsedProperty( ele, util.copy(prop) ) || ret; |
|
|
|
if( updateTransitions ){ |
|
diffProp.next = ele.pstyle( prop.name ); |
|
} |
|
|
|
} |
|
|
|
if( ret ){ |
|
this.updateStyleHints( ele ); |
|
} |
|
|
|
if( updateTransitions ){ |
|
this.updateTransitions( ele, diffProps, isBypass ); |
|
} |
|
} |
|
|
|
return ret; |
|
}; |
|
|
|
|
|
styfn.overrideBypass = function( eles, name, value ){ |
|
name = util.camel2dash( name ); |
|
|
|
for( let i = 0; i < eles.length; i++ ){ |
|
let ele = eles[ i ]; |
|
let prop = ele._private.style[ name ]; |
|
let type = this.properties[ name ].type; |
|
let isColor = type.color; |
|
let isMulti = type.mutiple; |
|
let oldValue = !prop ? null : prop.pfValue != null ? prop.pfValue : prop.value; |
|
|
|
if( !prop || !prop.bypass ){ |
|
this.applyBypass( ele, name, value ); |
|
} else { |
|
prop.value = value; |
|
|
|
if( prop.pfValue != null ){ |
|
prop.pfValue = value; |
|
} |
|
|
|
if( isColor ){ |
|
prop.strValue = 'rgb(' + value.join( ',' ) + ')'; |
|
} else if( isMulti ){ |
|
prop.strValue = value.join( ' ' ); |
|
} else { |
|
prop.strValue = '' + value; |
|
} |
|
|
|
this.updateStyleHints( ele ); |
|
} |
|
|
|
this.checkTriggers( ele, name, oldValue, value ); |
|
} |
|
}; |
|
|
|
styfn.removeAllBypasses = function( eles, updateTransitions ){ |
|
return this.removeBypasses( eles, this.propertyNames, updateTransitions ); |
|
}; |
|
|
|
styfn.removeBypasses = function( eles, props, updateTransitions ){ |
|
let isBypass = true; |
|
|
|
for( let j = 0; j < eles.length; j++ ){ |
|
let ele = eles[ j ]; |
|
let diffProps = {}; |
|
|
|
for( let i = 0; i < props.length; i++ ){ |
|
let name = props[ i ]; |
|
let prop = this.properties[ name ]; |
|
let prevProp = ele.pstyle( prop.name ); |
|
|
|
if( !prevProp || !prevProp.bypass ){ |
|
|
|
continue; |
|
} |
|
|
|
let value = ''; |
|
let parsedProp = this.parse( name, value, true ); |
|
let diffProp = diffProps[ prop.name ] = { prev: prevProp }; |
|
|
|
this.applyParsedProperty( ele, parsedProp ); |
|
|
|
diffProp.next = ele.pstyle( prop.name ); |
|
} |
|
|
|
this.updateStyleHints( ele ); |
|
|
|
if( updateTransitions ){ |
|
this.updateTransitions( ele, diffProps, isBypass ); |
|
} |
|
} |
|
}; |
|
|
|
export default styfn; |
|
|