7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2012 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var Color = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var colorField; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
var color = {}; |
7604 |
25 Feb 19 |
nicklas |
31 |
|
7604 |
25 Feb 19 |
nicklas |
color.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
33 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Get the current color from the parent window |
7604 |
25 Feb 19 |
nicklas |
colorField = window.opener.document.getElementById(Data.get('page-data', 'textarea')); |
7604 |
25 Feb 19 |
nicklas |
36 |
|
7604 |
25 Feb 19 |
nicklas |
var colorValue = colorField.value; |
7604 |
25 Feb 19 |
nicklas |
// Split into r,g,b values |
7604 |
25 Feb 19 |
nicklas |
var rgb = colorValue.match('([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})'); |
7604 |
25 Feb 19 |
nicklas |
40 |
|
7604 |
25 Feb 19 |
nicklas |
// Put r,g,b values in input fields |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['color']; |
7604 |
25 Feb 19 |
nicklas |
frm.red.value = rgb[1]; |
7604 |
25 Feb 19 |
nicklas |
frm.green.value = rgb[2]; |
7604 |
25 Feb 19 |
nicklas |
frm.blue.value = rgb[3]; |
7604 |
25 Feb 19 |
nicklas |
46 |
|
7604 |
25 Feb 19 |
nicklas |
// Initialize color boxes |
7604 |
25 Feb 19 |
nicklas |
var titleToFocus = '#'+rgb[0]; |
7604 |
25 Feb 19 |
nicklas |
for (var x = 0; x < 18; x++) |
7604 |
25 Feb 19 |
nicklas |
50 |
{ |
7604 |
25 Feb 19 |
nicklas |
for (var y = 0; y < 12; y++) |
7604 |
25 Feb 19 |
nicklas |
52 |
{ |
7604 |
25 Feb 19 |
nicklas |
var colorBox = Doc.element('x'+x+'y'+y); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler(colorBox, color.colorOnClick); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler(colorBox, 'keypress', color.handleArrowKeys); |
7604 |
25 Feb 19 |
nicklas |
56 |
|
7604 |
25 Feb 19 |
nicklas |
if (colorBox.title == titleToFocus) |
7604 |
25 Feb 19 |
nicklas |
58 |
{ |
7604 |
25 Feb 19 |
nicklas |
colorBox.focus(); |
7604 |
25 Feb 19 |
nicklas |
60 |
} |
7604 |
25 Feb 19 |
nicklas |
61 |
} |
7604 |
25 Feb 19 |
nicklas |
62 |
} |
7604 |
25 Feb 19 |
nicklas |
63 |
|
7604 |
25 Feb 19 |
nicklas |
// Dialog buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSave', color.save); |
7604 |
25 Feb 19 |
nicklas |
67 |
} |
7604 |
25 Feb 19 |
nicklas |
68 |
|
7604 |
25 Feb 19 |
nicklas |
69 |
/** |
7604 |
25 Feb 19 |
nicklas |
Save the selected color back to the parent |
7604 |
25 Feb 19 |
nicklas |
form and close the window. |
7604 |
25 Feb 19 |
nicklas |
72 |
*/ |
7604 |
25 Feb 19 |
nicklas |
color.save = function() |
7604 |
25 Feb 19 |
nicklas |
74 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['color']; |
7604 |
25 Feb 19 |
nicklas |
if (!color.validateColorValue(frm.red.value)) |
7604 |
25 Feb 19 |
nicklas |
77 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.red, 'Invalid red color value'); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
80 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (!color.validateColorValue(frm.green.value)) |
7604 |
25 Feb 19 |
nicklas |
82 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.green, 'Invalid green color value'); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
85 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (!color.validateColorValue(frm.blue.value)) |
7604 |
25 Feb 19 |
nicklas |
87 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.blue, 'Invalid blue color value'); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
90 |
} |
7604 |
25 Feb 19 |
nicklas |
// Save the value to the date field |
7604 |
25 Feb 19 |
nicklas |
colorField.value = frm.red.value + frm.green.value + frm.blue.value; |
7604 |
25 Feb 19 |
nicklas |
// Fire an 'onchange' event |
7604 |
25 Feb 19 |
nicklas |
Events.sendChangeEvent(colorField); |
7604 |
25 Feb 19 |
nicklas |
95 |
|
7604 |
25 Feb 19 |
nicklas |
window.close(); |
7604 |
25 Feb 19 |
nicklas |
97 |
} |
7604 |
25 Feb 19 |
nicklas |
98 |
|
7604 |
25 Feb 19 |
nicklas |
99 |
/** |
7604 |
25 Feb 19 |
nicklas |
Event handler for selecting a color among the |
7604 |
25 Feb 19 |
nicklas |
color boxes. |
7604 |
25 Feb 19 |
nicklas |
102 |
*/ |
7604 |
25 Feb 19 |
nicklas |
color.colorOnClick = function(event) |
7604 |
25 Feb 19 |
nicklas |
104 |
{ |
7604 |
25 Feb 19 |
nicklas |
var target = event.currentTarget; |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['color']; |
7604 |
25 Feb 19 |
nicklas |
frm.red.value = Data.get(target, 'red'); |
7604 |
25 Feb 19 |
nicklas |
frm.green.value = Data.get(target, 'green'); |
7604 |
25 Feb 19 |
nicklas |
frm.blue.value = Data.get(target, 'blue'); |
7604 |
25 Feb 19 |
nicklas |
110 |
} |
7604 |
25 Feb 19 |
nicklas |
111 |
|
7604 |
25 Feb 19 |
nicklas |
112 |
|
7604 |
25 Feb 19 |
nicklas |
113 |
/** |
7604 |
25 Feb 19 |
nicklas |
Set focus to 'next' color when arrow keys are pressed. |
7604 |
25 Feb 19 |
nicklas |
115 |
*/ |
7604 |
25 Feb 19 |
nicklas |
color.handleArrowKeys = function(event) |
7604 |
25 Feb 19 |
nicklas |
117 |
{ |
7604 |
25 Feb 19 |
nicklas |
var keyCode = event.keyCode; |
7604 |
25 Feb 19 |
nicklas |
if (keyCode >= 37 && keyCode <= 40) |
7604 |
25 Feb 19 |
nicklas |
120 |
{ |
7604 |
25 Feb 19 |
nicklas |
var y = Data.int(event.currentTarget, 'y'); |
7604 |
25 Feb 19 |
nicklas |
var x = Data.int(event.currentTarget, 'x'); |
7604 |
25 Feb 19 |
nicklas |
// 37 - left, 38 - up, 39 - right, 40 - down |
7604 |
25 Feb 19 |
nicklas |
if (keyCode == 37) x--; |
7604 |
25 Feb 19 |
nicklas |
if (keyCode == 38) y--; |
7604 |
25 Feb 19 |
nicklas |
if (keyCode == 39) x++; |
7604 |
25 Feb 19 |
nicklas |
if (keyCode == 40) y++; |
7604 |
25 Feb 19 |
nicklas |
var next = Doc.element('x'+x+'y'+y); |
7604 |
25 Feb 19 |
nicklas |
if (next && next.tabIndex != -1) |
7604 |
25 Feb 19 |
nicklas |
130 |
{ |
7604 |
25 Feb 19 |
nicklas |
next.focus(); |
7604 |
25 Feb 19 |
nicklas |
132 |
} |
7604 |
25 Feb 19 |
nicklas |
133 |
} |
7604 |
25 Feb 19 |
nicklas |
134 |
} |
7604 |
25 Feb 19 |
nicklas |
135 |
|
7604 |
25 Feb 19 |
nicklas |
136 |
/** |
7604 |
25 Feb 19 |
nicklas |
A color value must be two characters using |
7604 |
25 Feb 19 |
nicklas |
0-9 or A-F. |
7604 |
25 Feb 19 |
nicklas |
139 |
*/ |
7604 |
25 Feb 19 |
nicklas |
color.validateColorValue = function(value) |
7604 |
25 Feb 19 |
nicklas |
141 |
{ |
7604 |
25 Feb 19 |
nicklas |
return value.match('[0-9A-Fa-f]{2}'); |
7604 |
25 Feb 19 |
nicklas |
143 |
} |
7604 |
25 Feb 19 |
nicklas |
144 |
|
7604 |
25 Feb 19 |
nicklas |
return color; |
7604 |
25 Feb 19 |
nicklas |
146 |
}(); |
7604 |
25 Feb 19 |
nicklas |
147 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Color.initPage); |
7604 |
25 Feb 19 |
nicklas |
149 |
|
7604 |
25 Feb 19 |
nicklas |
150 |
|