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