Merge branch 'pryor'
[lambda.git] / jsMath / plugins / CHMmode.js
1 /*
2  *  CHMmode.js
3  *  
4  *  Part of the jsMath package for mathematics on the web.
5  *
6  *  This file makes jsMath work with MicroSoft's HTML Help system
7  *  from within .chm files (compiled help archives).
8  *  
9  *  This file should be loaded BEFORE jsMath.js.
10  *
11  *  ---------------------------------------------------------------------
12  *
13  *  Copyright 2006-2007 by Davide P. Cervone
14  * 
15  *  Licensed under the Apache License, Version 2.0 (the "License");
16  *  you may not use this file except in compliance with the License.
17  *  You may obtain a copy of the License at
18  * 
19  *      http://www.apache.org/licenses/LICENSE-2.0
20  * 
21  *  Unless required by applicable law or agreed to in writing, software
22  *  distributed under the License is distributed on an "AS IS" BASIS,
23  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  *  See the License for the specific language governing permissions and
25  *  limitations under the License.
26  */
27
28 if (!window.jsMath) {window.jsMath = {}}
29 if (!jsMath.Controls) {jsMath.Controls = {}}
30 if (!jsMath.Controls.cookie) {jsMath.Controls.cookie = {}}
31
32 jsMath.isCHMmode = 1;
33
34 jsMath.noChangeGlobal = 1;
35 jsMath.noShowGlobal = 1;
36 jsMath.noImgFonts = 1;
37 jsMath.Controls.cookie.global = 'always';
38 jsMath.Controls.cookie.hiddenGlobal = 1;
39
40 if (window.location.protocol == "mk:") {
41
42   /*
43    *  Work around bug in hh.exe that causes it to run at 100% CPU
44    *  and not exit if the page is reloaded after an IFRAME is used
45    *  to load the controls file, so fake it using XMLHttpRequest.
46    *  Load the data into a DIV instead of an IFRAME, and make sure
47    *  that the styles are correct for it.  Change the GetPanel()
48    *  call to hide the other panel and open the correct one.
49    */
50
51   jsMath.Controls.Init = function () {
52     this.controlPanels = jsMath.Setup.DIV("controlPanels");
53     if (!jsMath.Browser.msieButtonBug) {this.Button()}
54     else {setTimeout("jsMath.Controls.Button()",500)}
55   }
56   
57   jsMath.Controls.Panel = function () {
58     jsMath.Translate.Cancel();
59     jsMath.Setup.AddStyleSheet({
60       '#jsMath_options': jsMath.styles['#jsMath_panel'],
61       '#jsMath_options .disabled': jsMath.styles['#jsMath_panel .disabled'],
62       '#jsMath_options .infoLink': jsMath.styles['#jsMath_panel .infoLink']
63     });
64     if (this.loaded) {this.panel = jsMath.Element("panel"); this.Main(); return}
65     var html = jsMath.Script.xmlRequest(jsMath.root+"jsMath-controls.html");
66     var body = (html.match(/<body>([\s\S]*)<\/body>/))[1];
67     this.controlPanels.innerHTML = body;
68     var script = (body.match(/<script>([\s\S]*?)<\/script>/))[1];
69     jsMath.window.eval(script);
70     jsMath.Controls.GetPanel = function (name) {
71       if (this.panel) {this.panel.style.display = "none"}
72       this.panel = jsMath.Element(name);
73     }
74     jsMath.Controls.oldClose = jsMath.Controls.Close;
75     jsMath.Controls.Close = function () {this.oldClose(); this.panel = null}
76     jsMath.Element("options").style.display = "none";
77     jsMath.Controls.Main();
78     if (!jsMath.Browser.IE7 || jsMath.Browser.quirks) {
79       jsMath.window.attachEvent("onscroll",jsMath.Controls.MoveButton);
80       if (jsMath.Browser.IE7) jsMath.window.attachEvent("onresize",jsMath.Controls.MoveButton);
81     }
82   }
83   
84 }
85