JAL-1859 JAL-857 updated all reference of JmolApplet-12.2.4.jar to JmolApplet-14...
[jalview.git] / examples / javascriptLaunch.html
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 <!-- boiler plate link to alternate demopage -->
21 <div style="width: 100%">
22 <div style="width:35%; align:left; float:right;">
23
24 <div style="margin:8px; padding:10px; border: 2px solid black; align: left;">
25 <p>Quick Links to jars for example:<br/><a href="jalviewApplet.jar">jalviewApplet.jar</a> and <a href="JmolApplet-14.2.14_2015.06.11.jar">JmolApplet.jar</a>
26 </p></div>
27 </div>
28 </div>
29
30 <!-- content template start -->
31   <SCRIPT type="text/javascript">
32   /* <![CDATA[ // */
33 // From http://snipplr.com/view.php?codeview&id=1272
34 //----------------------------------------
35 //Wrapper function for constructing a request object.
36 //      Parameters:
37 //              reqType: The HTTP request type, such as GET or POST.
38 //              url: The URL of the server program.
39 //              asynch: Whether to send the request asynchronously or not.
40 //----------------------------------------
41
42 function httpRequest(reqType,url,asynch,respHandle) {
43
44         // Mozilla-based browsers
45         if (window.XMLHttpRequest) {
46                 request = new XMLHttpRequest();
47         } else if (window.ActiveXObject) {
48                 request = new ActiveXObject("Msxml2.XMLHTTP");
49                 if (!request) {
50                         request = new ActiveXObject("Microsoft.XMLHTTP");
51                 }
52         }
53         
54         // Request could still be null if neither ActiveXObject
55         //   initialization succeeded
56         if (request) {
57                 // If the reqType param is POST, then the fifth arg is the POSTed data
58                 if (reqType.toLowerCase() != "post") {
59                         initReq(reqType, url, asynch, respHandle);
60                 } else {
61                         // The POSTed data
62                         var args = arguments[5];
63                         if (args != null && args.length > 0) {
64                                 initReq(reqType, url, asynch, respHandle, args);
65                         }
66                 }
67         } else {
68                 alert("Your browser does not permit the use of all " +
69                         "of this application's features!");
70         }
71
72 }
73
74 //----------------------------------------
75 //Initialize a request object that is already constructed
76 //----------------------------------------
77
78 function initReq(reqType, url, bool, respHandle) {
79         try {
80                 // Specify the function that will handle the HTTP response
81                 request.onreadystatechange = respHandle;
82                 request.open(reqType, url, bool);
83                 // If the reqType param is POST, then the
84                 //   fifth argument to the function is the POSTed data
85                 if (reqType.toLowerCase() == "post") {
86                         // Set the Content-Type header for a POST request
87                         request.setRequestHeader("Content-Type", "application/x-ww-form-urlencoded; charset=UTF-8");
88                         request.send(arguments[4]);
89                 } else {
90                         request.send(null);
91                 }
92         } catch (errv) {
93                 alert("The application cannot contact the server at the moment. " +
94                         "Please try again in a few seconds.\n" +
95                         "Error detail: " + errv.message);
96         }
97 }
98
99 // jalview launching with fetched data
100
101 function startJalview(aligURL,title,alwvar) {
102                 var aligment = "";
103                 httpRequest("get",aligURL,true,function() {
104                                 if (request.readyState == 4) { 
105                                         alignment = request.responseText; 
106                                         eval("var "+alwvar+" = document.JalviewLite.loadAlignment(alignment,title)");
107                                 }
108                 })
109                 
110 }
111
112 /* ]]> */
113 </SCRIPT>
114   <form name="Form1">
115 <applet name="JalviewLite"  code="jalview.bin.JalviewLite"
116 archive="jalviewApplet.jar,JmolApplet-14.2.14_2015.06.11.jar" width="0" height="0">
117 <param name="debug" value="true"/>
118 <param name="showbutton" value="false"/>
119 </applet>
120
121 <h2>Javascript Launch Button</h2><p>The button below demonstrates how JalviewLite can be launched via a javascript action.</p>
122
123   <input type="button" name="Button1" value="Start"
124 onClick="startJalview('plantfdx.fa','Button1.alignment','alwvar')"/>
125   </form>
126 <!-- content template end -->