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