9ea3a5a20264760a970820d6605ebbb78cb8a495
[jalview.git] / examples / u_javascriptLaunch.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2 <!--
3     * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
4     * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5     * 
6     * This file is part of Jalview.
7     * 
8     * Jalview is free software: you can redistribute it and/or
9     * modify it under the terms of the GNU General Public License 
10     * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11     *  
12     * Jalview is distributed in the hope that it will be useful, but 
13     * WITHOUT ANY WARRANTY; without even the implied warranty 
14     * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15     * PURPOSE.  See the GNU General Public License for more details.
16     * 
17     * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
18   -->
19 <head>
20   <TITLE>Javascript Launch</TITLE>
21   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
22
23   <link href="css/reset.css" rel="stylesheet" type="text/css" />
24   <link href="css/style.css" rel="stylesheet" type="text/css" />
25   
26   <!--[if IE 6]>
27       <link rel="stylesheet" type="text/css" href="css/ie6.css" />
28       <![endif]-->
29
30   <!--[if IE 7]>
31       <link rel="stylesheet" type="text/css" href="css/ie7.css" />
32       <![endif]-->
33
34   <!-- dd menu -->
35   <script type="text/javascript">
36     <!--
37         var timeout         = 500;
38         var closetimer  = 0;
39         var ddmenuitem      = 0;
40
41         // open hidden layer
42         function mopen(id)
43         { 
44         // cancel close timer
45         mcancelclosetime();
46
47         // close old layer
48         if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
49
50         // get new layer and show it
51         ddmenuitem = document.getElementById(id);
52         ddmenuitem.style.visibility = 'visible';
53
54         }
55         // close showed layer
56         function mclose()
57         {
58         if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
59         }
60
61         // go close timer
62         function mclosetime()
63         {
64         closetimer = window.setTimeout(mclose, timeout);
65         }
66
67         // cancel close timer
68         function mcancelclosetime()
69         {
70         if(closetimer)
71         {
72         window.clearTimeout(closetimer);
73         closetimer = null;
74         }
75         }
76
77         // close layer when click-out
78         document.onclick = mclose; 
79         // -->
80   </script>
81   <script>
82     <!--//--><![CDATA[//><!--
83 var _gaq = _gaq || [];_gaq.push(["_setAccount", "UA-9060947-1"]);_gaq.push(["_trackPageview"]);(function() {var ga = document.createElement("script");ga.type = "text/javascript";ga.async = true;ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(ga, s);})();
84 //--><!]]>
85   </script>
86
87 </head>
88
89
90 <body>
91
92
93   <div id="header">
94     <div id="logo"><a href="http://www.jalview.org" title="Home"></a></div>
95     <ul id="buttons">
96       <li id="applet"><a href="applets.html" title="applet"></a></li>
97       <li id="desktop"><a href="../webstart/jalview.jnlp" title="desktop"></a></li>
98     </ul>
99   </div>
100
101   
102   <div id ="nav">
103     <div id="navInner">
104
105       <ul id="sddm">
106         <li><a href="http://www.jalview.org">Home</a></li>
107         <li><a href="http://www.jalview.org/about" onmouseover="mopen('m1')" onmouseout="mclosetime()">About</a>
108           <div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
109             <a href="http://www.jalview.org/about/documentation">Documentation</a>
110             <a href="http://www.jalview.org/about/citation">Publications</a>
111             <a href="http://www.jalview.org/about/credits">Credits</a>
112           </div>
113         </li>
114         <li><a href="http://www.jalview.org/faq">FAQ</a></li>
115         <li><a href="http://www.jalview.org/community" onmouseover="mopen('m3')" onmouseout="mclosetime()" class="community">Community</a>
116           <div id="m3" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
117             <a href="http://www.jalview.org/mailman/listinfo/jalview-announce">News Mailing List</a>
118             <a href="http://www.jalview.org/mailman/listinfo/jalview-discuss">Discussion Mailing List</a>
119             <a href="http://www.jalview.org/community/links">Links</a>
120             <a href="http://www.jalview.org/community/community-news">Community News</a>
121           </div>
122         </li>
123         <li><a href="http://www.jalview.org/development" onmouseover="mopen('m4')" onmouseout="mclosetime()" class="development">Development</a>
124           <div id="m4" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
125             <a href="http://www.jalview.org/development/release-history">Release History</a>
126             <a href="http://issues.jalview.org">Jalview Bug Tracker</a>
127             <a href="http://source.jalview.org/gitweb/">Jalview Git Web</a>
128             <a href="http://www.jalview.org/development/development-news">Development News</a>
129           </div>
130         </li>
131         <li><a href="http://www.jalview.org/training" onmouseover="mopen('m5')" onmouseout="mclosetime()" class="training">Training</a>
132           <div id="m5" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">
133             <a href="http://www.jalview.org/training/training-courses">Training Courses</a>
134             <a href="http://www.jalview.org/training/training-news">Training News</a>
135           </div>
136         </li>
137         <li><a href="http://www.jalview.org/download" class="download-right">Download</a></li>
138       </ul>
139       <div style="clear:both"></div>
140     </div>
141
142   </div>
143 <div id="pageWrap">
144
145 <div id="sideNav">
146   <ul>
147       <li ><a href="u_applets.html">JalviewLite Examples</a></li>
148       <li ><a href="jalviewLiteJs.html">Javascript API</a></li>
149       <li ><a href="appletParameters.html">Applet Parameters</a></li>
150       <li ><a href="u_embedded.html">Embedded Alignment</a></li>
151       <li ><a href="u_embeddedWJmol.html">Jalview and Jmol</a></li>
152       <li ><a href="u_formComplete.html">Access from Javascript</a></li>
153       <li class="jvlite-nav-small"><a href="u_javascriptLaunch.html">Javascript Launch</a></li>
154       <li ><a href="u_linkedapplets_ng.html">Linked JalviewLites</a></li>
155   </ul>
156 </div>
157
158 <div id="content" class="content">
159
160
161 <!-- boiler plate link to alternate demopage -->
162
163 <div style="width: 100%">
164 <div style="width:35%; align:left; float:right;">
165 <div style="margin:8px; padding:8px; border: 2px solid black; align: center; float:center;">
166  Scary Java warnings ?<br/>Try <a href="javascriptLaunch.html">the signed applet demos</a>
167 </div>
168 <div style="margin:8px; padding:10px; align: left;">
169 <p>Quick Links to jars for example:<br/><a href="u_jalviewApplet.jar">jalviewApplet.jar</a> and <a href="u_JmolApplet-12.2.4.jar">JmolApplet.jar</a>
170 </p></div>
171 </div>
172 </div>
173
174 <!-- content template start -->
175   <SCRIPT type="text/javascript">
176   /* <![CDATA[ // */
177 // From http://snipplr.com/view.php?codeview&id=1272
178 //----------------------------------------
179 //Wrapper function for constructing a request object.
180 //      Parameters:
181 //              reqType: The HTTP request type, such as GET or POST.
182 //              url: The URL of the server program.
183 //              asynch: Whether to send the request asynchronously or not.
184 //----------------------------------------
185
186 function httpRequest(reqType,url,asynch,respHandle) {
187
188         // Mozilla-based browsers
189         if (window.XMLHttpRequest) {
190                 request = new XMLHttpRequest();
191         } else if (window.ActiveXObject) {
192                 request = new ActiveXObject("Msxml2.XMLHTTP");
193                 if (!request) {
194                         request = new ActiveXObject("Microsoft.XMLHTTP");
195                 }
196         }
197         
198         // Request could still be null if neither ActiveXObject
199         //   initialization succeeded
200         if (request) {
201                 // If the reqType param is POST, then the fifth arg is the POSTed data
202                 if (reqType.toLowerCase() != "post") {
203                         initReq(reqType, url, asynch, respHandle);
204                 } else {
205                         // The POSTed data
206                         var args = arguments[5];
207                         if (args != null && args.length > 0) {
208                                 initReq(reqType, url, asynch, respHandle, args);
209                         }
210                 }
211         } else {
212                 alert("Your browser does not permit the use of all " +
213                         "of this application's features!");
214         }
215
216 }
217
218 //----------------------------------------
219 //Initialize a request object that is already constructed
220 //----------------------------------------
221
222 function initReq(reqType, url, bool, respHandle) {
223         try {
224                 // Specify the function that will handle the HTTP response
225                 request.onreadystatechange = respHandle;
226                 request.open(reqType, url, bool);
227                 // If the reqType param is POST, then the
228                 //   fifth argument to the function is the POSTed data
229                 if (reqType.toLowerCase() == "post") {
230                         // Set the Content-Type header for a POST request
231                         request.setRequestHeader("Content-Type", "application/x-ww-form-urlencoded; charset=UTF-8");
232                         request.send(arguments[4]);
233                 } else {
234                         request.send(null);
235                 }
236         } catch (errv) {
237                 alert("The application cannot contact the server at the moment. " +
238                         "Please try again in a few seconds.\n" +
239                         "Error detail: " + errv.message);
240         }
241 }
242
243 // jalview launching with fetched data
244
245 function startJalview(aligURL,title,alwvar) {
246                 var aligment = "";
247                 httpRequest("get",aligURL,true,function() {
248                                 if (request.readyState == 4) { 
249                                         alignment = request.responseText; 
250                                         eval("var "+alwvar+" = document.JalviewLite.loadAlignment(alignment,title)");
251                                 }
252                 })
253                 
254 }
255
256 /* ]]> */
257 </SCRIPT>
258   <form name="Form1">
259 <applet name="JalviewLite"  code="jalview.bin.JalviewLite"
260 archive="u_jalviewApplet.jar" width="0" height="0">
261 <param name="debug" value="true"/>
262 <param name="showbutton" value="false"/>
263 </applet>
264
265 <h2>Javascript Launch Button</h2><p>The button below demonstrates how JalviewLite can be launched via a javascript action.</p>
266
267   <input type="button" name="Button1" value="Start"
268 onClick="startJalview('plantfdx.fa','Button1.alignment','alwvar')"/>
269   </form>
270 <!-- content template end -->
271
272
273
274 </div> <!-- end content div -->
275
276 </div> <!-- content -->
277 </div> <!-- pagewrap -->
278 <div id ="footer">
279 <div id="innerFooter">
280 <div id="copyright"><p>Published under <a href="http://creativecommons.org/licenses/by-sa/3.0/">CC-SA 3.0</a></p></div>
281 <div id="cite">
282 <p>
283 If you use Jalview in your work, please cite this publication:
284 </p>
285 <br />
286 <p>
287 Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)
288 "Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
289 Bioinformatics 25 (9) 1189-1191 <a href="http://dx.doi.org/10.1093/bioinformatics/btp033">doi: 10.1093/bioinformatics/btp033</a>
290 </p>
291 </div>
292 </div>
293 </div>
294 </body>
295 </html>