PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/js/color_functions.php

http://wowroster.googlecode.com/
PHP | 748 lines | 623 code | 95 blank | 30 comment | 106 complexity | ee042999b56c7c972d91b3d50c89ef7f MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * WoWRoster.net WoWRoster
  4. *
  5. * Color pallet javascript file
  6. *
  7. * @copyright 2005 dhtmlgoodies.com
  8. * @license http://www.dhtmlgoodies.com/index.html?page=termsOfUse dhtmlgoodies.com License
  9. * @version SVN: $Id: color_functions.php 2346 2011-09-10 09:10:23Z c.treyce@gmail.com $
  10. * @link http://www.dhtmlgoodies.com
  11. * @since File available since Release 1.8.0
  12. */
  13. header('content-type: application/x-javascript');
  14. $path = ( isset($_GET['path']) ? $_GET['path'] : 'templates/default' )
  15. ?>/************************************************************************************************************
  16. (C) www.dhtmlgoodies.com, October 2005
  17. This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.
  18. Terms of use:
  19. You are free to use this script as long as the copyright message is kept intact. However, you may not
  20. redistribute, sell or repost it without our permission.
  21. Thank you!
  22. www.dhtmlgoodies.com
  23. Alf Magne Kalleland
  24. ************************************************************************************************************/
  25. var MSIE = navigator.userAgent.indexOf('MSIE') >= 0 ? true : false;
  26. var navigatorVersion = navigator.appVersion.replace(/.*?MSIE (\d\.\d).*/g, '$1') / 1;
  27. var form_widget_path = '<?php echo $path; ?>';
  28. var form_widget_close = form_widget_path + '/images/color/close.gif';
  29. var form_widget_amount_slider_handle = form_widget_path + '/images/color/slider_handle.gif';
  30. var form_widget_tab_right_active = form_widget_path + '/images/color/tab_right_active.gif';
  31. var form_widget_tab_right_inactive = form_widget_path + '/images/color/tab_right_inactive.gif';
  32. var slider_handle_image_obj = false;
  33. var sliderObjectArray = new Array();
  34. var slider_counter = 0;
  35. var slideInProgress = false;
  36. var handle_start_x;
  37. var event_start_x;
  38. var currentSliderIndex;
  39. var iframe = document.getElementById('DivShim');
  40. function form_widget_cancel_event() {
  41. return false;
  42. }
  43. function getImageSliderHeight() {
  44. if (!slider_handle_image_obj) {
  45. slider_handle_image_obj = new Image();
  46. slider_handle_image_obj.src = form_widget_amount_slider_handle;
  47. }
  48. if (slider_handle_image_obj.width > 0) {
  49. return;
  50. } else {
  51. setTimeout('getImageSliderHeight()', 50);
  52. }
  53. }
  54. function positionSliderImage(e, theIndex, inputObj) {
  55. if (this) inputObj = this;
  56. if (!theIndex) theIndex = inputObj.getAttribute('sliderIndex');
  57. var handleImg = document.getElementById('slider_handle' + theIndex);
  58. var ratio = sliderObjectArray[theIndex]['width'] / (sliderObjectArray[theIndex]['max'] - sliderObjectArray[theIndex]['min']);
  59. var currentValue = sliderObjectArray[theIndex]['formTarget'].value - sliderObjectArray[theIndex]['min'];
  60. handleImg.style.left = currentValue * ratio + 'px';
  61. setColorByRGB();
  62. }
  63. function adjustFormValue(theIndex) {
  64. var handleImg = document.getElementById('slider_handle' + theIndex);
  65. var ratio = sliderObjectArray[theIndex]['width'] / (sliderObjectArray[theIndex]['max'] - sliderObjectArray[theIndex]['min']);
  66. var currentPos = handleImg.style.left.replace('px', '');
  67. sliderObjectArray[theIndex]['formTarget'].value = Math.round(currentPos / ratio) + sliderObjectArray[theIndex]['min'];
  68. }
  69. function initMoveSlider(e) {
  70. if (document.all) e = event;
  71. slideInProgress = true;
  72. event_start_x = e.clientX;
  73. handle_start_x = this.style.left.replace('px', '');
  74. currentSliderIndex = this.id.replace(/[^\d]/g, '');
  75. return false;
  76. }
  77. function startMoveSlider(e) {
  78. if (document.all) e = event;
  79. if (!slideInProgress) return;
  80. var leftPos = handle_start_x / 1 + e.clientX / 1 - event_start_x;
  81. if (leftPos < 0) leftPos = 0;
  82. if (leftPos / 1 > sliderObjectArray[currentSliderIndex]['width']) leftPos = sliderObjectArray[currentSliderIndex]['width'];
  83. document.getElementById('slider_handle' + currentSliderIndex).style.left = leftPos + 'px';
  84. adjustFormValue(currentSliderIndex);
  85. if (sliderObjectArray[currentSliderIndex]['onchangeAction']) eval(sliderObjectArray[currentSliderIndex]['onchangeAction']);
  86. }
  87. function stopMoveSlider() {
  88. slideInProgress = false;
  89. }
  90. function form_widget_amount_slider(targetElId, formTarget, width, min, max, onchangeAction) {
  91. if (!slider_handle_image_obj) getImageSliderHeight();
  92. slider_counter = slider_counter + 1;
  93. sliderObjectArray[slider_counter] = new Array();
  94. sliderObjectArray[slider_counter] = {
  95. "width": width - slider_handle_image_obj.width,
  96. "min": min,
  97. "max": max,
  98. "formTarget": formTarget,
  99. "onchangeAction": onchangeAction
  100. };
  101. formTarget.setAttribute('sliderIndex', slider_counter);
  102. formTarget.onchange = positionSliderImage;
  103. var parentObj = document.createElement('DIV');
  104. parentObj.style.width = width + 'px';
  105. parentObj.style.height = '12px'; // The height of the image
  106. parentObj.style.position = 'relative';
  107. parentObj.id = 'slider_container' + slider_counter;
  108. document.getElementById(targetElId).appendChild(parentObj);
  109. var obj = document.createElement('DIV');
  110. obj.className = 'form_widget_amount_slider';
  111. obj.innerHTML = '<span></span>';
  112. obj.style.width = width + 'px';
  113. obj.id = 'slider_slider' + slider_counter;
  114. obj.style.position = 'absolute';
  115. obj.style.bottom = '0px';
  116. parentObj.appendChild(obj);
  117. var handleImg = document.createElement('IMG');
  118. handleImg.style.position = 'absolute';
  119. handleImg.style.cursor = 'pointer';
  120. handleImg.style.left = '0px';
  121. handleImg.style.zIndex = 5;
  122. handleImg.src = slider_handle_image_obj.src;
  123. handleImg.id = 'slider_handle' + slider_counter;
  124. handleImg.onmousedown = initMoveSlider;
  125. if (document.body.onmouseup) {
  126. if (document.body.onmouseup.toString().indexOf('stopMoveSlider') == -1) alert('You already have an onmouseup event assigned to the body tag');
  127. } else {
  128. document.body.onmouseup = stopMoveSlider;
  129. document.body.onmousemove = startMoveSlider;
  130. }
  131. handleImg.ondragstart = form_widget_cancel_event;
  132. parentObj.appendChild(handleImg);
  133. positionSliderImage(false, slider_counter);
  134. }
  135. var namedColors = new Array('AliceBlue', 'AntiqueWhite', 'Aqua', 'Aquamarine', 'Azure', 'Beige', 'Bisque', 'Black', 'BlanchedAlmond', 'Blue', 'BlueViolet', 'Brown', 'BurlyWood', 'CadetBlue', 'Chartreuse', 'Chocolate', 'Coral', 'CornflowerBlue', 'Cornsilk', 'Crimson', 'Cyan', 'DarkBlue', 'DarkCyan', 'DarkGoldenRod', 'DarkGray', 'DarkGreen', 'DarkKhaki', 'DarkMagenta', 'DarkOliveGreen', 'DarkOrchid', 'DarkRed', 'DarkSalmon', 'DarkSeaGreen', 'DarkSlateBlue', 'DarkSlateGray', 'DarkTurquoise', 'DarkViolet', 'Darkorange', 'DeepPink', 'DeepSkyBlue', 'DimGray', 'DodgerBlue', 'Feldspar', 'FireBrick', 'FloralWhite', 'ForestGreen', 'Fuchsia', 'Gainsboro', 'GhostWhite', 'Gold', 'GoldenRod', 'Gray', 'Green', 'GreenYellow', 'HoneyDew', 'HotPink', 'IndianRed', 'Indigo', 'Ivory', 'Khaki', 'Lavender', 'LavenderBlush', 'LawnGreen', 'LemonChiffon', 'LightBlue', 'LightCoral', 'LightCyan', 'LightGoldenRodYellow', 'LightGreen', 'LightGrey', 'LightPink', 'LightSalmon', 'LightSeaGreen', 'LightSkyBlue', 'LightSlateBlue', 'LightSlateGray', 'LightSteelBlue', 'LightYellow', 'Lime', 'LimeGreen', 'Linen', 'Magenta', 'Maroon', 'Medium Purple', 'MediumAquaMarine', 'MediumBlue', 'MediumOrchid', 'MediumPurple', 'MediumSeaGreen', 'MediumSlateBlue', 'MediumSpringGreen', 'MediumTurquoise', 'MediumVioletRed', 'MidnightBlue', 'MintCream', 'MistyRose', 'Moccasin', 'NavajoWhite', 'Navy', 'OldLace', 'Olive', 'OliveDrab', 'Orange', 'OrangeRed', 'Orchid', 'Pale Violet Red', 'PaleGoldenRod', 'PaleGreen', 'PaleTurquoise', 'PaleVioletRed', 'PapayaWhip', 'PeachPuff', 'Peru', 'Pink', 'Plum', 'PowderBlue', 'Purple', 'Red', 'RosyBrown', 'RoyalBlue', 'SaddleBrown', 'Salmon', 'SandyBrown', 'SeaGreen', 'SeaShell', 'Sienna', 'Silver', 'SkyBlue', 'SlateBlue', 'SlateGray', 'Snow', 'SpringGreen', 'SteelBlue', 'Tan', 'Teal', 'Thistle', 'Tomato', 'Turquoise', 'Violet', 'VioletRed', 'Wheat', 'White', 'WhiteSmoke', 'Yellow', 'YellowGreen');
  136. var namedColorRGB = new Array('#F0F8FF', '#FAEBD7', '#00FFFF', '#7FFFD4', '#F0FFFF', '#F5F5DC', '#FFE4C4', '#000000', '#FFEBCD', '#0000FF', '#8A2BE2', '#A52A2A', '#DEB887', '#5F9EA0', '#7FFF00', '#D2691E', '#FF7F50', '#6495ED', '#FFF8DC', '#DC143C', '#00FFFF', '#00008B', '#008B8B', '#B8860B', '#A9A9A9', '#006400', '#BDB76B', '#8B008B', '#556B2F', '#9932CC', '#8B0000', '#E9967A', '#8FBC8F', '#483D8B', '#2F4F4F', '#00CED1', '#9400D3', '#FF8C00', '#FF1493', '#00BFFF', '#696969', '#1E90FF', '#D19275', '#B22222', '#FFFAF0', '#228B22', '#FF00FF', '#DCDCDC', '#F8F8FF', '#FFD700', '#DAA520', '#808080', '#008000', '#ADFF2F', '#F0FFF0', '#FF69B4', '#CD5C5C', '#4B0082', '#FFFFF0', '#F0E68C', '#E6E6FA', '#FFF0F5', '#7CFC00', '#FFFACD', '#ADD8E6', '#F08080', '#E0FFFF', '#FAFAD2', '#90EE90', '#D3D3D3', '#FFB6C1', '#FFA07A', '#20B2AA', '#87CEFA', '#8470FF', '#778899', '#B0C4DE', '#FFFFE0', '#00FF00', '#32CD32', '#FAF0E6', '#FF00FF', '#800000', '#9370DB', '#66CDAA', '#0000CD', '#BA55D3', '#9370D8', '#3CB371', '#7B68EE', '#00FA9A', '#48D1CC', '#C71585', '#191970', '#F5FFFA', '#FFE4E1', '#FFE4B5', '#FFDEAD', '#000080', '#FDF5E6', '#808000', '#6B8E23', '#FFA500', '#FF4500', '#DA70D6', '#DB7093', '#EEE8AA', '#98FB98', '#AFEEEE', '#D87093', '#FFEFD5', '#FFDAB9', '#CD853F', '#FFC0CB', '#DDA0DD', '#B0E0E6', '#800080', '#FF0000', '#BC8F8F', '#4169E1', '#8B4513', '#FA8072', '#F4A460', '#2E8B57', '#FFF5EE', '#A0522D', '#C0C0C0', '#87CEEB', '#6A5ACD', '#708090', '#FFFAFA', '#00FF7F', '#4682B4', '#D2B48C', '#008080', '#D8BFD8', '#FF6347', '#40E0D0', '#EE82EE', '#D02090', '#F5DEB3', '#FFFFFF', '#F5F5F5', '#FFFF00', '#9ACD32');
  137. var color_picker_div = false;
  138. var color_picker_active_tab = false;
  139. var color_picker_form_field = false;
  140. var color_picker_active_input = false;
  141. function baseConverter(number, ob, nb) {
  142. number = number + "";
  143. number = number.toUpperCase();
  144. var list = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  145. var dec = 0;
  146. for (var i = 0; i <= number.length; i++)
  147. dec += (list.indexOf(number.charAt(i))) * (Math.pow(ob, (number.length - i - 1)));
  148. number = "";
  149. var magnitude = Math.floor((Math.log(dec)) / (Math.log(nb)));
  150. for (var i = magnitude; i >= 0; i--) {
  151. var amount = Math.floor(dec / Math.pow(nb, i));
  152. number = number + list.charAt(amount);
  153. dec -= amount * (Math.pow(nb, i));
  154. }
  155. if (number.length == 0) number = 0;
  156. return number;
  157. }
  158. function colorPickerGetTopPos(inputObj) {
  159. var returnValue = inputObj.offsetTop;
  160. while ((inputObj = inputObj.offsetParent) != null)
  161. returnValue += inputObj.offsetTop;
  162. return returnValue;
  163. }
  164. function colorPickerGetLeftPos(inputObj) {
  165. var returnValue = inputObj.offsetLeft;
  166. while ((inputObj = inputObj.offsetParent) != null)
  167. returnValue += inputObj.offsetLeft;
  168. return returnValue;
  169. }
  170. function cancelColorPickerEvent() {
  171. return false;
  172. }
  173. function showHideColorOptions(e, inputObj) {
  174. var thisObj = this;
  175. if (inputObj) {
  176. var parentNode = inputObj.parentNode;
  177. thisObj = inputObj;
  178. } else {
  179. var parentNode = this.parentNode;
  180. }
  181. var activeColorDiv = false;
  182. var subDiv = parentNode.getElementsByTagName('DIV')[0];
  183. counter = 0;
  184. var initZIndex = 10;
  185. var contentDiv = document.getElementById('color_picker_content').getElementsByTagName('DIV')[0];
  186. do {
  187. if (subDiv.tagName == 'DIV' && subDiv.className != 'colorPickerCloseButton') {
  188. if (subDiv == thisObj) {
  189. thisObj.className = 'colorPickerTab_active';
  190. thisObj.style.zIndex = 50;
  191. var img = thisObj.getElementsByTagName('IMG')[0];
  192. img.src = form_widget_tab_right_active;
  193. img.src = img.src.replace(/inactive/, 'active');
  194. contentDiv.style.display = 'block';
  195. activeColorDiv = contentDiv;
  196. iframe.style.height = color_picker_div.offsetHeight;
  197. } else {
  198. subDiv.className = 'colorPickerTab_inactive';
  199. var img = subDiv.getElementsByTagName('IMG')[0];
  200. img.src = form_widget_tab_right_inactive;
  201. if (activeColorDiv) subDiv.style.zIndex = initZIndex - counter;
  202. else
  203. subDiv.style.zIndex = counter;
  204. contentDiv.style.display = 'none';
  205. iframe.style.height = color_picker_div.offsetHeight;
  206. }
  207. counter++;
  208. }
  209. subDiv = subDiv.nextSibling;
  210. if (contentDiv.nextSibling) contentDiv = contentDiv.nextSibling;
  211. }
  212. while (subDiv);
  213. document.getElementById('colorPicker_statusBarTxt').innerHTML = '&nbsp;';
  214. }
  215. function createColorPickerTopRow(inputObj) {
  216. var tabs = ['RGB', 'Named colors', 'Color slider'];
  217. var tabWidths = [37, 90, 70];
  218. var div = document.createElement('DIV');
  219. div.className = 'colorPicker_topRow';
  220. inputObj.appendChild(div);
  221. var currentWidth = 0;
  222. for (var no = 0; no < tabs.length; no++) {
  223. var tabDiv = document.createElement('DIV');
  224. tabDiv.onselectstart = cancelColorPickerEvent;
  225. tabDiv.ondragstart = cancelColorPickerEvent;
  226. if (no == 0) {
  227. suffix = 'active';
  228. color_picker_active_tab = this;
  229. } else {
  230. suffix = 'inactive';
  231. }
  232. tabDiv.id = 'colorPickerTab' + no;
  233. tabDiv.onclick = showHideColorOptions;
  234. if (no == 0) tabDiv.style.zIndex = 50;
  235. else
  236. tabDiv.style.zIndex = 1 + (tabs.length - no);
  237. tabDiv.style.left = currentWidth + 'px';
  238. tabDiv.style.position = 'absolute';
  239. tabDiv.className = 'colorPickerTab_' + suffix;
  240. var tabSpan = document.createElement('SPAN');
  241. tabSpan.innerHTML = tabs[no];
  242. tabDiv.appendChild(tabSpan);
  243. var tabImg = document.createElement('IMG');
  244. tabImg.src = form_widget_path + '/images/color/tab_right_' + suffix + '.gif';
  245. tabDiv.appendChild(tabImg);
  246. div.appendChild(tabDiv);
  247. if (navigatorVersion < 6 && MSIE) /* Lower IE version fix */
  248. {
  249. tabSpan.style.position = 'relative';
  250. tabImg.style.position = 'relative';
  251. tabImg.style.left = '-3px';
  252. tabDiv.style.cursor = 'hand';
  253. }
  254. currentWidth = currentWidth + tabWidths[no];
  255. }
  256. var closeImg = document.createElement('IMG');
  257. closeImg.className = 'colorPickerCloseButton';
  258. closeImg.style.zIndex = 5;
  259. closeImg.src = form_widget_close;
  260. closeImg.onclick = closeColorPicker;
  261. div.appendChild(closeImg);
  262. }
  263. function closeColorPicker() {
  264. color_picker_div.style.display = 'none';
  265. iframe.style.display = 'none';
  266. }
  267. function createWebColors(inputObj) {
  268. var webColorDiv = document.createElement('DIV');
  269. webColorDiv.style.paddingTop = '1px';
  270. inputObj.appendChild(webColorDiv);
  271. for (var r = 15; r >= 0; r -= 3) {
  272. for (var g = 0; g <= 15; g += 3) {
  273. for (var b = 0; b <= 15; b += 3) {
  274. var red = baseConverter(r, 10, 16) + '';
  275. var green = baseConverter(g, 10, 16) + '';
  276. var blue = baseConverter(b, 10, 16) + '';
  277. var color = '#' + red + red + green + green + blue + blue;
  278. var div = document.createElement('DIV');
  279. div.style.backgroundColor = color;
  280. div.innerHTML = '<span></span>';
  281. div.className = 'colorSquare';
  282. div.title = color;
  283. div.onclick = chooseColor;
  284. div.setAttribute('rgbColor', color);
  285. div.onmouseover = colorPickerShowStatusBarText;
  286. div.onmouseout = colorPickerHideStatusBarText;
  287. webColorDiv.appendChild(div);
  288. }
  289. }
  290. }
  291. }
  292. function createNamedColors(inputObj) {
  293. var namedColorDiv = document.createElement('DIV');
  294. namedColorDiv.style.paddingTop = '1px';
  295. namedColorDiv.style.display = 'none';
  296. inputObj.appendChild(namedColorDiv);
  297. for (var no = 0; no < namedColors.length; no++) {
  298. var color = namedColorRGB[no];
  299. var div = document.createElement('DIV');
  300. div.style.backgroundColor = color;
  301. div.innerHTML = '<span></span>';
  302. div.className = 'colorSquare';
  303. div.title = namedColors[no];
  304. div.onclick = chooseColor;
  305. div.onmouseover = colorPickerShowStatusBarText;
  306. div.onmouseout = colorPickerHideStatusBarText;
  307. div.setAttribute('rgbColor', color);
  308. namedColorDiv.appendChild(div);
  309. }
  310. }
  311. function colorPickerHideStatusBarText() {
  312. document.getElementById('colorPicker_statusBarTxt').innerHTML = '&nbsp;';
  313. }
  314. function colorPickerShowStatusBarText() {
  315. var txt = this.getAttribute('rgbColor');
  316. if (this.title.indexOf('#') < 0) txt = txt + " (" + this.title + ")";
  317. document.getElementById('colorPicker_statusBarTxt').innerHTML = txt;
  318. }
  319. function createAllColorDiv(inputObj) {
  320. var allColorDiv = document.createElement('DIV');
  321. allColorDiv.style.display = 'none';
  322. allColorDiv.className = 'js_color_picker_allColorDiv';
  323. allColorDiv.style.paddingLeft = '3px';
  324. allColorDiv.style.paddingTop = '5px';
  325. allColorDiv.style.paddingBottom = '5px';
  326. inputObj.appendChild(allColorDiv);
  327. var labelDiv = document.createElement('DIV');
  328. labelDiv.className = 'colorSliderLabel';
  329. labelDiv.innerHTML = 'R';
  330. allColorDiv.appendChild(labelDiv);
  331. var innerDiv = document.createElement('DIV');
  332. innerDiv.className = 'colorSlider';
  333. innerDiv.id = 'sliderRedColor';
  334. allColorDiv.appendChild(innerDiv);
  335. var innerDivInput = document.createElement('DIV');
  336. innerDivInput.className = 'colorInput';
  337. var input = document.createElement('INPUT');
  338. input.id = 'js_color_picker_red_color';
  339. input.maxlength = 3;
  340. input.style.width = '48px';
  341. input.style.fontSize = '11px';
  342. input.name = 'redColor';
  343. input.value = 0;
  344. innerDivInput.appendChild(input);
  345. allColorDiv.appendChild(innerDivInput);
  346. var labelDiv = document.createElement('DIV');
  347. labelDiv.className = 'colorSliderLabel';
  348. labelDiv.innerHTML = 'G';
  349. allColorDiv.appendChild(labelDiv);
  350. var innerDiv = document.createElement('DIV');
  351. innerDiv.className = 'colorSlider';
  352. innerDiv.id = 'sliderGreenColor';
  353. allColorDiv.appendChild(innerDiv);
  354. var innerDivInput = document.createElement('DIV');
  355. innerDivInput.className = 'colorInput';
  356. var input = document.createElement('INPUT');
  357. input.id = 'js_color_picker_green_color';
  358. input.maxlength = 3;
  359. input.style.width = '48px';
  360. input.style.fontSize = '11px';
  361. input.name = 'GreenColor';
  362. input.value = 0;
  363. innerDivInput.appendChild(input);
  364. allColorDiv.appendChild(innerDivInput);
  365. var labelDiv = document.createElement('DIV');
  366. labelDiv.className = 'colorSliderLabel';
  367. labelDiv.innerHTML = 'B';
  368. allColorDiv.appendChild(labelDiv);
  369. var innerDiv = document.createElement('DIV');
  370. innerDiv.className = 'colorSlider';
  371. innerDiv.id = 'sliderBlueColor';
  372. allColorDiv.appendChild(innerDiv);
  373. var innerDivInput = document.createElement('DIV');
  374. innerDivInput.className = 'colorInput';
  375. var input = document.createElement('INPUT');
  376. input.id = 'js_color_picker_blue_color';
  377. input.maxlength = 3;
  378. input.style.width = '48px';
  379. input.style.fontSize = '11px';
  380. input.name = 'BlueColor';
  381. input.value = 0;
  382. innerDivInput.appendChild(input);
  383. allColorDiv.appendChild(innerDivInput);
  384. var colorPreview = document.createElement('DIV');
  385. colorPreview.className = 'colorPreviewDiv';
  386. colorPreview.id = 'colorPreview';
  387. colorPreview.style.backgroundColor = '#000000';
  388. colorPreview.innerHTML = '<span></span>';
  389. colorPreview.title = 'Click on me to assign color';
  390. allColorDiv.appendChild(colorPreview);
  391. colorPreview.onclick = chooseColorSlider;
  392. var colorCodeDiv = document.createElement('DIV');
  393. colorCodeDiv.className = 'colorCodeDiv';
  394. var input = document.createElement('INPUT');
  395. input.id = 'js_color_picker_color_code';
  396. colorCodeDiv.appendChild(input);
  397. input.maxLength = 7;
  398. input.style.fontSize = '11px';
  399. input.style.width = '55px';
  400. input.value = '#000000';
  401. input.onchange = setPreviewColorFromTxt;
  402. input.onblur = setPreviewColorFromTxt;
  403. allColorDiv.appendChild(colorCodeDiv);
  404. var clearingDiv = document.createElement('DIV');
  405. clearingDiv.style.clear = 'both';
  406. allColorDiv.appendChild(clearingDiv);
  407. form_widget_amount_slider('sliderRedColor', document.getElementById('js_color_picker_red_color'), 170, 0, 255, "setColorByRGB()");
  408. form_widget_amount_slider('sliderGreenColor', document.getElementById('js_color_picker_green_color'), 170, 0, 255, "setColorByRGB()");
  409. form_widget_amount_slider('sliderBlueColor', document.getElementById('js_color_picker_blue_color'), 170, 0, 255, "setColorByRGB()");
  410. }
  411. function setPreviewColorFromTxt() {
  412. if (this.value.match(/\#[0-6A-F]{6}/g)) {
  413. document.getElementById('colorPreview').style.backgroundColor = this.value;
  414. var r = this.value.substr(1, 2);
  415. var g = this.value.substr(3, 2);
  416. var b = this.value.substr(5, 2);
  417. document.getElementById('js_color_picker_red_color').value = baseConverter(r, 16, 10);
  418. document.getElementById('js_color_picker_green_color').value = baseConverter(g, 16, 10);
  419. document.getElementById('js_color_picker_blue_color').value = baseConverter(b, 16, 10);
  420. positionSliderImage(false, 1, document.getElementById('js_color_picker_red_color'));
  421. positionSliderImage(false, 2, document.getElementById('js_color_picker_green_color'));
  422. positionSliderImage(false, 3, document.getElementById('js_color_picker_blue_color'));
  423. }
  424. }
  425. function chooseColor() {
  426. color_picker_form_field.value = this.getAttribute('rgbColor');
  427. color_picker_form_field.style.backgroundColor = this.getAttribute('rgbColor');
  428. color_picker_div.style.display = 'none';
  429. iframe.style.display = 'none';
  430. }
  431. function createStatusBar(inputObj) {
  432. var div = document.createElement('DIV');
  433. div.className = 'colorPicker_statusBar';
  434. var innerSpan = document.createElement('SPAN');
  435. innerSpan.id = 'colorPicker_statusBarTxt';
  436. div.appendChild(innerSpan);
  437. inputObj.appendChild(div);
  438. }
  439. function chooseColorSlider() {
  440. color_picker_form_field.value = document.getElementById('js_color_picker_color_code').value;
  441. color_picker_form_field.style.backgroundColor = document.getElementById('js_color_picker_color_code').value;
  442. color_picker_div.style.display = 'none';
  443. iframe.style.display = 'none';
  444. }
  445. function showColorPicker(inputObj, formField) {
  446. if (!color_picker_div) {
  447. color_picker_div = document.createElement('DIV');
  448. color_picker_div.id = 'colorPicker';
  449. color_picker_div.style.zIndex = 40;
  450. color_picker_div.style.display = 'none';
  451. document.body.appendChild(color_picker_div);
  452. createColorPickerTopRow(color_picker_div);
  453. var contentDiv = document.createElement('DIV');
  454. contentDiv.id = 'color_picker_content';
  455. color_picker_div.appendChild(contentDiv);
  456. createWebColors(contentDiv);
  457. createNamedColors(contentDiv);
  458. createAllColorDiv(contentDiv);
  459. createStatusBar(color_picker_div);
  460. }
  461. if (!iframe) {
  462. iframe = document.createElement('IFRAME');
  463. iframe.id = 'DivShim';
  464. iframe.frameBorder = 0;
  465. iframe.style.position = 'absolute'
  466. //iframe.style.top='0px';
  467. //iframe.style.left='0px';
  468. iframe.style.display = 'none';
  469. document.body.appendChild(iframe);
  470. }
  471. if (color_picker_div.style.display == 'none' || color_picker_active_input != inputObj) color_picker_div.style.display = 'block';
  472. else color_picker_div.style.display = 'none';
  473. color_picker_div.style.left = colorPickerGetLeftPos(inputObj) + 30 + 'px';
  474. color_picker_div.style.top = colorPickerGetTopPos(inputObj) + inputObj.offsetHeight - 90 + 'px';
  475. color_picker_form_field = formField;
  476. color_picker_active_input = inputObj;
  477. if (color_picker_div.style.display == 'block') {
  478. iframe.style.width = color_picker_div.offsetWidth;
  479. iframe.style.height = color_picker_div.offsetHeight;
  480. iframe.style.top = color_picker_div.style.top;
  481. iframe.style.left = color_picker_div.style.left;
  482. iframe.style.zIndex = color_picker_div.style.zIndex - 1;
  483. iframe.style.display = 'block';
  484. } else {
  485. iframe.style.display = 'none';
  486. }
  487. }
  488. function setColorByRGB() {
  489. var formObj = document.forms[0];
  490. var r = document.getElementById('js_color_picker_red_color').value.replace(/[^\d]/, '');
  491. var g = document.getElementById('js_color_picker_green_color').value.replace(/[^\d]/, '');
  492. var b = document.getElementById('js_color_picker_blue_color').value.replace(/[^\d]/, '');
  493. if (r / 1 > 255) r = 255;
  494. if (g / 1 > 255) g = 255;
  495. if (b / 1 > 255) b = 255;
  496. r = baseConverter(r, 10, 16) + '';
  497. g = baseConverter(g, 10, 16) + '';
  498. b = baseConverter(b, 10, 16) + '';
  499. if (r.length == 1) r = '0' + r;
  500. if (g.length == 1) g = '0' + g;
  501. if (b.length == 1) b = '0' + b;
  502. document.getElementById('colorPreview').style.backgroundColor = '#' + r + g + b;
  503. document.getElementById('js_color_picker_color_code').value = '#' + r + g + b;
  504. }
  505. function baseConverter(number, ob, nb) {
  506. number = number + "";
  507. number = number.toUpperCase();
  508. var list = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  509. var dec = 0;
  510. for (var i = 0; i <= number.length; i++) {
  511. dec += (list.indexOf(number.charAt(i))) * (Math.pow(ob, (number.length - i - 1)));
  512. }
  513. number = "";
  514. var magnitude = Math.floor((Math.log(dec)) / (Math.log(nb)));
  515. for (var i = magnitude; i >= 0; i--) {
  516. var amount = Math.floor(dec / Math.pow(nb, i));
  517. number = number + list.charAt(amount);
  518. dec -= amount * (Math.pow(nb, i));
  519. }
  520. if (number.length == 0) number = 0;
  521. return number;
  522. }
  523. // Converts a RGB color to HSV
  524. function toHSV(rgbColor) {
  525. rgbColor = rgbColor.replace('#', '');
  526. red = baseConverter(rgbColor.substr(0, 2), 16, 10);
  527. green = baseConverter(rgbColor.substr(2, 2), 16, 10);
  528. blue = baseConverter(rgbColor.substr(4, 2), 16, 10);
  529. if (red.length == 0) red = 0;
  530. if (green.length == 0) green = 0;
  531. if (blue.length == 0) blue = 0;
  532. red = red / 255;
  533. green = green / 255;
  534. blue = blue / 255;
  535. maxValue = Math.max(red, green, blue);
  536. minValue = Math.min(red, green, blue);
  537. var hue = 0;
  538. if (maxValue == minValue) {
  539. hue = 0;
  540. saturation = 0;
  541. } else {
  542. if (red == maxValue) {
  543. hue = (green - blue) / (maxValue - minValue) / 1;
  544. } else if (green == maxValue) {
  545. hue = 2 + (blue - red) / 1 / (maxValue - minValue) / 1;
  546. } else if (blue == maxValue) {
  547. hue = 4 + (red - green) / (maxValue - minValue) / 1;
  548. }
  549. saturation = (maxValue - minValue) / maxValue;
  550. }
  551. hue = hue * 60;
  552. valueBrightness = maxValue;
  553. if (valueBrightness / 1 < 0.5) {
  554. //saturation = (maxValue - minValue) / (maxValue + minValue);
  555. }
  556. if (valueBrightness / 1 >= 0.5) {
  557. //saturation = (maxValue - minValue) / (2 - maxValue - minValue);
  558. }
  559. returnArray = [hue, saturation, valueBrightness];
  560. return returnArray;
  561. }
  562. function toRgb(hue, saturation, valueBrightness) {
  563. Hi = Math.floor(hue / 60);
  564. if (hue == 360) Hi = 0;
  565. f = hue / 60 - Hi;
  566. p = (valueBrightness * (1 - saturation)).toPrecision(2);
  567. q = (valueBrightness * (1 - (f * saturation))).toPrecision(2);
  568. t = (valueBrightness * (1 - ((1 - f) * saturation))).toPrecision(2);
  569. switch (Hi) {
  570. case 0:
  571. red = valueBrightness;
  572. green = t;
  573. blue = p;
  574. break;
  575. case 1:
  576. red = q;
  577. green = valueBrightness;
  578. blue = p;
  579. break;
  580. case 2:
  581. red = q;
  582. green = valueBrightness;
  583. blue = t;
  584. break;
  585. case 3:
  586. red = p;
  587. green = q;;
  588. blue = valueBrightness;
  589. break;
  590. case 4:
  591. red = t;
  592. green = p;
  593. blue = valueBrightness;
  594. break;
  595. case 5:
  596. red = valueBrightness;
  597. green = p;
  598. blue = q;
  599. break;
  600. }
  601. if (saturation == 0) {
  602. red = valueBrightness;
  603. green = valueBrightness;
  604. blue = valueBrightness;
  605. }
  606. red *= 255;
  607. green *= 255;
  608. blue *= 255;
  609. red = Math.round(red);
  610. green = Math.round(green);
  611. blue = Math.round(blue);
  612. red = baseConverter(red, 10, 16);
  613. green = baseConverter(green, 10, 16);
  614. blue = baseConverter(blue, 10, 16);
  615. red = red + "";
  616. green = green + "";
  617. blue = blue + "";
  618. while (red.length < 2) {
  619. red = "0" + red;
  620. }
  621. while (green.length < 2) {
  622. green = "0" + green;
  623. }
  624. while (blue.length < 2) {
  625. blue = "0" + "" + blue;
  626. }
  627. rgbColor = "#" + red + "" + green + "" + blue;
  628. return rgbColor.toUpperCase();
  629. }
  630. function findColorByDegrees(rgbColor, degrees) {
  631. rgbColor = rgbColor.replace('#', '');
  632. myArray = toHSV(rgbColor);
  633. myArray[0] += degrees;
  634. if (myArray[0] >= 360) myArray[0] -= 360;
  635. if (myArray[0] < 0) myArray[0] += 360;
  636. return toRgb(myArray[0], myArray[1], myArray[2]);
  637. }
  638. function findColorByBrightness(rgbColor, brightness) {
  639. rgbColor = rgbColor.replace('#', '');
  640. myArray = toHSV(rgbColor);
  641. myArray[2] += brightness / 100;
  642. if (myArray[2] > 1) myArray[2] = 1;
  643. if (myArray[2] < 0) myArray[2] = 0;
  644. myArray[1] += brightness / 100;
  645. if (myArray[1] > 1) myArray[1] = 1;
  646. if (myArray[1] < 0) myArray[1] = 0;
  647. return toRgb(myArray[0], myArray[1], myArray[2]);
  648. }