| [21] | 1 | Event.observe(window, 'load', watchInkFields, false); |
|---|
| 2 | Event.observe(window, 'unload', Event.unloadCache, false); |
|---|
| 3 | |
|---|
| 4 | function watchInkFields() { |
|---|
| 5 | if($('enableInk').checked == false) { toggleForm('ink'); } |
|---|
| 6 | if($('restore')) { Event.observe('restore', 'click', restoreInk, false); } |
|---|
| 7 | updateInkColors(); |
|---|
| 8 | Event.observe('enableInk', 'click', function(){ toggleForm('ink'); }, false); |
|---|
| 9 | new Form.Element.EventObserver('red', function(){ saveInkVariables($F('activeField')); ink_rgb2hex(); setSliders($F($F('activeField'))) }); |
|---|
| 10 | new Form.Element.EventObserver('green', function(){ saveInkVariables($F('activeField')); ink_rgb2hex(); setSliders($F($F('activeField'))) }); |
|---|
| 11 | new Form.Element.EventObserver('blue', function(){ saveInkVariables($F('activeField')); ink_rgb2hex(); setSliders($F($F('activeField'))) }); |
|---|
| 12 | Form.getElements('ink').each(function(item){ |
|---|
| 13 | new Form.Element.EventObserver(item, function(item){ saveInkVariables(item.id); updateInkColor(item); }); |
|---|
| 14 | Event.observe(item.id, 'keyup', function(){ saveInkVariables(item.id), updateInkColor(item.id); }, false) |
|---|
| 15 | }); |
|---|
| 16 | document.getElementsByClassName('color').each(function(item){ |
|---|
| 17 | Event.observe(item.id, 'click', function(){ toggleColorSwatch(item.id); }, false); |
|---|
| 18 | }); |
|---|
| 19 | redSlider = new Control.Slider('red_slider','red_bar', {axis: 'horizontal', onSlide:function(v){$('red').value = (v*255).toFixed(); ink_rgb2hex();}, onChange:function(){ if($F('activeField') != '') saveInkVariables($F('activeField')); }} ); |
|---|
| 20 | greenSlider = new Control.Slider('green_slider','green_bar', {axis: 'horizontal', onSlide:function(v){$('green').value = (v*255).toFixed(); ink_rgb2hex();}, onChange:function(){ if($F('activeField') != '') saveInkVariables($F('activeField')); }} ); |
|---|
| 21 | blueSlider = new Control.Slider('blue_slider','blue_bar', {axis: 'horizontal', onSlide:function(v){$('blue').value = (v*255).toFixed(); ink_rgb2hex();}, onChange:function(){ if($F('activeField') != '') saveInkVariables($F('activeField')); }} ); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | function toggleForm(form) { |
|---|
| 25 | if($('activeField').disabled == false) { |
|---|
| 26 | $(form).style.color = '#777777'; |
|---|
| 27 | Form.disable(form); |
|---|
| 28 | updateInkOption('enableInk', 'false'); |
|---|
| 29 | } else { |
|---|
| 30 | updateInkOption('enableInk', 'true'); |
|---|
| 31 | $(form).style.color = '#000000'; |
|---|
| 32 | Form.enable(form); |
|---|
| 33 | } |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | function toggleColorSwatch(element) { |
|---|
| 37 | if($F('activeField') != '') { $($F('activeField')).style.backgroundImage = 'url(JS_CANVASURI + "images/colorswatch.png")'; |
|---|
| 38 | if($F($F('activeField')) == '') { $($F('activeField')).style.backgroundColor = ''; } |
|---|
| 39 | } |
|---|
| 40 | $('activeField').value = element; |
|---|
| 41 | $(element).style.backgroundImage = 'url(JS_CANVASURI + "images/colorswatch-active.png")'; |
|---|
| 42 | if($F($F('activeField')) != '') { setSliders($F($F('activeField'))); } |
|---|
| 43 | else { resetSliders(); } |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | function setSliders(value) { |
|---|
| 47 | ink_hex2rgb(value); |
|---|
| 48 | redSlider.setValue($F('red')/255); |
|---|
| 49 | greenSlider.setValue($F('green')/255); |
|---|
| 50 | blueSlider.setValue($F('blue')/255); |
|---|
| 51 | ink_rgb2hex(); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | function resetSliders() { |
|---|
| 55 | $('red').value = '0'; |
|---|
| 56 | $('green').value = '0'; |
|---|
| 57 | $('blue').value = '0'; |
|---|
| 58 | redSlider.setValue(0); |
|---|
| 59 | greenSlider.setValue(0); |
|---|
| 60 | blueSlider.setValue(0); |
|---|
| 61 | $('colorfield').style.backgroundColor = '#000000'; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | function saveInkVariables(element) { |
|---|
| 65 | if($F(element).length == 6 || $F(element) == '') { |
|---|
| 66 | var value = escape($F(element)); |
|---|
| 67 | var string = element.split('__'); |
|---|
| 68 | var pars = 'element='+string[0]+'&definition='+string[1]+'&value='+value; |
|---|
| 69 | var url = JS_CANVASURI + 'Ink/ink-ajax.php'; |
|---|
| 70 | var myAjax = new Ajax.Request(url, |
|---|
| 71 | {method: 'get', |
|---|
| 72 | parameters: pars} |
|---|
| 73 | ); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | function updateInkColors() { |
|---|
| 78 | document.getElementsByClassName('color').each(function(item){ |
|---|
| 79 | if($F(item) != '') $(item).style.backgroundColor = '#'+$F(item); |
|---|
| 80 | }); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | function updateInkColor(item) { |
|---|
| 84 | if($F(item) != '' && ($F(item).length == 6)) { |
|---|
| 85 | $(item).style.backgroundColor = '#'+$F(item); |
|---|
| 86 | setSliders($F(item)); |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | function ink_rgb2hex() { |
|---|
| 91 | var hexindex = "0123456789ABCDEF"; |
|---|
| 92 | var R = $F('red'); |
|---|
| 93 | var G = $F('green'); |
|---|
| 94 | var B = $F('blue'); |
|---|
| 95 | R = hexindex.charAt((R - R % 16) / 16) + hexindex.charAt(R % 16); |
|---|
| 96 | G = hexindex.charAt((G - G % 16) / 16) + hexindex.charAt(G % 16); |
|---|
| 97 | B = hexindex.charAt((B - B % 16) / 16) + hexindex.charAt(B % 16); |
|---|
| 98 | $('colorfield').style.backgroundColor = '#'+R+G+B; |
|---|
| 99 | if($F('activeField') != '') { |
|---|
| 100 | $($F('activeField')).style.backgroundColor = '#'+R+G+B; |
|---|
| 101 | $($F('activeField')).value = R+G+B; |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | function ink_hex2rgb(hex) { |
|---|
| 106 | var hexindex = "0123456789ABCDEF"; |
|---|
| 107 | var R = hexindex.indexOf(hex.charAt(0).toUpperCase()) * 16 + hexindex.indexOf(hex.charAt(1).toUpperCase()); |
|---|
| 108 | var G = hexindex.indexOf(hex.charAt(2).toUpperCase()) * 16 + hexindex.indexOf(hex.charAt(3).toUpperCase()); |
|---|
| 109 | var B = hexindex.indexOf(hex.charAt(4).toUpperCase()) * 16 + hexindex.indexOf(hex.charAt(5).toUpperCase()); |
|---|
| 110 | $('red').value = R; |
|---|
| 111 | $('green').value = G; |
|---|
| 112 | $('blue').value = B; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | function updateInkOption(option, value) { |
|---|
| 116 | var pars = 'option='+option+'&value='+value; |
|---|
| 117 | var url = JS_CANVASURI + 'Ink/ink-ajax.php'; |
|---|
| 118 | var myAjax = new Ajax.Request(url, |
|---|
| 119 | {method: 'get', |
|---|
| 120 | parameters: pars} |
|---|
| 121 | ); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | function restoreInk() { |
|---|
| 125 | if(window.confirm('Are you sure you restore default values? All changes will be lost.')) { |
|---|
| 126 | var pars = 'restore=true'; |
|---|
| 127 | var url = JS_CANVASURI + 'Ink/ink-ajax.php'; |
|---|
| 128 | var myAjax = new Ajax.Request(url, |
|---|
| 129 | {method: 'get', |
|---|
| 130 | parameters: pars, |
|---|
| 131 | onComplete: function() { window.location.href=window.location.href; } |
|---|
| 132 | }); |
|---|
| 133 | } |
|---|
| 134 | } |
|---|