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