Diff for /loncom/html/adm/jsMath/plugins/autoload.js between versions 1.3 and 1.4

version 1.3, 2006/05/17 22:19:38 version 1.4, 2007/10/09 21:29:28
Line 9 Line 9
  *     *  
  *  You can control the items to look for via the variables   *  You can control the items to look for via the variables
  *     *  
  *      jsMath.Autoload.findMathElements  
  *      jsMath.Autoload.findTeXstrings   *      jsMath.Autoload.findTeXstrings
  *      jsMath.Autoload.findLaTeXstrings   *      jsMath.Autoload.findLaTeXstrings
  *      jsMath.Autoload.findCustomStrings   *      jsMath.Autoload.findCustomStrings
  *      jsMath.Autoload.findCustomSettings   *      jsMath.Autoload.findCustomSettings
  *     *  
  *  which control whether to look for SPAN and DIV elements of class   *  which control whether to look for TeX strings that will be converted
  *  "math", TeX strings that will be converted by jsMath.ConvertTeX(), or   *  by jsMath.ConvertTeX(), or LaTeX strings that will be converted by
  *  LaTeX strings that will be converted by jsMath.ConvertLaTeX().  By   *  jsMath.ConvertLaTeX().  By default, the first is true and the second
  *  default, the first is true and the second and third are false.  The   *  and third are false.  The findCustomStrings can be used to specify your
  *  findCustomStrings can be used to specify your own delimiters for   *  own delimiters for in-line and display mathematics, e.g.
  *  in-line and display mathematics, e.g  
  *     *  
  *      jsMath.Autoload.findCustomStrings = [   *      jsMath.Autoload.findCustomStrings = [
  *         '[math],'[/math]',          // start and end in-line math   *         '[math],'[/math]',          // start and end in-line math
Line 95  jsMath.Add(jsMath.Autoload,{ Line 93  jsMath.Add(jsMath.Autoload,{
       
   Script: {    Script: {
   
     iframe: null,  // the hidden iframe      request: null,  // XMLHttpRequest object (if we can get it)
       iframe: null,   // the hidden iframe (if not)
   
     /*      /*
      *  Load an external JavaScript file asynchronously       *  Get XMLHttpRequest object, if possible, and look up the URL root
        *  (MSIE can't use xmlReuest to load local files, so avoid that)
        */
       Init: function () {
         if (!(document.URL && document.URL.match(/^file:\/\/.*\\/))) {
           if (window.XMLHttpRequest) {try {this.request = new XMLHttpRequest} catch (err) {}}
           if (!this.request && window.ActiveXObject) {
             var xml = ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0",
                        "MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
             for (var i = 0; i < xml.length && !this.request; i++) {
               try {this.request = new ActiveXObject(xml[i])} catch (err) {}
             }
           }
         }
         this.Root();
       },
   
       /*
        *  Load an external JavaScript file
      */       */
     Load: function (url) {      Load: function (url) {
         if (this.request) {
           setTimeout(function () {jsMath.Autoload.Script.xmlLoad(url)},1);
         } else {
           this.startLoad(url);
         }
       },
   
       /*
        *  Load an external JavaScript file via XMLHttpRequest
        */
       xmlLoad: function (url) {
         try {
           this.request.open("GET",jsMath.Autoload.root+url,false);
           this.request.send(null);
         } catch (err) {
           throw "autoload: can't load the file '"+url+"'\n"
               + "Message: "+err.message;
         }
         if (this.request.status && this.request.status >= 400) {
           throw "autoload: can't load the file '"+url+"'\n"
               + "Error status: "+this.request.status;
         }
         window.eval(this.request.responseText);
         this.endLoad();
       },
   
       /*
        *  Load an external JavaScript file via jsMath-autoload.html
        */
       startLoad: function (url) {
       this.iframe = document.createElement('iframe');        this.iframe = document.createElement('iframe');
       this.iframe.style.visibility = 'hidden';        this.iframe.style.visibility = 'hidden';
       this.iframe.style.position = 'absolute';        this.iframe.style.position = 'absolute';
Line 144  jsMath.Add(jsMath.Autoload,{ Line 191  jsMath.Add(jsMath.Autoload,{
         if (data.length == 1) {jsMath[name](data[0])}          if (data.length == 1) {jsMath[name](data[0])}
           else {jsMath[name](data[0],data[1],data[2],data[3])}            else {jsMath[name](data[0],data[1],data[2],data[3])}
       }        }
        this.queue = [];
     },      },
       
     AfterLoad: function () {jsMath.Autoload.Script.RunStack()},      AfterLoad: function () {jsMath.Autoload.Script.RunStack()},
Line 157  jsMath.Add(jsMath.Autoload,{ Line 205  jsMath.Add(jsMath.Autoload,{
       if (script) {        if (script) {
         for (var i = 0; i < script.length; i++) {          for (var i = 0; i < script.length; i++) {
           var src = script[i].src;            var src = script[i].src;
           if (src && src.match('(^|/)plugins/autoload.js$')) {            if (src && src.match('(^|/|\\\\)plugins/autoload.js$')) {
             jsMath.Autoload.root = src.replace(/plugins\/autoload.js$/,'');              jsMath.Autoload.root = src.replace(/plugins\/autoload.js$/,'');
             break;              break;
           }            }
Line 176  jsMath.Add(jsMath.Autoload,{ Line 224  jsMath.Add(jsMath.Autoload,{
    */     */
   Check: function () {    Check: function () {
     if (this.checked) return; this.checked = 1;      if (this.checked) return; this.checked = 1;
     if (this.findTeXstrings || this.findLaTeXstrings ||      if ((this.findTeXstrings || this.findLaTeXstrings ||
         this.findCustomStrings || this.findCustomSettings) {           this.findCustomStrings || this.findCustomSettings) &&
            (!jsMath.tex2math || !jsMath.tex2math.loaded)) {
       this.Script.tex2math = 1;        this.Script.tex2math = 1;
       this.Script.Load('plugins/tex2math.js');        this.Script.Load('plugins/tex2math.js');
     } else {      } else {
Line 185  jsMath.Add(jsMath.Autoload,{ Line 234  jsMath.Add(jsMath.Autoload,{
       this.Check2();        this.Check2();
     }      }
   },    },
     ReCheck: function () {
       if (jsMath.loaded) return;
       this.InitStubs();
       this.checked = 0;
       this.Script.queue = [];
       this.Check();
     },
   
   /*    /*
    *  Once tex2math is loaded, use it to check for math that     *  Once tex2math is loaded, use it to check for math that
    *  needs to be tagged for jsMath, and load jsMath if it is needed     *  needs to be tagged for jsMath, and load jsMath if it is needed
    */     */
   Check2: function () {    Check2: function () {
     this.Script.tex2math = 0;      this.Script.tex2math = 0; this.needsJsMath = 0;
     this.needsJsMath = 0; if (this.checkElement == null) {this.checkElement = null}      if (this.checkElement == null) {this.checkElement = null}
     if (this.findMathElements) {  
       this.needsJsMath = this.areMathElements(this.checkElement);      if (this.findTeXstrings)     {jsMath.tex2math.ConvertTeX(this.checkElement)}
     }      if (this.findLaTeXstrings)   {jsMath.tex2math.ConvertLaTeX(this.checkElement)}
     jsMath.tex2math.callback = this.tex2mathCallback;      if (this.findCustomSettings) {jsMath.tex2math.Convert(this.checkElement,this.findCustomSettings)}
     if (this.findTeXstrings && !this.needsJsMath) {      if (this.findCustomStrings)  {
       jsMath.tex2math.ConvertTeX(this.checkElement);  
     }  
     if (this.findLaTeXstrings && !this.needsJsMath) {  
       jsMath.tex2math.ConvertLaTeX(this.checkElement);  
     }  
     if (this.findCustomSettings && !this.needsJsMath) {  
       jsMath.tex2math.Convert(this.checkElement,this.findCustomSettings);  
     }  
     if (this.findCustomStrings && !this.needsJsMath) {  
       var s = this.findCustomStrings;        var s = this.findCustomStrings;
       jsMath.tex2math.CustomSearch(s[0],s[1],s[2],s[3]);        jsMath.tex2math.CustomSearch(s[0],s[1],s[2],s[3]);
       jsMath.tex2math.ConvertCustom(this.checkElement);        jsMath.tex2math.ConvertCustom(this.checkElement);
     }      }
     jsMath.tex2math.callback = null;  
   
       this.needsJsMath = this.areMathElements(this.checkElement);
     if (this.needsJsMath) {      if (this.needsJsMath) {
       this.LoadJsMath();        this.LoadJsMath();
     } else {      } else {
       jsMath.Autoload.Script = null;  
       jsMath.Process = function () {};        jsMath.Process = function () {};
       jsMath.ProcessBeforeShowing = function () {};        jsMath.ProcessBeforeShowing = function () {};
       jsMath.Synchronize = function () {};  
       jsMath.ConvertTeX = function () {};        jsMath.ConvertTeX = function () {};
       jsMath.ConvertTeX2 = function () {};        jsMath.ConvertTeX2 = function () {};
       jsMath.ConvertLaTeX = function () {};        jsMath.ConvertLaTeX = function () {};
       jsMath.ConvertCustom = function () {};        jsMath.ConvertCustom = function () {};
       jsMath.CustomSearch = function () {};        jsMath.CustomSearch = function () {};
       jsMath.Macro = function () {};        jsMath.Macro = function () {};
       jsMath.Autoload.Run = function () {};        jsMath.Synchronize = function (code,data) {
           if (typeof(code) == 'string') {eval(code)} else {code(data)}
         };
         jsMath.Autoload.Script.RunStack(); // perform pending commands
         jsMath.Autoload.setMessage();
     }      }
   },    },
   
Line 240  jsMath.Add(jsMath.Autoload,{ Line 289  jsMath.Add(jsMath.Autoload,{
   },    },
   
   /*    /*
    *  jsMath.Autoload.Run() can be called to perform the      *  jsMath.Autoload.Run() is now longer needed
    *  tex2math calls given by the Autoload parameters.  
    */     */
   Run: function (data) {this.Script.Push('Autorun',[data])},    Run: function (data) {},
   
   Autorun: function () {  
     if (this.findTeXstrings) {jsMath.ConvertTeX(this.checkElement)}  
     if (this.findLaTeXstrings) {jsMath.ConvertLaTeX(this.checkElement)}  
     if (this.findCustomSettings) {  
       jsMath.Synchronize(function () {  
         jsMath.tex2math.Convert(jsMath.Autoload.checkElement,  
                                 jsMath.Autoload.findCustomSettings);  
       });  
     }  
     if (this.findCustomStrings) {  
       var s = this.findCustomStrings;  
       jsMath.CustomSearch(s[0],s[1],s[2],s[3]);  
       jsMath.ConvertCustom(this.checkElement);  
     }  
   },  
   
   /*    /*
    *  Look to see if there are SPAN or DIV elements of class "math".     *  Look to see if there are SPAN or DIV elements of class "math".
Line 283  jsMath.Add(jsMath.Autoload,{ Line 315  jsMath.Add(jsMath.Autoload,{
    *  and then do any pending commands.     *  and then do any pending commands.
    */     */
   LoadJsMath: function () {    LoadJsMath: function () {
       if (this.loading) return;
       if (jsMath.loaded) {this.afterLoad(); return}
     if (this.root) {      if (this.root) {
         this.loading = 1;
       this.setMessage('Loading jsMath...');        this.setMessage('Loading jsMath...');
       this.Script.AfterLoad = this.afterLoad;        this.Script.AfterLoad = this.afterLoad;
       this.Script.Load('jsMath.js');        this.Script.Load('jsMath.js');
Line 292  jsMath.Add(jsMath.Autoload,{ Line 327  jsMath.Add(jsMath.Autoload,{
     }      }
   },    },
   afterLoad: function () {    afterLoad: function () {
       jsMath.Autoload.loading = 0;
     if (jsMath.tex2math.window) {jsMath.tex2math.window.jsMath = jsMath}      if (jsMath.tex2math.window) {jsMath.tex2math.window.jsMath = jsMath}
     //      //
     //  Handle MSIE bug where jsMath.window both is and is not the actual window      //  Handle MSIE bug where jsMath.window both is and is not the actual window
Line 300  jsMath.Add(jsMath.Autoload,{ Line 336  jsMath.Add(jsMath.Autoload,{
     var fonts = jsMath.Autoload.loadFonts;      var fonts = jsMath.Autoload.loadFonts;
     if (fonts) {      if (fonts) {
       if (typeof(fonts) != 'object') {fonts = [fonts]}        if (typeof(fonts) != 'object') {fonts = [fonts]}
       for (var i in fonts) {jsMath.Font.Load(fonts[i])}        for (var i = 0; i < fonts.length; i++) {jsMath.Font.Load(fonts[i])}
     }      }
     var files = jsMath.Autoload.loadFiles;      var files = jsMath.Autoload.loadFiles;
     if (files) {      if (files) {
       if (typeof(files) != 'object') {files = [files]}        if (typeof(files) != 'object') {files = [files]}
       for (var i in files) {jsMath.Setup.Script(files[i])}        for (var i = 0; i < files.length; i++) {jsMath.Setup.Script(files[i])}
     }      }
     jsMath.Synchronize(function () {jsMath.Autoload.Script.RunStack()});      jsMath.Synchronize(function () {jsMath.Autoload.Script.RunStack()});
     jsMath.Autoload.setMessage();      jsMath.Autoload.setMessage();
Line 320  jsMath.Add(jsMath.Autoload,{ Line 356  jsMath.Add(jsMath.Autoload,{
       if (!document.body.hasChildNodes) {document.body.appendChild(this.div)}        if (!document.body.hasChildNodes) {document.body.appendChild(this.div)}
         else {document.body.insertBefore(this.div,document.body.firstChild)}          else {document.body.insertBefore(this.div,document.body.firstChild)}
       var style = {        var style = {
         position:'absolute', bottom:'1px', left:'2px',          position:'fixed', bottom:'1px', left:'2px',
         backgroundColor:'#E6E6E6', border:'solid 1px #959595',          backgroundColor:'#E6E6E6', border:'solid 1px #959595',
         margin:'0px', padding:'1px 8px', zIndex:102,          margin:'0px', padding:'1px 8px', zIndex:102,
         color:'black', fontSize:'75%', width:'auto'          color:'black', fontSize:'75%', width:'auto'
       };        };
       for (var id in style) {this.div.style[id] = style[id]}        for (var id in style) {this.div.style[id] = style[id]}
       this.div.appendChild(jsMath.document.createTextNode(message));        this.div.appendChild(jsMath.document.createTextNode(message));
     } else {      } else if (this.div) {
       this.div.firstChild.nodeValue = "";        this.div.firstChild.nodeValue = "";
       this.div.style.visibility = 'hidden';        this.div.style.visibility = 'hidden';
     }      }
   }    },
     
 });  
   
 /*    /*
  *  Queue these so we can do them after jsMath has been loaded     *  Queue these so we can do them after jsMath has been loaded
  */     */
 jsMath.Add(jsMath,{    stubs: {
   Process: function (data) {jsMath.Autoload.Script.Push('Process',[data])},      Process: function (data) {jsMath.Autoload.Script.Push('Process',[data])},
   ProcessBeforeShowing: function (data) {jsMath.Autoload.Script.Push('ProcessBeforeShowing',[data])},      ProcessBeforeShowing: function (data) {jsMath.Autoload.Script.Push('ProcessBeforeShowing',[data])},
   ConvertTeX: function (data) {jsMath.Autoload.Script.Push('ConvertTeX',[data])},      ConvertTeX: function (data) {jsMath.Autoload.Script.Push('ConvertTeX',[data])},
   ConvertTeX2: function (data) {jsMath.Autoload.Script.Push('ConvertTeX2',[data])},      ConvertTeX2: function (data) {jsMath.Autoload.Script.Push('ConvertTeX2',[data])},
   ConvertLaTeX: function (data) {jsMath.Autoload.Script.Push('ConvertLaTeX',[data])},      ConvertLaTeX: function (data) {jsMath.Autoload.Script.Push('ConvertLaTeX',[data])},
   ConvertCustom: function (data) {jsMath.Autoload.Script.Push('ConvertCustom',[data])},      ConvertCustom: function (data) {jsMath.Autoload.Script.Push('ConvertCustom',[data])},
   CustomSearch: function (d1,d2,d3,d4) {jsMath.Autoload.Script.Push('CustomSearch',[d1,d2,d3,d4])},      CustomSearch: function (d1,d2,d3,d4) {jsMath.Autoload.Script.Push('CustomSearch',[d1,d2,d3,d4])},
   Synchronize: function (data) {jsMath.Autoload.Script.Push('Synchronize',[data])},      Synchronize: function (data) {jsMath.Autoload.Script.Push('Synchronize',[data])},
   Macro: function (cs,def,params) {jsMath.Autoload.Script.Push('Macro',[cs,def,params])},      Macro: function (cs,def,params) {jsMath.Autoload.Script.Push('Macro',[cs,def,params])}
   Autorun: function () {jsMath.Autoload.Autorun()}    },
   
     InitStubs: function () {jsMath.Add(jsMath,jsMath.Autoload.stubs)}
     
 });  });
   
 /*  /*
  *  Initialize   *  Initialize
  */   */
   
 if (jsMath.Autoload.findMathElements == null) {jsMath.Autoload.findMathElements = 1}  
 if (jsMath.Autoload.findTeXstrings == null)   {jsMath.Autoload.findTeXstrings = 0}  if (jsMath.Autoload.findTeXstrings == null)   {jsMath.Autoload.findTeXstrings = 0}
 if (jsMath.Autoload.findLaTeXstrings == null) {jsMath.Autoload.findLaTeXstrings = 0}  if (jsMath.Autoload.findLaTeXstrings == null) {jsMath.Autoload.findLaTeXstrings = 0}
   
 jsMath.Autoload.Script.Root();  jsMath.Autoload.Script.Init();
   jsMath.Autoload.InitStubs();
 if (document.body) {jsMath.Autoload.Check()}  if (document.body) {jsMath.Autoload.Check()}

Removed from v.1.3  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>