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