Requires

Provides

Contains the CSS animation logic. Used by Fx.Tween, Fx.Morph, Fx.Elements.

License:
MIT-style license.
  1. 18
  2. 19
  3. 20
Fx.CSS = new Class({ Extends: Fx,

prepares the base from/to object

  1. 24
  2. 25
  3. 26
  4. 27
  5. 28
  6. 29
  7. 30
  8. 31
  9. 32
prepare: function(element, property, values){ values = Array.from(values); if (values[1] == null){ values[1] = values[0]; values[0] = element.getStyle(property); } var parsed = values.map(this.parse); return {from: parsed[0], to: parsed[1]}; },

parses a value into an array

  1. 36
  2. 37
  3. 38
  4. 39
  5. 40
  6. 41
  7. 42
  8. 43
  9. 44
  10. 45
  11. 46
  12. 47
  13. 48
  14. 49
  15. 50
parse: function(value){ value = Function.from(value)(); value = (typeof value == 'string') ? value.split(' ') : Array.from(value); return value.map(function(val){ val = String(val); var found = false; Object.each(Fx.CSS.Parsers, function(parser, key){ if (found) return; var parsed = parser.parse(val); if (parsed || parsed === 0) found = {value: parsed, parser: parser}; }); found = found || {value: val, parser: Fx.CSS.Parsers.String}; return found; }); },

computes by a from and to prepared objects, using their parsers.

  1. 54
  2. 55
  3. 56
  4. 57
  5. 58
  6. 59
  7. 60
  8. 61
compute: function(from, to, delta){ var computed = []; (Math.min(from.length, to.length)).times(function(i){ computed.push({value: from[i].parser.compute(from[i].value, to[i].value, delta), parser: from[i].parser}); }); computed.$family = Function.from('fx:css:value'); return computed; },

serves the value as settable

  1. 65
  2. 66
  3. 67
  4. 68
  5. 69
  6. 70
  7. 71
  8. 72
serve: function(value, unit){ if (typeOf(value) != 'fx:css:value') value = this.parse(value); var returned = []; value.each(function(bit){ returned = returned.concat(bit.parser.serve(bit.value, unit)); }); return returned; },

renders the change to an element

  1. 76
  2. 77
  3. 78
render: function(element, property, value, unit){ element.setStyle(property, this.serve(value, unit)); },

searches inside the page css to find the values for a selector

  1. 82
  2. 83
  3. 84
  4. 85
  5. 86
  6. 87
  7. 88
  8. 89
  9. 90
  10. 91
  11. 92
  12. 93
  13. 94
  14. 95
  15. 96
  16. 97
  17. 98
  18. 99
  19. 100
  20. 101
  21. 102
  22. 103
  23. 104
  24. 105
  25. 106
  26. 107
  27. 108
  28. 109
  29. 110
  30. 111
  31. 112
  32. 113
  33. 114
  34. 115
  35. 116
  36. 117
  37. 118
  38. 119
  39. 120
  40. 121
  41. 122
  42. 123
  43. 124
  44. 125
  45. 126
  46. 127
  47. 128
  48. 129
  49. 130
  50. 131
  51. 132
  52. 133
  53. 134
  54. 135
  55. 136
  56. 137
  57. 138
  58. 139
  59. 140
  60. 141
  61. 142
  62. 143
  63. 144
search: function(selector){ if (Fx.CSS.Cache[selector]) return Fx.CSS.Cache[selector]; var to = {}, selectorTest = new RegExp('^' + selector.escapeRegExp() + '$'); Array.each(document.styleSheets, function(sheet, j){ var href = sheet.href; if (href && href.contains('://') && !href.contains(document.domain)) return; var rules = sheet.rules || sheet.cssRules; Array.each(rules, function(rule, i){ if (!rule.style) return; var selectorText = (rule.selectorText) ? rule.selectorText.replace(/^\w+/, function(m){ return m.toLowerCase(); }) : null; if (!selectorText || !selectorTest.test(selectorText)) return; Object.each(Element.Styles, function(value, style){ if (!rule.style[style] || Element.ShortStyles[style]) return; value = String(rule.style[style]); to[style] = ((/^rgb/).test(value)) ? value.rgbToHex() : value; }); }); }); return Fx.CSS.Cache[selector] = to; } }); Fx.CSS.Cache = {}; Fx.CSS.Parsers = { Color: { parse: function(value){ if (value.match(/^#[0-9a-f]{3,6}$/i)) return value.hexToRgb(true); return ((value = value.match(/(\d+),\s*(\d+),\s*(\d+)/))) ? [value[1], value[2], value[3]] : false; }, compute: function(from, to, delta){ return from.map(function(value, i){ return Math.round(Fx.compute(from[i], to[i], delta)); }); }, serve: function(value){ return value.map(Number); } }, Number: { parse: parseFloat, compute: Fx.compute, serve: function(value, unit){ return (unit) ? value + unit : value; } }, String: { parse: Function.from(false), compute: function(zero, one){ return one; }, serve: function(zero){ return zero; } } };

<1.2compat>

  1. 148
Fx.CSS.Parsers = new Hash(Fx.CSS.Parsers);

</1.2compat>