Mam sobie taki kod jak poniżej, 3linki zmieniają kolor diva na biały, szary lub czarny.
Przy zmianie zapisywane jest ciastko z kolorem.
Problem w tym, ze po odświeżeniu wszystko się resetuje, tak jakby nie czytało stanu ciastka.

Co jest nie tak w tym kodzie?
  1.  
  2. <style type="text/css">
  3. .white {
  4. background-color:#FFFFFF;
  5. color:#333333;
  6. }
  7. .grey {
  8. background-color:#999999;
  9. color:#FFFFFF;
  10. }
  11. .black {
  12. background-color:#333333;
  13. color:#FFFFFF;
  14. }
  15.  
  16. <script type="text/javascript" src="mootools.js"></script>
  17.  
  18. <script type="text/javascript">
  19. window.addEvent('domready', function(){
  20.  
  21. Fx.Morph = Fx.Styles.extend({
  22.  
  23. start: function(className){
  24.  
  25. var to = {};
  26.  
  27. $each(document.styleSheets, function(style){
  28. var rules = style.rules || style.cssRules;
  29. $each(rules, function(rule){
  30. if (!rule.selectorText.test('\.' + className + '$')) return;
  31. Fx.CSS.Styles.each(function(style){
  32. if (!rule.style || !rule.style[style]) return;
  33. var ruleStyle = rule.style[style];
  34. to[style] = (style.test(/color/i) && ruleStyle.test(/^rgb/)) ? ruleStyle.rgbToHex() : ruleStyle;
  35. });
  36. });
  37. });
  38. return this.parent(to);
  39. }
  40. });
  41.  
  42. Fx.CSS.Styles = ["backgroundColor", "backgroundPosition", "color", "width", "height", "left", "top", "bottom", "right", "fontSize", "letterSpacing", "lineHeight", "textIndent", "opacity"];
  43.  
  44. Fx.CSS.Styles.extend(Element.Styles.padding);
  45. Fx.CSS.Styles.extend(Element.Styles.margin);
  46.  
  47. Element.Styles.border.each(function(border){
  48. ['Width', 'Color'].each(function(property){
  49. Fx.CSS.Styles.push(border + property);
  50. });
  51. });
  52.  
  53. var myMorph = new Fx.Morph('container', {wait: false});
  54.  
  55. $('white').addEvent('click', function(e){
  56. new Event(e).stop();
  57.  
  58. myMorph.start('white');
  59. Cookie.set("style", "white", {duration: 15});
  60. });
  61.  
  62. $('grey').addEvent('click', function(e){
  63. new Event(e).stop();
  64.  
  65. myMorph.start('grey');
  66. Cookie.set("style", "grey", {duration: 15});
  67. });
  68.  
  69. $('black').addEvent('click', function(e){
  70. new Event(e).stop();
  71.  
  72. myMorph.start('black');
  73. Cookie.set("style", "black", {duration: 15});
  74. });
  75.  
  76. if(Cookie.get("style") == "black"){
  77. myMorph.set('black');
  78. }else if(Cookie.get("style") == "grey"){
  79. myMorph.set('grey');
  80. }else{
  81. myMorph.set('white');
  82. }
  83.  
  84. });
  85.  
  86. </head>
  87.  
  88. <div id="container" class="widthwide">
  89.  
  90. <ul style="list-style-type: none;">
  91. <li style="display:inline;"><a href="#" id="white" name="white">white</a></li>
  92. <li style="display:inline;"><a href="#" id="grey" name="grey">grey</a></li>
  93. <li style="display:inline;"><a href="#" id="black" name="black">black</a></li>
  94. </ul>
  95.  
  96. </div>
  97.  
  98. </body>
  99. </html>


-----------------------------
---- UPDATE ------------------
---------------------------------------------------------------------------------------------


Tylko częściowo rozwiązałęm problem. Dałem myMorph.start() zamiast myMorph.set()
działa jednak tylko dla jednego wywołania (jedno ciastko - jedno wywołąnie myMorph.start() )
-czyli np. tylko do obsługi koloru.

Gdy jednak kod rozszerzę o obsługe np. rozmiaru czcioki (tu klasa fontsmall)
...zapiszę drugie ciacho i dodam jeszcze jedno wywołanie myMorph.start() pojawia się znowu problem.
-oto klikam na link fontsmall -ok zmienia rozmiar fontu, klikam na black -zmienia kolor tła, daję odśwież
...i tło się resetuje a czcionka jest ok bo jak powinna zminimalizowana.

