All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openscience.chimetojmol.ChimeToJmol.js Maven / Gradle / Ivy

There is a newer version: 14.31.10
Show newest version
/*

ChimeToJmol.js
[email protected] 8:07 AM 4/21/2010
# last update 10/18/2010 7:24:31 AM (comments added 12:35 PM 4/13/2011)

A set of functions that will (when fully developed) 
allow just about any Chime page to be converted automatically 
from Chime EMBED tags to Jmol applets and buttons.

Also changes older Jmol "applet" code to use Jmol.js

1) Set jmolDirectory (below) to the desired directory to contain
   the standard Jmol files (Jmol.js, JmolApplet*.jar) 
   as well as this file, ChimeToJmol.js
   and add those files to it.

2) add these lines to your page's  section (with the appropriate directory, if needed):

 
 

3) using a multi-file text editor such as superFix.exe 
  (http://stolaf.edu/people/hansonr/origami/WIN/SUPERFIX.EXE)
  change allow occurances of "= 0)return
	var body = document.body.innerHTML
	if (body.indexOf("JmolApplet") >= 0) {
		if(body.indexOf("JmolAppletControl") >= 0)__fixJmol()
		return
	}
	if (body.indexOf("= 0 || body.indexOf("= 0) __fixChime()
}

window.onload = checkJmol

function __fixJmol() {
	var body = document.body.innerHTML
	var ptAPPLET = -1
	var Text = body.split("")
		if (text.indexOf("JmolAppletControl") >= 0) {
			Text[i] = __jmolFixJmolAppletControl(text.substring(0, pt)) + text.substring(pt + 9)
		} else if (text.indexOf("JmolApplet") >= 0) {
			Text[i] = __jmolFixJmolApplet(text.substring(0, pt)) + text.substring(pt + 9)
		} else {
			Text[i] = "" + jmolButton(A.script,"X",A.target) + ""
}

function __fixChime() {
	jmolInitialize(jmolDirectory, 
		(document.location.protocol=="file:" || useSignedApplet ? "JmolAppletSigned0.jar" : "JmolApplet0.jar"))
	jmolSetDocument(0)
	var body = document.body.innerHTML
	var Text = body.split("= 0;pt++) {
      switch (text.charAt(pt)) {
      case '"':
      case "'":
        iq += 1
        break
      case '>':
        if (iq%2==0) {
          iq = -1
        }
      }
      if (iq < 0)
        break;
    }
		var isButton = (text.indexOf("target=") >= 0) 
		if (isButton) {
			Text[i] = __jmolFixChimeButton(text.substring(0, pt), i) + text.substring(pt + 1)
		} else {
			Text[i] = __jmolFixChimeApplet(text.substring(0, pt)) + text.substring(pt + 1)
		}
	}
	document.body.innerHTML = Text.join("")
}

function __jmolFixChimeApplet(tag) {
	var A = __jmolGetAttributes(tag)
  if (A.width.indexOf("%") < 0)
  	A.width = parseInt(A.width)
  if (A.height.indexOf("%") < 0)
  	A.height = parseInt(A.height)
	A.script = (A.script ? __jmolFixChimeScript(A.script) : "")
	if (A.animmode) A.script += ";animation mode " + A.animmode + ";"
	if (A.animfps) A.script += ";animation fps " + A.animfps + ";"
	if (A.startanim && A.startanim.toLowerCase() == "true") A.script += ";animation on;"
	if (A.src.indexOf(".spt")>= 0) {
  	A.src = 'chimeScript = load("' + A.src + '"); javascript "__jmolRunChimeScript(\''+A.name+'\')";'	  
  } else {
    A.src = "load = \"" + A.src + "\";"
  }
  if (A.name)
    jmolSetTarget(A.name)
  var s = jmolApplet([A.width,A.height],A.src + A.script + ";set errorCallback '__jmolGenericCallback'", A.name)	
	return s
}

function __jmolRunChimeScript(target) {
  var script = jmolEvaluate('chimeScript', target)
  script = __jmolFixChimeScript(script)
  jmolScript(script, target);
}

function __jmolFixChimeButton(tag, iBtn) {
	var A = __jmolGetAttributes(tag, iBtn) 
	if (!A.width)A.width = 12
	if (!A.height)A.height = 12
	if (A.src) {
  	A.script = 'chimeScript = load("' + A.src + '"); javascript "__jmolRunChimeScript(\''+A.target+'\')"'	  
  } else {
  	A.script = __jmolFixChimeScript(A.script)
  }
  jmolSetTarget(A.target)
  var text = (chimebtn ? "" : "[x]")
  var s = "" + jmolLink(A.script,text, Math.random(), A.script.replace(/\"/g,"'")) + " "
	return s
}

function __jmolGetAttributes(tag, iBtn) {
  var S = {}
  var name = ""
  var value = ""
  var inName = false
  var inValue = false
  tag = tag.replace(/\/g, " ")
  tag = tag.replace(/\
/g, " ") if (tag.substring(tag.length-1, tag.length) == "/") tag = tag.substring(0, tag.length-1) if (tag.indexOf("= 0) tag = tag.replace(/\/g, " ") .replace(/\>/g, " ") tag = tag.replace(/\s+/g, " ") tag = tag.replace(/ \=/g, "=") tag = tag.replace(/\= /g, "=") tag += " =" for (var i = 0; i < tag.length - 2; i++) { if (tag.charAt(i) == " ") continue var pts = tag.indexOf(" ", i) var pte = tag.indexOf("=", i) var ptq = tag.indexOf("'", pte + 1) var ptqq = tag.indexOf("\"", pte + 1) if (ptqq == pte + 1)ptq = ptqq var ptq2 = tag.indexOf((ptq == ptqq ? "\"" : "'"), ptq + 1) if (pts < pte) { //




© 2015 - 2024 Weber Informatics LLC | Privacy Policy