colorize.js
1    function updateColors(color) 
2    { 
3      //if no color is sent in (undefined) then use orange 
4      color = color || "orange"; 
5       
6      var gameInterface = document.getElementById("interface"); 
7      var gameTitle = document.getElementById("gameTitle"); 
8       
9      if (gameInterface) 
10     { 
11       gameInterface.style.borderColor = color; 
12     } 
13    
14     if (gameTitle) 
15     { 
16       gameTitle.style.color = color; 
17     } 
18   } 
19    
20    
21
//this is crazy 22 function updateColorScheme(scheme, reset) 23 { 24 //these lists may differ based on what optional features you've added 25 26 //get all UI elements that we have ids for 27 var idSections = ["interface", "gameTitle", "info", "description", "broken", "fixed", "score", "navigation", "imagewrapper", 28 "caption", "inventory"]; 29 var idSingleButtons = ["start", "replay", "exit", "leave", "passcode", "backspace", "clear", "hintButton", 30 "playerName"]; 31 var idSet = idSections.concat(idSingleButtons); 32 33 var ids = {}; 34 for (var i = 0; i < idSet.length; i++) 35 { 36 var tempId = idSet[i]; 37 var element = document.getElementById(tempId); 38 if (element) 39 { 40 ids[tempId] = element; 41 } 42 } 43 44 //get all the style classes in use 45 var classSet = ["text", "item", "inventory", "even", "odd", "hide", "show"]; 46 var classes = {}; 47 for (var i = 0; i < classSet.length; i++) 48 { 49 var tempClass = classSet[i]; 50 var list = document.getElementsByClassName(tempClass); 51 if (list) 52 { 53 classes[tempClass] = list; 54 } 55 } 56 57 //let's get the HTML tags we may want to format 58 var tagSet = ["h1", "h3", "table", "td", "button", "img", "a"]; 59 var tags = {}; 60 for (var i = 0; i < tagSet.length; i++) 61 { 62 var tempTag = tagSet[i]; 63 var list = document.getElementsByTagName(tempTag); 64 if (list) 65 { 66 tags[tempTag] = list; 67 } 68 } 69 70 //now we have all the things we might want to format. whew. 71 //it's time to start creating color schemes 72 73 switch (scheme) 74 { 75 default: 76 var td = {backgroundColor: "black", borderColor: "black"}; 77 var h1 = {color: "orange"}; 78 var h3 = {color: "black"}; 79 var button = {backgroundColor: "slateblue", color: "white"}; 80 var _text = {backgroundColor: "cornsilk", color: "slateblue"}; 81 var _inventory = {backgroundColor: "slateblue", color: "white"}; 82 var _odd = {backgroundColor: "slateblue", color: "white"}; 83 var _even = {backgroundColor: "orange", color: "black"}; 84 var $interface = {backgroundColor: "black", borderColor: "orange"}; 85 var $info = {backgroundColor: "orange", color: "cornsilk"}; 86 var $caption = {color: "silver"}; 87 var $inventory = {backgroundColor: "orange"}; 88 var $start = {backgroundColor: "slateblue"}; 89 var $replay = {backgroundColor: "slateblue"}; 90 var $leave = {backgroundColor: "orange"}; 91 var $exit = {backgroundColor: "#2f2475", color: "white"}; 92 var $passcode = {backgroundColor: "#2f2475", color: "white"}; 93 var $playerName = {backgroundColor: "#2f2475", borderColor: "slateblue", color: "orange"}; 94 var $backspace = {backgroundColor: "darkred", color: "cornsilk"}; 95 var $clear = {backgroundColor: "darkred", color: "cornsilk"}; 96 var $hintButton = {backgroundColor: "orange", color: "#2f2475"}; 97 } 98 }