Subversion Repositories oidplus

Rev

Rev 144 | Go to most recent revision | View as "text/javascript" | Blame | Last modification | View Log | RSS feed

  1. g_hue_shift = null;
  2. g_sat_shift = null;
  3. g_val_shift = null;
  4. g_invcolors = null;
  5. g_hue_shift_saved = null;
  6. g_sat_shift_saved = null;
  7. g_val_shift_saved = null;
  8. g_invcolors_saved = null;
  9.  
  10. function color_reset_sliders_factory() {
  11.         $("#hshift").val(g_hue_shift = 0);
  12.         $("#sshift").val(g_sat_shift = 0);
  13.         $("#vshift").val(g_val_shift = 0);
  14.         $("#icolor").val(g_invcolors = 0);
  15.         $("#slider-hshift").slider("option", "value", g_hue_shift);
  16.         $("#slider-sshift").slider("option", "value", g_sat_shift);
  17.         $("#slider-vshift").slider("option", "value", g_val_shift);
  18.         $("#slider-icolor").slider("option", "value", g_invcolors);
  19.         test_color_theme();
  20. }
  21.  
  22. function color_reset_sliders_cfg() {
  23.         $("#hshift").val(g_hue_shift = g_hue_shift_saved);
  24.         $("#sshift").val(g_sat_shift = g_sat_shift_saved);
  25.         $("#vshift").val(g_val_shift = g_val_shift_saved);
  26.         $("#icolor").val(g_invcolors = g_invcolors_saved);
  27.         $("#slider-hshift").slider("option", "value", g_hue_shift);
  28.         $("#slider-sshift").slider("option", "value", g_sat_shift);
  29.         $("#slider-vshift").slider("option", "value", g_val_shift);
  30.         $("#slider-icolor").slider("option", "value", g_invcolors);
  31.         test_color_theme();
  32. }
  33.  
  34. function setup_color_sliders() {
  35.         $("#slider-hshift").slider({
  36.                 value: g_hue_shift,
  37.                 min:   -360,
  38.                 max:   360,
  39.                 slide: function(event, ui) {
  40.                         $("#hshift").val(ui.value);
  41.                 }
  42.         });
  43.         $("#hshift").val($("#slider-hshift").slider("value"));
  44.  
  45.         $("#slider-sshift").slider({
  46.                 value: g_sat_shift,
  47.                 min:   -100,
  48.                 max:   100,
  49.                 slide: function(event, ui) {
  50.                         $("#sshift").val(ui.value);
  51.                 }
  52.         });
  53.         $("#sshift").val($("#slider-sshift").slider("value"));
  54.  
  55.         $("#slider-vshift").slider({
  56.                 value: g_val_shift,
  57.                 min:   -100,
  58.                 max:   100,
  59.                 slide: function(event, ui) {
  60.                         $("#vshift").val(ui.value);
  61.                 }
  62.         });
  63.         $("#vshift").val($("#slider-vshift").slider("value"));
  64.  
  65.         /* ToDo: Checkbox instead */
  66.         $("#slider-icolor").slider({
  67.                 value: g_invcolors,
  68.                 min:   0,
  69.                 max:   1,
  70.                 slide: function(event, ui) {
  71.                         $("#icolor").val(ui.value);
  72.                 }
  73.         });
  74.         $("#icolor").val($("#slider-icolor").slider("value"));
  75. }
  76.  
  77. function test_color_theme() {
  78.         g_hue_shift = $("#hshift").val();
  79.         g_sat_shift = $("#sshift").val();
  80.         g_val_shift = $("#vshift").val();
  81.         g_invcolors = $("#icolor").val();
  82.         changeCSS('oidplus.min.css.php?invert='+$("#icolor").val()+'&h_shift='+$("#hshift").val()/360+'&s_shift='+$("#sshift" ).val()/100+'&v_shift='+$("#vshift" ).val()/100, 0);
  83. }
  84.  
  85. function changeCSS(cssFile, cssLinkIndex) {
  86.         var oldlink = document.getElementsByTagName("link").item(cssLinkIndex);
  87.  
  88.         var newlink = document.createElement("link");
  89.         newlink.setAttribute("rel", "stylesheet");
  90.         newlink.setAttribute("type", "text/css");
  91.         newlink.setAttribute("href", cssFile);
  92.  
  93.         document.getElementsByTagName("head").item(0).replaceChild(newlink, oldlink);
  94. }
  95.  
  96. function crudActionColorUpdate(name) {
  97.         if(!window.confirm("Are you sure that you want to permanently change the color? Please make sure you have tested the colors first, because if the contrast is too extreme, you might not be able to see the controls anymore, in order to correct the colors.")) return false;
  98.  
  99.         $.ajax({
  100.                 url:"ajax.php",
  101.                 method:"POST",
  102.                 data: {
  103.                         action:"color_update",
  104.                         hue_shift:document.getElementById('hshift').value,
  105.                         sat_shift:document.getElementById('sshift').value,
  106.                         val_shift:document.getElementById('vshift').value,
  107.                         invcolors:document.getElementById('icolor').value,
  108.                 },
  109.                 error:function(jqXHR, textStatus, errorThrown) {
  110.                         alert("Error: " + errorThrown);
  111.                 },
  112.                 success:function(data) {
  113.                         if ("error" in data) {
  114.                                 alert("Error: " + data.error);
  115.                         } else if (data.status == 0) {
  116.                                 g_hue_shift_saved = g_hue_shift;
  117.                                 g_sat_shift_saved = g_sat_shift;
  118.                                 g_val_shift_saved = g_val_shift;
  119.                                 g_invcolors_saved = g_invcolors;
  120.                                 test_color_theme(); // apply visually
  121.                                 alert("Update OK");
  122.                         } else {
  123.                                 alert("Error: " + data);
  124.                         }
  125.                 }
  126.         });
  127. }
  128.  
  129.