Wniosek, przy kilkukrotnym wywołaniu myMorph.start() zastosowane są tylko zmiany z ostatniego
czyli np. dla:
myMorph.start('fontsmall');
myMorph.start('black');


zostanie tylko tło zmienione na czarne, a czcionka pozostanie niezmieniona.

Co i jak zmienić by rozwiązać ten problem?

  1.  
  2. <style type="text/css">
  3. .white {
  4. background-color:#FFFFFF;
  5. color:#333333;
  6. }
  7. .grey {
  8. background-color:#999999;
  9. color:#FFFFFF;
  10. }
  11. .black {
  12. background-color:#333333;
  13. color:#FFFFFF;
  14. }
  15.  
  16. .fontsmall {
  17. font-size: 10px;
  18. }
  19.  
  20. <script type="text/javascript" src="mootools.js"></script>
  21.  
  22. <script type="text/javascript">
  23. window.addEvent('domready', function(){
  24.  
  25. Fx.Morph = Fx.Styles.extend({
  26.  
  27. start: function(className){
  28.  
  29. var to = {};
  30.  
  31. $each(document.styleSheets, function(style){
  32. var rules = style.rules || style.cssRules;
  33. $each(rules, function(rule){
  34. if (!rule.selectorText.test('\.' + className + '$')) return;
  35. Fx.CSS.Styles.each(function(style){
  36. if (!rule.style || !rule.style[style]) return;
  37. var ruleStyle = rule.style[style];
  38. to[style] = (style.test(/color/i) && ruleStyle.test(/^rgb/)) ? ruleStyle.rgbToHex() : ruleStyle;
  39. });
  40. });
  41. });
  42. return this.parent(to);
  43. }
  44. });
  45.  
  46. Fx.CSS.Styles = ["backgroundColor", "backgroundPosition", "color", "width", "height", "left", "top", "bottom", "right", "fontSize", "letterSpacing", "lineHeight", "textIndent", "opacity"];
  47.  
  48. Fx.CSS.Styles.extend(Element.Styles.padding);
  49. Fx.CSS.Styles.extend(Element.Styles.margin);
  50.  
  51. Element.Styles.border.each(function(border){
  52. ['Width', 'Color'].each(function(property){
  53. Fx.CSS.Styles.push(border + property);
  54. });
  55. });
  56.  
  57. var myMorph = new Fx.Morph('container', {wait: false});
  58.  
  59. $('white').addEvent('click', function(e){
  60. new Event(e).stop();
  61.  
  62. myMorph.start('white');
  63. Cookie.set("style1", "white", {duration: 15});
  64. });
  65.  
  66. $('grey').addEvent('click', function(e){
  67. new Event(e).stop();
  68.  
  69. myMorph.start('grey');
  70. Cookie.set("style1", "grey", {duration: 15});
  71. });
  72.  
  73. $('black').addEvent('click', function(e){
  74. new Event(e).stop();
  75.  
  76. myMorph.start('black');
  77. Cookie.set("style1", "black", {duration: 15});
  78. });
  79.  
  80.  
  81. $('fontsmall').addEvent('click', function(e){
  82. new Event(e).stop();
  83.  
  84. myMorph.start('fontsmall');
  85. Cookie.set("style2", "fontsmall", {duration: 15});
  86. });
  87.  
  88. s1=Cookie.get("style1");
  89. s2=Cookie.get("style2");
  90.  
  91. myMorph.start(s1);
  92. myMorph.start(s2);
  93.  
  94. tekst=document.getElementById("tekst");
  95. tekst.innerHTML='style1:'+s1+' style2:'+s2;
  96.  
  97. });
  98.  
  99. </head>
  100.  
  101. <div id="container" class="widthwide">
  102.  
  103. <ul style="list-style-type: none;">
  104. <li style="display:inline;"><a href="#" id="white" name="white">white</a></li>
  105. <li style="display:inline;"><a href="#" id="grey" name="grey">grey</a></li>
  106. <li style="display:inline;"><a href="#" id="black" name="black">black</a></li>
  107. <li style="display:inline;"><a href="#" id="fontsmall" name="black">fontsmall</a></li>
  108. </ul>
  109.  
  110. </div>
  111.  
  112. <span id="tekst"></span>
  113.  
  114. </body>
  115. </html>