Subversion Repositories wimsdev

Rev

Rev 1365 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1365 Rev 2876
Line 1... Line 1...
1
/* Jmol 11.7 script library Jmol.js  15:32 06.12.2008 Bob Hanson
1
/* Jmol 11.7 script library Jmol.js  12:17 AM 4/20/2009 Bob Hanson
2
 
2
 
3
 checkbox heirarchy -- see http://chemapps.stolaf.edu/jmol/docs/examples-11/check.htm
3
 checkbox heirarchy -- see http://chemapps.stolaf.edu/jmol/docs/examples-11/check.htm
4
 
4
 
5
    based on:
5
    based on:
6
 *
6
 *
Line 30... Line 30...
30
 
30
 
31
// place "?NOAPPLET" on your command line to check applet control action with a textarea
31
// place "?NOAPPLET" on your command line to check applet control action with a textarea
32
// place "?JMOLJAR=xxxxx" to use a specific jar file
32
// place "?JMOLJAR=xxxxx" to use a specific jar file
33
 
33
 
34
// bob hanson -- jmolResize(w,h) -- resizes absolutely or by percent (w or h 0.5 means 50%)
34
// bob hanson -- jmolResize(w,h) -- resizes absolutely or by percent (w or h 0.5 means 50%)
-
 
35
//    angel herraez -- update of jmolResize(w,h,targetSuffix) so it is not tied to first applet
35
// bob hanson -- jmolEvaluate -- evaluates molecular math 8:37 AM 2/23/2007
36
// bob hanson -- jmolEvaluate -- evaluates molecular math 8:37 AM 2/23/2007
36
// bob hanson -- jmolScriptMessage -- returns all "scriptStatus" messages 8:37 AM 2/23/2007
37
// bob hanson -- jmolScriptMessage -- returns all "scriptStatus" messages 8:37 AM 2/23/2007
37
// bob hanson -- jmolScriptEcho -- returns all "scriptEcho" messages 8:37 AM 2/23/2007
38
// bob hanson -- jmolScriptEcho -- returns all "scriptEcho" messages 8:37 AM 2/23/2007
38
// bob hanson -- jmolScriptWait -- 11:31 AM 5/2/2006
39
// bob hanson -- jmolScriptWait -- 11:31 AM 5/2/2006
39
// bob hanson -- remove trailing separatorHTML in radio groups -- 12:18 PM 5/6/2006
40
// bob hanson -- remove trailing separatorHTML in radio groups -- 12:18 PM 5/6/2006
Line 62... Line 63...
62
// bh 6/2008  -- adds jmolSetAppletWindow()
63
// bh 6/2008  -- adds jmolSetAppletWindow()
63
// Angel H. 6/2008  -- added html <label> tags to checkboxes and radio buttons [in jmolCheckbox() and _jmolRadio() functions]
64
// Angel H. 6/2008  -- added html <label> tags to checkboxes and radio buttons [in jmolCheckbox() and _jmolRadio() functions]
64
// bh 7/2008  -- code fix "for(i..." not "for(var i..."
65
// bh 7/2008  -- code fix "for(i..." not "for(var i..."
65
// bh 12/2008 -- jmolLoadInline, jmolLoadInlineArray, jmolLoadInlineScript, jmolAppendInlineScript, jmolAppendInlineArray all return error message or null (Jmol 11.7.16)
66
// bh 12/2008 -- jmolLoadInline, jmolLoadInlineArray, jmolLoadInlineScript, jmolAppendInlineScript, jmolAppendInlineArray all return error message or null (Jmol 11.7.16)
66
// bh 12/2008 -- jmolScriptWaitOutput() -- waits for script to complete and delivers output normally sent to console
67
// bh 12/2008 -- jmolScriptWaitOutput() -- waits for script to complete and delivers output normally sent to console
-
 
68
 
-
 
69
// bh 5/2009  -- Support for XHTML using jmolSetXHTML(id)
-
 
70
// ah & bh 6/2009 -- New jmolResizeApplet() more flexible, similar to jmolApplet() size syntax
67
 
71
 
68
var defaultdir = "."
72
var defaultdir = "."
69
var defaultjar = "JmolApplet.jar"
73
var defaultjar = "JmolApplet.jar"
70
 
74
 
71
 
75
 
Line 75... Line 79...
75
// the JAR file specified in the jmolInitialize() call.
79
// the JAR file specified in the jmolInitialize() call.
76
 
80
 
77
// The idea is that it can be very useful to test a web page with different JAR files
81
// The idea is that it can be very useful to test a web page with different JAR files
78
// Or for an expert user to substitute a signed applet for an unsigned one
82
// Or for an expert user to substitute a signed applet for an unsigned one
79
// so as to use a broader range of models or to create JPEG files, for example.
83
// so as to use a broader range of models or to create JPEG files, for example.
80
 
84
 
81
// If the JAR file is not in the current directory (has any sort of "/" in its name)
85
// If the JAR file is not in the current directory (has any sort of "/" in its name)
82
// then the user is presented with a warning and asked whether it is OK to change Jar files.
86
// then the user is presented with a warning and asked whether it is OK to change Jar files.
83
// The default action, if the user just presses "OK" is to NOT allow the change. 
87
// The default action, if the user just presses "OK" is to NOT allow the change. 
84
// The user must type the word "yes" in the prompt box for the change to be approved.
88
// The user must type the word "yes" in the prompt box for the change to be approved.
85
 
89
 
86
// If you don't want people to be able to switch in their own JAR file on your page,
90
// If you don't want people to be able to switch in their own JAR file on your page,
87
// simply set this next line to read "var allowJMOLJAR = false".
91
// simply set this next line to read "var allowJMOLJAR = false".
88
 
92
 
89
 
93
 
90
var allowJMOLJAR = true  
94
var allowJMOLJAR = true  
91
 
95
 
92
 
96
 
93
var undefined; // for IE 5 ... wherein undefined is undefined
97
var undefined; // for IE 5 ... wherein undefined is undefined
94
 
98
 
Line 170... Line 174...
170
    id = "jmolButton" + _jmol.buttonCount;
174
    id = "jmolButton" + _jmol.buttonCount;
171
  if (label == undefined || label == null)
175
  if (label == undefined || label == null)
172
    label = script.substring(0, 32);
176
    label = script.substring(0, 32);
173
  ++_jmol.buttonCount;
177
  ++_jmol.buttonCount;
174
  var scriptIndex = _jmolAddScript(script);
178
  var scriptIndex = _jmolAddScript(script);
175
  var t = "<span id=\"span_"+id+"\""+(title ? " title =\"" + title + "\"":"")+"><input type='button' name='" + id + "' id='" + id +
179
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input type='button' name='" + id + "' id='" + id +
176
          "' value='" + label +
180
          "' value='" + label +
177
          "' onClick='_jmolClick(" + scriptIndex + _jmol.targetText +
181
          "' onclick='_jmolClick(" + scriptIndex + _jmol.targetText +
178
          ")' onMouseover='_jmolMouseOver(" + scriptIndex +
182
          ")' onmouseover='_jmolMouseOver(" + scriptIndex +
179
          ");return true' onMouseout='_jmolMouseOut()' " +
183
          ");return true' onmouseout='_jmolMouseOut()' " +
180
          _jmol.buttonCssText + "/></span>";
184
          _jmol.buttonCssText + " /></span>";
181
  if (_jmol.debugAlert)
185
  if (_jmol.debugAlert)
182
    alert(t);
186
    alert(t);
183
  return _jmolDocumentWrite(t);
187
  return _jmolDocumentWrite(t);
184
}
188
}
185
 
189
 
186
function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked,
190
function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked,
187
                      labelHtml, isChecked, id, title) {
191
                      labelHtml, isChecked, id, title) {
Line 199... Line 203...
199
    return;
203
    return;
200
  }
204
  }
201
  var indexChecked = _jmolAddScript(scriptWhenChecked);
205
  var indexChecked = _jmolAddScript(scriptWhenChecked);
202
  var indexUnchecked = _jmolAddScript(scriptWhenUnchecked);
206
  var indexUnchecked = _jmolAddScript(scriptWhenUnchecked);
203
  var eospan = "</span>"
207
  var eospan = "</span>"
204
  var t = "<span id=\"span_"+id+"\""+(title ? " title =\"" + title + "\"":"")+"><input type='checkbox' name='" + id + "' id='" + id +
208
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input type='checkbox' name='" + id + "' id='" + id +
205
          "' onClick='_jmolCbClick(this," +
209
          "' onclick='_jmolCbClick(this," +
206
          indexChecked + "," + indexUnchecked + _jmol.targetText +
210
          indexChecked + "," + indexUnchecked + _jmol.targetText +
207
          ")' onMouseover='_jmolCbOver(this," + indexChecked + "," +
211
          ")' onmouseover='_jmolCbOver(this," + indexChecked + "," +
208
          indexUnchecked +
212
          indexUnchecked +
209
          ");return true' onMouseout='_jmolMouseOut()' " +
213
          ");return true' onmouseout='_jmolMouseOut()' " +
210
          (isChecked ? "checked " : "") + _jmol.checkboxCssText + "/>"
214
          (isChecked ? "checked='true' " : "")+ _jmol.checkboxCssText + " />"
211
  if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
215
  if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
212
        t += eospan
216
        t += eospan
213
        eospan = "";
217
        eospan = "";
214
  }
218
  }
215
  t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan;
219
  t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan;
Line 248... Line 252...
248
      separatorHtml = "";
252
      separatorHtml = "";
249
    var radio = arrayOfRadioButtons[i];
253
    var radio = arrayOfRadioButtons[i];
250
    type = typeof radio;
254
    type = typeof radio;
251
    if (type == "object") {
255
    if (type == "object") {
252
      t += _jmolRadio(radio[0], radio[1], radio[2], separatorHtml, groupName, (radio.length > 3 ? radio[3]: (id ? id : groupName)+"_"+i), (radio.length > 4 ? radio[4] : 0), title);
256
      t += _jmolRadio(radio[0], radio[1], radio[2], separatorHtml, groupName, (radio.length > 3 ? radio[3]: (id ? id : groupName)+"_"+i), (radio.length > 4 ? radio[4] : 0), title);
253
    } else {
257
    } else {
254
      t += _jmolRadio(radio, null, null, separatorHtml, groupName, (id ? id : groupName)+"_"+i, title);
258
      t += _jmolRadio(radio, null, null, separatorHtml, groupName, (id ? id : groupName)+"_"+i, title);
255
    }
259
    }
256
  }
260
  }
257
  t+="</span>"
261
  t+="</span>"
258
  if (_jmol.debugAlert)
262
  if (_jmol.debugAlert)
259
    alert(t);
263
    alert(t);
260
  return _jmolDocumentWrite(t);
264
  return _jmolDocumentWrite(t);
261
}
265
}
262
 
266
 
263
 
267
 
264
function jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
268
function jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
265
  _jmolInitCheck();
269
  _jmolInitCheck();
266
  if (_jmol.radioGroupCount == 0)
270
  if (_jmol.radioGroupCount == 0)
267
    ++_jmol.radioGroupCount;
271
    ++_jmol.radioGroupCount;
268
  var t = _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, (id ? id : groupName + "_" + _jmol.radioCount), title ? title : 0);
272
  var t = _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, (id ? id : groupName + "_" + _jmol.radioCount), title ? title : 0);
269
  if (_jmol.debugAlert)
273
  if (_jmol.debugAlert)
270
    alert(t);
274
    alert(t);
271
  return _jmolDocumentWrite(t);
275
  return _jmolDocumentWrite(t);
272
}
276
}
273
 
277
 
274
function jmolLink(script, label, id, title) {
278
function jmolLink(script, label, id, title) {
275
  _jmolInitCheck();
279
  _jmolInitCheck();
276
  if (id == undefined || id == null)
280
  if (id == undefined || id == null)
277
    id = "jmolLink" + _jmol.linkCount;
281
    id = "jmolLink" + _jmol.linkCount;
278
  if (label == undefined || label == null)
282
  if (label == undefined || label == null)
279
    label = script.substring(0, 32);
283
    label = script.substring(0, 32);
280
  ++_jmol.linkCount;
284
  ++_jmol.linkCount;
281
  var scriptIndex = _jmolAddScript(script);
285
  var scriptIndex = _jmolAddScript(script);
282
  var t = "<span id=\"span_"+id+"\""+(title ? " title =\"" + title + "\"":"")+"><a name='" + id + "' id='" + id +
286
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><a name='" + id + "' id='" + id +
283
          "' href='javascript:_jmolClick(" + scriptIndex + _jmol.targetText + ");' onMouseover='_jmolMouseOver(" + scriptIndex +
287
          "' href='javascript:_jmolClick(" + scriptIndex + _jmol.targetText + ");' onmouseover='_jmolMouseOver(" + scriptIndex +
284
          ");return true;' onMouseout='_jmolMouseOut()' " +
288
          ");return true;' onmouseout='_jmolMouseOut()' " +
285
          _jmol.linkCssText + ">" + label + "</a></span>";
289
          _jmol.linkCssText + ">" + label + "</a></span>";
286
  if (_jmol.debugAlert)
290
  if (_jmol.debugAlert)
287
    alert(t);
291
    alert(t);
288
  return _jmolDocumentWrite(t);
292
  return _jmolDocumentWrite(t);
289
}
293
}
290
 
294
 
291
function jmolCommandInput(label, size, id, title) {
295
function jmolCommandInput(label, size, id, title) {
Line 295... Line 299...
295
  if (label == undefined || label == null)
299
  if (label == undefined || label == null)
296
    label = "Execute";
300
    label = "Execute";
297
  if (size == undefined || isNaN(size))
301
  if (size == undefined || isNaN(size))
298
    size = 60;
302
    size = 60;
299
  ++_jmol.cmdCount;
303
  ++_jmol.cmdCount;
300
  var t = "<span id=\"span_"+id+"\""+(title ? " title =\"" + title + "\"":"")+"><input name='" + id + "' id='" + id +
304
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='" + id + "' id='" + id +
301
          "' size='"+size+"'><input type=button value = '"+label+"' onClick='jmolScript(document.getElementById(\""+id+"\").value" + _jmol.targetText + ")'/></span>";
305
          "' size='"+size+"' onkeypress='_jmolCommandKeyPress(event,\""+id+"\"" + _jmol.targetText + ")'><input type=button value = '"+label+"' onclick='jmolScript(document.getElementById(\""+id+"\").value" + _jmol.targetText + ")' /></span>";
302
  if (_jmol.debugAlert)
306
  if (_jmol.debugAlert)
303
    alert(t);
307
    alert(t);
304
  return _jmolDocumentWrite(t);
308
  return _jmolDocumentWrite(t);
305
}
309
}
-
 
310
 
-
 
311
function _jmolCommandKeyPress(e, id, target) {
-
 
312
        var keycode = (window.event ? window.event.keyCode : e ? e.which : 0);
-
 
313
        if (keycode == 13) {
-
 
314
                jmolScript(document.getElementById(id).value, target)
-
 
315
        }
-
 
316
}
-
 
317
 
-
 
318
 
306
 
319
 
307
function jmolMenu(arrayOfMenuItems, size, id, title) {
320
function jmolMenu(arrayOfMenuItems, size, id, title) {
308
  _jmolInitCheck();
321
  _jmolInitCheck();
309
  if (id == undefined || id == null)
322
  if (id == undefined || id == null)
310
    id = "jmolMenu" + _jmol.menuCount;
323
    id = "jmolMenu" + _jmol.menuCount;
Line 315... Line 328...
315
    if (typeof size != "number" || size == 1)
328
    if (typeof size != "number" || size == 1)
316
      size = null;
329
      size = null;
317
    else if (size < 0)
330
    else if (size < 0)
318
      size = len;
331
      size = len;
319
    var sizeText = size ? " size='" + size + "' " : "";
332
    var sizeText = size ? " size='" + size + "' " : "";
320
    var t = "<span id=\"span_"+id+"\""+(title ? " title =\"" + title + "\"":"")+"><select name='" + id + "' id='" + id +
333
    var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><select name='" + id + "' id='" + id +
321
            "' onChange='_jmolMenuSelected(this" + _jmol.targetText + ")'" +
334
            "' onChange='_jmolMenuSelected(this" + _jmol.targetText + ")'" +
322
            sizeText + _jmol.menuCssText + ">";
335
            sizeText + _jmol.menuCssText + ">";
323
    for (var i = 0; i < len; ++i) {
336
    for (var i = 0; i < len; ++i) {
324
      var menuItem = arrayOfMenuItems[i];
337
      var menuItem = arrayOfMenuItems[i];
325
      type = typeof menuItem;
338
      type = typeof menuItem;
Line 338... Line 351...
338
        t += "<optgroup label='" + text + "'>";  
351
        t += "<optgroup label='" + text + "'>";  
339
          } else if (script=="#optgroupEnd") {
352
          } else if (script=="#optgroupEnd") {
340
        t += "</optgroup>";      
353
        t += "</optgroup>";      
341
          } else {             
354
          } else {             
342
        var scriptIndex = _jmolAddScript(script);
355
        var scriptIndex = _jmolAddScript(script);
343
        var selectedText = isSelected ? "' selected>" : "'>";
356
        var selectedText = isSelected ? "' selected='true'>" : "'>";
344
        t += "<option value='" + scriptIndex + selectedText + text + "</option>";
357
        t += "<option value='" + scriptIndex + selectedText + text + "</option>";
345
          }
358
          }
346
    }
359
    }
347
    t += "</select></span>";
360
    t += "</select></span>";
348
    if (_jmol.debugAlert)
361
    if (_jmol.debugAlert)
Line 528... Line 541...
528
  modelbase: ".",
541
  modelbase: ".",
529
 
542
 
530
  appletCount: 0,
543
  appletCount: 0,
531
  appletSuffixes: [],
544
  appletSuffixes: [],
532
  appletWindow: null,
545
  appletWindow: null,
-
 
546
  allowedJmolSize: [25, 2048, 300],   // min, max, default (pixels)
-
 
547
          /*  By setting the _jmol.allowedJmolSize[] variable in the webpage
-
 
548
              before calling jmolApplet(), limits for applet size can be overriden.
-
 
549
                    2048 standard for GeoWall (http://geowall.geo.lsa.umich.edu/home.html)
533
 
550
          */  
534
  buttonCount: 0,
551
  buttonCount: 0,
535
  checkboxCount: 0,
552
  checkboxCount: 0,
536
  linkCount: 0,
553
  linkCount: 0,
537
  cmdCount: 0,
554
  cmdCount: 0,
538
  menuCount: 0,
555
  menuCount: 0,
Line 782... Line 799...
782
    jmolSetTarget(nameSuffix);
799
    jmolSetTarget(nameSuffix);
783
    ready["jmolApplet" + nameSuffix] = false;
800
    ready["jmolApplet" + nameSuffix] = false;
784
    if (_jmol.debugAlert)
801
    if (_jmol.debugAlert)
785
      alert(t);
802
      alert(t);
786
    return _jmolDocumentWrite(t);
803
    return _jmolDocumentWrite(t);
787
  }
804
  }
788
}
805
}
789
 
806
 
790
function _jmolParams() {
807
function _jmolParams() {
791
 var t = "";
808
 var t = "";
792
 for (i in _jmol.params)
809
 for (var i in _jmol.params)
793
        if(_jmol.params[i]!="")
810
        if(_jmol.params[i]!="")
794
                 t+="  <param name='"+i+"' value='"+_jmol.params[i]+"' />\n";
811
                 t+="  <param name='"+i+"' value='"+_jmol.params[i]+"' />\n";
795
 return t
812
 return t
796
}
813
}
797
 
814
 
Line 820... Line 837...
820
      if (msg == null)
837
      if (msg == null)
821
        msg = "Your web browser is not fully compatible with Jmol\n\n" +
838
        msg = "Your web browser is not fully compatible with Jmol\n\n" +
822
              "browser: " + browser +
839
              "browser: " + browser +
823
              "   version: " + browserVersion +
840
              "   version: " + browserVersion +
824
              "   os: " + os +
841
              "   os: " + os +
-
 
842
              "   isBrowserCompliant: " + isBrowserCompliant +
-
 
843
              "   isJavaCompliant: " + isJavaCompliant +
825
              "\n\n" + ua;
844
              "\n\n" + ua;
826
      alert(msg);
845
      alert(msg);
827
    }
846
    }
828
  }
847
  }
829
  return false;
848
  return false;
-
 
849
}
-
 
850
 
-
 
851
function jmolSetXHTML(id) {
-
 
852
        _jmol.isXHTML = true
-
 
853
        _jmol.XhtmlElement = null
-
 
854
        _jmol.XhtmlAppendChild = false
-
 
855
        if (id){
-
 
856
                _jmol.XhtmlElement = document.getElementById(id)
-
 
857
                _jmol.XhtmlAppendChild = true
-
 
858
        }
830
}
859
}
831
 
860
 
832
function _jmolDocumentWrite(text) {
861
function _jmolDocumentWrite(text) {
833
  if (_jmol.currentDocument)
862
        if (_jmol.currentDocument) {
-
 
863
                if (_jmol.isXHTML && !_jmol.XhtmlElement) {
-
 
864
                        var s = document.getElementsByTagName("script")
-
 
865
                        _jmol.XhtmlElement = s.item(s.length - 1)
-
 
866
                        _jmol.XhtmlAppendChild = false
-
 
867
                }
-
 
868
                if (_jmol.XhtmlElement) {
-
 
869
                        _jmolDomDocumentWrite(text)
-
 
870
                } else {
834
    _jmol.currentDocument.write(text);
871
                        _jmol.currentDocument.write(text);
-
 
872
                }
-
 
873
        }
835
  return text;
874
        return text;
-
 
875
}
-
 
876
 
-
 
877
function _jmolDomDocumentWrite(data) {
-
 
878
        var pt = 0
-
 
879
        var Ptr = []
-
 
880
        Ptr[0] = 0
-
 
881
        while (Ptr[0] < data.length) {
-
 
882
                var child = _jmolGetDomElement(data, Ptr)
-
 
883
                if (!child)break
-
 
884
                if (_jmol.XhtmlAppendChild)
-
 
885
                        _jmol.XhtmlElement.appendChild(child)
-
 
886
                else
-
 
887
                        _jmol.XhtmlElement.parentNode.insertBefore(child, _jmol.XhtmlElement);
-
 
888
        }
-
 
889
}
-
 
890
function _jmolGetDomElement(data, Ptr, closetag, lvel) {
-
 
891
        var e = document.createElement("span")
-
 
892
        e.innerHTML = data
-
 
893
        Ptr[0] = data.length
-
 
894
        return e
-
 
895
 
-
 
896
//unnecessary?
-
 
897
 
-
 
898
        if (!closetag)closetag = ""
-
 
899
        if (!lvel) lvel = 0
-
 
900
        var pt0 = Ptr[0]
-
 
901
        var pt = pt0
-
 
902
        while (pt < data.length && data.charAt(pt) != "<") pt++
-
 
903
        if (pt != pt0) {
-
 
904
                var text = data.substring(pt0, pt)
-
 
905
                Ptr[0] = pt
-
 
906
                return document.createTextNode(text)
-
 
907
        }      
-
 
908
        pt0 = ++pt
-
 
909
        var ch
-
 
910
        while (pt < data.length && "\n\r\t >".indexOf(ch = data.charAt(pt)) < 0) pt++
-
 
911
        var tagname = data.substring(pt0, pt)
-
 
912
        var e = (tagname == closetag  || tagname == "/" ? ""
-
 
913
                : document.createElementNS ? document.createElementNS('http://www.w3.org/1999/xhtml', tagname)
-
 
914
                : document.createElement(tagname));
-
 
915
        if (ch == ">") {
-
 
916
                Ptr[0] = ++pt
-
 
917
                return e
-
 
918
        }
-
 
919
        while (pt < data.length && (ch = data.charAt(pt)) != ">") {
-
 
920
                while (pt < data.length && "\n\r\t ".indexOf(ch = data.charAt(pt)) >= 0) pt++
-
 
921
                pt0 = pt
-
 
922
                while (pt < data.length && "\n\r\t =/>".indexOf(ch = data.charAt(pt)) < 0) pt++
-
 
923
                var attrname = data.substring(pt0, pt).toLowerCase()
-
 
924
                if (attrname && ch != "=")
-
 
925
                        e.setAttribute(attrname, "true")
-
 
926
                while (pt < data.length && "\n\r\t ".indexOf(ch = data.charAt(pt)) >= 0) pt++
-
 
927
                if (ch == "/") {
-
 
928
                        Ptr[0] = pt + 2
-
 
929
                        return e
-
 
930
                } else if (ch == "=") {
-
 
931
                        var quote = data.charAt(++pt)
-
 
932
                        pt0 = ++pt
-
 
933
                        while (pt < data.length && (ch = data.charAt(pt)) != quote) pt++
-
 
934
                        var attrvalue = data.substring(pt0, pt)
-
 
935
                        e.setAttribute(attrname, attrvalue)
-
 
936
                        pt++
-
 
937
                }
-
 
938
        }
-
 
939
        Ptr[0] = ++pt
-
 
940
        while (Ptr[0] < data.length) {
-
 
941
                var child = _jmolGetDomElement(data, Ptr, "/" + tagname, lvel+1)
-
 
942
                if (!child)break
-
 
943
                e.appendChild(child)
-
 
944
        }
-
 
945
        return e
836
}
946
}
837
 
947
 
838
function _jmolPopup(url) {
948
function _jmolPopup(url) {
839
  var popup = window.open(url, "JmolPopup",
949
  var popup = window.open(url, "JmolPopup",
840
                          "left=150,top=150,height=400,width=600," +
950
                          "left=150,top=150,height=400,width=600," +
Line 862... Line 972...
862
  var inlineModel =
972
  var inlineModel =
863
    model.replace(/\r|\n|\r\n/g, "|").replace(/'/g, "&#39;");
973
    model.replace(/\r|\n|\r\n/g, "|").replace(/'/g, "&#39;");
864
  if (_jmol.debugAlert)
974
  if (_jmol.debugAlert)
865
    alert("inline model:\n" + inlineModel);
975
    alert("inline model:\n" + inlineModel);
866
  return inlineModel;
976
  return inlineModel;
867
}
-
 
868
 
-
 
869
        /*  AngelH, mar2007:
-
 
870
                By (re)setting this variable in the webpage before calling jmolApplet(), limits for applet size can be overriden.
-
 
871
        */
-
 
872
 
-
 
873
        /* hansonr, jun2007:
-
 
874
                2048 standard for GeoWall (http://geowall.geo.lsa.umich.edu/home.html)
-
 
875
        */
-
 
876
 
-
 
877
if (allowedJmolSize==undefined) var allowedJmolSize = [1, 2048, 300]   // min, max, default (pixels)
-
 
878
function _jmolGetAppletSize(size) {
-
 
879
        /*  AngelH, mar2007
-
 
880
                Accepts single number or 2-value array, each one can be either:
-
 
881
           percent (text string ending %), decimal 0 to 1 (percent/100), number, or text string (interpreted as nr.)
-
 
882
           Size is now returned as string or number, no "px".
-
 
883
        */
-
 
884
  var width, height;
-
 
885
  if ( (typeof size) == "object" && size != null ) {
-
 
886
    width = size[0]; height = size[1];
-
 
887
  } else {
-
 
888
    width = height = size;
-
 
889
  }
-
 
890
  // if percent, leave it as it is:
-
 
891
  if ( width.toString().charAt(width.toString().length-1) != "%" ) {
-
 
892
    width = parseFloat(width);  // convert to nr., or strip text, or make zero
-
 
893
        if ( width <= 1 && width > 0 ) { width = (width*100)+"%" }      // decimal: convert to percent and quit
-
 
894
        else if ( width >= allowedJmolSize[0] && width <= allowedJmolSize[1] ) { width = parseInt(width) }      // accept only that range (pixels)
-
 
895
        else { width = allowedJmolSize[2] }     // default size 300 pixels
-
 
896
  }
-
 
897
  if ( height.toString().charAt(height.toString().length-1) != "%" ) {
-
 
898
    height = parseFloat(height);
-
 
899
        if ( height <= 1 && height > 0 ) { height = (height*100)+"%" }
-
 
900
        else if ( height >= allowedJmolSize[0] && height <= allowedJmolSize[1] ) { height = parseInt(height) }
-
 
901
        else { height = allowedJmolSize[2] }
-
 
902
  }
-
 
903
  return [width, height];
-
 
904
}
977
}
905
 
978
 
906
function _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
979
function _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
907
  ++_jmol.radioCount;
980
  ++_jmol.radioCount;
908
  if (groupName == undefined || groupName == null)
981
  if (groupName == undefined || groupName == null)
Line 913... Line 986...
913
    labelHtml = script.substring(0, 32);
986
    labelHtml = script.substring(0, 32);
914
  if (! separatorHtml)
987
  if (! separatorHtml)
915
    separatorHtml = "";
988
    separatorHtml = "";
916
  var scriptIndex = _jmolAddScript(script);
989
  var scriptIndex = _jmolAddScript(script);
917
  var eospan = "</span>"
990
  var eospan = "</span>"
918
  var t = "<span id=\"span_"+id+"\""+(title ? " title =\"" + title + "\"":"")+"><input name='"
991
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='"
919
        + groupName + "' id='"+id+"' type='radio' onClick='_jmolClick(" +
992
        + groupName + "' id='"+id+"' type='radio' onclick='_jmolClick(" +
920
         scriptIndex + _jmol.targetText + ");return true;' onMouseover='_jmolMouseOver(" +
993
         scriptIndex + _jmol.targetText + ");return true;' onmouseover='_jmolMouseOver(" +
921
         scriptIndex + ");return true;' onMouseout='_jmolMouseOut()' " +
994
         scriptIndex + ");return true;' onmouseout='_jmolMouseOut()' " +
922
         (isChecked ? "checked " : "") + _jmol.radioCssText + "/>"
995
         (isChecked ? "checked='true' " : "") + _jmol.radioCssText + " />"
923
  if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
996
  if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
924
        t += eospan
997
        t += eospan
925
        eospan = "";
998
        eospan = "";
926
  }
999
  }
927
  t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan + separatorHtml;
1000
  t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan + separatorHtml;
Line 1337... Line 1410...
1337
 if(!targetSuffix)targetSuffix="0"
1410
 if(!targetSuffix)targetSuffix="0"
1338
  return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo
1411
  return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo
1339
}
1412
}
1340
 
1413
 
1341
function jmolRestoreOrientation(id, targetSuffix) {
1414
function jmolRestoreOrientation(id, targetSuffix) {
1342
 if(!targetSuffix)targetSuffix="0"
1415
 if(!targetSuffix)targetSuffix="0"
1343
 var s=_jmol["savedOrientation"+id]
1416
 var s=_jmol["savedOrientation"+id]
1344
 if (!s || s == "")return
1417
 if (!s || s == "")return
1345
 s=s.replace(/1\.0/,"0")
1418
 s=s.replace(/1\.0/,"0")
1346
 return jmolScriptWait(s,targetSuffix)
1419
 return jmolScriptWait(s,targetSuffix)
1347
}
1420
}
Line 1381... Line 1454...
1381
 if(!_jmol.RCSBserver)_jmol.RCSBserver="http://www.rcsb.org"
1454
 if(!_jmol.RCSBserver)_jmol.RCSBserver="http://www.rcsb.org"
1382
 if(!_jmol.defaultURL_RCSB)_jmol.defaultURL_RCSB=_jmol.RCSBserver+"/pdb/files/1CRN.CIF"
1455
 if(!_jmol.defaultURL_RCSB)_jmol.defaultURL_RCSB=_jmol.RCSBserver+"/pdb/files/1CRN.CIF"
1383
 if(!fileformat)fileformat="PDB"
1456
 if(!fileformat)fileformat="PDB"
1384
 if(!pdbid)pdbid=prompt("Enter a 4-digit PDB ID:",_jmol.thismodel)
1457
 if(!pdbid)pdbid=prompt("Enter a 4-digit PDB ID:",_jmol.thismodel)
1385
 if(!pdbid || pdbid.length != 4)return ""
1458
 if(!pdbid || pdbid.length != 4)return ""
1386
 if(!targetSuffix)targetSuffix="0"
1459
 if(!targetSuffix)targetSuffix="0"
1387
 if(!optionalscript)optionalscript=""
1460
 if(!optionalscript)optionalscript=""
1388
 var url=_jmol.defaultURL_RCSB.replace(/1CRN/g,pdbid.toUpperCase())
1461
 var url=_jmol.defaultURL_RCSB.replace(/1CRN/g,pdbid.toUpperCase())
1389
 if(fileformat!="CIF")url=url.replace(/CIF/,fileformat)
1462
 if(fileformat!="CIF")url=url.replace(/CIF/,fileformat)
1390
 _jmol.optionalscript=optionalscript
1463
 _jmol.optionalscript=optionalscript
1391
 _jmol.thismodel=pdbid
1464
 _jmol.thismodel=pdbid
Line 1401... Line 1474...
1401
 
1474
 
1402
function jmolLoadAjax_STOLAF_ANY(url, userid, optionalscript,targetSuffix){
1475
function jmolLoadAjax_STOLAF_ANY(url, userid, optionalscript,targetSuffix){
1403
 _jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"
1476
 _jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"
1404
 if(!_jmol.thisurlANY)_jmol.thisurlANY = "http://www.stolaf.edu/depts/chemistry/mo/struc/data/ycp3-1.mol"
1477
 if(!_jmol.thisurlANY)_jmol.thisurlANY = "http://www.stolaf.edu/depts/chemistry/mo/struc/data/ycp3-1.mol"
1405
 if(!url)url=prompt("Enter any (uncompressed file) URL:", _jmol.thisurlANY)
1478
 if(!url)url=prompt("Enter any (uncompressed file) URL:", _jmol.thisurlANY)
1406
 if(!userid)userid="0"
1479
 if(!userid)userid="0"
1407
 if(!targetSuffix)targetSuffix="0"
1480
 if(!targetSuffix)targetSuffix="0"
1408
 if(!optionalscript)optionalscript=""
1481
 if(!optionalscript)optionalscript=""
1409
 _jmol.optionalscript=optionalscript
1482
 _jmol.optionalscript=optionalscript
1410
 _jmol.thistargetsuffix=targetSuffix
1483
 _jmol.thistargetsuffix=targetSuffix
1411
 _jmol.modelArray = []
1484
 _jmol.modelArray = []
1412
 _jmol.thisurl = url
1485
 _jmol.thisurl = url
1413
 url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)
1486
 url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)
1414
 _jmolDomScriptLoad(url)
1487
 _jmolDomScriptLoad(url)
1415
}
1488
}
1416
 
1489
 
1417
 
1490
 
1418
/////////////// Mineralogical Society of America (MSA) data /////////
1491
/////////////// Mineralogical Society of America (MSA) data /////////
1419
 
1492
 
1420
function jmolLoadAjax_MSA(key,value,optionalscript,targetSuffix){
1493
function jmolLoadAjax_MSA(key,value,optionalscript,targetSuffix){
1421
 
1494
 
1422
 if(!_jmol.thiskeyMSA)_jmol.thiskeyMSA = "mineral"
1495
 if(!_jmol.thiskeyMSA)_jmol.thiskeyMSA = "mineral"
1423
 if(!_jmol.thismodelMSA)_jmol.thismodelMSA = "quartz"
1496
 if(!_jmol.thismodelMSA)_jmol.thismodelMSA = "quartz"
1424
 if(!_jmol.ajaxURL_MSA)_jmol.ajaxURL_MSA="http://rruff.geo.arizona.edu/AMS/result.php?mineral=quartz&viewing=ajaxjs"
1497
 if(!_jmol.ajaxURL_MSA)_jmol.ajaxURL_MSA="http://rruff.geo.arizona.edu/AMS/result.php?mineral=quartz&viewing=ajaxjs"
1425
 if(!key)key=prompt("Enter a field:", _jmol.thiskeyMSA)
1498
 if(!key)key=prompt("Enter a field:", _jmol.thiskeyMSA)
1426
 if(!key)return ""
1499
 if(!key)return ""
1427
 if(!value)value=prompt("Enter a "+key+":", _jmol.thismodelMSA)
1500
 if(!value)value=prompt("Enter a "+key+":", _jmol.thismodelMSA)
1428
 if(!value)return ""
1501
 if(!value)return ""
1429
 if(!targetSuffix)targetSuffix="0"
1502
 if(!targetSuffix)targetSuffix="0"
1430
 if(!optionalscript)optionalscript=""
1503
 if(!optionalscript)optionalscript=""
1431
 if(optionalscript == 1)optionalscript='load "" {1 1 1}'
1504
 if(optionalscript == 1)optionalscript='load "" {1 1 1}'
1432
 var url=_jmol.ajaxURL_MSA.replace(/mineral/g,key).replace(/quartz/g,value)
1505
 var url=_jmol.ajaxURL_MSA.replace(/mineral/g,key).replace(/quartz/g,value)
1433
 _jmol.optionalscript=optionalscript
1506
 _jmol.optionalscript=optionalscript
1434
 _jmol.thiskeyMSA=key
1507
 _jmol.thiskeyMSA=key
1435
 _jmol.thismodelMSA=value
1508
 _jmol.thismodelMSA=value
Line 1501... Line 1574...
1501
}
1574
}
1502
 
1575
 
1503
 
1576
 
