JAL-857 disabled javascript page state storage in cookies
[jalview.git] / examples / javascript / jvcontroller.js
1 /**
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19
20  
21     //var currentPage = (readCookie("current_page")) ? readCookie("current_page") : "applets";
22     var currentPage = "applets";
23     var signedJars = "jalviewApplet.jar,JmolApplet-12.2.4.jar,java-json.jar,json_simple-1.1.jar";
24     var unsignedJars = "u_jalviewApplet.jar,u_JmolApplet-12.2.4.jar,u_java-json.jar,u_json_simple-1.1.jar";
25     setOrUpdateCookie('jv_applet_mode', 'false', '1');
26     //var isSignedAppletMode = readCookie("jv_applet_mode");
27     var appletJars = (isSignedAppletMode === 'true') ? signedJars : unsignedJars;
28     //alert(unsigned);
29
30
31     function createAppletTag(code, name, archive, width, height, params){
32         var app = document.createElement('applet');
33         app.code= code;
34         app.width = width;
35         app.height = height;
36         app.archive = archive;
37
38         var arrayLength = params.length;
39         for (var i = 0; i < arrayLength; i++) {
40             //console.log('name : '+ params[i][0] + ' code : '+ params[i][1]);              
41             var param = document.createElement('param');
42             param.name = params[i][0];
43             param.value = params[i][1];
44             app.appendChild(param);
45         }
46         return app;
47     }
48
49     function readCookie(name) {
50         var nameEQ = name + "=";
51         var ca = document.cookie.split(';');
52         for(var i=0;i < ca.length;i++) {
53             var c = ca[i];
54             while (c.charAt(0)==' ') c = c.substring(1,c.length);
55             if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
56         }
57         return null;
58     }
59
60     function setOrUpdateCookie(name, value, days) {
61         var expires;
62         if (days) {
63             var date = new Date();
64             date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
65             expires = "; expires=" + date.toGMTString();
66         }
67         else {
68             expires = "";
69         }
70         document.cookie = name + "=" + value + expires + "; path=/";
71     }
72
73    $(function(){
74        //alert("cur page : " + currentPage); 
75        $('#header').load("includes/header_jv.html");
76        $('#content').load(currentPage+".html");
77        $('#nav').load("includes/nav_jv.html");
78        $('#footer').load("includes/footer_jv.html"); 
79        $('#'+ currentPage).addClass('active-trail active');       
80    });
81    
82   $(document).ready(function(){
83     //var currentPage = (readCookie("current_page")) ? readCookie("current_page") : "applets.html";
84     //updateLinks(currentPage);
85     var params = [["file","uniref50.fa"],
86                   ["treeFile","ferredoxin.nw"],
87                   ["userDefinedColour","C=yellow; R,K,H=FF5555; D,E=5555F"],
88                   ["sortByTree","True"],
89                   ["showSequenceLogo","true"],
90                   ["showGroupConsensus","true"],
91                   ["showFullId","false"],
92                   ["linkLabel_1","Uniprot"],
93                   ["linkUrl_1","http://www.uniprot.org/uniprot/$SEQUENCE_ID$"],
94                   ["linkLabel_2","EMBL-EBI Search"],
95                   ["linkUrl_2","http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"],
96                   ["APPLICATION_URL","http://www.jalview.org/services/launchApp"]];
97     var app = createAppletTag('jalview.bin.JalviewLite','',appletJars,'140','35', params);
98     console.log('—————————> app ———————>  ' + app);
99     //var appDiv = document.getElementById("applet_div");
100     //var appDiv = document.getElementById("applet_div");
101     //appDiv.appendChild(app);
102     $("<div class='newbox'>I'm new box by appendTo</div>").appendTo('.applet_div');
103     //$(‘.applet_div').append(app);
104   });
105
106 function doSubmit(target){
107    //setOrUpdateCookie('current_page', target, '1');
108    //alert('current page : ' + readCookie("current_page"));
109    var currentPage = target+'.html';
110    $('#content').load(currentPage);
111    updateLinks(target);
112 }
113
114 function updateLinks(target) {
115     var ul = document.getElementById("menu");
116     var items = ul.getElementsByTagName("li");
117     for (var i = 0; i < items.length; ++i) {
118         removeClass(items[i], "active-trail active");
119     }
120    $('#'+ target).addClass('active-trail active');
121 }
122
123 function hasClass(ele,cls) {
124   return !!ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
125 }
126
127 function addClass(ele,cls) {
128   if (!hasClass(ele,cls)) ele.className += " "+cls;
129 }
130
131 function removeClass(ele,cls) {
132   if (hasClass(ele,cls)) {
133     var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
134     ele.className=ele.className.replace(reg,' ');
135   }
136 }