OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 Google Inc. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 (function(scope, testing) { |
| 16 |
| 17 var propertyHandlers = {}; |
| 18 |
| 19 function addPropertyHandler(parser, merger, property) { |
| 20 propertyHandlers[property] = propertyHandlers[property] || []; |
| 21 propertyHandlers[property].push([parser, merger]); |
| 22 } |
| 23 function addPropertiesHandler(parser, merger, properties) { |
| 24 for (var i = 0; i < properties.length; i++) { |
| 25 var property = properties[i]; |
| 26 WEB_ANIMATIONS_TESTING && console.assert(property.toLowerCase() === proper
ty); |
| 27 addPropertyHandler(parser, merger, property); |
| 28 if (/-/.test(property)) { |
| 29 // Add camel cased variant. |
| 30 addPropertyHandler(parser, merger, property.replace(/-(.)/g, function(_,
c) { |
| 31 return c.toUpperCase(); |
| 32 })); |
| 33 } |
| 34 } |
| 35 } |
| 36 scope.addPropertiesHandler = addPropertiesHandler; |
| 37 |
| 38 function propertyInterpolation(property, left, right) { |
| 39 var handlers = left == right ? [] : propertyHandlers[property]; |
| 40 for (var i = 0; handlers && i < handlers.length; i++) { |
| 41 var parsedLeft = handlers[i][0](left); |
| 42 var parsedRight = handlers[i][0](right); |
| 43 if (parsedLeft !== undefined && parsedRight !== undefined) { |
| 44 var interpolationArgs = handlers[i][1](parsedLeft, parsedRight); |
| 45 if (interpolationArgs) { |
| 46 var interp = scope.Interpolation.apply(null, interpolationArgs); |
| 47 return function(t) { |
| 48 if (t == 0) return left; |
| 49 if (t == 1) return right; |
| 50 return interp(t); |
| 51 }; |
| 52 } |
| 53 } |
| 54 } |
| 55 return scope.Interpolation(false, true, function(bool) { |
| 56 return bool ? right : left; |
| 57 }); |
| 58 } |
| 59 scope.propertyInterpolation = propertyInterpolation; |
| 60 |
| 61 })(webAnimationsMinifill, webAnimationsTesting); |
| 62 |
OLD | NEW |