Site resources for running pages with swingjs/JalviewJS.js
[jalview.git] / site-resources / javascript / JalviewApplet.js
1 Jalview = {}
2
3
4 $(document).ready(function() {
5         Jalview.processAllAppletElements();
6 });
7
8  
9 var currentPage = "applets";
10
11 Jalview.processAllAppletElements = function() {
12         var apps = document.getElementsByTagName("applet");
13         for (var i = apps.length; --i >= 0;) {
14                 processAppletElement(apps[i]);
15         }
16 }
17  
18 Jalview.jvid = 0;
19
20 Jalview.doStartJalview = function(e) {
21         var element = e.target.appletElement;
22         var text = element.outerHTML;
23         
24         var Info = self.JalviewInfo || {
25 code: null,
26 main: "jalview.bin.Jalview",
27 core: "NONE",
28         width: 850,
29         height: 550,
30         readyFunction: null,
31         serverURL: 'https://chemapps.stolaf.edu/jmol/jsmol/php/jsmol.php',
32         j2sPath: 'swingjs/j2s',
33         console:'sysoutdiv',
34         allowjavascript: true
35         }
36
37 var addParam = function(key,value) {
38         args.push("name=\"" + key + "\" value=\"" + value + "\""); 
39 }
40
41 var id = "JVApplet" + jvid++;
42 var args = text.replace(/[\n\t]/g, " ").split("<param ");
43 Info.j2sAppletID = i;
44 Info.j2sAppletID = id;
45 Info.jalview_SCREEN_X= 10,
46 Info.jalview_SCREEN_Y= 10;
47 //Info.jalview_EMBEDDED= true;
48
49
50 Info.jalview_SCREEN_WIDTH = 400;
51 Info.jalview_SCREEN_HEIGHT = 100;
52 for (var i in Info) {
53         var v = ("" + Info[i] || "null").replace(/\"/g,"'");
54         addParam(args, "Info." + i, v);
55 }
56         Info.args = args;
57         SwingJS.getApplet(id, Info);
58         document.title = id;
59         e.target.style.visibility="hidden";
60 }
61  
62 Jalview.processAppletElement = function(element) {
63 var code = element.getAttribute("code");
64 var parent = element.parentElement;
65 if (code == "jalview.bin.JalviewLite") {
66                 var text = element.outerHTML;
67                 console.log(text);
68                 var btn = document.createElement("button");
69                 btn.innerHTML = "Start Jalview";
70                 var a = element.getAttribute("width");
71                 btn.style.width = (a || 140) + "px";
72                 a = element.getAttribute("height");
73                 btn.style.height = (a || 25) + "px";
74         btn.appletElement = element;
75         parent.replaceChild(btn, element); 
76         $(btn).click(doStartJalview)
77 } else {
78         parent.removeElement(element);
79 }
80 }
81  
82
83  /** 
84  * Generate an applet tag
85  * 
86  * @param code
87  * @param name
88  * @param archive
89  * @param width
90  * @param height
91  * @param params
92  * @returns a DOM APPLET element
93  */
94
95 Jalview.createAppletTag = function(code, name, archive, width, height, params){
96         var app = document.createElement('applet');
97         app.code= code;
98         app.width = width;
99         app.height = height;
100         app.archive = archive;
101
102         var arrayLength = params.length;
103         for (var i = 0; i < arrayLength; i++) {
104          //console.log('name : '+ params[i][0] + ' code : '+ params[i][1]);      
105          var param = document.createElement('param');
106          param.name = params[i][0];
107          param.value = params[i][1];
108          app.appendChild(param);
109         }
110         return app;
111 }
112