MCPcopy Create free account
hub / github.com/TruthHun/BookStack / adjustCSS

Function adjustCSS

static/jquery/1.12.4/jquery.js:4314–4370  ·  view source on GitHub ↗
( elem, prop, valueParts, tween )

Source from the content-addressed store, hash-verified

4312
4313
4314function adjustCSS( elem, prop, valueParts, tween ) {
4315 var adjusted,
4316 scale = 1,
4317 maxIterations = 20,
4318 currentValue = tween ?
4319 function() { return tween.cur(); } :
4320 function() { return jQuery.css( elem, prop, "" ); },
4321 initial = currentValue(),
4322 unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
4323
4324 // Starting value computation is required for potential unit mismatches
4325 initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) &&
4326 rcssNum.exec( jQuery.css( elem, prop ) );
4327
4328 if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
4329
4330 // Trust units reported by jQuery.css
4331 unit = unit || initialInUnit[ 3 ];
4332
4333 // Make sure we update the tween properties later on
4334 valueParts = valueParts || [];
4335
4336 // Iteratively approximate from a nonzero starting point
4337 initialInUnit = +initial || 1;
4338
4339 do {
4340
4341 // If previous iteration zeroed out, double until we get *something*.
4342 // Use string for doubling so we don't accidentally see scale as unchanged below
4343 scale = scale || ".5";
4344
4345 // Adjust and apply
4346 initialInUnit = initialInUnit / scale;
4347 jQuery.style( elem, prop, initialInUnit + unit );
4348
4349 // Update scale, tolerating zero or NaN from tween.cur()
4350 // Break the loop if scale is unchanged or perfect, or if we've just had enough.
4351 } while (
4352 scale !== ( scale = currentValue() / initial ) && scale !== 1 && --maxIterations
4353 );
4354 }
4355
4356 if ( valueParts ) {
4357 initialInUnit = +initialInUnit || +initial || 0;
4358
4359 // Apply relative offset (+=/-=) if specified
4360 adjusted = valueParts[ 1 ] ?
4361 initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
4362 +valueParts[ 2 ];
4363 if ( tween ) {
4364 tween.unit = unit;
4365 tween.start = initialInUnit;
4366 tween.end = adjusted;
4367 }
4368 }
4369 return adjusted;
4370}
4371

Callers 1

jquery.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected