fix for JAL-1510 - workaround for IE9
authorJim Procter <jprocter@dundee.ac.uk>
Wed, 28 May 2014 14:15:21 +0000 (15:15 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Wed, 28 May 2014 14:18:22 +0000 (15:18 +0100)
examples-jbake/assets/javascript/jalview.js
examples/javascript/jalview.js

index 293b73a..c9e5d1e 100644 (file)
@@ -27,6 +27,21 @@ var _modeltofiles = new Array();
 // counter for jmol structures
 var mnum = 1;
 
+function getDocumentBase() {
+       var dburi = document.baseURI;
+       // IE does not support document.baseURI
+       // logic from patch to TYPO3:
+       // http://forge.typo3.org/projects/typo3cms-core/repository/revisions/f61358afad28adb6dcaeb270ba480e998dfb0b79/diff/typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js
+       if (!dburi) {
+               var baseTags = document.getElementsByTagName('base');
+               if (baseTags.length > 0) {
+                       dburi = baseTags[0].href;
+               } else {
+                       dburi = document.URL;
+               }
+       }
+       return dburi.substring(0, dburi.lastIndexOf("/") + 1);
+}
 function setConsole(console) {
        _console = console;
 }
@@ -147,7 +162,7 @@ function linkJvJmol(applet, jmolView, modeltofiles) {
                jmbinding._jmol=jmolView;
                // now update structureListener list
                mtf="";
-               var dbase = document.baseURI.substring(0,document.baseURI.lastIndexOf("/")+1);
+               var dbase = getDocumentBase();
                for (m in jmbinding._modelstofiles)
                { if (m>0) { mtf+=sep; }
                mtf+=jmbinding._modelstofiles[m];
@@ -190,10 +205,8 @@ function _structure(list1, list2, list3, list4) {
                                ("" + list4));
                // 1 is pdb file, 2 is residue number, 3 is chain
                // list1 = new Object(list1);
-               var base = list[1].indexOf(document.baseURI
-                               .substring(0, document.baseURI.lastIndexOf('/'))
-                               ); // .indexOf(_path);
-               if (base==0) { base = document.baseURI.lastIndexOf('/'); }
+               var base = list[1].indexOf(getDocumentBase()); // .indexOf(_path);
+               if (base==0) { base = getDocumentBase(); }
                var sid = list[1]; // .substring(base);
                base = list[1].substring(0, base);
                if (_console) {
@@ -298,8 +311,7 @@ function _jmolhover(jmid, atomlabel, atomidx) {
        // use atomlabel[5] to look up model filename so we can highlight associated positions in any jalviews
        for (ap in _jvapps) {
                _jvapps[ap].mouseOverStructure(atomlabel[2], atomlabel[3],
-                               document.baseURI
-                                               .substring(0, document.baseURI.lastIndexOf('/'))
+                               getDocumentBase()
                                                + "/" + 
                                                modeltofiles[atomlabel[5]]);
                msg = _jmolhovermsg;
index 293b73a..c9e5d1e 100644 (file)
@@ -27,6 +27,21 @@ var _modeltofiles = new Array();
 // counter for jmol structures
 var mnum = 1;
 
+function getDocumentBase() {
+       var dburi = document.baseURI;
+       // IE does not support document.baseURI
+       // logic from patch to TYPO3:
+       // http://forge.typo3.org/projects/typo3cms-core/repository/revisions/f61358afad28adb6dcaeb270ba480e998dfb0b79/diff/typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js
+       if (!dburi) {
+               var baseTags = document.getElementsByTagName('base');
+               if (baseTags.length > 0) {
+                       dburi = baseTags[0].href;
+               } else {
+                       dburi = document.URL;
+               }
+       }
+       return dburi.substring(0, dburi.lastIndexOf("/") + 1);
+}
 function setConsole(console) {
        _console = console;
 }
@@ -147,7 +162,7 @@ function linkJvJmol(applet, jmolView, modeltofiles) {
                jmbinding._jmol=jmolView;
                // now update structureListener list
                mtf="";
-               var dbase = document.baseURI.substring(0,document.baseURI.lastIndexOf("/")+1);
+               var dbase = getDocumentBase();
                for (m in jmbinding._modelstofiles)
                { if (m>0) { mtf+=sep; }
                mtf+=jmbinding._modelstofiles[m];
@@ -190,10 +205,8 @@ function _structure(list1, list2, list3, list4) {
                                ("" + list4));
                // 1 is pdb file, 2 is residue number, 3 is chain
                // list1 = new Object(list1);
-               var base = list[1].indexOf(document.baseURI
-                               .substring(0, document.baseURI.lastIndexOf('/'))
-                               ); // .indexOf(_path);
-               if (base==0) { base = document.baseURI.lastIndexOf('/'); }
+               var base = list[1].indexOf(getDocumentBase()); // .indexOf(_path);
+               if (base==0) { base = getDocumentBase(); }
                var sid = list[1]; // .substring(base);
                base = list[1].substring(0, base);
                if (_console) {
@@ -298,8 +311,7 @@ function _jmolhover(jmid, atomlabel, atomidx) {
        // use atomlabel[5] to look up model filename so we can highlight associated positions in any jalviews
        for (ap in _jvapps) {
                _jvapps[ap].mouseOverStructure(atomlabel[2], atomlabel[3],
-                               document.baseURI
-                                               .substring(0, document.baseURI.lastIndexOf('/'))
+                               getDocumentBase()
                                                + "/" + 
                                                modeltofiles[atomlabel[5]]);
                msg = _jmolhovermsg;