1504
///////////////////////////////////////////
1577
///////////////////////////////////////////
1505
 
1578
 
1506
//new 9:49 AM 3/6/2007:
1579
  //  This should no longer be needed, jmolResizeApplet() is better; kept for backwards compatibility
1507
 
1580
  /*
-
 
1581
        Resizes absolutely (pixels) or by percent of window (w or h 0.5 means 50%).
-
 
1582
        targetSuffix is optional and defaults to zero (first applet in page).
-
 
1583
        Both w and h are optional, but needed if you want to use targetSuffix.
-
 
1584
                h defaults to w
1508
//both w and h are optional. 
1585
                w defaults to 100% of window
1509
//if either is between 0 and 1, then it is taken as percent/100.
1586
        If either w or h is between 0 and 1, then it is taken as percent/100.
1510
//if either is greater than 1, then it is taken as a size. 
1587
        If either w or h is greater than 1, then it is taken as a size (pixels).
-
 
1588
        */
1511
function jmolResize(w,h) {
1589
function jmolResize(w,h,targetSuffix) {
1512
 _jmol.alerted = true;
1590
 _jmol.alerted = true;
1513
 var percentW = (!w ? 100 : w <= 1  && w > 0 ? w * 100 : 0)
1591
 var percentW = (!w ? 100 : w <= 1  && w > 0 ? w * 100 : 0);
1514
 var percentH = (!h ? percentW : h <= 1 && h > 0 ? h * 100 : 0)
1592
 var percentH = (!h ? percentW : h <= 1 && h > 0 ? h * 100 : 0);
1515
 if (_jmol.browser=="msie") {
1593
 if (_jmol.browser=="msie") {
1516
   var width=document.body.clientWidth;
1594
   var width=document.body.clientWidth;
1517
   var height=document.body.clientHeight;
1595
   var height=document.body.clientHeight;
1518
 } else {
1596
 } else {
1519
   var netscapeScrollWidth=15;
1597
   var netscapeScrollWidth=15;
1520
   var width=window.innerWidth - netscapeScrollWidth;
1598
   var width=window.innerWidth - netscapeScrollWidth;
1521
   var height=window.innerHeight-netscapeScrollWidth;
1599
   var height=window.innerHeight-netscapeScrollWidth;
1522
 }
1600
 }
1523
 var applet = _jmolGetApplet(0);
1601
 var applet = _jmolGetApplet(targetSuffix);
-
 
1602
 if(!applet)return;
-
 
1603
 applet.style.width = (percentW ? width * percentW/100 : w)+"px";
-
 
1604
 applet.style.height = (percentH ? height * percentH/100 : (h ? h : w))+"px";
-
 
1605
 //title=width +  " " + height + " " + (new Date());
-
 
1606
}
-
 
1607
 
-
 
1608
// 13 Jun 09 -- makes jmolResize() obsolete  (kept for backwards compatibility)
-
 
1609
function jmolResizeApplet(size,targetSuffix) {
-
 
1610
 // See _jmolGetAppletSize() for the formats accepted as size [same used by jmolApplet()]
-
 
1611
 //  Special case: an empty value for width or height is accepted, meaning no change in that dimension.
-
 
1612
 _jmol.alerted = true;
-
 
1613
 var applet = _jmolGetApplet(targetSuffix);
1524
 if(!applet)return;
1614
 if(!applet)return;
1525
 applet.style.width = (percentW ? width * percentW/100 : w)+"px"
1615
 var sz = _jmolGetAppletSize(size, "px");
1526
 applet.style.height = (percentH ? height * percentH/100 : h)+"px"
1616
 sz[0] && (applet.style.width = sz[0]);
1527
 title=width +  " " + height + " " + (new Date())
1617
 sz[1] && (applet.style.height = sz[1]);
1528
}
1618
}
-
 
1619
 
-
 
1620
function _jmolGetAppletSize(size, units) {
-
 
1621
        /* Accepts single number or 2-value array, each one can be one of:
-
 
1622
           percent (text string ending %), decimal 0 to 1 (percent/100), number, or text string (interpreted as nr.)
-
 
1623
           [width, height] array of strings is returned, with units added if specified.
-
 
1624
           Percent is relative to container div or element (which should have explicitly set size).
-
 
1625
        */
-
 
1626
  var width, height;
-
 
1627
  if ( (typeof size) == "object" && size != null ) {
-
 
1628
    width = size[0]; height = size[1];
-
 
1629
  } else {
-
 
1630
    width = height = size;
-
 
1631
  }
-
 
1632
  return [_jmolFixDim(width, units), _jmolFixDim(height, units)];
-
 
1633
}
-
 
1634
 
-
 
1635
function _jmolFixDim(x, units) {
-
 
1636
  var sx = "" + x;
-
 
1637
  return (sx.length == 0 ? (units ? "" : _jmol.allowedJmolSize[2])
-
 
1638
        : sx.indexOf("%") == sx.length-1 ? sx
-
 
1639
        : (x = parseFloat(x)) <= 1 && x > 0 ? x * 100 + "%"
-
 
1640
        : (isNaN(x = Math.floor(x)) ? _jmol.allowedJmolSize[2]
-
 
1641
                : x < _jmol.allowedJmolSize[0] ? _jmol.allowedJmolSize[0]
-
 
1642
            : x > _jmol.allowedJmolSize[1] ? _jmol.allowedJmolSize[1]
-
 
1643
        : x) + (units ? units : ""));
-
 
1644
}
-
 
1645
 
-
 
1646
 
-
 
1647
 
1529
 
1648