adding a semicolon... yay!
[cxgn-jslib.git] / CXGN / Effects.js
blob0bdf2f53cec5ff9433eec7dced1282ba12e5ec76
1 /** 
3 =head1 CXGN.Effects
5  Visual effects handler.  We will want to sub-class this heavily, as there will exist a myriad of effects. Singleton object.
7  Exports object 'Effects' to window namespace
9 =head1 Author
11  Chris Carpita <csc32@cornell.edu>
13 =cut
17 JSAN.use("MochiKit.Logging");
19 var Effects = {
20         //Here's an example of a function which should exist in a subclass:
21         switchHotlistButton: function(buttonId, switchTo, content, clearOnClick){
22                 var button = document.getElementById(buttonId);
23                 var imgAdd = document.getElementById(buttonId + ":imgAdd");
24                 var imgRemove = document.getElementById(buttonId + ":imgRemove");
25         
26                 var optionalText = "All AGIs on this Page ";
27                 if(!content.match(/:/)) {optionalText = "";}
28                 if(switchTo == 'remove'){  
29                         imgAdd.style.display = "none";
30                         imgRemove.style.display = "inline";
31                         button.firstChild.nodeValue = "Remove " + optionalText + "from Hotlist";
32                         if(clearOnClick){
33                                 button.setAttribute("onClick", "alert('some')");
34                         }
35                         else {
36                                 button.setAttribute("onClick", "Hotlist.remove('" + buttonId + "', '" + content + "'); return false;");
37                         }
38                 }
39                 else if (switchTo == 'add'){ 
40                         imgAdd.style.display = "inline";
41                         imgRemove.style.display = "none";
42                         button.firstChild.nodeValue = "Add " + optionalText + "to Hotlist";
43                         if(clearOnClick){
44                                 button.setAttribute("onClick", "alert('some')");
45                         }
46                         else {
47                                 button.setAttribute("onClick", "Hotlist.add('" + buttonId + "', '" + content + "'); return false;");
48                         }
49                 }
50                 else { alert("You sent a bad switchTo variable to switchHotlistButton"); }
51         },
52         //These, on the other hand, are generic and belong in CXGN.Effects:
53         showElement: function(elementId, displayMethod) {
54                 var element = document.getElementById(elementId);
55                 var dispMethod;
56                 if(displayMethod) {
57                         dispMethod = displayMethod;
58                 }
59                 else { dispMethod = "inline"; }
60                 element.style.display = dispMethod;
61         },
62         hideElement: function(elementId, displayMethod) {
63                 var element = document.getElementById(elementId);
64                 var dispMethod = "";
65                 if(displayMethod) {
66                         dispMethod = displayMethod;
67                 }
68                 else { dispMethod = "none"; } //alternative is "hidden", which causes it to continue occupying space on the page
69                 element.style.display = dispMethod;
70         },
71         swapElements: function(elementIdFrom, elementIdTo, displayMethod){
72                 try {   
73                         var dispMethod = displayMethod || "inline";
74                         var elementFrom = document.getElementById(elementIdFrom);
75                         var elementTo = document.getElementById(elementIdTo);
76                         elementFrom.style.display = "none";
77                         elementTo.style.display = dispMethod;
78                 }
79                 catch(e) { MochiKit.Logging.logError("CXGN.Effects.swapElements: " + e); }
80         }